diff --git a/src/backend/distributed/commands/non_main_db_distribute_object_ops.c b/src/backend/distributed/commands/non_main_db_distribute_object_ops.c index 2254d0d68..54e58aa71 100644 --- a/src/backend/distributed/commands/non_main_db_distribute_object_ops.c +++ b/src/backend/distributed/commands/non_main_db_distribute_object_ops.c @@ -367,9 +367,21 @@ GetNonMainDbDistributeObjectOps(Node *parsetree) case T_AlterDatabaseSetStmt: { - return &Any_AlterDatabaseSet; + AlterDatabaseSetStmt *stmt = castNode(AlterDatabaseSetStmt, parsetree); + /* + * We don't try to send the query to the main database if the ALTER + * DATABASE command is for the main database itself, this is a very + * rare case but it's exercised by our test suite. + */ + if (strcmp(stmt->dbname, MainDb) != 0) + { + return &Any_AlterDatabaseSet; + } + + return NULL; } + #if PG_VERSION_NUM >= PG_VERSION_15 case T_AlterDatabaseRefreshCollStmt: { diff --git a/src/test/regress/expected/alter_database_from_nonmain_db.out b/src/test/regress/expected/alter_database_from_nonmain_db.out index 763db4396..2743fffca 100644 --- a/src/test/regress/expected/alter_database_from_nonmain_db.out +++ b/src/test/regress/expected/alter_database_from_nonmain_db.out @@ -5,23 +5,43 @@ create database altered_database; reset citus.enable_create_database_propagation; \c regression; set citus.enable_create_database_propagation=on; +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts3' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; +\c - - - :worker_1_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts4' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; +\c - - - :worker_2_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts5' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; \c test_alter_db_from_nonmain_db set citus.log_remote_commands = true; set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database altered_database set tablespace alter_db_tablespace; +NOTICE: issuing ALTER DATABASE altered_database SET TABLESPACE alter_db_tablespace +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database rename to altered_database_renamed; alter database altered_database_renamed rename to altered_database; alter database altered_database with ALLOW_CONNECTIONS false CONNECTION LIMIT 1 IS_TEMPLATE true; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database WITH ALLOW_CONNECTIONS false CONNECTION LIMIT 1 IS_TEMPLATE true;', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database WITH ALLOW_CONNECTIONS false CONNECTION LIMIT 1 IS_TEMPLATE true; DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database with ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database WITH ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false;', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database WITH ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false; DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx \c regression create role test_owner_non_main_db; \c test_alter_db_from_nonmain_db @@ -31,81 +51,162 @@ set citus.enable_create_database_propagation=on; alter database altered_database owner to test_owner_non_main_db; alter database altered_database owner to CURRENT_USER; alter database altered_database set default_transaction_read_only = true; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_read_only = ''true''', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_read_only = 'true' DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx set default_transaction_read_only = false; alter database altered_database set default_transaction_read_only from current; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_read_only FROM CURRENT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_read_only FROM CURRENT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set default_transaction_read_only to DEFAULT; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_read_only TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_read_only TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET default_transaction_read_only; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET default_transaction_read_only', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET default_transaction_read_only DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database SET TIME ZONE '-7'; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET timezone = ''-7''', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET timezone = '-7' DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set TIME ZONE LOCAL; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET timezone TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET timezone TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set TIME ZONE DEFAULT; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET timezone TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET timezone TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET TIME ZONE; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET timezone', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET timezone DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database SET TIME ZONE INTERVAL '-08:00' HOUR TO MINUTE; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET TIME ZONE INTERVAL ''@ 8 hours ago''', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET TIME ZONE INTERVAL '@ 8 hours ago' DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET TIME ZONE; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET timezone', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET timezone DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set default_transaction_isolation = 'serializable'; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_isolation = ''serializable''', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_isolation = 'serializable' DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx set default_transaction_isolation = 'read committed'; alter database altered_database set default_transaction_isolation from current; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_isolation FROM CURRENT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_isolation FROM CURRENT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set default_transaction_isolation to DEFAULT; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET default_transaction_isolation TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET default_transaction_isolation TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET default_transaction_isolation; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET default_transaction_isolation', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET default_transaction_isolation DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set statement_timeout = 1000; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET statement_timeout = 1000', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET statement_timeout = 1000 DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx set statement_timeout = 2000; alter database altered_database set statement_timeout from current; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET statement_timeout FROM CURRENT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET statement_timeout FROM CURRENT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set statement_timeout to DEFAULT; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET statement_timeout TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET statement_timeout TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET statement_timeout; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET statement_timeout', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET statement_timeout DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set lock_timeout = 1201.5; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET lock_timeout = 1201.5', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET lock_timeout = 1201.5 DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx set lock_timeout = 1202.5; alter database altered_database set lock_timeout from current; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET lock_timeout FROM CURRENT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET lock_timeout FROM CURRENT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database set lock_timeout to DEFAULT; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database SET lock_timeout TO DEFAULT', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database SET lock_timeout TO DEFAULT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx alter database altered_database RESET lock_timeout; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET lock_timeout', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET lock_timeout DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx ALTER DATABASE altered_database RESET ALL; -NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database RESET ALL', 'postgres') +NOTICE: issuing ALTER DATABASE altered_database RESET ALL DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +CONTEXT: while executing command on localhost:xxxxx \c regression set citus.enable_create_database_propagation=on; drop database altered_database; drop database test_alter_db_from_nonmain_db; reset citus.enable_create_database_propagation; drop role test_owner_non_main_db; +SELECT result FROM run_command_on_all_nodes( + $$ + drop tablespace alter_db_tablespace + $$ +); + result +--------------------------------------------------------------------- + DROP TABLESPACE + DROP TABLESPACE + DROP TABLESPACE +(3 rows) + diff --git a/src/test/regress/sql/alter_database_from_nonmain_db.sql b/src/test/regress/sql/alter_database_from_nonmain_db.sql index aa9a5d191..04ab1e7ef 100644 --- a/src/test/regress/sql/alter_database_from_nonmain_db.sql +++ b/src/test/regress/sql/alter_database_from_nonmain_db.sql @@ -5,9 +5,23 @@ create database altered_database; reset citus.enable_create_database_propagation; \c regression; set citus.enable_create_database_propagation=on; + +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts3' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; + +\c - - - :worker_1_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts4' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; + +\c - - - :worker_2_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts5' +CREATE TABLESPACE alter_db_tablespace LOCATION :'alter_db_tablespace'; + \c test_alter_db_from_nonmain_db set citus.log_remote_commands = true; set citus.grep_remote_commands = "%ALTER DATABASE%"; + +alter database altered_database set tablespace alter_db_tablespace; alter database altered_database rename to altered_database_renamed; alter database altered_database_renamed rename to altered_database; @@ -62,3 +76,9 @@ drop database test_alter_db_from_nonmain_db; reset citus.enable_create_database_propagation; drop role test_owner_non_main_db; + +SELECT result FROM run_command_on_all_nodes( + $$ + drop tablespace alter_db_tablespace + $$ +);