Skip to content
Snippets Groups Projects
Commit 0c172909 authored by Tom Lane's avatar Tom Lane
Browse files

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.
parent 8cf63ba9
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment