Commit 4fafa579 authored by Stephen Frost's avatar Stephen Frost

Add --no-blobs option to pg_dump

Add an option to exclude blobs when running pg_dump.  By default, blobs
are included but this option can be used to exclude them while keeping
the rest of the dump.

Commment updates and regression tests from me.

Author: Guillaume Lelarge
Reviewed-by: Amul Sul
Discussion: https://postgr.es/m/VisenaEmail.48.49926ea6f91dceb6.15355a48249@tc7-visena
parent d6c8b34e
......@@ -147,6 +147,22 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>-B</></term>
<term><option>--no-blobs</></term>
<listitem>
<para>
Exclude large objects in the dump.
</para>
<para>
When both <option>-b</> and <option>-B</> are given, the behavior
is to output large objects, when data is being dumped, see the
<option>-b</> documentation.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<term><option>--clean</option></term>
......
......@@ -159,6 +159,7 @@ typedef struct _dumpOptions
int outputClean;
int outputCreateDB;
bool outputBlobs;
bool dontOutputBlobs;
int outputNoOwner;
char *outputSuperuser;
......
......@@ -291,6 +291,7 @@ main(int argc, char **argv)
static struct option long_options[] = {
{"data-only", no_argument, NULL, 'a'},
{"blobs", no_argument, NULL, 'b'},
{"no-blobs", no_argument, NULL, 'B'},
{"clean", no_argument, NULL, 'c'},
{"create", no_argument, NULL, 'C'},
{"dbname", required_argument, NULL, 'd'},
......@@ -379,7 +380,7 @@ main(int argc, char **argv)
InitDumpOptions(&dopt);
while ((c = getopt_long(argc, argv, "abcCd:E:f:F:h:j:n:N:oOp:RsS:t:T:U:vwWxZ:",
while ((c = getopt_long(argc, argv, "abBcCd:E:f:F:h:j:n:N:oOp:RsS:t:T:U:vwWxZ:",
long_options, &optindex)) != -1)
{
switch (c)
......@@ -392,6 +393,10 @@ main(int argc, char **argv)
dopt.outputBlobs = true;
break;
case 'B': /* Don't dump blobs */
dopt.dontOutputBlobs = true;
break;
case 'c': /* clean (i.e., drop) schema prior to create */
dopt.outputClean = 1;
break;
......@@ -713,10 +718,15 @@ main(int argc, char **argv)
/* non-matching exclusion patterns aren't an error */
/*
* Dumping blobs is now default unless we saw an inclusion switch or -s
* ... but even if we did see one of these, -b turns it back on.
* Dumping blobs is the default for dumps where an inclusion switch is not
* used (an "include everything" dump). -B can be used to exclude blobs
* from those dumps. -b can be used to include blobs even when an
* inclusion switch is used.
*
* -s means "schema only" and blobs are data, not schema, so we never
* include blobs when -s is used.
*/
if (dopt.include_everything && !dopt.schemaOnly)
if (dopt.include_everything && !dopt.schemaOnly && !dopt.dontOutputBlobs)
dopt.outputBlobs = true;
/*
......@@ -876,6 +886,7 @@ help(const char *progname)
printf(_("\nOptions controlling the output content:\n"));
printf(_(" -a, --data-only dump only the data, not the schema\n"));
printf(_(" -b, --blobs include large objects in dump\n"));
printf(_(" -B, --no-blobs exclude large objects in dump\n"));
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
printf(_(" -C, --create include commands to create database in dump\n"));
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
......
This diff is collapsed.
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