diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index 3586fa2cd..aaaef2aab 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -249,7 +249,7 @@ FilterDistributedDatabases(List *databases) * IsSetTablespaceStatement returns true if the statement is a SET TABLESPACE statement, * false otherwise. */ -static bool +bool IsSetTablespaceStatement(AlterDatabaseStmt *stmt) { DefElem *def = NULL; @@ -288,7 +288,9 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString, return NIL; } - EnsureCoordinator(); + + EnsurePropagationToCoordinator(); + EnsureAllObjectDependenciesExistOnAllNodes(list_make1(dbAddress)); SerializeDistributedDDLsOnObjectClassObject(OCLASS_DATABASE, stmt->dbname); char *sql = DeparseTreeNode((Node *) stmt); @@ -305,12 +307,12 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString, * the transaction block. */ bool warnForPartialFailure = true; - return NontransactionalNodeDDLTaskList(NON_COORDINATOR_NODES, commands, + return NontransactionalNodeDDLTaskList(REMOTE_NODES, commands, warnForPartialFailure); } else { - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return NodeDDLTaskList(REMOTE_NODES, commands); } } @@ -339,7 +341,9 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString, return NIL; } - EnsureCoordinator(); + EnsurePropagationToCoordinator(); + EnsureAllObjectDependenciesExistOnAllNodes(list_make1(dbAddress)); + SerializeDistributedDDLsOnObjectClassObject(OCLASS_DATABASE, stmt->dbname); char *sql = DeparseTreeNode((Node *) stmt); @@ -348,7 +352,7 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString, (void *) sql, ENABLE_DDL_PROPAGATION); - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return NodeDDLTaskList(REMOTE_NODES, commands); } @@ -378,7 +382,8 @@ PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString, return NIL; } - EnsureCoordinator(); + EnsurePropagationToCoordinator(); + EnsureAllObjectDependenciesExistOnAllNodes(list_make1(dbAddress)); /* * Different than other ALTER DATABASE commands, we first acquire a lock @@ -412,7 +417,8 @@ PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString) return NIL; } - EnsureCoordinator(); + EnsurePropagationToCoordinator(); + EnsureAllObjectDependenciesExistOnAllNodes(list_make1(dbAddress)); char *sql = DeparseTreeNode((Node *) stmt); @@ -420,7 +426,7 @@ PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString) (void *) sql, ENABLE_DDL_PROPAGATION); - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return NodeDDLTaskList(REMOTE_NODES, commands); } @@ -448,7 +454,8 @@ PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString, return NIL; } - EnsureCoordinator(); + EnsurePropagationToCoordinator(); + EnsureAllObjectDependenciesExistOnAllNodes(list_make1(dbAddress)); SerializeDistributedDDLsOnObjectClassObject(OCLASS_DATABASE, stmt->dbname); char *sql = DeparseTreeNode((Node *) stmt); @@ -457,7 +464,7 @@ PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString, (void *) sql, ENABLE_DDL_PROPAGATION); - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return NodeDDLTaskList(REMOTE_NODES, commands); } @@ -678,6 +685,44 @@ PreprocessDropDatabaseStmt(Node *node, const char *queryString, } +List * +PreprocessAlterDatabaseOwnerStmt(Node *node, const char *queryString, + ProcessUtilityContext processUtilityContext) +{ + if (!EnableAlterDatabaseOwner) + { + return NIL; + } + + List *addresses = GetObjectAddressListFromParseTree(node, false, false); + + /* the code-path only supports a single object */ + Assert(list_length(addresses) == 1); + + if (!ShouldPropagateAnyObject(addresses)) + { + return NIL; + } + + EnsurePropagationToCoordinator(); + + AlterOwnerStmt *stmt = (AlterOwnerStmt *) node; + char *databaseName = strVal((String *) stmt->object); + SerializeDistributedDDLsOnObjectClassObject(OCLASS_DATABASE, databaseName); + + EnsureSequentialMode(stmt->objectType); + QualifyTreeNode(node); + + const char *sql = DeparseTreeNode((Node *) node); + + List *commands = list_make3(DISABLE_DDL_PROPAGATION, + (void *) sql, + ENABLE_DDL_PROPAGATION); + + return NodeDDLTaskList(REMOTE_NODES, commands); +} + + /* * DropDatabaseStmtObjectAddress gets the ObjectAddress of the database that is the * object of the DropdbStmt. diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index 8d1c6bc23..53530a750 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -495,7 +495,7 @@ static DistributeObjectOps Collation_Rename = { static DistributeObjectOps Database_AlterOwner = { .deparse = DeparseAlterDatabaseOwnerStmt, .qualify = NULL, - .preprocess = PreprocessAlterDistributedObjectStmt, + .preprocess = PreprocessAlterDatabaseOwnerStmt, .postprocess = PostprocessAlterDistributedObjectStmt, .objectType = OBJECT_DATABASE, .operationType = DIST_OPS_ALTER, 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 fdd29b1e1..a48b193d1 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 @@ -28,6 +28,7 @@ #include "utils/builtins.h" #include "distributed/commands.h" +#include "distributed/commands/utility_hook.h" #include "distributed/deparser.h" #include "distributed/listutils.h" #include "distributed/metadata_cache.h" @@ -61,7 +62,7 @@ */ typedef struct NonMainDbDistributeObjectOps { - bool cannotBeExecutedInTransaction; + bool (*cannotBeExecutedInTransaction)(Node *parsetree); bool (*checkSupportedObjectType)(Node *parsetree); } NonMainDbDistributeObjectOps; @@ -73,41 +74,72 @@ static bool CreateDbStmtCheckSupportedObjectType(Node *node); static bool DropDbStmtCheckSupportedObjectType(Node *node); static bool GrantStmtCheckSupportedObjectType(Node *node); static bool SecLabelStmtCheckSupportedObjectType(Node *node); +static bool AlterDbRenameCheckSupportedObjectType(Node *node); +static bool AlterDbOwnerCheckSupportedObjectType(Node *node); + +/* + * cannotBeExecutedInTransaction callbacks for OperationArray. + */ +static bool CannotBeExecutedInTransaction_True(Node *node); +static bool CannotBeExecutedInTransaction_False(Node *node); +static bool AlterDbCannotBeExecutedInTransaction(Node *node); /* * OperationArray that holds NonMainDbDistributeObjectOps for different command types. */ static const NonMainDbDistributeObjectOps *const OperationArray[] = { [T_CreateRoleStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = NULL }, [T_DropRoleStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = NULL }, [T_AlterRoleStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = NULL }, [T_GrantRoleStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = NULL }, [T_CreatedbStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = true, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_True, .checkSupportedObjectType = CreateDbStmtCheckSupportedObjectType }, [T_DropdbStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = true, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_True, .checkSupportedObjectType = DropDbStmtCheckSupportedObjectType }, + [T_AlterDatabaseSetStmt] = &(NonMainDbDistributeObjectOps) { + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, + .checkSupportedObjectType = NULL + }, + [T_AlterDatabaseStmt] = &(NonMainDbDistributeObjectOps) { + .cannotBeExecutedInTransaction = AlterDbCannotBeExecutedInTransaction, + .checkSupportedObjectType = NULL + }, +#if PG_VERSION_NUM >= PG_VERSION_15 + [T_AlterDatabaseRefreshCollStmt] = &(NonMainDbDistributeObjectOps) { + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, + .checkSupportedObjectType = NULL + }, +#endif + [T_RenameStmt] = &(NonMainDbDistributeObjectOps) { + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, + .checkSupportedObjectType = AlterDbRenameCheckSupportedObjectType + }, + [T_AlterOwnerStmt] = &(NonMainDbDistributeObjectOps) { + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, + .checkSupportedObjectType = AlterDbOwnerCheckSupportedObjectType + }, [T_GrantStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = GrantStmtCheckSupportedObjectType }, [T_SecLabelStmt] = &(NonMainDbDistributeObjectOps) { - .cannotBeExecutedInTransaction = false, + .cannotBeExecutedInTransaction = CannotBeExecutedInTransaction_False, .checkSupportedObjectType = SecLabelStmtCheckSupportedObjectType }, }; @@ -132,7 +164,7 @@ static void UnmarkObjectDistributedOnLocalMainDb(uint16 catalogRelId, Oid object bool RunPreprocessNonMainDBCommand(Node *parsetree) { - if (IsMainDB) + if (IsMainDB || !EnableDDLPropagation) { return false; } @@ -150,7 +182,7 @@ RunPreprocessNonMainDBCommand(Node *parsetree) * transactional visibility issues. We directly route them to main database * so that we only have to consider one code-path for such commands. */ - if (ops->cannotBeExecutedInTransaction) + if (ops->cannotBeExecutedInTransaction(parsetree)) { IsMainDBCommandInXact = false; RunCitusMainDBQuery((char *) queryString); @@ -188,7 +220,7 @@ RunPreprocessNonMainDBCommand(Node *parsetree) void RunPostprocessNonMainDBCommand(Node *parsetree) { - if (IsMainDB || !GetNonMainDbDistributeObjectOps(parsetree)) + if (IsMainDB || !EnableDDLPropagation || !GetNonMainDbDistributeObjectOps(parsetree)) { return; } @@ -335,6 +367,22 @@ DropDbStmtCheckSupportedObjectType(Node *node) } +static bool +AlterDbRenameCheckSupportedObjectType(Node *node) +{ + RenameStmt *stmt = castNode(RenameStmt, node); + return stmt->renameType == OBJECT_DATABASE; +} + + +static bool +AlterDbOwnerCheckSupportedObjectType(Node *node) +{ + AlterOwnerStmt *stmt = castNode(AlterOwnerStmt, node); + return stmt->objectType == OBJECT_DATABASE; +} + + static bool GrantStmtCheckSupportedObjectType(Node *node) { @@ -349,3 +397,28 @@ SecLabelStmtCheckSupportedObjectType(Node *node) SecLabelStmt *stmt = castNode(SecLabelStmt, node); return stmt->objtype == OBJECT_ROLE; } + + +/* + * cannotBeExecutedInTransaction callbacks for OperationArray lie below. + */ +static bool +CannotBeExecutedInTransaction_True(Node *node) +{ + return true; +} + + +static bool +CannotBeExecutedInTransaction_False(Node *node) +{ + return false; +} + + +static bool +AlterDbCannotBeExecutedInTransaction(Node *node) +{ + AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, node); + return IsSetTablespaceStatement(stmt); +} diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 19919e32c..c31fd64e7 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -234,6 +234,8 @@ extern List * PreprocessAlterDatabaseStmt(Node *node, const char *queryString, extern List * PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext); +extern List * PreprocessAlterDatabaseOwnerStmt(Node *node, const char *queryString, + ProcessUtilityContext processUtilityContext); extern List * GetDatabaseMetadataSyncCommands(Oid dbOid); @@ -256,6 +258,7 @@ extern List * PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryStr extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString); extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt); extern char * CreateDatabaseDDLCommand(Oid dbId); +extern bool IsSetTablespaceStatement(AlterDatabaseStmt *stmt); /* domain.c - forward declarations */ diff --git a/src/test/regress/base_isolation_schedule b/src/test/regress/base_isolation_schedule index 1fc2f7de5..d19a0463b 100644 --- a/src/test/regress/base_isolation_schedule +++ b/src/test/regress/base_isolation_schedule @@ -1,5 +1,6 @@ # ---------- # isolation setup steps # ---------- +test: isolation_enable_ddl_propagation test: isolation_setup test: isolation_cluster_management diff --git a/src/test/regress/base_schedule b/src/test/regress/base_schedule index 65f439acc..f56adb5a3 100644 --- a/src/test/regress/base_schedule +++ b/src/test/regress/base_schedule @@ -1,6 +1,7 @@ # ---------- # Only run few basic tests to set up a testing environment # ---------- +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser multi_create_fdw columnar_test_helpers failure_test_helpers test: multi_cluster_management test: multi_test_catalog_views diff --git a/src/test/regress/citus_tests/run_test.py b/src/test/regress/citus_tests/run_test.py index 9a648c0ab..45a52fe2c 100755 --- a/src/test/regress/citus_tests/run_test.py +++ b/src/test/regress/citus_tests/run_test.py @@ -224,6 +224,7 @@ DEPS = { ], repeatable=False, ), + "multi_follower_sanity_check": TestDeps("multi_follower_schedule"), } @@ -324,6 +325,8 @@ def run_schedule_with_multiregress(test_name, schedule, dependencies, args): "failure" ): make_recipe = "check-failure-custom-schedule" + elif dependencies.schedule == "multi_follower_schedule": + make_recipe = "check-follower-cluster" else: make_recipe = "check-custom-schedule" @@ -360,6 +363,9 @@ def default_base_schedule(test_schedule, args): if "operations" in test_schedule: return "minimal_schedule" + if "follower" in test_schedule: + return "multi_follower_schedule" + if "pg_upgrade" in test_schedule: return "minimal_pg_upgrade_schedule" @@ -416,7 +422,26 @@ def find_test_schedule_and_line(test_name, args): def test_dependencies(test_name, test_schedule, schedule_line, args): if test_name in DEPS: - return DEPS[test_name] + # Since enable_ddl_propagation is a must to execute tests, + # below block adds enable_ddl_propagation as a dependency + # as the first element of extra tests if schedule is not + # configured. We don't do so if the schedule is confugured + # because all base schedules include enable_ddl_propagation + # anyway. + test_deps = DEPS[test_name] + ddl_propagation_test = ( + "isolation_enable_ddl_propagation" + if test_name.startswith("isolation") + else "enable_ddl_propagation" + ) + + if test_deps is not None and test_deps.schedule is None: + test_deps.direct_extra_tests = [ + ddl_propagation_test + ] + test_deps.direct_extra_tests + return test_deps + else: + return DEPS[test_name] if "citus_upgrade" in test_schedule: return TestDeps(None, citus_upgrade_infra=True) diff --git a/src/test/regress/columnar_schedule b/src/test/regress/columnar_schedule index 602af0fc7..ef8b2b288 100644 --- a/src/test/regress/columnar_schedule +++ b/src/test/regress/columnar_schedule @@ -1,3 +1,4 @@ +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser columnar_test_helpers test: multi_cluster_management test: multi_test_catalog_views diff --git a/src/test/regress/enterprise_isolation_logicalrep_1_schedule b/src/test/regress/enterprise_isolation_logicalrep_1_schedule index 2656e96d5..10a77aa18 100644 --- a/src/test/regress/enterprise_isolation_logicalrep_1_schedule +++ b/src/test/regress/enterprise_isolation_logicalrep_1_schedule @@ -1,3 +1,4 @@ +test: isolation_enable_ddl_propagation test: isolation_setup # tests that change node metadata should precede diff --git a/src/test/regress/enterprise_isolation_logicalrep_2_schedule b/src/test/regress/enterprise_isolation_logicalrep_2_schedule index e8915cb27..167190391 100644 --- a/src/test/regress/enterprise_isolation_logicalrep_2_schedule +++ b/src/test/regress/enterprise_isolation_logicalrep_2_schedule @@ -1,3 +1,4 @@ +test: isolation_enable_ddl_propagation test: isolation_setup # tests that change node metadata should precede diff --git a/src/test/regress/enterprise_isolation_logicalrep_3_schedule b/src/test/regress/enterprise_isolation_logicalrep_3_schedule index 105dcc049..9b252005e 100644 --- a/src/test/regress/enterprise_isolation_logicalrep_3_schedule +++ b/src/test/regress/enterprise_isolation_logicalrep_3_schedule @@ -1,3 +1,4 @@ +test: isolation_enable_ddl_propagation test: isolation_setup # tests that change node metadata should precede diff --git a/src/test/regress/enterprise_isolation_schedule b/src/test/regress/enterprise_isolation_schedule index 689a7db75..e0fc691d8 100644 --- a/src/test/regress/enterprise_isolation_schedule +++ b/src/test/regress/enterprise_isolation_schedule @@ -1,3 +1,4 @@ +test: isolation_enable_ddl_propagation test: isolation_setup # tests that change node metadata should precede diff --git a/src/test/regress/enterprise_minimal_schedule b/src/test/regress/enterprise_minimal_schedule index 32a671caf..10c4f623b 100644 --- a/src/test/regress/enterprise_minimal_schedule +++ b/src/test/regress/enterprise_minimal_schedule @@ -1,3 +1,4 @@ +test: enable_ddl_propagation test: single_node_enterprise test: multi_test_helpers multi_test_helpers_superuser test: multi_cluster_management diff --git a/src/test/regress/enterprise_schedule b/src/test/regress/enterprise_schedule index 9a832c4d6..59156def7 100644 --- a/src/test/regress/enterprise_schedule +++ b/src/test/regress/enterprise_schedule @@ -1,5 +1,6 @@ # should come before multi_cluster_management # as it touches node metadata +test: enable_ddl_propagation test: single_node_enterprise test: multi_test_helpers multi_test_helpers_superuser 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..937dc9b9d --- /dev/null +++ b/src/test/regress/expected/alter_database_from_nonmain_db.out @@ -0,0 +1,607 @@ +SET citus.superuser TO 'postgres'; +set citus.enable_create_database_propagation=on; +create database test_alter_db_from_nonmain_db; +create database "altered_database!'2"; +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 "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; +\c - - - :worker_1_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts4' +CREATE TABLESPACE "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; +\c - - - :worker_2_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts5' +CREATE TABLESPACE "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; +-- Below tests test the ALTER DATABASE command from main and non-main databases +-- The tests are run on the master and worker nodes to ensure that the command is +-- executed on all nodes. +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- In the below tests, we test the ALTER DATABASE ..set tablespace command +-- repeatedly to ensure that the command does not stuck when executed multiple times +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "pg_default"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE pg_default +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET TABLESPACE "ts-needs\!escape2" +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" rename to altered_database_renamed; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" RENAME TO altered_database_renamed', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database altered_database_renamed rename to "altered_database!'2"; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE altered_database_renamed RENAME TO "altered_database!''2"', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" 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!''2" WITH ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false;', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" with + ALLOW_CONNECTIONS false + CONNECTION LIMIT 1 + IS_TEMPLATE true; +NOTICE: issuing ALTER DATABASE "altered_database!'2" WITH ALLOW_CONNECTIONS false CONNECTION LIMIT 1 IS_TEMPLATE true; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" WITH ALLOW_CONNECTIONS false CONNECTION LIMIT 1 IS_TEMPLATE true; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": false, "datconnlimit": 1, "daticulocale": null, "datistemplate": true, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": false, "datconnlimit": 1, "daticulocale": null, "datistemplate": true, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": false, "datconnlimit": 1, "daticulocale": null, "datistemplate": true, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" with + ALLOW_CONNECTIONS true + CONNECTION LIMIT 0 + IS_TEMPLATE false; +NOTICE: issuing ALTER DATABASE "altered_database!'2" WITH ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" WITH ALLOW_CONNECTIONS true CONNECTION LIMIT 0 IS_TEMPLATE false; +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!'2" owner to test_owner_non_main_db; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" OWNER TO test_owner_non_main_db;', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to CURRENT_USER; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" OWNER TO postgres;', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +set default_transaction_read_only = false; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to test_owner_non_main_db; +NOTICE: issuing ALTER DATABASE "altered_database!'2" OWNER TO test_owner_non_main_db; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" OWNER TO test_owner_non_main_db; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +set default_transaction_read_only = false; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +\c regression - - :master_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to CURRENT_USER; +NOTICE: issuing ALTER DATABASE "altered_database!'2" OWNER TO postgres; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" OWNER TO postgres; +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +set default_transaction_read_only = false; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +set citus.enable_alter_database_owner to off; +alter database "altered_database!'2" owner to test_owner_non_main_db; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "test_owner_non_main_db", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +alter database "altered_database!'2" owner to CURRENT_USER; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": {"datacl": null, "datname": "altered_database!'2", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape2", "daticurules": null, "datallowconn": true, "datconnlimit": 0, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + +reset citus.enable_alter_database_owner; +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set default_transaction_read_only to true; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" SET default_transaction_read_only = ''true''', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | on +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | on +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | on +(1 row) + +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" reset default_transaction_read_only; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" RESET default_transaction_read_only', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | off +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | off +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + name | setting +--------------------------------------------------------------------- + default_transaction_read_only | off +(1 row) + +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set log_duration from current; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" SET log_duration FROM CURRENT', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set log_duration to DEFAULT; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" SET log_duration TO DEFAULT', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" set log_duration = true; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" SET log_duration = ''true''', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | on +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | on +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | on +(1 row) + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" RESET log_duration; +NOTICE: issuing SELECT citus_internal.execute_command_on_remote_nodes_as_user('ALTER DATABASE "altered_database!''2" RESET log_duration', 'postgres') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | off +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | off +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='log_duration'; + name | setting +--------------------------------------------------------------------- + log_duration | off +(1 row) + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set statement_timeout = 1000; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET statement_timeout = 1000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET statement_timeout = 1000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 1000 +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 1000 +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 1000 +(1 row) + +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set statement_timeout to DEFAULT; +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET statement_timeout TO DEFAULT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" SET statement_timeout TO DEFAULT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +alter database "altered_database!'2" RESET statement_timeout; +NOTICE: issuing ALTER DATABASE "altered_database!'2" RESET statement_timeout +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ALTER DATABASE "altered_database!'2" RESET statement_timeout +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 0 +(1 row) + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 0 +(1 row) + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='statement_timeout'; + name | setting +--------------------------------------------------------------------- + statement_timeout | 0 +(1 row) + +\c regression +set citus.enable_create_database_propagation=on; +drop database "altered_database!'2"; +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 "ts-needs\!escape2" + $$ +); + result +--------------------------------------------------------------------- + DROP TABLESPACE + DROP TABLESPACE + DROP TABLESPACE +(3 rows) + diff --git a/src/test/regress/expected/enable_ddl_propagation.out b/src/test/regress/expected/enable_ddl_propagation.out new file mode 100644 index 000000000..11cc7b82f --- /dev/null +++ b/src/test/regress/expected/enable_ddl_propagation.out @@ -0,0 +1,16 @@ +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + result +--------------------------------------------------------------------- + ALTER SYSTEM + ALTER SYSTEM + ALTER SYSTEM +(3 rows) + +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); + result +--------------------------------------------------------------------- + t + t + t +(3 rows) + diff --git a/src/test/regress/expected/enable_ddl_propagation_0.out b/src/test/regress/expected/enable_ddl_propagation_0.out new file mode 100644 index 000000000..efbedf854 --- /dev/null +++ b/src/test/regress/expected/enable_ddl_propagation_0.out @@ -0,0 +1,12 @@ +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + result +--------------------------------------------------------------------- + ALTER SYSTEM +(1 row) + +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); + result +--------------------------------------------------------------------- + t +(1 row) + diff --git a/src/test/regress/expected/failure_setup.out b/src/test/regress/expected/failure_setup.out index 4cbb4b0a4..d799718ca 100644 --- a/src/test/regress/expected/failure_setup.out +++ b/src/test/regress/expected/failure_setup.out @@ -17,3 +17,19 @@ SELECT master_add_node('localhost', :worker_2_proxy_port); -- an mitmproxy whic 2 (1 row) +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + result +--------------------------------------------------------------------- + ALTER SYSTEM + ALTER SYSTEM + ALTER SYSTEM +(3 rows) + +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); + result +--------------------------------------------------------------------- + t + t + t +(3 rows) + diff --git a/src/test/regress/expected/failure_test_helpers.out b/src/test/regress/expected/failure_test_helpers.out index da63a985f..7689e986c 100644 --- a/src/test/regress/expected/failure_test_helpers.out +++ b/src/test/regress/expected/failure_test_helpers.out @@ -4,6 +4,7 @@ ALTER SYSTEM SET citus.distributed_deadlock_detection_factor TO -1; ALTER SYSTEM SET citus.recover_2pc_interval TO -1; ALTER SYSTEM set citus.enable_statistics_collection TO false; +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; SELECT pg_reload_conf(); pg_reload_conf --------------------------------------------------------------------- diff --git a/src/test/regress/expected/isolation_cluster_management.out b/src/test/regress/expected/isolation_cluster_management.out index 63488f743..c978d10e4 100644 --- a/src/test/regress/expected/isolation_cluster_management.out +++ b/src/test/regress/expected/isolation_cluster_management.out @@ -4,6 +4,8 @@ starting permutation: s1a step s1a: SELECT 1 FROM master_add_node('localhost', 57637); SELECT 1 FROM master_add_node('localhost', 57638); + SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); ?column? --------------------------------------------------------------------- @@ -15,3 +17,17 @@ step s1a: 1 (1 row) +result +--------------------------------------------------------------------- +ALTER SYSTEM +ALTER SYSTEM +ALTER SYSTEM +(3 rows) + +result +--------------------------------------------------------------------- +t +t +t +(3 rows) + diff --git a/src/test/regress/expected/isolation_enable_ddl_propagation.out b/src/test/regress/expected/isolation_enable_ddl_propagation.out new file mode 100644 index 000000000..d5cea0b6f --- /dev/null +++ b/src/test/regress/expected/isolation_enable_ddl_propagation.out @@ -0,0 +1,16 @@ +Parsed test spec with 1 sessions + +starting permutation: s1a +all_ok +--------------------------------------------------------------------- +t +(1 row) + +step s1a: + SELECT 1; + +?column? +--------------------------------------------------------------------- + 1 +(1 row) + diff --git a/src/test/regress/expected/isolation_enable_ddl_propagation_0.out b/src/test/regress/expected/isolation_enable_ddl_propagation_0.out new file mode 100644 index 000000000..8bfe44546 --- /dev/null +++ b/src/test/regress/expected/isolation_enable_ddl_propagation_0.out @@ -0,0 +1,14 @@ +Parsed test spec with 1 sessions + +starting permutation: s1-begin s1-commit +result +--------------------------------------------------------------------- +t +(1 row) + +step s1-begin: + BEGIN; + +step s1-commit: + COMMIT; + diff --git a/src/test/regress/expected/minimal_cluster_management.out b/src/test/regress/expected/minimal_cluster_management.out index d05e83ed5..2d752e12f 100644 --- a/src/test/regress/expected/minimal_cluster_management.out +++ b/src/test/regress/expected/minimal_cluster_management.out @@ -69,3 +69,20 @@ DROP TABLE test_dist; ALTER SEQUENCE pg_catalog.pg_dist_node_nodeid_seq RESTART 30; ALTER SEQUENCE pg_catalog.pg_dist_groupid_seq RESTART 18; ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 83; +-- enable ddl propagation in all nodes +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + result +--------------------------------------------------------------------- + ALTER SYSTEM + ALTER SYSTEM + ALTER SYSTEM +(3 rows) + +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); + result +--------------------------------------------------------------------- + t + t + t +(3 rows) + diff --git a/src/test/regress/expected/multi_cluster_management.out b/src/test/regress/expected/multi_cluster_management.out index e6634d5c6..4fea375c9 100644 --- a/src/test/regress/expected/multi_cluster_management.out +++ b/src/test/regress/expected/multi_cluster_management.out @@ -1288,3 +1288,20 @@ SELECT bool_and(hasmetadata) AND bool_and(metadatasynced) FROM pg_dist_node WHER -- keep permissions compatible accross versions, in regression -- tests. GRANT ALL ON SCHEMA public TO PUBLIC; +-- enable ddl propagation in all nodes +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + result +--------------------------------------------------------------------- + ALTER SYSTEM + ALTER SYSTEM + ALTER SYSTEM +(3 rows) + +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); + result +--------------------------------------------------------------------- + t + t + t +(3 rows) + diff --git a/src/test/regress/expected/multi_follower_sanity_check.out b/src/test/regress/expected/multi_follower_sanity_check.out index 6d5a0e1f6..6124f26c9 100644 --- a/src/test/regress/expected/multi_follower_sanity_check.out +++ b/src/test/regress/expected/multi_follower_sanity_check.out @@ -1,4 +1,28 @@ -- check that the nodes are all in read-only mode and rejecting write queries +\c - - - :follower_master_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + pg_reload_conf +--------------------------------------------------------------------- + t +(1 row) + +\c - - - :follower_worker_1_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + pg_reload_conf +--------------------------------------------------------------------- + t +(1 row) + +\c - - - :follower_worker_2_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + pg_reload_conf +--------------------------------------------------------------------- + t +(1 row) + \c - - - :follower_master_port CREATE TABLE tab (a int); ERROR: cannot execute CREATE TABLE in a read-only transaction diff --git a/src/test/regress/expected/pg15.out b/src/test/regress/expected/pg15.out index 66299af08..f389997d9 100644 --- a/src/test/regress/expected/pg15.out +++ b/src/test/regress/expected/pg15.out @@ -1550,3 +1550,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/failure_base_schedule b/src/test/regress/failure_base_schedule index 03ee96ff7..491b3b94a 100644 --- a/src/test/regress/failure_base_schedule +++ b/src/test/regress/failure_base_schedule @@ -1,4 +1,5 @@ # import this file (from psql you can use \i) to use mitmproxy manually +test: enable_ddl_propagation test: failure_test_helpers # this should only be run by pg_regress_multi, you don't need it diff --git a/src/test/regress/failure_schedule b/src/test/regress/failure_schedule index c0dfeac1f..010088aa0 100644 --- a/src/test/regress/failure_schedule +++ b/src/test/regress/failure_schedule @@ -1,4 +1,5 @@ # import this file (from psql you can use \i) to use mitmproxy manually +test: enable_ddl_propagation test: failure_test_helpers # this should only be run by pg_regress_multi, you don't need it diff --git a/src/test/regress/isolation_schedule b/src/test/regress/isolation_schedule index 1b0f1427a..5c5f9ccbb 100644 --- a/src/test/regress/isolation_schedule +++ b/src/test/regress/isolation_schedule @@ -1,3 +1,4 @@ +test: isolation_enable_ddl_propagation test: isolation_setup test: isolation_add_remove_node test: isolation_update_node diff --git a/src/test/regress/minimal_schedule b/src/test/regress/minimal_schedule index 8b0cfff70..fe2d9ce94 100644 --- a/src/test/regress/minimal_schedule +++ b/src/test/regress/minimal_schedule @@ -1,2 +1,3 @@ +test: enable_ddl_propagation test: minimal_cluster_management test: multi_test_helpers multi_test_helpers_superuser multi_create_fdw columnar_test_helpers multi_test_catalog_views tablespace diff --git a/src/test/regress/multi_1_schedule b/src/test/regress/multi_1_schedule index 2ce74e9a7..9e8120699 100644 --- a/src/test/regress/multi_1_schedule +++ b/src/test/regress/multi_1_schedule @@ -15,6 +15,7 @@ # --- # Tests around schema changes, these are run first, so there's no preexisting objects. # --- +test: enable_ddl_propagation test: multi_extension test: multi_test_helpers multi_test_helpers_superuser multi_create_fdw test: single_node @@ -69,6 +70,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/multi_follower_schedule b/src/test/regress/multi_follower_schedule index c1f0ac6cb..686d6a38c 100644 --- a/src/test/regress/multi_follower_schedule +++ b/src/test/regress/multi_follower_schedule @@ -1,3 +1,4 @@ +test: enable_ddl_propagation test: multi_follower_sanity_check test: follower_single_node test: multi_follower_select_statements diff --git a/src/test/regress/multi_mx_schedule b/src/test/regress/multi_mx_schedule index 6654b4ab0..6e8b652e4 100644 --- a/src/test/regress/multi_mx_schedule +++ b/src/test/regress/multi_mx_schedule @@ -13,6 +13,7 @@ # --- # Tests around schema changes, these are run first, so there's no preexisting objects. # --- +test: enable_ddl_propagation test: multi_extension test: multi_test_helpers multi_test_helpers_superuser test: multi_mx_node_metadata diff --git a/src/test/regress/multi_schedule b/src/test/regress/multi_schedule index 3d7bd6e98..df57cac9a 100644 --- a/src/test/regress/multi_schedule +++ b/src/test/regress/multi_schedule @@ -1,3 +1,4 @@ +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser test: multi_cluster_management test: create_role_propagation diff --git a/src/test/regress/mx_base_schedule b/src/test/regress/mx_base_schedule index 598e03d13..947986640 100644 --- a/src/test/regress/mx_base_schedule +++ b/src/test/regress/mx_base_schedule @@ -1,6 +1,7 @@ # ---------- # Only run few basic tests to set up a testing environment # ---------- +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser test: multi_cluster_management test: multi_mx_function_table_reference diff --git a/src/test/regress/operations_schedule b/src/test/regress/operations_schedule index 6dbc303c2..0f8b5b816 100644 --- a/src/test/regress/operations_schedule +++ b/src/test/regress/operations_schedule @@ -1,3 +1,4 @@ +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser test: multi_cluster_management test: multi_test_catalog_views diff --git a/src/test/regress/pg_regress_multi.pl b/src/test/regress/pg_regress_multi.pl index 17c0a1179..7fb583973 100755 --- a/src/test/regress/pg_regress_multi.pl +++ b/src/test/regress/pg_regress_multi.pl @@ -494,6 +494,7 @@ push(@pgOptions, "citus.stat_tenants_limit = 2"); push(@pgOptions, "citus.stat_tenants_track = 'ALL'"); push(@pgOptions, "citus.enable_stat_counters=on"); push(@pgOptions, "citus.superuser = 'postgres'"); +push(@pgOptions, "citus.enable_ddl_propagation=false"); # Some tests look at shards in pg_class, make sure we can usually see them: push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'"); diff --git a/src/test/regress/spec/isolation_cluster_management.spec b/src/test/regress/spec/isolation_cluster_management.spec index 4715a7509..29d954467 100644 --- a/src/test/regress/spec/isolation_cluster_management.spec +++ b/src/test/regress/spec/isolation_cluster_management.spec @@ -3,6 +3,8 @@ step "s1a" { SELECT 1 FROM master_add_node('localhost', 57637); SELECT 1 FROM master_add_node('localhost', 57638); + SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); } permutation "s1a" diff --git a/src/test/regress/spec/isolation_enable_ddl_propagation.spec b/src/test/regress/spec/isolation_enable_ddl_propagation.spec new file mode 100644 index 000000000..cd2b0bf12 --- /dev/null +++ b/src/test/regress/spec/isolation_enable_ddl_propagation.spec @@ -0,0 +1,16 @@ +// The code we care about is in the setup stage, because it needs to be executed outside of a transaction. +// For the setup stage to be executed we need at least one permutation though. +// Therefore, we added s1a as a non-functional step, just make the setup step to work. +setup +{ + SELECT bool_and(result='ALTER SYSTEM') AS all_ok FROM run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); + SELECT bool_and(result='t') AS all_ok FROM run_command_on_all_nodes('SELECT pg_reload_conf()'); +} + +session "s1" +step "s1a" +{ + SELECT 1; +} + +permutation "s1a" diff --git a/src/test/regress/split_schedule b/src/test/regress/split_schedule index 53c422eab..fa445f151 100644 --- a/src/test/regress/split_schedule +++ b/src/test/regress/split_schedule @@ -1,5 +1,6 @@ # Split Shard tests. # Include tests from 'minimal_schedule' for setup. +test: enable_ddl_propagation test: multi_test_helpers multi_test_helpers_superuser columnar_test_helpers test: multi_cluster_management test: remove_coordinator_from_metadata 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..9d1d1f913 --- /dev/null +++ b/src/test/regress/sql/alter_database_from_nonmain_db.sql @@ -0,0 +1,288 @@ +SET citus.superuser TO 'postgres'; +set citus.enable_create_database_propagation=on; +create database test_alter_db_from_nonmain_db; +create database "altered_database!'2"; +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 "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; + +\c - - - :worker_1_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts4' +CREATE TABLESPACE "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; + +\c - - - :worker_2_port +\set alter_db_tablespace :abs_srcdir '/tmp_check/ts5' +CREATE TABLESPACE "ts-needs\!escape2" LOCATION :'alter_db_tablespace'; + +-- Below tests test the ALTER DATABASE command from main and non-main databases +-- The tests are run on the master and worker nodes to ensure that the command is +-- executed on all nodes. + +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; + +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; + +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +-- In the below tests, we test the ALTER DATABASE ..set tablespace command +-- repeatedly to ensure that the command does not stuck when executed multiple times + +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; + +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +\c regression - - :master_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +alter database "altered_database!'2" set tablespace "pg_default"; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; +alter database "altered_database!'2" set tablespace "pg_default"; +alter database "altered_database!'2" set tablespace "ts-needs\!escape2"; + +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" rename to altered_database_renamed; +alter database altered_database_renamed rename to "altered_database!'2"; + +alter database "altered_database!'2" with + ALLOW_CONNECTIONS true + CONNECTION LIMIT 0 + IS_TEMPLATE false; + +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; + +alter database "altered_database!'2" with + ALLOW_CONNECTIONS false + CONNECTION LIMIT 1 + IS_TEMPLATE true; + +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" 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!'2" owner to test_owner_non_main_db; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to CURRENT_USER; +set default_transaction_read_only = false; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to test_owner_non_main_db; +set default_transaction_read_only = false; +\c regression - - :master_port +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +\c regression - - :master_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" owner to CURRENT_USER; +set default_transaction_read_only = false; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; + +set citus.enable_alter_database_owner to off; +alter database "altered_database!'2" owner to test_owner_non_main_db; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +alter database "altered_database!'2" owner to CURRENT_USER; +SELECT * FROM public.check_database_on_all_nodes($$altered_database!''2$$) ORDER BY node_type; +reset citus.enable_alter_database_owner; + +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; + +alter database "altered_database!'2" set default_transaction_read_only to true; + +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + +\c test_alter_db_from_nonmain_db +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" reset default_transaction_read_only; + +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='default_transaction_read_only'; + + +\c test_alter_db_from_nonmain_db - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set log_duration from current; +alter database "altered_database!'2" set log_duration to DEFAULT; +alter database "altered_database!'2" set log_duration = true; +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='log_duration'; + +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='log_duration'; + +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='log_duration'; + +\c test_alter_db_from_nonmain_db - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" RESET log_duration; + +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='log_duration'; +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='log_duration'; +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='log_duration'; + +\c regression - - :worker_2_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set statement_timeout = 1000; + +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='statement_timeout'; +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='statement_timeout'; +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='statement_timeout'; + +\c regression - - :worker_1_port +set citus.log_remote_commands = true; +set citus.grep_remote_commands = "%ALTER DATABASE%"; +alter database "altered_database!'2" set statement_timeout to DEFAULT; +alter database "altered_database!'2" RESET statement_timeout; + +\c "altered_database!'2" - - :master_port +select name,setting from pg_settings + where name ='statement_timeout'; +\c "altered_database!'2" - - :worker_1_port +select name,setting from pg_settings + where name ='statement_timeout'; +\c "altered_database!'2" - - :worker_2_port +select name,setting from pg_settings + where name ='statement_timeout'; + +\c regression +set citus.enable_create_database_propagation=on; +drop database "altered_database!'2"; +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 "ts-needs\!escape2" + $$ +); diff --git a/src/test/regress/sql/enable_ddl_propagation.sql b/src/test/regress/sql/enable_ddl_propagation.sql new file mode 100644 index 000000000..4f1640744 --- /dev/null +++ b/src/test/regress/sql/enable_ddl_propagation.sql @@ -0,0 +1,2 @@ +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); diff --git a/src/test/regress/sql/failure_setup.sql b/src/test/regress/sql/failure_setup.sql index 4c209f14d..9a4c21e53 100644 --- a/src/test/regress/sql/failure_setup.sql +++ b/src/test/regress/sql/failure_setup.sql @@ -3,3 +3,6 @@ SELECT citus.mitmproxy('conn.allow()'); -- add the workers SELECT master_add_node('localhost', :worker_1_port); SELECT master_add_node('localhost', :worker_2_proxy_port); -- an mitmproxy which forwards to the second worker + +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); diff --git a/src/test/regress/sql/failure_test_helpers.sql b/src/test/regress/sql/failure_test_helpers.sql index b7f9eae3a..56938783d 100644 --- a/src/test/regress/sql/failure_test_helpers.sql +++ b/src/test/regress/sql/failure_test_helpers.sql @@ -4,6 +4,7 @@ ALTER SYSTEM SET citus.distributed_deadlock_detection_factor TO -1; ALTER SYSTEM SET citus.recover_2pc_interval TO -1; ALTER SYSTEM set citus.enable_statistics_collection TO false; +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; SELECT pg_reload_conf(); -- Add some helper functions for sending commands to mitmproxy diff --git a/src/test/regress/sql/minimal_cluster_management.sql b/src/test/regress/sql/minimal_cluster_management.sql index 30f69d43d..360931eba 100644 --- a/src/test/regress/sql/minimal_cluster_management.sql +++ b/src/test/regress/sql/minimal_cluster_management.sql @@ -41,3 +41,6 @@ DROP TABLE test_dist; ALTER SEQUENCE pg_catalog.pg_dist_node_nodeid_seq RESTART 30; ALTER SEQUENCE pg_catalog.pg_dist_groupid_seq RESTART 18; ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 83; +-- enable ddl propagation in all nodes +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); diff --git a/src/test/regress/sql/multi_cluster_management.sql b/src/test/regress/sql/multi_cluster_management.sql index a1e0e9b09..21c0a62d4 100644 --- a/src/test/regress/sql/multi_cluster_management.sql +++ b/src/test/regress/sql/multi_cluster_management.sql @@ -546,3 +546,6 @@ SELECT bool_and(hasmetadata) AND bool_and(metadatasynced) FROM pg_dist_node WHER -- keep permissions compatible accross versions, in regression -- tests. GRANT ALL ON SCHEMA public TO PUBLIC; +-- enable ddl propagation in all nodes +SELECT result from run_command_on_all_nodes('ALTER SYSTEM SET citus.enable_ddl_propagation TO ON'); +SELECT result from run_command_on_all_nodes('SELECT pg_reload_conf()'); diff --git a/src/test/regress/sql/multi_follower_sanity_check.sql b/src/test/regress/sql/multi_follower_sanity_check.sql index 3059b9f9f..bdd0f5b55 100644 --- a/src/test/regress/sql/multi_follower_sanity_check.sql +++ b/src/test/regress/sql/multi_follower_sanity_check.sql @@ -1,4 +1,16 @@ -- check that the nodes are all in read-only mode and rejecting write queries +\c - - - :follower_master_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + +\c - - - :follower_worker_1_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + +\c - - - :follower_worker_2_port +ALTER SYSTEM SET citus.enable_ddl_propagation = 'true'; +SELECT pg_reload_conf(); + \c - - - :follower_master_port CREATE TABLE tab (a int); diff --git a/src/test/regress/sql/pg15.sql b/src/test/regress/sql/pg15.sql index 96eec9bb2..a3164894d 100644 --- a/src/test/regress/sql/pg15.sql +++ b/src/test/regress/sql/pg15.sql @@ -997,3 +997,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;