From 7ad5a2479b4429329188ce8c2da07a0fcfd8ddf6 Mon Sep 17 00:00:00 2001 From: gurkanindibay Date: Mon, 18 Mar 2024 16:26:08 +0300 Subject: [PATCH] Moves code from the branch --- .../non_main_db_distribute_object_ops.c | 48 ++++++++ .../alter_database_from_nonmain_db.out | 111 ++++++++++++++++++ src/test/regress/expected/pg15.out | 16 +++ src/test/regress/multi_1_schedule | 1 + .../sql/alter_database_from_nonmain_db.sql | 64 ++++++++++ src/test/regress/sql/pg15.sql | 18 +++ 6 files changed, 258 insertions(+) create mode 100644 src/test/regress/expected/alter_database_from_nonmain_db.out create mode 100644 src/test/regress/sql/alter_database_from_nonmain_db.sql 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 3c21c7b4e..2254d0d68 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 @@ -159,6 +159,25 @@ static const NonMainDbDistributeObjectOps Any_DropDatabase = { .getUnmarkDistributedParams = NULL, .cannotBeExecutedInTransaction = true }; + +static const NonMainDbDistributeObjectOps Any_AlterDatabase = { + .getMarkDistributedParams = NULL, + .getUnmarkDistributedParams = NULL, + .cannotBeExecutedInTransaction = true +}; + +static const NonMainDbDistributeObjectOps Any_AlterDatabaseSet = { + .getMarkDistributedParams = NULL, + .getUnmarkDistributedParams = NULL, + .cannotBeExecutedInTransaction = true +}; + +static const NonMainDbDistributeObjectOps Any_AlterDatabaseRefreshColl = { + .getMarkDistributedParams = NULL, + .getUnmarkDistributedParams = NULL, + .cannotBeExecutedInTransaction = false +}; + static const NonMainDbDistributeObjectOps Database_Grant = { .getMarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL, @@ -329,6 +348,35 @@ GetNonMainDbDistributeObjectOps(Node *parsetree) return NULL; } + case T_AlterDatabaseStmt: + { + AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, 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_AlterDatabase; + } + + return NULL; + } + + case T_AlterDatabaseSetStmt: + { + return &Any_AlterDatabaseSet; + + } +#if PG_VERSION_NUM >= PG_VERSION_15 + case T_AlterDatabaseRefreshCollStmt: + { + return &Any_AlterDatabaseRefreshColl; + } +#endif + case T_GrantStmt: { GrantStmt *stmt = castNode(GrantStmt, parsetree); diff --git a/src/test/regress/expected/alter_database_from_nonmain_db.out b/src/test/regress/expected/alter_database_from_nonmain_db.out new file mode 100644 index 000000000..763db4396 --- /dev/null +++ b/src/test/regress/expected/alter_database_from_nonmain_db.out @@ -0,0 +1,111 @@ +SET citus.superuser TO 'postgres'; +set citus.enable_create_database_propagation=on; +create database test_alter_db_from_nonmain_db; +create database altered_database; +reset citus.enable_create_database_propagation; +\c regression; +set citus.enable_create_database_propagation=on; +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression +create role test_owner_non_main_db; +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +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') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\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; diff --git a/src/test/regress/expected/pg15.out b/src/test/regress/expected/pg15.out index eff8b0ce6..a5c69b704 100644 --- a/src/test/regress/expected/pg15.out +++ b/src/test/regress/expected/pg15.out @@ -1546,3 +1546,19 @@ SET client_min_messages TO ERROR; DROP SCHEMA pg15 CASCADE; DROP ROLE rls_tenant_1; DROP ROLE rls_tenant_2; +-- test refresh collation version on non-main databases +SET citus.enable_create_database_propagation TO on; +create database alter_db_from_nonmain_db_pg15; +\c alter_db_from_nonmain_db_pg15 +set citus.log_remote_commands = true; +set citus.grep_remote_commands = '%ALTER DATABASE%'; +ALTER DATABASE alter_db_from_nonmain_db_pg15 REFRESH COLLATION VERSION; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE alter_db_from_nonmain_db_pg15 REFRESH COLLATION VERSION;', 'postgres') +NOTICE: version has not changed +reset citus.log_remote_commands; +reset citus.grep_remote_commands; +\c regression +SET citus.enable_create_database_propagation TO on; +drop database alter_db_from_nonmain_db_pg15; +reset citus.enable_create_database_propagation; +SET citus.enable_create_database_propagation TO OFF; diff --git a/src/test/regress/multi_1_schedule b/src/test/regress/multi_1_schedule index 015f74973..868d78cdf 100644 --- a/src/test/regress/multi_1_schedule +++ b/src/test/regress/multi_1_schedule @@ -63,6 +63,7 @@ test: alter_database_propagation test: citus_shards test: reassign_owned +test: alter_database_from_nonmain_db # ---------- # multi_citus_tools tests utility functions written for citus tools diff --git a/src/test/regress/sql/alter_database_from_nonmain_db.sql b/src/test/regress/sql/alter_database_from_nonmain_db.sql new file mode 100644 index 000000000..aa9a5d191 --- /dev/null +++ b/src/test/regress/sql/alter_database_from_nonmain_db.sql @@ -0,0 +1,64 @@ +SET citus.superuser TO 'postgres'; +set citus.enable_create_database_propagation=on; +create database test_alter_db_from_nonmain_db; +create database altered_database; +reset citus.enable_create_database_propagation; +\c regression; +set citus.enable_create_database_propagation=on; +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +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; +alter database altered_database with + ALLOW_CONNECTIONS true + CONNECTION LIMIT 0 + IS_TEMPLATE false; + +\c regression +create role test_owner_non_main_db; +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +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; +set default_transaction_read_only = false; +alter database altered_database set default_transaction_read_only from current; +alter database altered_database set default_transaction_read_only to DEFAULT; +alter database altered_database RESET default_transaction_read_only; +alter database altered_database SET TIME ZONE '-7'; +alter database altered_database set TIME ZONE LOCAL; +alter database altered_database set TIME ZONE DEFAULT; +alter database altered_database RESET TIME ZONE; +alter database altered_database SET TIME ZONE INTERVAL '-08:00' HOUR TO MINUTE; +alter database altered_database RESET TIME ZONE; +alter database altered_database set default_transaction_isolation = 'serializable'; +set default_transaction_isolation = 'read committed'; +alter database altered_database set default_transaction_isolation from current; +alter database altered_database set default_transaction_isolation to DEFAULT; +alter database altered_database RESET default_transaction_isolation; +alter database altered_database set statement_timeout = 1000; +set statement_timeout = 2000; +alter database altered_database set statement_timeout from current; +alter database altered_database set statement_timeout to DEFAULT; +alter database altered_database RESET statement_timeout; +alter database altered_database set lock_timeout = 1201.5; +set lock_timeout = 1202.5; +alter database altered_database set lock_timeout from current; +alter database altered_database set lock_timeout to DEFAULT; +alter database altered_database RESET lock_timeout; +ALTER DATABASE altered_database RESET ALL; +\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; diff --git a/src/test/regress/sql/pg15.sql b/src/test/regress/sql/pg15.sql index cd9dab58c..4ecd1866e 100644 --- a/src/test/regress/sql/pg15.sql +++ b/src/test/regress/sql/pg15.sql @@ -989,3 +989,21 @@ SET client_min_messages TO ERROR; DROP SCHEMA pg15 CASCADE; DROP ROLE rls_tenant_1; DROP ROLE rls_tenant_2; + +-- test refresh collation version on non-main databases +SET citus.enable_create_database_propagation TO on; +create database alter_db_from_nonmain_db_pg15; + +\c alter_db_from_nonmain_db_pg15 +set citus.log_remote_commands = true; +set citus.grep_remote_commands = '%ALTER DATABASE%'; +ALTER DATABASE alter_db_from_nonmain_db_pg15 REFRESH COLLATION VERSION; + +reset citus.log_remote_commands; +reset citus.grep_remote_commands; + +\c regression +SET citus.enable_create_database_propagation TO on; +drop database alter_db_from_nonmain_db_pg15; +reset citus.enable_create_database_propagation; +SET citus.enable_create_database_propagation TO OFF;