diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index 637e14cbb..a59345b90 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -186,6 +186,9 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString, if (strstr(sql, "SET TABLESPACE") != NULL) { + /*Set tablespace does not work inside a transaction.Therefore, we close the transaction before set tablespace + * and open it again after set tablespace. + */ commands = list_make5(DISABLE_DDL_PROPAGATION, COMMIT_TRANSACTION, sql, diff --git a/src/test/regress/expected/alter_database_propagation.out b/src/test/regress/expected/alter_database_propagation.out index e22957e0a..94eca2190 100644 --- a/src/test/regress/expected/alter_database_propagation.out +++ b/src/test/regress/expected/alter_database_propagation.out @@ -156,17 +156,34 @@ NOTICE: issuing ALTER DATABASE regression2 WITH IS_TEMPLATE false; DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing ALTER DATABASE regression2 WITH IS_TEMPLATE false; DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -alter database regression2 set TABLESPACE pg_default; -NOTICE: Citus partially supports ALTER DATABASE SET TABLESPACE for distributed databases -DETAIL: Citus does not propagate ALTER DATABASE SET TABLESPACE command to workers -HINT: You can manually alter a tablespace for a database and its extensions on workers. +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts3' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; \c - - - :worker_1_port -alter database regression2 set TABLESPACE pg_default; +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts4' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; \c - - - :worker_2_port -alter database regression2 set TABLESPACE pg_default; +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts5' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; \c - - - :master_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = '%ALTER DATABASE%'; +alter database regression2 set TABLESPACE alter_db_tablespace; +NOTICE: issuing ALTER DATABASE regression2 SET TABLESPACE alter_db_tablespace; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE regression2 SET TABLESPACE alter_db_tablespace; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx set citus.enable_create_database_propagation=on; alter database regression2 rename to regression3; +NOTICE: issuing ALTER DATABASE regression2 RENAME TO regression3 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE regression2 RENAME TO regression3 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx drop database regression3; set citus.log_remote_commands = false; set citus.enable_create_database_propagation=off; +drop tablespace alter_db_tablespace; +\c - - - :worker_1_port +drop tablespace alter_db_tablespace; +\c - - - :worker_2_port +drop tablespace alter_db_tablespace; +\c - - - :master_port