@@ -231,6 +231,15 @@ BgwMainLoop() {
231
231
elog (LOG, " pg_duckdb background worker for database '%s' (%u) has now terminated." , db_name, MyDatabaseId);
232
232
}
233
233
234
+ void recordDependencyOnMDServer (ObjectAddress *object_address) {
235
+ ObjectAddress server_address = {
236
+ .classId = ForeignServerRelationId,
237
+ .objectId = GetMotherduckForeignServerOid (),
238
+ .objectSubId = 0 ,
239
+ };
240
+ recordDependencyOn (object_address, &server_address, DEPENDENCY_NORMAL);
241
+ }
242
+
234
243
} // namespace pgduckdb
235
244
236
245
extern " C" {
@@ -774,6 +783,25 @@ CreateTable(const char *postgres_schema_name, const char *table_name, const char
774
783
return false ;
775
784
}
776
785
786
+ // Record the dependency on the MotherDuck server
787
+ {
788
+ HeapTuple new_table_tuple = SearchSysCache2 (RELNAMENSP, CStringGetDatum (table_name), ObjectIdGetDatum (schema_oid));
789
+ if (HeapTupleIsValid (new_table_tuple)) {
790
+ Form_pg_class postgres_relation = (Form_pg_class)GETSTRUCT (new_table_tuple);
791
+ auto oid = postgres_relation->oid ;
792
+ ReleaseSysCache (new_table_tuple);
793
+ ObjectAddress object_address = {
794
+ .classId = RelationRelationId,
795
+ .objectId = oid,
796
+ .objectSubId = 0 ,
797
+ };
798
+ recordDependencyOnMDServer (&object_address);
799
+ } else {
800
+ // Something went really wrong (since `create_table_succeeded`)
801
+ elog (WARNING, " Failed to find table '%s.%s' so won't record dependency to 'motherduck' SERVER" , table_name, postgres_schema_name);
802
+ }
803
+ }
804
+
777
805
if (did_delete_table) {
778
806
/*
779
807
* Commit the subtransaction that contains both the drop and the create that
@@ -933,12 +961,7 @@ CreateSchemaIfNotExists(const char *postgres_schema_name, bool is_default_db) {
933
961
.objectId = schema_oid,
934
962
.objectSubId = 0 ,
935
963
};
936
- ObjectAddress server_address = {
937
- .classId = ForeignServerRelationId,
938
- .objectId = GetMotherduckForeignServerOid (), // pgduckdb::ExtensionOid(),
939
- .objectSubId = 0 ,
940
- };
941
- recordDependencyOn (&schema_address, &server_address, DEPENDENCY_NORMAL);
964
+ recordDependencyOnMDServer (&schema_address);
942
965
}
943
966
944
967
/* Success, so we commit the subtransaction */
0 commit comments