diff --git a/src/backend/columnar/columnar_metadata.c b/src/backend/columnar/columnar_metadata.c index 60c6af762..5991c5434 100644 --- a/src/backend/columnar/columnar_metadata.c +++ b/src/backend/columnar/columnar_metadata.c @@ -335,8 +335,13 @@ DeleteColumnarTableOptions(Oid regclass, bool missingOk) */ Assert(!IsBinaryUpgrade); - Relation columnarOptions = relation_open(ColumnarOptionsRelationId(), - RowExclusiveLock); + Relation columnarOptions = try_relation_open(ColumnarOptionsRelationId(), + RowExclusiveLock); + if (columnarOptions == NULL) + { + /* extension has been dropped */ + return false; + } /* find existing item to remove */ ScanKeyData scanKey[1] = { 0 }; diff --git a/src/test/regress/after_pg_upgrade_schedule b/src/test/regress/after_pg_upgrade_schedule index 524ff6e72..c8a1b6b40 100644 --- a/src/test/regress/after_pg_upgrade_schedule +++ b/src/test/regress/after_pg_upgrade_schedule @@ -1 +1,5 @@ -test: upgrade_basic_after upgrade_columnar_after upgrade_type_after upgrade_ref2ref_after upgrade_distributed_function_after upgrade_rebalance_strategy_after upgrade_list_citus_objects upgrade_autoconverted_after +test: upgrade_basic_after upgrade_type_after upgrade_ref2ref_after upgrade_distributed_function_after upgrade_rebalance_strategy_after upgrade_list_citus_objects upgrade_autoconverted_after + +# This attempts dropping citus extension (and rollbacks), so please do +# not run in parallel with any other tests. +test: upgrade_columnar_after diff --git a/src/test/regress/expected/upgrade_columnar_after.out b/src/test/regress/expected/upgrade_columnar_after.out index 3032d3128..58ea3fd3d 100644 --- a/src/test/regress/expected/upgrade_columnar_after.out +++ b/src/test/regress/expected/upgrade_columnar_after.out @@ -247,3 +247,15 @@ BEGIN; -- since we run "after schedule" twice, rollback the transaction -- to avoid getting "table already exists" errors ROLLBACK; +BEGIN; + -- Show that we can still drop the extension after upgrading + SET client_min_messages TO WARNING; + -- Drop extension migth cascade to columnar.options before dropping a + -- columnar table. In that case, we were getting below error when opening + -- columnar.options to delete records for the columnar table that we are + -- about to drop.: "ERROR: could not open relation with OID 0". + -- + -- I somehow reproduced this bug easily when upgrading pg, that is why + -- adding the test to this file. + DROP EXTENSION citus CASCADE; +ROLLBACK; diff --git a/src/test/regress/sql/upgrade_columnar_after.sql b/src/test/regress/sql/upgrade_columnar_after.sql index 49c90eaf4..0faa88d24 100644 --- a/src/test/regress/sql/upgrade_columnar_after.sql +++ b/src/test/regress/sql/upgrade_columnar_after.sql @@ -117,3 +117,17 @@ BEGIN; -- since we run "after schedule" twice, rollback the transaction -- to avoid getting "table already exists" errors ROLLBACK; + +BEGIN; + -- Show that we can still drop the extension after upgrading + SET client_min_messages TO WARNING; + + -- Drop extension migth cascade to columnar.options before dropping a + -- columnar table. In that case, we were getting below error when opening + -- columnar.options to delete records for the columnar table that we are + -- about to drop.: "ERROR: could not open relation with OID 0". + -- + -- I somehow reproduced this bug easily when upgrading pg, that is why + -- adding the test to this file. + DROP EXTENSION citus CASCADE; +ROLLBACK;