From 0c172909d567cdf95df1d920a4d9be4cf36dfc23 Mon Sep 17 00:00:00 2001 From: Tom Lane <tgl@sss.pgh.pa.us> Date: Thu, 17 Jul 2003 20:13:57 +0000 Subject: [PATCH] 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. --- src/backend/commands/comment.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index 99b1fadbcf8..13882dc6a6e 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.64 2003/07/04 02:51:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.65 2003/07/17 20:13:57 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 (!pg_database_ownercheck(oid, GetUserId())) 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); } -- GitLab