Skip to content

Commit 0c17290

Browse files
committed
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.
1 parent 8cf63ba commit 0c17290

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/backend/commands/comment.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.64 2003/07/04 02:51:33 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.65 2003/07/17 20:13:57 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -403,21 +403,39 @@ CommentDatabase(List *qualname, char *comment)
403403
elog(ERROR, "CommentDatabase: database name may not be qualified");
404404
database = strVal(lfirst(qualname));
405405

406+
/*
407+
* We cannot currently support cross-database comments (since other DBs
408+
* cannot see pg_description of this database). So, we reject attempts
409+
* to comment on a database other than the current one. Someday this
410+
* might be improved, but it would take a redesigned infrastructure.
411+
*
412+
* When loading a dump, we may see a COMMENT ON DATABASE for the old name
413+
* of the database. Erroring out would prevent pg_restore from completing
414+
* (which is really pg_restore's fault, but for now we will work around
415+
* the problem here). Consensus is that the best fix is to treat wrong
416+
* database name as a WARNING not an ERROR.
417+
*/
418+
406419
/* First get the database OID */
407420
oid = get_database_oid(database);
408421
if (!OidIsValid(oid))
409-
elog(ERROR, "database \"%s\" does not exist", database);
422+
{
423+
elog(WARNING, "database \"%s\" does not exist", database);
424+
return;
425+
}
410426

411-
/* Allow if the user matches the database dba or is a superuser */
427+
/* Only allow comments on the current database */
428+
if (oid != MyDatabaseId)
429+
{
430+
elog(WARNING, "database comments may only be applied to the current database");
431+
return;
432+
}
412433

434+
/* Allow if the user matches the database dba or is a superuser */
413435
if (!pg_database_ownercheck(oid, GetUserId()))
414436
elog(ERROR, "you are not permitted to comment on database \"%s\"",
415437
database);
416438

417-
/* Only allow comments on the current database */
418-
if (oid != MyDatabaseId)
419-
elog(ERROR, "Database comments may only be applied to the current database");
420-
421439
/* Create the comment with the pg_database oid */
422440
CreateComments(oid, RelOid_pg_database, 0, comment);
423441
}

0 commit comments

Comments
 (0)