Repository: incubator-hawq Updated Branches: refs/heads/HAWQ-369 a23f631da -> f63652ab9 (forced update)
HAWQ-369. Hcatalog as reserved name. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/f63652ab Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/f63652ab Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/f63652ab Branch: refs/heads/HAWQ-369 Commit: f63652ab99cc3d4f3568849201b497dc83fc1291 Parents: 226a55c Author: Oleksandr Diachenko <odiache...@pivotal.io> Authored: Thu Jan 28 19:31:02 2016 -0800 Committer: Oleksandr Diachenko <odiache...@pivotal.io> Committed: Tue Feb 2 13:21:41 2016 -0800 ---------------------------------------------------------------------- doc/src/sgml/ref/alter_database.sgml | 10 ++++++ doc/src/sgml/ref/create_database.sgml | 4 +++ src/backend/commands/dbcommands.c | 28 +++++++++++++++-- src/backend/utils/init/postinit.c | 16 ++++++++++ src/test/regress/input/hcatalog_lookup.source | 35 +++++++++++++++++++++ src/test/regress/output/hcatalog_lookup.source | 29 +++++++++++++++++ 6 files changed, 119 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/doc/src/sgml/ref/alter_database.sgml ---------------------------------------------------------------------- diff --git a/doc/src/sgml/ref/alter_database.sgml b/doc/src/sgml/ref/alter_database.sgml index 8ddff97..1452e9a 100755 --- a/doc/src/sgml/ref/alter_database.sgml +++ b/doc/src/sgml/ref/alter_database.sgml @@ -154,6 +154,16 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <repla User-specific settings override database-specific ones if there is a conflict. </para> + + <para> + Currently RENAME TO is supported only when called by pgdump utility. + </para> + <para> + User can not use "hcatalog" as a name for database, because it's reserved for Hcatalog integration feature. + </para> + <para> + User can not rename "hcatalog" database, because it's reserved for Hcatalog integration feature. + </para> </refsect1> <refsect1> http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/doc/src/sgml/ref/create_database.sgml ---------------------------------------------------------------------- diff --git a/doc/src/sgml/ref/create_database.sgml b/doc/src/sgml/ref/create_database.sgml index 3183e2a..0e28619 100755 --- a/doc/src/sgml/ref/create_database.sgml +++ b/doc/src/sgml/ref/create_database.sgml @@ -184,6 +184,10 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> connection <quote>slot</> remains for the database, it is possible that both will fail. Also, the limit is not enforced against superusers. </para> + + <para> + User can not create database named "hcatalog", because it's reserved for Hcatalog feature integration. + </para> </refsect1> <refsect1> http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/src/backend/commands/dbcommands.c ---------------------------------------------------------------------- diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index f80e01a..635d986 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -848,11 +848,18 @@ createdb(CreatedbStmt *stmt) * Check for db name conflict. This is just to give a more friendly error * message than "unique index violation". There's a race condition but * we're willing to accept the less friendly message in that case. + * Also check that user is not trying to use "hcatalog" as a database name, + * because it's already reserved for hcatalog feature integration. */ if (OidIsValid(get_database_oid(dbname))) - ereport(ERROR, - (errcode(ERRCODE_DUPLICATE_DATABASE), - errmsg("database \"%s\" already exists", dbname))); + if (strcmp(dbname, HcatalogDbName) == 0) + ereport(ERROR, + (errcode(ERRCODE_RESERVED_NAME), + errmsg("\"%s\" is a reserved name for hcatalog feature integration", HcatalogDbName))); + else + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_DATABASE), + errmsg("database \"%s\" already exists", dbname))); /* * Select an OID for the new database, checking that it doesn't have @@ -1533,6 +1540,14 @@ RenameDatabase(const char *oldname, const char *newname) cqContext cqc; cqContext *pcqCtx; + + /* + * Make sure "hcatalog" is not used as new name, because it's reserved for + * hcatalog feature integration*/ + if (strcmp(newname, HcatalogDbName) == 0) + ereport(ERROR, + (errcode(ERRCODE_RESERVED_NAME), + errmsg("\"%s\" is a reserved name for hcatalog feature integration", HcatalogDbName))); /* * Look up the target database's OID, and get exclusive lock on it. We * need this for the same reasons as DROP DATABASE. @@ -1555,6 +1570,13 @@ RenameDatabase(const char *oldname, const char *newname) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("current database may not be renamed"))); + /* + * "hcatalog" database cannot be renamed + * */ + if (db_id == HcatalogDbOid) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("permission denied to ALTER DATABASE \"%s\" is reserved for system use", HcatalogDbName))); /* * Make sure the database does not have active sessions. This is the same http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/src/backend/utils/init/postinit.c ---------------------------------------------------------------------- diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index e4d0752..57848e1 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -368,6 +368,22 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, char dbname[NAMEDATALEN]; /* + * User is not supposed to connect to hcatalog database, + * because it's reserved for hcatalog feature integration + */ + if (!bootstrap) + { + if (strcmp(in_dbname, HcatalogDbName) == 0) + { + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_DATABASE), + errmsg("\"%s\" database is only for system use", + HcatalogDbName))); + } + } + + + /* * Set up the global variables holding database id and path. But note we * won't actually try to touch the database just yet. * http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/src/test/regress/input/hcatalog_lookup.source ---------------------------------------------------------------------- diff --git a/src/test/regress/input/hcatalog_lookup.source b/src/test/regress/input/hcatalog_lookup.source index a011abf..e295449 100644 --- a/src/test/regress/input/hcatalog_lookup.source +++ b/src/test/regress/input/hcatalog_lookup.source @@ -138,16 +138,51 @@ alter table test_schema.p exchange partition p1 with table hcatalog.test_schema. select pg_catalog.pg_database_size('hcatalog'); select pg_catalog.pg_database_size(6120); +--positive test: should be able to create table named "hcatalog" +CREATE TABLE hcatalog(a int); + +--negative test: cannot create database named "hcatalog" +CREATE DATABASE hcatalog; + +--allow renaming schemas and databases +SET gp_called_by_pgdump = true; + +--negative test: cannot rename exiting database to "hcatalog" +ALTER DATABASE regression RENAME TO hcatalog; + +--positive test: can rename exiting schema to "hcatalog" +CREATE SCHEMA test_schema3; +ALTER SCHEMA test_schema3 RENAME to hcatalog; +ALTER SCHEMA hcatalog RENAME to hcatalog1; + +--positive test: should be able to create schema named "hcatalog" +CREATE SCHEMA hcatalog; + +--positive test: can rename schema "hcatalog" +ALTER SCHEMA hcatalog RENAME to hcatalog2; + +--negative test: cannot create a database using "hcatalog" as a template +CREATE DATABASE hcatalog2 TEMPLATE hcatalog; + +--restrict renaming schemas and databases +SET gp_called_by_pgdump = false; + -- cleanup DROP schema test_schema cascade; SELECT convert_to_internal_schema('test_schema'); DROP schema test_schema cascade; DROP schema test_schema2 cascade; +DROP schema hcatalog1 cascade; +DROP schema hcatalog2 cascade; select nspname,nspdboid from pg_namespace where nspname='test_schema'; DROP FUNCTION convert_to_hcatalog_schema(text); DROP FUNCTION convert_to_internal_schema(text); DROP FUNCTION trigger_func(); DROP USER newuser; +DROP TABLE hcatalog; -- disable GUC SET hcatalog_enable = false; + +--negative test: cannot connect to "hcatalog" database +\connect hcatalog; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f63652ab/src/test/regress/output/hcatalog_lookup.source ---------------------------------------------------------------------- diff --git a/src/test/regress/output/hcatalog_lookup.source b/src/test/regress/output/hcatalog_lookup.source index 8708e59..b28b665 100644 --- a/src/test/regress/output/hcatalog_lookup.source +++ b/src/test/regress/output/hcatalog_lookup.source @@ -266,6 +266,29 @@ select pg_catalog.pg_database_size('hcatalog'); ERROR: database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC) select pg_catalog.pg_database_size(6120); ERROR: database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC) +--positive test: should be able to create table named "hcatalog" +CREATE TABLE hcatalog(a int); +--negative test: cannot create database named "hcatalog" +CREATE DATABASE hcatalog; +ERROR: "hcatalog" is a reserved name for hcatalog feature integration +--allow renaming schemas and databases +SET gp_called_by_pgdump = true; +--negative test: cannot rename exiting database to "hcatalog" +ALTER DATABASE regression RENAME TO hcatalog; +ERROR: "hcatalog" is a reserved name for hcatalog feature integration +--positive test: can rename exiting schema to "hcatalog" +CREATE SCHEMA test_schema3; +ALTER SCHEMA test_schema3 RENAME to hcatalog; +ALTER SCHEMA hcatalog RENAME to hcatalog1; +--positive test: should be able to create schema named "hcatalog" +CREATE SCHEMA hcatalog; +--positive test: can rename schema "hcatalog" +ALTER SCHEMA hcatalog RENAME to hcatalog2; +--negative test: cannot create a database using "hcatalog" as a template +CREATE DATABASE hcatalog2 TEMPLATE hcatalog; +ERROR: copy non template database is not supported +--restrict renaming schemas and databases +SET gp_called_by_pgdump = false; -- cleanup DROP schema test_schema cascade; NOTICE: drop cascades to append only table test_schema.r @@ -286,6 +309,8 @@ NOTICE: drop cascades to append only table test_schema.tt NOTICE: drop cascades to append only table test_schema.t NOTICE: drop cascades to append only table test_schema.r DROP schema test_schema2 cascade; +DROP schema hcatalog1 cascade; +DROP schema hcatalog2 cascade; select nspname,nspdboid from pg_namespace where nspname='test_schema'; nspname | nspdboid ---------+---------- @@ -295,5 +320,9 @@ DROP FUNCTION convert_to_hcatalog_schema(text); DROP FUNCTION convert_to_internal_schema(text); DROP FUNCTION trigger_func(); DROP USER newuser; +DROP TABLE hcatalog; -- disable GUC SET hcatalog_enable = false; +--negative test: cannot connect to "hcatalog" database +\connect hcatalog; +\connect: FATAL: "hcatalog" database is only for system use