Skip deleting options if columnar.options is already dropped (#5458)

Drop extension might 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 added the test to after_pg_upgrade_schedule.

(cherry picked from commit 25024b776e)

 Conflicts:
	src/test/regress/after_pg_upgrade_schedule
	src/test/regress/expected/upgrade_columnar_after.out
	src/test/regress/sql/upgrade_columnar_after.sql
pull/5978/head
Onur Tirtir 2021-11-12 12:30:09 +03:00
parent d13b989cff
commit 6b87b3ea27
4 changed files with 37 additions and 3 deletions

View File

@ -311,8 +311,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 };

View File

@ -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
test: upgrade_basic_after upgrade_type_after upgrade_ref2ref_after upgrade_distributed_function_after upgrade_rebalance_strategy_after upgrade_list_citus_objects
# This attempts dropping citus extension (and rollbacks), so please do
# not run in parallel with any other tests.
test: upgrade_columnar_after

View File

@ -141,3 +141,15 @@ SELECT count(*), sum(a), sum(b) FROM test_options_2;
20000 | 100010000 | 65015
(1 row)
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;

View File

@ -39,3 +39,16 @@ SELECT * FROM columnar.options WHERE regclass = 'test_options_2'::regclass;
VACUUM VERBOSE test_options_2;
SELECT count(*), sum(a), sum(b) FROM test_options_2;
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;