Commit 0d4e6ed3 authored by Tom Lane's avatar Tom Lane

Clean up some aspects of pg_dump/pg_restore item-selection logic.

Ensure that CREATE DATABASE and related commands are issued when, and
only when, --create is specified.  Previously there were scenarios
where using selective-dump switches would prevent --create from having
any effect.  For example, it would fail to do anything in pg_restore
if the archive file had been made by a selective dump, because there
would be no TOC entry for the database.

Since we don't issue \connect either if we don't issue CREATE DATABASE,
this could result in unexpectedly restoring objects into the wrong
database.

Also fix pg_restore's selective restore logic so that when an object is
selected to be restored, we also restore its ACL, comment, and security
label if any.  Previously there was no way to get the latter properties
except through tedious mucking about with a -L file.  If, for some
reason, you don't want these properties, you can match the old behavior
by adding --no-acl etc.

While at it, try to make _tocEntryRequired() a little better organized
and better documented.

Discussion: https://postgr.es/m/32668.1516848577@sss.pgh.pa.us
parent 05fb5d66
......@@ -446,6 +446,11 @@
flag of <application>pg_dump</application>. There is not currently
any provision for wild-card matching in <application>pg_restore</application>,
nor can you include a schema name within its <option>-t</option>.
And, while <application>pg_dump</application>'s <option>-t</option>
flag will also dump subsidiary objects (such as indexes) of the
selected table(s),
<application>pg_restore</application>'s <option>-t</option>
flag does not include such subsidiary objects.
</para>
</note>
......@@ -564,7 +569,7 @@
<listitem>
<para>
Use conditional commands (i.e. add an <literal>IF EXISTS</literal>
clause) when cleaning database objects. This option is not valid
clause) to drop database objects. This option is not valid
unless <option>--clean</option> is also specified.
</para>
</listitem>
......
This diff is collapsed.
......@@ -631,6 +631,13 @@ main(int argc, char **argv)
compressLevel = 0;
#endif
/*
* If emitting an archive format, we always want to emit a DATABASE item,
* in case --create is specified at pg_restore time.
*/
if (!plainText)
dopt.outputCreateDB = 1;
/*
* On Windows we can only have at most MAXIMUM_WAIT_OBJECTS (= 64 usually)
* parallel jobs because that's the maximum limit for the
......@@ -841,7 +848,7 @@ main(int argc, char **argv)
dumpStdStrings(fout);
/* The database items are always next, unless we don't want them at all */
if (dopt.include_everything && !dopt.dataOnly)
if (dopt.outputCreateDB)
dumpDatabase(fout);
/* Now the rearrangeable objects. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment