Skip to content

Commit 4fafa57

Browse files
committed
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
1 parent d6c8b34 commit 4fafa57

File tree

4 files changed

+117
-5
lines changed

4 files changed

+117
-5
lines changed

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ PostgreSQL documentation
147147
</listitem>
148148
</varlistentry>
149149

150+
<varlistentry>
151+
<term><option>-B</></term>
152+
<term><option>--no-blobs</></term>
153+
<listitem>
154+
<para>
155+
Exclude large objects in the dump.
156+
</para>
157+
158+
<para>
159+
When both <option>-b</> and <option>-B</> are given, the behavior
160+
is to output large objects, when data is being dumped, see the
161+
<option>-b</> documentation.
162+
</para>
163+
</listitem>
164+
</varlistentry>
165+
150166
<varlistentry>
151167
<term><option>-c</option></term>
152168
<term><option>--clean</option></term>

src/bin/pg_dump/pg_backup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ typedef struct _dumpOptions
159159
int outputClean;
160160
int outputCreateDB;
161161
bool outputBlobs;
162+
bool dontOutputBlobs;
162163
int outputNoOwner;
163164
char *outputSuperuser;
164165

src/bin/pg_dump/pg_dump.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ main(int argc, char **argv)
291291
static struct option long_options[] = {
292292
{"data-only", no_argument, NULL, 'a'},
293293
{"blobs", no_argument, NULL, 'b'},
294+
{"no-blobs", no_argument, NULL, 'B'},
294295
{"clean", no_argument, NULL, 'c'},
295296
{"create", no_argument, NULL, 'C'},
296297
{"dbname", required_argument, NULL, 'd'},
@@ -379,7 +380,7 @@ main(int argc, char **argv)
379380

380381
InitDumpOptions(&dopt);
381382

382-
while ((c = getopt_long(argc, argv, "abcCd:E:f:F:h:j:n:N:oOp:RsS:t:T:U:vwWxZ:",
383+
while ((c = getopt_long(argc, argv, "abBcCd:E:f:F:h:j:n:N:oOp:RsS:t:T:U:vwWxZ:",
383384
long_options, &optindex)) != -1)
384385
{
385386
switch (c)
@@ -392,6 +393,10 @@ main(int argc, char **argv)
392393
dopt.outputBlobs = true;
393394
break;
394395

396+
case 'B': /* Don't dump blobs */
397+
dopt.dontOutputBlobs = true;
398+
break;
399+
395400
case 'c': /* clean (i.e., drop) schema prior to create */
396401
dopt.outputClean = 1;
397402
break;
@@ -713,10 +718,15 @@ main(int argc, char **argv)
713718
/* non-matching exclusion patterns aren't an error */
714719

715720
/*
716-
* Dumping blobs is now default unless we saw an inclusion switch or -s
717-
* ... but even if we did see one of these, -b turns it back on.
721+
* Dumping blobs is the default for dumps where an inclusion switch is not
722+
* used (an "include everything" dump). -B can be used to exclude blobs
723+
* from those dumps. -b can be used to include blobs even when an
724+
* inclusion switch is used.
725+
*
726+
* -s means "schema only" and blobs are data, not schema, so we never
727+
* include blobs when -s is used.
718728
*/
719-
if (dopt.include_everything && !dopt.schemaOnly)
729+
if (dopt.include_everything && !dopt.schemaOnly && !dopt.dontOutputBlobs)
720730
dopt.outputBlobs = true;
721731

722732
/*
@@ -876,6 +886,7 @@ help(const char *progname)
876886
printf(_("\nOptions controlling the output content:\n"));
877887
printf(_(" -a, --data-only dump only the data, not the schema\n"));
878888
printf(_(" -b, --blobs include large objects in dump\n"));
889+
printf(_(" -B, --no-blobs exclude large objects in dump\n"));
879890
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
880891
printf(_(" -C, --create include commands to create database in dump\n"));
881892
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy