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

Commit2158628

Browse files
committed
Add support for --no-table-access-method in pg_{dump,dumpall,restore}
The logic is similar to default_tablespace in some ways, so as no SETqueries on default_table_access_method are generated before dumping orrestoring an object (table or materialized view support table AMs) whenspecifying this new option.This option is useful to enforce the use of a default access method evenif some tables included in a dump use an AM different than the system'sdefault.There are already two cases in the TAP tests of pg_dump with a table anda materialized view that use a non-default table AM, and these areextended that the new option does not generate SET clauses ondefault_table_access_method.Author: Justin PryzbyDiscussion:https://postgr.es/m/20211207153930.GR17618@telsasoft.com
1 parentf47ed79 commit2158628

File tree

9 files changed

+79
-2
lines changed

9 files changed

+79
-2
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,23 @@ PostgreSQL documentation
931931
</listitem>
932932
</varlistentry>
933933

934+
<varlistentry>
935+
<term><option>--no-table-access-method</option></term>
936+
<listitem>
937+
<para>
938+
Do not output commands to select table access methods.
939+
With this option, all objects will be created with whichever
940+
table access method is the default during restore.
941+
</para>
942+
943+
<para>
944+
This option is ignored when emitting an archive (non-text) output
945+
file. For the archive formats, you can specify the option when you
946+
call <command>pg_restore</command>.
947+
</para>
948+
</listitem>
949+
</varlistentry>
950+
934951
<varlistentry>
935952
<term><option>--no-tablespaces</option></term>
936953
<listitem>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ PostgreSQL documentation
446446
</listitem>
447447
</varlistentry>
448448

449+
<varlistentry>
450+
<term><option>--no-table-access-method</option></term>
451+
<listitem>
452+
<para>
453+
Do not output commands to select table access methods.
454+
With this option, all objects will be created with whichever
455+
table access method is the default during restore.
456+
</para>
457+
</listitem>
458+
</varlistentry>
459+
449460
<varlistentry>
450461
<term><option>--no-tablespaces</option></term>
451462
<listitem>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,17 @@ PostgreSQL documentation
649649
</listitem>
650650
</varlistentry>
651651

652+
<varlistentry>
653+
<term><option>--no-table-access-method</option></term>
654+
<listitem>
655+
<para>
656+
Do not output commands to select table access methods.
657+
With this option, all objects will be created with whichever
658+
access method is the default during restore.
659+
</para>
660+
</listitem>
661+
</varlistentry>
662+
652663
<varlistentry>
653664
<term><option>--no-tablespaces</option></term>
654665
<listitem>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef struct _restoreOptions
9393
{
9494
intcreateDB;/* Issue commands to create the database */
9595
intnoOwner;/* Don't try to match original object owner */
96+
intnoTableAm;/* Don't issue table-AM-related commands */
9697
intnoTablespace;/* Don't issue tablespace-related commands */
9798
intdisable_triggers;/* disable triggers during data-only
9899
* restore */
@@ -179,6 +180,7 @@ typedef struct _dumpOptions
179180
intno_unlogged_table_data;
180181
intserializable_deferrable;
181182
intdisable_triggers;
183+
intoutputNoTableAm;
182184
intoutputNoTablespaces;
183185
intuse_setsessauth;
184186
intenable_row_security;

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
194194
dopt->outputSuperuser=ropt->superuser;
195195
dopt->outputCreateDB=ropt->createDB;
196196
dopt->outputNoOwner=ropt->noOwner;
197+
dopt->outputNoTableAm=ropt->noTableAm;
197198
dopt->outputNoTablespaces=ropt->noTablespace;
198199
dopt->disable_triggers=ropt->disable_triggers;
199200
dopt->use_setsessauth=ropt->use_setsessauth;
@@ -3171,6 +3172,11 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname)
31713172
if (AH->currSchema)
31723173
free(AH->currSchema);
31733174
AH->currSchema=NULL;
3175+
3176+
if (AH->currTableAm)
3177+
free(AH->currTableAm);
3178+
AH->currTableAm=NULL;
3179+
31743180
if (AH->currTablespace)
31753181
free(AH->currTablespace);
31763182
AH->currTablespace=NULL;
@@ -3340,10 +3346,15 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
33403346
staticvoid
33413347
_selectTableAccessMethod(ArchiveHandle*AH,constchar*tableam)
33423348
{
3349+
RestoreOptions*ropt=AH->public.ropt;
33433350
PQExpBuffercmd;
33443351
constchar*want,
33453352
*have;
33463353

3354+
/* do nothing in --no-table-access-method mode */
3355+
if (ropt->noTableAm)
3356+
return;
3357+
33473358
have=AH->currTableAm;
33483359
want=tableam;
33493360

@@ -4770,6 +4781,7 @@ CloneArchive(ArchiveHandle *AH)
47704781
clone->connCancel=NULL;
47714782
clone->currUser=NULL;
47724783
clone->currSchema=NULL;
4784+
clone->currTableAm=NULL;
47734785
clone->currTablespace=NULL;
47744786

47754787
/* savedPassword must be local in case we change it while connecting */

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ main(int argc, char **argv)
389389
{"if-exists", no_argument, &dopt.if_exists, 1},
390390
{"inserts", no_argument, NULL, 9},
391391
{"lock-wait-timeout", required_argument, NULL, 2},
392+
{"no-table-access-method", no_argument, &dopt.outputNoTableAm, 1},
392393
{"no-tablespaces", no_argument, &dopt.outputNoTablespaces, 1},
393394
{"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
394395
{"load-via-partition-root", no_argument, &dopt.load_via_partition_root, 1},
@@ -933,6 +934,7 @@ main(int argc, char **argv)
933934
ropt->superuser = dopt.outputSuperuser;
934935
ropt->createDB = dopt.outputCreateDB;
935936
ropt->noOwner = dopt.outputNoOwner;
937+
ropt->noTableAm = dopt.outputNoTableAm;
936938
ropt->noTablespace = dopt.outputNoTablespaces;
937939
ropt->disable_triggers = dopt.disable_triggers;
938940
ropt->use_setsessauth = dopt.use_setsessauth;
@@ -1038,6 +1040,7 @@ help(const char *progname)
10381040
printf(_(" --no-publications do not dump publications\n"));
10391041
printf(_(" --no-security-labels do not dump security label assignments\n"));
10401042
printf(_(" --no-subscriptions do not dump subscriptions\n"));
1043+
printf(_(" --no-table-access-method do not dump table access methods\n"));
10411044
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
10421045
printf(_(" --no-toast-compression do not dump TOAST compression methods\n"));
10431046
printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static intdisable_dollar_quoting = 0;
7070
staticintdisable_triggers=0;
7171
staticintif_exists=0;
7272
staticintinserts=0;
73+
staticintno_table_access_method=0;
7374
staticintno_tablespaces=0;
7475
staticintuse_setsessauth=0;
7576
staticintno_comments=0;
@@ -133,6 +134,7 @@ main(int argc, char *argv[])
133134
{"if-exists",no_argument,&if_exists,1},
134135
{"inserts",no_argument,&inserts,1},
135136
{"lock-wait-timeout",required_argument,NULL,2},
137+
{"no-table-access-method",no_argument,&no_table_access_method,1},
136138
{"no-tablespaces",no_argument,&no_tablespaces,1},
137139
{"quote-all-identifiers",no_argument,&quote_all_identifiers,1},
138140
{"load-via-partition-root",no_argument,&load_via_partition_root,1},
@@ -413,6 +415,8 @@ main(int argc, char *argv[])
413415
appendPQExpBufferStr(pgdumpopts," --disable-triggers");
414416
if (inserts)
415417
appendPQExpBufferStr(pgdumpopts," --inserts");
418+
if (no_table_access_method)
419+
appendPQExpBufferStr(pgdumpopts," --no-table-access-method");
416420
if (no_tablespaces)
417421
appendPQExpBufferStr(pgdumpopts," --no-tablespaces");
418422
if (quote_all_identifiers)
@@ -649,6 +653,7 @@ help(void)
649653
printf(_(" --no-security-labels do not dump security label assignments\n"));
650654
printf(_(" --no-subscriptions do not dump subscriptions\n"));
651655
printf(_(" --no-sync do not wait for changes to be written safely to disk\n"));
656+
printf(_(" --no-tables-access-method do not dump table access methods\n"));
652657
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
653658
printf(_(" --no-toast-compression do not dump TOAST compression methods\n"));
654659
printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));

‎src/bin/pg_dump/pg_restore.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ main(int argc, char **argv)
6666
staticintenable_row_security=0;
6767
staticintif_exists=0;
6868
staticintno_data_for_failed_tables=0;
69+
staticintoutputNoTableAm=0;
6970
staticintoutputNoTablespaces=0;
7071
staticintuse_setsessauth=0;
7172
staticintno_comments=0;
@@ -112,6 +113,7 @@ main(int argc, char **argv)
112113
{"enable-row-security",no_argument,&enable_row_security,1},
113114
{"if-exists",no_argument,&if_exists,1},
114115
{"no-data-for-failed-tables",no_argument,&no_data_for_failed_tables,1},
116+
{"no-table-access-method",no_argument,&outputNoTableAm,1},
115117
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
116118
{"role",required_argument,NULL,2},
117119
{"section",required_argument,NULL,3},
@@ -358,6 +360,7 @@ main(int argc, char **argv)
358360
opts->disable_triggers=disable_triggers;
359361
opts->enable_row_security=enable_row_security;
360362
opts->noDataForFailedTables=no_data_for_failed_tables;
363+
opts->noTableAm=outputNoTableAm;
361364
opts->noTablespace=outputNoTablespaces;
362365
opts->use_setsessauth=use_setsessauth;
363366
opts->no_comments=no_comments;
@@ -487,6 +490,7 @@ usage(const char *progname)
487490
printf(_(" --no-publications do not restore publications\n"));
488491
printf(_(" --no-security-labels do not restore security labels\n"));
489492
printf(_(" --no-subscriptions do not restore subscriptions\n"));
493+
printf(_(" --no-table-access-method do not restore table access methods\n"));
490494
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
491495
printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
492496
printf(_(" --strict-names require table and/or schema include patterns to\n"

‎src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@
275275
'postgres',
276276
],
277277
},
278+
no_table_access_method=> {
279+
dump_cmd=> [
280+
'pg_dump','--no-sync',
281+
"--file=$tempdir/no_table_access_method.sql",
282+
'--no-table-access-method','postgres',
283+
],
284+
},
278285
only_dump_test_schema=> {
279286
dump_cmd=> [
280287
'pg_dump','--no-sync',
@@ -426,6 +433,7 @@
426433
no_blobs=> 1,
427434
no_owner=> 1,
428435
no_privs=> 1,
436+
no_table_access_method=> 1,
429437
pg_dumpall_dbprivs=> 1,
430438
pg_dumpall_exclude=> 1,
431439
schema_only=> 1,);
@@ -2972,6 +2980,7 @@
29722980
no_blobs => 1,
29732981
no_privs => 1,
29742982
no_owner => 1,
2983+
no_table_access_method => 1,
29752984
only_dump_test_schema => 1,
29762985
pg_dumpall_dbprivs => 1,
29772986
pg_dumpall_exclude => 1,
@@ -3045,6 +3054,7 @@
30453054
no_blobs => 1,
30463055
no_privs => 1,
30473056
no_owner => 1,
3057+
no_table_access_method => 1,
30483058
pg_dumpall_dbprivs => 1,
30493059
pg_dumpall_exclude => 1,
30503060
role => 1,
@@ -3648,7 +3658,8 @@
36483658
like => {
36493659
%full_runs,%dump_test_schema_runs, section_pre_data => 1,
36503660
},
3651-
unlike => { exclude_dump_test_schema => 1 },
3661+
unlike =>
3662+
{ exclude_dump_test_schema => 1, no_table_access_method => 1 },
36523663
},
36533664
36543665
'CREATE MATERIALIZED VIEW regress_pg_dump_matview_am' => {
@@ -3668,7 +3679,8 @@
36683679
like => {
36693680
%full_runs,%dump_test_schema_runs, section_pre_data => 1,
36703681
},
3671-
unlike => { exclude_dump_test_schema => 1 },
3682+
unlike =>
3683+
{ exclude_dump_test_schema => 1, no_table_access_method => 1 },
36723684
});
36733685
36743686
#########################################

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp