mirror of
https://github.com/postgres/postgres.git
synced 2026-05-19 16:57:03 -04:00
Reject invalid databases in pg_get_database_ddl()
An invalid database has datconnlimit set to -2. pg_get_database_ddl() emits this verbatim as CONNECTION LIMIT = -2, which ALTER DATABASE rejects. Error out early instead. Reported-by: Lakshmi N <lakshmin.jhs@gmail.com> Author: Lakshmi N <lakshmin.jhs@gmail.com> Reviewed-by: Amit Langote <amitlangote09@gmail.com> Reviewed-by: Euler Taveira <euler@eulerto.com> Reviewed-by: Hu Xunqi <huxunqi.08@gmail.com> Discussion: https://postgr.es/m/CA+3i_M8m1k2gFch+tU0JmAQh9FRV+pFrfTXDrJo+BqmwsTmOhg@mail.gmail.com
This commit is contained in:
parent
f3c28c2f2b
commit
cda0c4c5d6
1 changed files with 10 additions and 0 deletions
|
|
@ -887,6 +887,16 @@ pg_get_database_ddl_internal(Oid dbid, bool pretty,
|
|||
dbform = (Form_pg_database) GETSTRUCT(tuple);
|
||||
dbname = pstrdup(NameStr(dbform->datname));
|
||||
|
||||
/*
|
||||
* Reject invalid databases. Deparsing a pg_database row in invalid state
|
||||
* can produce SQL that is not executable, such as CONNECTION LIMIT = -2.
|
||||
*/
|
||||
if (database_is_invalid_form(dbform))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot generate DDL for invalid database \"%s\"",
|
||||
dbname)));
|
||||
|
||||
/*
|
||||
* We don't support generating DDL for system databases. The primary
|
||||
* reason for this is that users shouldn't be recreating them.
|
||||
|
|
|
|||
Loading…
Reference in a new issue