diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-17 20:14:09 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-17 20:14:09 +0000 |
commit | 19de9d2fee9ea6939f8ed1cd7e52e190d3197ba4 (patch) | |
tree | f4f0d8c24e0f27ad3b9643f0fbe77d7e1b07a24d | |
parent | 0a49e774b1ba172b9d2387152bb843ea7fb3c622 (diff) | |
download | postgresql-19de9d2fee9ea6939f8ed1cd7e52e190d3197ba4.tar.gz postgresql-19de9d2fee9ea6939f8ed1cd7e52e190d3197ba4.zip |
For COMMENT ON DATABASE where database name is unknown or not the current
database, emit a WARNING and do nothing, rather than raising ERROR.
Per recent discussion in which we concluded this is the best way to deal
with database dumps that are reloaded into a database of a new name.
-rw-r--r-- | src/backend/commands/comment.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index bff639cf261..bdc126e6680 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -7,7 +7,7 @@ * Copyright (c) 1996-2001, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.61 2002/10/09 16:26:46 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.61.2.1 2003/07/17 20:14:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -403,21 +403,39 @@ CommentDatabase(List *qualname, char *comment) elog(ERROR, "CommentDatabase: database name may not be qualified"); database = strVal(lfirst(qualname)); + /* + * We cannot currently support cross-database comments (since other DBs + * cannot see pg_description of this database). So, we reject attempts + * to comment on a database other than the current one. Someday this + * might be improved, but it would take a redesigned infrastructure. + * + * When loading a dump, we may see a COMMENT ON DATABASE for the old name + * of the database. Erroring out would prevent pg_restore from completing + * (which is really pg_restore's fault, but for now we will work around + * the problem here). Consensus is that the best fix is to treat wrong + * database name as a WARNING not an ERROR. + */ + /* First get the database OID */ oid = get_database_oid(database); if (!OidIsValid(oid)) - elog(ERROR, "database \"%s\" does not exist", database); + { + elog(WARNING, "database \"%s\" does not exist", database); + return; + } - /* Allow if the user matches the database dba or is a superuser */ + /* Only allow comments on the current database */ + if (oid != MyDatabaseId) + { + elog(WARNING, "Database comments may only be applied to the current database"); + return; + } + /* Allow if the user matches the database dba or is a superuser */ if (!(superuser() || is_dbadmin(oid))) elog(ERROR, "you are not permitted to comment on database \"%s\"", database); - /* Only allow comments on the current database */ - if (oid != MyDatabaseId) - elog(ERROR, "Database comments may only be applied to the current database"); - /* Create the comment with the pg_database oid */ CreateComments(oid, RelOid_pg_database, 0, comment); } |