mirror of https://github.com/citusdata/citus.git
Adds locale restrictions
parent
d99737e8b2
commit
d8639d58de
|
@ -263,6 +263,23 @@ PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString,
|
|||
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
|
||||
}
|
||||
|
||||
List *
|
||||
PreprocessCreateDatabaseStmt(Node *node, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext)
|
||||
{
|
||||
if (!EnableCreateDatabasePropagation || !ShouldPropagate())
|
||||
{
|
||||
return NIL;
|
||||
}
|
||||
|
||||
EnsureCoordinator();
|
||||
|
||||
//Validate the statement
|
||||
DeparseTreeNode(node);
|
||||
|
||||
return NIL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* PostprocessCreatedbStmt is executed after the statement is applied to the local
|
||||
|
|
|
@ -469,7 +469,7 @@ static DistributeObjectOps Database_Alter = {
|
|||
static DistributeObjectOps Database_Create = {
|
||||
.deparse = DeparseCreateDatabaseStmt,
|
||||
.qualify = NULL,
|
||||
.preprocess = NULL,
|
||||
.preprocess = PreprocessCreateDatabaseStmt,
|
||||
.postprocess = PostprocessCreateDatabaseStmt,
|
||||
.objectType = OBJECT_DATABASE,
|
||||
.operationType = DIST_OPS_CREATE,
|
||||
|
|
|
@ -237,6 +237,21 @@ AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
|
|||
|
||||
foreach_ptr(option, stmt->options)
|
||||
{
|
||||
//If option is template, lc_type, locale or lc_collate, propagation will not be supportted
|
||||
// since template database is not stored in the catalog
|
||||
if (strcmp(option->defname, "template") == 0 ||
|
||||
strcmp(option->defname, "strategy") == 0 ||
|
||||
strcmp(option->defname, "lc_ctype") == 0 ||
|
||||
strcmp(option->defname, "locale") == 0 ||
|
||||
strcmp(option->defname, "lc_collate") == 0 ||
|
||||
strcmp(option->defname, "icu_locale") == 0 ||
|
||||
strcmp(option->defname, "locale_provider") == 0 )
|
||||
{
|
||||
ereport(ERROR,
|
||||
errmsg("CREATE DATABASE option \"%s\" is not supported",
|
||||
option->defname));
|
||||
}
|
||||
|
||||
optionToStatement(buf, option, create_database_option_formats, lengthof(
|
||||
create_database_option_formats));
|
||||
}
|
||||
|
|
|
@ -237,6 +237,8 @@ extern List * CreateDatabaseStmtObjectAddress(Node *node, bool missing_ok, bool
|
|||
extern List * PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext);
|
||||
|
||||
extern List * PreprocessCreateDatabaseStmt(Node *node, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext);
|
||||
extern List * PostprocessCreateDatabaseStmt(Node *node, const char *queryString);
|
||||
extern List * PreprocessDropDatabaseStmt(Node *node, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext);
|
||||
|
|
|
@ -14,11 +14,8 @@ create user create_drop_db_test_user;
|
|||
set citus.enable_create_database_propagation=on;
|
||||
CREATE DATABASE mydatabase
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
TEMPLATE = 'template0'
|
||||
ENCODING = 'UTF8'
|
||||
CONNECTION LIMIT = 10
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false;
|
||||
|
@ -74,12 +71,9 @@ select 1 from citus_remove_node('localhost', :worker_2_port);
|
|||
|
||||
--test with is_template true and allow connections false
|
||||
CREATE DATABASE mydatabase
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
@ -161,11 +155,8 @@ SELECT result from run_command_on_all_nodes(
|
|||
|
||||
-- create a template database with all options set and allow connections false
|
||||
CREATE DATABASE my_template_database
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = true;
|
||||
|
@ -248,6 +239,35 @@ NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2"
|
|||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2"
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
--test for unsupported options
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_CTYPE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
ERROR: CREATE DATABASE option "lc_ctype" is not supported
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_CTYPE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
ERROR: CREATE DATABASE option "lc_ctype" is not supported
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
ERROR: CREATE DATABASE option "lc_collate" is not supported
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LOCALE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
ERROR: CREATE DATABASE option "locale" is not supported
|
||||
--clean up resources created by this test
|
||||
drop tablespace create_drop_db_tablespace;
|
||||
\c - - - :worker_1_port
|
||||
|
|
|
@ -23,24 +23,17 @@ set citus.enable_create_database_propagation=on;
|
|||
SET citus.log_remote_commands = true;
|
||||
set citus.grep_remote_commands = '%CREATE DATABASE%';
|
||||
CREATE DATABASE mydatabase
|
||||
WITH TEMPLATE = 'template0'
|
||||
WITH
|
||||
OWNER = create_drop_db_test_user
|
||||
CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = ''
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
ICU_LOCALE = 'und'
|
||||
LOCALE_PROVIDER = 'icu'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false
|
||||
OID = 966345;
|
||||
NOTICE: issuing CREATE DATABASE mydatabase TEMPLATE template0 OWNER create_drop_db_test_user CONNECTION LIMIT 10 ENCODING 'UTF8' STRATEGY 'wal_log' LOCALE '' LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' ICU_LOCALE 'und' LOCALE_PROVIDER 'icu' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
NOTICE: issuing CREATE DATABASE mydatabase OWNER create_drop_db_test_user CONNECTION LIMIT 10 ENCODING 'UTF8' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
NOTICE: issuing CREATE DATABASE mydatabase TEMPLATE template0 OWNER create_drop_db_test_user CONNECTION LIMIT 10 ENCODING 'UTF8' STRATEGY 'wal_log' LOCALE '' LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' ICU_LOCALE 'und' LOCALE_PROVIDER 'icu' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
NOTICE: issuing CREATE DATABASE mydatabase OWNER create_drop_db_test_user CONNECTION LIMIT 10 ENCODING 'UTF8' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
SET citus.log_remote_commands = false;
|
||||
SELECT result from run_command_on_all_nodes(
|
||||
|
@ -104,16 +97,11 @@ set citus.grep_remote_commands = '%CREATE DATABASE%';
|
|||
CREATE DATABASE mydatabase2
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = 'en_US.utf8'
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false
|
||||
OID = 966345;
|
||||
NOTICE: issuing CREATE DATABASE mydatabase2 OWNER create_drop_db_test_user ENCODING 'UTF8' STRATEGY 'wal_log' LOCALE 'en_US.utf8' LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
NOTICE: issuing CREATE DATABASE mydatabase2 OWNER create_drop_db_test_user ENCODING 'UTF8' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS true IS_TEMPLATE false OID 966345
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
SET citus.log_remote_commands = false;
|
||||
SELECT result from run_command_on_all_nodes(
|
||||
|
@ -196,22 +184,15 @@ SET citus.log_remote_commands = true;
|
|||
set citus.grep_remote_commands = '%CREATE DATABASE%';
|
||||
-- create a template database with all options set and allow connections false
|
||||
CREATE DATABASE my_template_database
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = 'en_US.utf8'
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
ICU_LOCALE = 'en-US'
|
||||
LOCALE_PROVIDER = 'icu'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = true;
|
||||
NOTICE: issuing CREATE DATABASE my_template_database TEMPLATE template0 OWNER create_drop_db_test_user ENCODING 'UTF8' STRATEGY 'wal_log' LOCALE 'en_US.utf8' LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' ICU_LOCALE 'en-US' LOCALE_PROVIDER 'icu' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS false IS_TEMPLATE true
|
||||
NOTICE: issuing CREATE DATABASE my_template_database OWNER create_drop_db_test_user ENCODING 'UTF8' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS false IS_TEMPLATE true
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
NOTICE: issuing CREATE DATABASE my_template_database TEMPLATE template0 OWNER create_drop_db_test_user ENCODING 'UTF8' STRATEGY 'wal_log' LOCALE 'en_US.utf8' LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' ICU_LOCALE 'en-US' LOCALE_PROVIDER 'icu' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS false IS_TEMPLATE true
|
||||
NOTICE: issuing CREATE DATABASE my_template_database OWNER create_drop_db_test_user ENCODING 'UTF8' COLLATION_VERSION '1.0' TABLESPACE create_drop_db_tablespace ALLOW_CONNECTIONS false IS_TEMPLATE true
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
SET citus.log_remote_commands = false;
|
||||
SELECT result from run_command_on_all_nodes(
|
||||
|
@ -235,10 +216,6 @@ SELECT result from run_command_on_all_nodes(
|
|||
[{"datacl": null, "datname": "my_template_database", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "create_drop_db_tablespace", "datallowconn": false, "datconnlimit": -1, "datistemplate": true, "database_owner": "create_drop_db_test_user"}]
|
||||
(3 rows)
|
||||
|
||||
SET citus.log_remote_commands = true;
|
||||
set citus.grep_remote_commands = '%DROP DATABASE%';
|
||||
drop database my_template_database;
|
||||
ERROR: cannot drop a template database
|
||||
SET citus.log_remote_commands = false;
|
||||
SELECT result from run_command_on_all_nodes(
|
||||
$$
|
||||
|
@ -275,7 +252,6 @@ SELECT result from run_command_on_all_nodes(
|
|||
UPDATE 1
|
||||
(3 rows)
|
||||
|
||||
;
|
||||
set citus.grep_remote_commands = '%DROP DATABASE%';
|
||||
drop database my_template_database;
|
||||
NOTICE: issuing DROP DATABASE my_template_database
|
||||
|
|
|
@ -21,17 +21,12 @@ set citus.enable_create_database_propagation=on;
|
|||
|
||||
CREATE DATABASE mydatabase
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
TEMPLATE = 'template0'
|
||||
ENCODING = 'UTF8'
|
||||
CONNECTION LIMIT = 10
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false;
|
||||
|
||||
|
||||
|
||||
SELECT result from run_command_on_all_nodes(
|
||||
$$
|
||||
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
|
||||
|
@ -73,12 +68,9 @@ select 1 from citus_remove_node('localhost', :worker_2_port);
|
|||
|
||||
--test with is_template true and allow connections false
|
||||
CREATE DATABASE mydatabase
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
@ -139,11 +131,8 @@ SELECT result from run_command_on_all_nodes(
|
|||
|
||||
-- create a template database with all options set and allow connections false
|
||||
CREATE DATABASE my_template_database
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C'
|
||||
LC_CTYPE = 'C'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = true;
|
||||
|
@ -203,6 +192,37 @@ create database "mydatabase#1'2";
|
|||
set citus.grep_remote_commands = '%DROP DATABASE%';
|
||||
drop database if exists "mydatabase#1'2";
|
||||
|
||||
--test for unsupported options
|
||||
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_CTYPE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_CTYPE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LC_COLLATE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
||||
CREATE DATABASE mydatabase
|
||||
with CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
LOCALE = 'C.UTF-8'
|
||||
ALLOW_CONNECTIONS = false
|
||||
IS_TEMPLATE = false;
|
||||
|
||||
|
||||
--clean up resources created by this test
|
||||
|
||||
drop tablespace create_drop_db_tablespace;
|
||||
|
|
|
@ -29,17 +29,10 @@ set citus.enable_create_database_propagation=on;
|
|||
SET citus.log_remote_commands = true;
|
||||
set citus.grep_remote_commands = '%CREATE DATABASE%';
|
||||
CREATE DATABASE mydatabase
|
||||
WITH TEMPLATE = 'template0'
|
||||
WITH
|
||||
OWNER = create_drop_db_test_user
|
||||
CONNECTION LIMIT = 10
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = ''
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
ICU_LOCALE = 'und'
|
||||
LOCALE_PROVIDER = 'icu'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false
|
||||
|
@ -91,11 +84,6 @@ set citus.grep_remote_commands = '%CREATE DATABASE%';
|
|||
CREATE DATABASE mydatabase2
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = 'en_US.utf8'
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = true
|
||||
IS_TEMPLATE = false
|
||||
|
@ -161,15 +149,8 @@ set citus.grep_remote_commands = '%CREATE DATABASE%';
|
|||
|
||||
-- create a template database with all options set and allow connections false
|
||||
CREATE DATABASE my_template_database
|
||||
WITH TEMPLATE = 'template0'
|
||||
OWNER = create_drop_db_test_user
|
||||
WITH OWNER = create_drop_db_test_user
|
||||
ENCODING = 'UTF8'
|
||||
STRATEGY = 'wal_log'
|
||||
LOCALE = 'en_US.utf8'
|
||||
LC_COLLATE = 'POSIX'
|
||||
LC_CTYPE = 'POSIX'
|
||||
ICU_LOCALE = 'en-US'
|
||||
LOCALE_PROVIDER = 'icu'
|
||||
COLLATION_VERSION = '1.0'
|
||||
TABLESPACE = create_drop_db_tablespace
|
||||
ALLOW_CONNECTIONS = false
|
||||
|
@ -192,9 +173,6 @@ SELECT result from run_command_on_all_nodes(
|
|||
$$
|
||||
) ORDER BY result;
|
||||
|
||||
SET citus.log_remote_commands = true;
|
||||
set citus.grep_remote_commands = '%DROP DATABASE%';
|
||||
drop database my_template_database;
|
||||
|
||||
SET citus.log_remote_commands = false;
|
||||
|
||||
|
@ -222,7 +200,6 @@ SELECT result from run_command_on_all_nodes(
|
|||
$$
|
||||
) ORDER BY result;
|
||||
|
||||
;
|
||||
|
||||
set citus.grep_remote_commands = '%DROP DATABASE%';
|
||||
drop database my_template_database;
|
||||
|
|
Loading…
Reference in New Issue