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

Commit1fd1bd8

Browse files
committed
Transfer statistics during pg_upgrade.
Add support to pg_dump for dumping stats, and use that duringpg_upgrade so that statistics are transferred during upgrade. In mostcases this removes the need for a costly re-analyze after upgrade.Some statistics are not transferred, such as extended statistics orstatistics with a custom stakind.Now pg_dump accepts the options --schema-only, --no-schema,--data-only, --no-data, --statistics-only, and --no-statistics; whichallow all combinations of schema, data, and/or stats. The options arenamed this way to preserve compatibility with the previous--schema-only and --data-only options.Statistics are in SECTION_DATA, unless the object itself is inSECTION_POST_DATA.The stats are represented as calls to pg_restore_relation_stats() andpg_restore_attribute_stats().Author: Corey Huinker, Jeff DavisReviewed-by: Jian HeDiscussion:https://postgr.es/m/CADkLM=fzX7QX6r78fShWDjNN3Vcr4PVAnvXxQ4DiGy6V=0bCUA@mail.gmail.comDiscussion:https://postgr.es/m/CADkLM%3DcB0rF3p_FuWRTMSV0983ihTRpsH%2BOCpNyiqE7Wk0vUWA%40mail.gmail.com
1 parent7da344b commit1fd1bd8

22 files changed

+858
-75
lines changed

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

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ PostgreSQL documentation
123123
<term><option>--data-only</option></term>
124124
<listitem>
125125
<para>
126-
Dump only the data, not the schema (data definitions).
126+
Dump only the data, not the schema (data definitions) or statistics.
127127
Table data, large objects, and sequence values are dumped.
128128
</para>
129129

@@ -141,13 +141,15 @@ PostgreSQL documentation
141141
<listitem>
142142
<para>
143143
Include large objects in the dump. This is the default behavior
144-
except when <option>--schema</option>, <option>--table</option>, or
145-
<option>--schema-only</option> is specified. The <option>-b</option>
146-
switch is therefore only useful to add large objects to dumps
147-
where a specific schema or table has been requested. Note that
148-
large objects are considered data and therefore will be included when
149-
<option>--data-only</option> is used, but not
150-
when <option>--schema-only</option> is.
144+
except when <option>--schema</option>, <option>--table</option>,
145+
<option>--schema-only</option>, <option>--statistics-only</option>, or
146+
<option>--no-data</option> is specified. The <option>-b</option>
147+
switch is therefore only useful to add large objects to dumps where a
148+
specific schema or table has been requested. Note that large objects
149+
are considered data and therefore will be included when
150+
<option>--data-only</option> is used, but not when
151+
<option>--schema-only</option> or <option>--statistics-only</option>
152+
is.
151153
</para>
152154
</listitem>
153155
</varlistentry>
@@ -516,10 +518,11 @@ PostgreSQL documentation
516518
<term><option>--schema-only</option></term>
517519
<listitem>
518520
<para>
519-
Dump only the object definitions (schema), not data.
521+
Dump only the object definitions (schema), not data or statistics.
520522
</para>
521523
<para>
522-
This option is the inverse of <option>--data-only</option>.
524+
This option is mutually exclusive to <option>--data-only</option>
525+
and <option>--statistics-only</option>.
523526
It is similar to, but for historical reasons not identical to,
524527
specifying
525528
<option>--section=pre-data --section=post-data</option>.
@@ -652,6 +655,17 @@ PostgreSQL documentation
652655
</listitem>
653656
</varlistentry>
654657

658+
<varlistentry>
659+
<term><option>--statistics-only</option></term>
660+
<listitem>
661+
<para>
662+
Dump only the statistics, not the schema (data definitions) or data.
663+
Statistics for tables, materialized views, and indexes are dumped.
664+
</para>
665+
666+
</listitem>
667+
</varlistentry>
668+
655669
<varlistentry>
656670
<term><option>-Z <replaceable class="parameter">level</replaceable></option></term>
657671
<term><option>-Z <replaceable class="parameter">method</replaceable></option>[:<replaceable>detail</replaceable>]</term>
@@ -741,7 +755,8 @@ PostgreSQL documentation
741755
<term><option>--disable-triggers</option></term>
742756
<listitem>
743757
<para>
744-
This option is relevant only when creating a data-only dump.
758+
This option is relevant only when creating a dump that includes data
759+
but does not include schema.
745760
It instructs <application>pg_dump</application> to include commands
746761
to temporarily disable triggers on the target tables while
747762
the data is restored. Use this if you have referential
@@ -833,7 +848,8 @@ PostgreSQL documentation
833848
though you do not need the data in it.
834849
</para>
835850
<para>
836-
To exclude data for all tables in the database, see <option>--schema-only</option>.
851+
To exclude data for all tables in the database, see <option>--schema-only</option>
852+
or <option>--statistics-only</option>.
837853
</para>
838854
</listitem>
839855
</varlistentry>
@@ -1080,6 +1096,15 @@ PostgreSQL documentation
10801096
</listitem>
10811097
</varlistentry>
10821098

1099+
<varlistentry>
1100+
<term><option>--no-data</option></term>
1101+
<listitem>
1102+
<para>
1103+
Do not dump data.
1104+
</para>
1105+
</listitem>
1106+
</varlistentry>
1107+
10831108
<varlistentry>
10841109
<term><option>--no-publications</option></term>
10851110
<listitem>
@@ -1098,6 +1123,24 @@ PostgreSQL documentation
10981123
</listitem>
10991124
</varlistentry>
11001125

1126+
<varlistentry>
1127+
<term><option>--no-schema</option></term>
1128+
<listitem>
1129+
<para>
1130+
Do not dump schema (data definitions).
1131+
</para>
1132+
</listitem>
1133+
</varlistentry>
1134+
1135+
<varlistentry>
1136+
<term><option>--no-statistics</option></term>
1137+
<listitem>
1138+
<para>
1139+
Do not dump statistics.
1140+
</para>
1141+
</listitem>
1142+
</varlistentry>
1143+
11011144
<varlistentry>
11021145
<term><option>--no-subscriptions</option></term>
11031146
<listitem>
@@ -1236,9 +1279,11 @@ PostgreSQL documentation
12361279
</para>
12371280
<para>
12381281
The data section contains actual table data, large-object
1239-
contents, and sequence values.
1282+
contents, statitistics for tables and materialized views and
1283+
sequence values.
12401284
Post-data items include definitions of indexes, triggers, rules,
1241-
and constraints other than validated check constraints.
1285+
statistics for indexes, and constraints other than validated check
1286+
constraints.
12421287
Pre-data items include all other data definition items.
12431288
</para>
12441289
</listitem>
@@ -1581,7 +1626,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
15811626
</para>
15821627

15831628
<para>
1584-
When adata-onlydump is chosen and the option <option>--disable-triggers</option>
1629+
When a dump without schema is chosen and the option <option>--disable-triggers</option>
15851630
is used, <application>pg_dump</application> emits commands
15861631
to disable triggers on user tables before inserting the data,
15871632
and then commands to re-enable them after the data has been

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ PostgreSQL documentation
8181
<term><option>--data-only</option></term>
8282
<listitem>
8383
<para>
84-
Dump only the data, not the schema (data definitions).
84+
Dump only the data, not the schema (data definitions) or statistics.
8585
</para>
8686
</listitem>
8787
</varlistentry>
@@ -265,6 +265,16 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
265265
</listitem>
266266
</varlistentry>
267267

268+
<varlistentry>
269+
<term><option>--statistics-only</option></term>
270+
<listitem>
271+
<para>
272+
Dump only the statistics, not the schema (data definitions) or data.
273+
Statistics for tables, materialized views, and indexes are dumped.
274+
</para>
275+
</listitem>
276+
</varlistentry>
277+
268278
<varlistentry>
269279
<term><option>--binary-upgrade</option></term>
270280
<listitem>
@@ -307,7 +317,7 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
307317
<term><option>--disable-triggers</option></term>
308318
<listitem>
309319
<para>
310-
This option is relevant only when creating a data-only dump.
320+
This option is relevant only when creating adump withdata and without schema.
311321
It instructs <application>pg_dumpall</application> to include commands
312322
to temporarily disable triggers on the target tables while
313323
the data is restored. Use this if you have referential
@@ -422,6 +432,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
422432
</listitem>
423433
</varlistentry>
424434

435+
<varlistentry>
436+
<term><option>--no-data</option></term>
437+
<listitem>
438+
<para>
439+
Do not dump data.
440+
</para>
441+
</listitem>
442+
</varlistentry>
443+
425444
<varlistentry>
426445
<term><option>--no-publications</option></term>
427446
<listitem>
@@ -447,6 +466,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
447466
</listitem>
448467
</varlistentry>
449468

469+
<varlistentry>
470+
<term><option>--no-schema</option></term>
471+
<listitem>
472+
<para>
473+
Do not dump schema (data definitions).
474+
</para>
475+
</listitem>
476+
</varlistentry>
477+
450478
<varlistentry>
451479
<term><option>--no-security-labels</option></term>
452480
<listitem>
@@ -456,6 +484,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
456484
</listitem>
457485
</varlistentry>
458486

487+
<varlistentry>
488+
<term><option>--no-statistics</option></term>
489+
<listitem>
490+
<para>
491+
Do not dump statistics.
492+
</para>
493+
</listitem>
494+
</varlistentry>
495+
459496
<varlistentry>
460497
<term><option>--no-subscriptions</option></term>
461498
<listitem>

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ PostgreSQL documentation
9494
<term><option>--data-only</option></term>
9595
<listitem>
9696
<para>
97-
Restore only the data, not the schema (data definitions).
97+
Restore only the data, not the schema (data definitions) or statistics.
9898
Table data, large objects, and sequence values are restored,
9999
if present in the archive.
100100
</para>
@@ -483,10 +483,11 @@ PostgreSQL documentation
483483
to the extent that schema entries are present in the archive.
484484
</para>
485485
<para>
486-
This option is the inverse of <option>--data-only</option>.
486+
This option is mutually exclusive of <option>--data-only</option>
487+
and <option>--statistics-only</option>.
487488
It is similar to, but for historical reasons not identical to,
488489
specifying
489-
<option>--section=pre-data --section=post-data</option>.
490+
<option>--section=pre-data --section=post-data --no-statistics</option>.
490491
</para>
491492
<para>
492493
(Do not confuse this with the <option>--schema</option> option, which
@@ -599,6 +600,15 @@ PostgreSQL documentation
599600
</listitem>
600601
</varlistentry>
601602

603+
<varlistentry>
604+
<term><option>--statistics-only</option></term>
605+
<listitem>
606+
<para>
607+
Restore only the statistics, not schema (data definitions) or data.
608+
</para>
609+
</listitem>
610+
</varlistentry>
611+
602612
<varlistentry>
603613
<term><option>-1</option></term>
604614
<term><option>--single-transaction</option></term>
@@ -617,7 +627,7 @@ PostgreSQL documentation
617627
<term><option>--disable-triggers</option></term>
618628
<listitem>
619629
<para>
620-
This option is relevant only when performing adata-onlyrestore.
630+
This option is relevant only when performing a restore without schema.
621631
It instructs <application>pg_restore</application> to execute commands
622632
to temporarily disable triggers on the target tables while
623633
the data is restored. Use this if you have referential
@@ -681,6 +691,16 @@ PostgreSQL documentation
681691
</listitem>
682692
</varlistentry>
683693

694+
<varlistentry>
695+
<term><option>--no-data</option></term>
696+
<listitem>
697+
<para>
698+
Do not output commands to restore data, even if the archive
699+
contains them.
700+
</para>
701+
</listitem>
702+
</varlistentry>
703+
684704
<varlistentry>
685705
<term><option>--no-data-for-failed-tables</option></term>
686706
<listitem>
@@ -713,6 +733,16 @@ PostgreSQL documentation
713733
</listitem>
714734
</varlistentry>
715735

736+
<varlistentry>
737+
<term><option>--no-schema</option></term>
738+
<listitem>
739+
<para>
740+
Do not output commands to restore schema (data definitions), even if
741+
the archive contains them.
742+
</para>
743+
</listitem>
744+
</varlistentry>
745+
716746
<varlistentry>
717747
<term><option>--no-security-labels</option></term>
718748
<listitem>
@@ -723,6 +753,16 @@ PostgreSQL documentation
723753
</listitem>
724754
</varlistentry>
725755

756+
<varlistentry>
757+
<term><option>--no-statistics</option></term>
758+
<listitem>
759+
<para>
760+
Do not output commands to restore statistics, even if the archive
761+
contains them.
762+
</para>
763+
</listitem>
764+
</varlistentry>
765+
726766
<varlistentry>
727767
<term><option>--no-subscriptions</option></term>
728768
<listitem>

‎doc/src/sgml/ref/pgupgrade.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ PostgreSQL documentation
145145
</listitem>
146146
</varlistentry>
147147

148+
<varlistentry>
149+
<term><option>--no-statistics</option></term>
150+
<listitem>
151+
<para>
152+
Do not restore statistics from the old cluster into the new cluster.
153+
</para>
154+
</listitem>
155+
</varlistentry>
156+
148157
<varlistentry>
149158
<term><option>-o</option> <replaceable class="parameter">options</replaceable></term>
150159
<term><option>--old-options</option> <replaceable class="parameter">options</replaceable></term>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ typedef struct _restoreOptions
160160
/* flags derived from the user-settable flags */
161161
booldumpSchema;
162162
booldumpData;
163+
booldumpStatistics;
163164
}RestoreOptions;
164165

165166
typedefstruct_dumpOptions
@@ -208,6 +209,7 @@ typedef struct _dumpOptions
208209
/* flags derived from the user-settable flags */
209210
booldumpSchema;
210211
booldumpData;
212+
booldumpStatistics;
211213
}DumpOptions;
212214

213215
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp