Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1368e92

Browse files
committed
Support --no-comments in pg_dump, pg_dumpall, pg_restore.
We have switches already to suppress other subsidiary object properties,such as ACLs, security labels, ownership, and tablespaces, so just onthe grounds of symmetry we should allow suppressing comments as well.Also, commit0d4e6ed added a positive reason to have this feature,i.e. to allow obtaining the old behavior of selective pg_restore shouldanyone desire that.Recent commits have removed the cases where pg_dump emitted comments onbuilt-in objects that the restoring user might not have privileges tocomment on, so the original primary motivation for this feature is gone,but it still seems at least somewhat useful in its own right.Robins Tharakan, reviewed by Fabrízio MelloDiscussion:https://postgr.es/m/CAEP4nAx22Z4ch74oJGzr5RyyjcyUSbpiFLyeYXX8pehfou92ug@mail.gmail.com
1 parentbb41567 commit1368e92

File tree

8 files changed

+62
-5
lines changed

8 files changed

+62
-5
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ PostgreSQL documentation
804804
</listitem>
805805
</varlistentry>
806806

807+
<varlistentry>
808+
<term><option>--no-comments</option></term>
809+
<listitem>
810+
<para>
811+
Do not dump comments.
812+
</para>
813+
</listitem>
814+
</varlistentry>
815+
807816
<varlistentry>
808817
<term><option>--no-publications</option></term>
809818
<listitem>

‎doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ PostgreSQL documentation
342342
</listitem>
343343
</varlistentry>
344344

345+
<varlistentry>
346+
<term><option>--no-comments</option></term>
347+
<listitem>
348+
<para>
349+
Do not dump comments.
350+
</para>
351+
</listitem>
352+
</varlistentry>
353+
345354
<varlistentry>
346355
<term><option>--no-publications</option></term>
347356
<listitem>

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,15 @@
575575
</listitem>
576576
</varlistentry>
577577

578+
<varlistentry>
579+
<term><option>--no-comments</option></term>
580+
<listitem>
581+
<para>
582+
Do not dump comments.
583+
</para>
584+
</listitem>
585+
</varlistentry>
586+
578587
<varlistentry>
579588
<term><option>--no-data-for-failed-tables</option></term>
580589
<listitem>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef struct _restoreOptions
7474
intdump_inserts;
7575
intcolumn_inserts;
7676
intif_exists;
77+
intno_comments;/* Skip comments */
7778
intno_publications;/* Skip publication entries */
7879
intno_security_labels;/* Skip security label entries */
7980
intno_subscriptions;/* Skip subscription entries */
@@ -146,6 +147,7 @@ typedef struct _dumpOptions
146147
intdump_inserts;
147148
intcolumn_inserts;
148149
intif_exists;
150+
intno_comments;
149151
intno_security_labels;
150152
intno_publications;
151153
intno_subscriptions;

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
169169
dopt->outputNoTablespaces=ropt->noTablespace;
170170
dopt->disable_triggers=ropt->disable_triggers;
171171
dopt->use_setsessauth=ropt->use_setsessauth;
172-
173172
dopt->disable_dollar_quoting=ropt->disable_dollar_quoting;
174173
dopt->dump_inserts=ropt->dump_inserts;
174+
dopt->no_comments=ropt->no_comments;
175175
dopt->no_publications=ropt->no_publications;
176176
dopt->no_security_labels=ropt->no_security_labels;
177177
dopt->no_subscriptions=ropt->no_subscriptions;
@@ -2841,6 +2841,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
28412841
if (ropt->aclsSkip&&_tocEntryIsACL(te))
28422842
return0;
28432843

2844+
/* If it's a comment, maybe ignore it */
2845+
if (ropt->no_comments&&strcmp(te->desc,"COMMENT")==0)
2846+
return0;
2847+
28442848
/* If it's a publication, maybe ignore it */
28452849
if (ropt->no_publications&&strcmp(te->desc,"PUBLICATION")==0)
28462850
return0;

‎src/bin/pg_dump/pg_dump.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ main(int argc, char **argv)
359359
{"snapshot", required_argument, NULL, 6},
360360
{"strict-names", no_argument, &strict_names, 1},
361361
{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
362+
{"no-comments", no_argument, &dopt.no_comments, 1},
362363
{"no-publications", no_argument, &dopt.no_publications, 1},
363364
{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
364365
{"no-synchronized-snapshots", no_argument, &dopt.no_synchronized_snapshots, 1},
@@ -877,6 +878,7 @@ main(int argc, char **argv)
877878
ropt->use_setsessauth = dopt.use_setsessauth;
878879
ropt->disable_dollar_quoting = dopt.disable_dollar_quoting;
879880
ropt->dump_inserts = dopt.dump_inserts;
881+
ropt->no_comments = dopt.no_comments;
880882
ropt->no_publications = dopt.no_publications;
881883
ropt->no_security_labels = dopt.no_security_labels;
882884
ropt->no_subscriptions = dopt.no_subscriptions;
@@ -967,6 +969,7 @@ help(const char *progname)
967969
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
968970
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
969971
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
972+
printf(_(" --no-comments do not dump comments\n"));
970973
printf(_(" --no-publications do not dump publications\n"));
971974
printf(_(" --no-security-labels do not dump security label assignments\n"));
972975
printf(_(" --no-subscriptions do not dump subscriptions\n"));
@@ -2780,7 +2783,7 @@ dumpDatabase(Archive *fout)
27802783
*/
27812784
char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
27822785

2783-
if (comment && *comment)
2786+
if (comment && *comment && !dopt->no_comments)
27842787
{
27852788
resetPQExpBuffer(dbQry);
27862789

@@ -2806,7 +2809,7 @@ dumpDatabase(Archive *fout)
28062809
dbCatId, 0, dbDumpId);
28072810
}
28082811

2809-
/* Dumpshared security label. */
2812+
/* DumpDB security label, if enabled */
28102813
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
28112814
{
28122815
PGresult *shres;
@@ -9416,6 +9419,10 @@ dumpComment(Archive *fout, const char *target,
94169419
CommentItem *comments;
94179420
intncomments;
94189421

9422+
/* do nothing, if --no-comments is supplied */
9423+
if (dopt->no_comments)
9424+
return;
9425+
94199426
/* Comments are schema not data ... except blob comments are data */
94209427
if (strncmp(target, "LARGE OBJECT ", 13) != 0)
94219428
{
@@ -9483,6 +9490,10 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
94839490
PQExpBuffer query;
94849491
PQExpBuffer target;
94859492

9493+
/* do nothing, if --no-comments is supplied */
9494+
if (dopt->no_comments)
9495+
return;
9496+
94869497
/* Comments are SCHEMA not data */
94879498
if (dopt->dataOnly)
94889499
return;
@@ -11152,6 +11163,10 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
1115211163
inti_attname;
1115311164
inti_attnum;
1115411165

11166+
/* do nothing, if --no-comments is supplied */
11167+
if (fout->dopt->no_comments)
11168+
return;
11169+
1115511170
query = createPQExpBuffer();
1115611171

1115711172
appendPQExpBuffer(query,

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static intif_exists = 0;
6868
staticintinserts=0;
6969
staticintno_tablespaces=0;
7070
staticintuse_setsessauth=0;
71+
staticintno_comments=0;
7172
staticintno_publications=0;
7273
staticintno_security_labels=0;
7374
staticintno_subscriptions=0;
@@ -127,6 +128,7 @@ main(int argc, char *argv[])
127128
{"load-via-partition-root",no_argument,&load_via_partition_root,1},
128129
{"role",required_argument,NULL,3},
129130
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
131+
{"no-comments",no_argument,&no_comments,1},
130132
{"no-publications",no_argument,&no_publications,1},
131133
{"no-role-passwords",no_argument,&no_role_passwords,1},
132134
{"no-security-labels",no_argument,&no_security_labels,1},
@@ -392,6 +394,8 @@ main(int argc, char *argv[])
392394
appendPQExpBufferStr(pgdumpopts," --load-via-partition-root");
393395
if (use_setsessauth)
394396
appendPQExpBufferStr(pgdumpopts," --use-set-session-authorization");
397+
if (no_comments)
398+
appendPQExpBufferStr(pgdumpopts," --no-comments");
395399
if (no_publications)
396400
appendPQExpBufferStr(pgdumpopts," --no-publications");
397401
if (no_security_labels)
@@ -606,6 +610,7 @@ help(void)
606610
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
607611
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
608612
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
613+
printf(_(" --no-comments do not dump comments\n"));
609614
printf(_(" --no-publications do not dump publications\n"));
610615
printf(_(" --no-role-passwords do not dump passwords for roles\n"));
611616
printf(_(" --no-security-labels do not dump security label assignments\n"));
@@ -914,7 +919,7 @@ dumpRoles(PGconn *conn)
914919

915920
appendPQExpBufferStr(buf,";\n");
916921

917-
if (!PQgetisnull(res,i,i_rolcomment))
922+
if (!no_comments&& !PQgetisnull(res,i,i_rolcomment))
918923
{
919924
appendPQExpBuffer(buf,"COMMENT ON ROLE %s IS ",fmtId(rolename));
920925
appendStringLiteralConn(buf,PQgetvalue(res,i,i_rolcomment),conn);
@@ -1220,7 +1225,7 @@ dumpTablespaces(PGconn *conn)
12201225
exit_nicely(1);
12211226
}
12221227

1223-
if (spccomment&&strlen(spccomment))
1228+
if (!no_comments&&spccomment&&spccomment[0]!='\0')
12241229
{
12251230
appendPQExpBuffer(buf,"COMMENT ON TABLESPACE %s IS ",fspcname);
12261231
appendStringLiteralConn(buf,spccomment,conn);

‎src/bin/pg_dump/pg_restore.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ main(int argc, char **argv)
7171
staticintno_data_for_failed_tables=0;
7272
staticintoutputNoTablespaces=0;
7373
staticintuse_setsessauth=0;
74+
staticintno_comments=0;
7475
staticintno_publications=0;
7576
staticintno_security_labels=0;
7677
staticintno_subscriptions=0;
@@ -119,6 +120,7 @@ main(int argc, char **argv)
119120
{"section",required_argument,NULL,3},
120121
{"strict-names",no_argument,&strict_names,1},
121122
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
123+
{"no-comments",no_argument,&no_comments,1},
122124
{"no-publications",no_argument,&no_publications,1},
123125
{"no-security-labels",no_argument,&no_security_labels,1},
124126
{"no-subscriptions",no_argument,&no_subscriptions,1},
@@ -358,6 +360,7 @@ main(int argc, char **argv)
358360
opts->noDataForFailedTables=no_data_for_failed_tables;
359361
opts->noTablespace=outputNoTablespaces;
360362
opts->use_setsessauth=use_setsessauth;
363+
opts->no_comments=no_comments;
361364
opts->no_publications=no_publications;
362365
opts->no_security_labels=no_security_labels;
363366
opts->no_subscriptions=no_subscriptions;
@@ -482,6 +485,7 @@ usage(const char *progname)
482485
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
483486
printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
484487
" created\n"));
488+
printf(_(" --no-comments do not dump comments\n"));
485489
printf(_(" --no-publications do not restore publications\n"));
486490
printf(_(" --no-security-labels do not restore security labels\n"));
487491
printf(_(" --no-subscriptions do not restore subscriptions\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp