-- -- MULTI_TABLE_DDL -- -- Tests around changing the schema and dropping of a distributed table ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 870000; ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 870000; CREATE TABLE testtableddl(somecol int, distributecol text NOT NULL); SELECT master_create_distributed_table('testtableddl', 'distributecol', 'append'); master_create_distributed_table --------------------------------- (1 row) -- verify that the citus extension can't be dropped while distributed tables exist DROP EXTENSION citus; ERROR: cannot drop extension citus because other objects depend on it DETAIL: table testtableddl depends on extension citus HINT: Use DROP ... CASCADE to drop the dependent objects too. -- verify that the distribution column can't have its type changed ALTER TABLE testtableddl ALTER COLUMN distributecol TYPE text; ERROR: cannot execute ALTER TABLE command involving partition column -- verify that the distribution column can't be dropped ALTER TABLE testtableddl DROP COLUMN distributecol; ERROR: cannot execute ALTER TABLE command involving partition column -- verify that the table cannot be dropped in a transaction block \set VERBOSITY terse BEGIN; DROP TABLE testtableddl; ERROR: DROP distributed table cannot run inside a transaction block ROLLBACK; \set VERBOSITY default -- verify that the table can be dropped DROP TABLE testtableddl; -- verify that the table can dropped even if shards exist CREATE TABLE testtableddl(somecol int, distributecol text NOT NULL); SELECT master_create_distributed_table('testtableddl', 'distributecol', 'append'); master_create_distributed_table --------------------------------- (1 row) SELECT 1 FROM master_create_empty_shard('testtableddl'); ?column? ---------- 1 (1 row) DROP TABLE testtableddl; -- ensure no metadata of distributed tables are remaining SELECT * FROM pg_dist_partition; logicalrelid | partmethod | partkey | colocationid | repmodel --------------+------------+---------+--------------+---------- (0 rows) SELECT * FROM pg_dist_shard; logicalrelid | shardid | shardstorage | shardalias | shardminvalue | shardmaxvalue --------------+---------+--------------+------------+---------------+--------------- (0 rows) SELECT * FROM pg_dist_shard_placement; shardid | shardstate | shardlength | nodename | nodeport ---------+------------+-------------+----------+---------- (0 rows) -- check that the extension now can be dropped (and recreated) DROP EXTENSION citus; CREATE EXTENSION citus; -- create a table with a SERIAL column CREATE TABLE testserialtable(id serial, group_id integer); SELECT master_create_distributed_table('testserialtable', 'group_id', 'hash'); master_create_distributed_table --------------------------------- (1 row) SELECT master_create_worker_shards('testserialtable', 2, 1); master_create_worker_shards ----------------------------- (1 row) -- should not be able to add additional serial columns ALTER TABLE testserialtable ADD COLUMN other_id serial; ERROR: cannot execute ADD COLUMN commands involving serial pseudotypes -- and we shouldn't be able to change a distributed sequence's owner ALTER SEQUENCE testserialtable_id_seq OWNED BY NONE; ERROR: cannot alter OWNED BY option of a sequence already owned by a distributed table -- or create a sequence with a distributed owner CREATE SEQUENCE standalone_sequence OWNED BY testserialtable.group_id; ERROR: cannot create sequences that specify a distributed table in their OWNED BY option HINT: Use a sequence in a distributed table by specifying a serial column type before creating any shards. -- or even change a manual sequence to be owned by a distributed table CREATE SEQUENCE standalone_sequence; ALTER SEQUENCE standalone_sequence OWNED BY testserialtable.group_id; ERROR: cannot associate an existing sequence with a distributed table HINT: Use a sequence in a distributed table by specifying a serial column type before creating any shards. -- an edge case, but it's OK to change an owner to the same distributed table ALTER SEQUENCE testserialtable_id_seq OWNED BY testserialtable.id; -- verify sequence was created on worker \c - - - :worker_1_port \ds List of relations Schema | Name | Type | Owner --------+------------------------+----------+---------- public | testserialtable_id_seq | sequence | postgres (1 row) -- drop distributed table \c - - - :master_port DROP TABLE testserialtable; -- verify owned sequence is dropped \c - - - :worker_1_port \ds List of relations Schema | Name | Type | Owner --------+------+------+------- (0 rows)