diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index a668c9ba6..c92191774 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -24,6 +24,7 @@ #include "distributed/commands.h" #include "distributed/commands/utility_hook.h" #include "distributed/deparser.h" +#include "distributed/metadata/distobject.h" #include "distributed/metadata_sync.h" #include "distributed/metadata_utility.h" #include "distributed/multi_executor.h" @@ -32,6 +33,8 @@ static AlterOwnerStmt * RecreateAlterDatabaseOwnerStmt(Oid databaseOid); static Oid get_database_owner(Oid db_oid); +static ObjectAddress * GetDatabaseAddressFromDatabaseName(char *databaseName, + bool missingOk); List * PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext); @@ -161,13 +164,15 @@ List * PreprocessAlterDatabaseStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext) { - if (!ShouldPropagate()) + AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, node); + bool missingOk = false; + ObjectAddress *dbAddress = GetDatabaseAddressFromDatabaseName(stmt->dbname, + missingOk); + if (!ShouldPropagate() || !IsAnyObjectDistributed(list_make1(dbAddress))) { return NIL; } - AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, node); - EnsureCoordinator(); char *sql = DeparseTreeNode((Node *) stmt); @@ -213,3 +218,17 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString, #endif + + +/* + * GetDatabaseAddressFromDatabaseName gets the database name and returns the ObjectAddress + * of the database. + */ +static ObjectAddress * +GetDatabaseAddressFromDatabaseName(char *databaseName, bool missingOk) +{ + Oid databaseOid = get_database_oid(databaseName, missingOk); + ObjectAddress *dbObjectAddress = palloc0(sizeof(ObjectAddress)); + ObjectAddressSet(*dbObjectAddress, DatabaseRelationId, databaseOid); + return dbObjectAddress; +} diff --git a/src/test/regress/expected/alter_database_propagation.out b/src/test/regress/expected/alter_database_propagation.out index b7d04c50f..b8a3a0ae9 100644 --- a/src/test/regress/expected/alter_database_propagation.out +++ b/src/test/regress/expected/alter_database_propagation.out @@ -33,4 +33,11 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -- this statement will get error since we don't have a multiple database support for now alter database regression rename to regression2; ERROR: current database cannot be renamed +-- this database is not distributed so we will not see any remote commands +CREATE DATABASE db_to_test; +NOTICE: Citus partially supports CREATE DATABASE for distributed databases +DETAIL: Citus does not propagate CREATE DATABASE command to workers +HINT: You can manually create a database and its extensions on workers. +alter database db_to_test with CONNECTION LIMIT 100; +DROP DATABASE db_to_test; set citus.log_remote_commands = false; diff --git a/src/test/regress/sql/alter_database_propagation.sql b/src/test/regress/sql/alter_database_propagation.sql index 748a66ddd..ace558cec 100644 --- a/src/test/regress/sql/alter_database_propagation.sql +++ b/src/test/regress/sql/alter_database_propagation.sql @@ -15,4 +15,9 @@ alter database regression with IS_TEMPLATE false; -- this statement will get error since we don't have a multiple database support for now alter database regression rename to regression2; +-- this database is not distributed so we will not see any remote commands +CREATE DATABASE db_to_test; +alter database db_to_test with CONNECTION LIMIT 100; +DROP DATABASE db_to_test; + set citus.log_remote_commands = false;