@@ -714,6 +714,42 @@ bdr_commandfilter_dbname(const char *dbname)
714714 }
715715}
716716
717+ static void
718+ prevent_drop_extension_bdr (DropStmt * stmt )
719+ {
720+ ListCell * cell ;
721+
722+ /* Only interested in DROP EXTENSION */
723+ if (stmt -> removeType != OBJECT_EXTENSION )
724+ return ;
725+
726+ /* Check to see if the BDR extension is being dropped */
727+ foreach (cell , stmt -> objects )
728+ {
729+ ObjectAddress address ;
730+ List * objname = lfirst (cell );
731+ Relation relation = NULL ;
732+
733+ /* Get an ObjectAddress for the object. */
734+ address = get_object_address (stmt -> removeType ,
735+ objname , NULL ,
736+ & relation ,
737+ AccessExclusiveLock ,
738+ stmt -> missing_ok );
739+
740+ if (!OidIsValid (address .objectId ))
741+ continue ;
742+
743+ /* for an extension the object name is unqualified */
744+ Assert (list_length (objname ) == 1 );
745+
746+ if (strcmp (strVal (linitial (objname )), "bdr" ) == 0 )
747+ ereport (ERROR ,
748+ (errmsg ("Dropping the BDR extension is prohibited while BDR is active" ),
749+ errhint ("Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)" )));
750+ }
751+ }
752+
717753static void
718754bdr_commandfilter (Node * parsetree ,
719755 const char * queryString ,
@@ -858,6 +894,8 @@ bdr_commandfilter(Node *parsetree,
858894 {
859895 DropStmt * stmt = (DropStmt * ) parsetree ;
860896
897+ prevent_drop_extension_bdr (stmt );
898+
861899 if (EventTriggerSupportsObjectType (stmt -> removeType ))
862900 break ;
863901 else
0 commit comments