1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Transfer statistics during pg_upgrade.

Add support to pg_dump for dumping stats, and use that during
pg_upgrade so that statistics are transferred during upgrade. In most
cases this removes the need for a costly re-analyze after upgrade.

Some statistics are not transferred, such as extended statistics or
statistics with a custom stakind.

Now pg_dump accepts the options --schema-only, --no-schema,
--data-only, --no-data, --statistics-only, and --no-statistics; which
allow all combinations of schema, data, and/or stats. The options are
named this way to preserve compatibility with the previous
--schema-only and --data-only options.

Statistics are in SECTION_DATA, unless the object itself is in
SECTION_POST_DATA.

The stats are represented as calls to pg_restore_relation_stats() and
pg_restore_attribute_stats().

Author: Corey Huinker, Jeff Davis
Reviewed-by: Jian He
Discussion: https://postgr.es/m/CADkLM=fzX7QX6r78fShWDjNN3Vcr4PVAnvXxQ4DiGy6V=0bCUA@mail.gmail.com
Discussion: https://postgr.es/m/CADkLM%3DcB0rF3p_FuWRTMSV0983ihTRpsH%2BOCpNyiqE7Wk0vUWA%40mail.gmail.com
This commit is contained in:
Jeff Davis
2025-02-20 01:29:06 -08:00
parent 7da344b9f8
commit 1fd1bd8710
22 changed files with 858 additions and 75 deletions

View File

@ -123,7 +123,7 @@ PostgreSQL documentation
<term><option>--data-only</option></term>
<listitem>
<para>
Dump only the data, not the schema (data definitions).
Dump only the data, not the schema (data definitions) or statistics.
Table data, large objects, and sequence values are dumped.
</para>
@ -141,13 +141,15 @@ PostgreSQL documentation
<listitem>
<para>
Include large objects in the dump. This is the default behavior
except when <option>--schema</option>, <option>--table</option>, or
<option>--schema-only</option> is specified. The <option>-b</option>
switch is therefore only useful to add large objects to dumps
where a specific schema or table has been requested. Note that
large objects are considered data and therefore will be included when
<option>--data-only</option> is used, but not
when <option>--schema-only</option> is.
except when <option>--schema</option>, <option>--table</option>,
<option>--schema-only</option>, <option>--statistics-only</option>, or
<option>--no-data</option> is specified. The <option>-b</option>
switch is therefore only useful to add large objects to dumps where a
specific schema or table has been requested. Note that large objects
are considered data and therefore will be included when
<option>--data-only</option> is used, but not when
<option>--schema-only</option> or <option>--statistics-only</option>
is.
</para>
</listitem>
</varlistentry>
@ -516,10 +518,11 @@ PostgreSQL documentation
<term><option>--schema-only</option></term>
<listitem>
<para>
Dump only the object definitions (schema), not data.
Dump only the object definitions (schema), not data or statistics.
</para>
<para>
This option is the inverse of <option>--data-only</option>.
This option is mutually exclusive to <option>--data-only</option>
and <option>--statistics-only</option>.
It is similar to, but for historical reasons not identical to,
specifying
<option>--section=pre-data --section=post-data</option>.
@ -652,6 +655,17 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--statistics-only</option></term>
<listitem>
<para>
Dump only the statistics, not the schema (data definitions) or data.
Statistics for tables, materialized views, and indexes are dumped.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-Z <replaceable class="parameter">level</replaceable></option></term>
<term><option>-Z <replaceable class="parameter">method</replaceable></option>[:<replaceable>detail</replaceable>]</term>
@ -741,7 +755,8 @@ PostgreSQL documentation
<term><option>--disable-triggers</option></term>
<listitem>
<para>
This option is relevant only when creating a data-only dump.
This option is relevant only when creating a dump that includes data
but does not include schema.
It instructs <application>pg_dump</application> to include commands
to temporarily disable triggers on the target tables while
the data is restored. Use this if you have referential
@ -833,7 +848,8 @@ PostgreSQL documentation
though you do not need the data in it.
</para>
<para>
To exclude data for all tables in the database, see <option>--schema-only</option>.
To exclude data for all tables in the database, see <option>--schema-only</option>
or <option>--statistics-only</option>.
</para>
</listitem>
</varlistentry>
@ -1080,6 +1096,15 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-data</option></term>
<listitem>
<para>
Do not dump data.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-publications</option></term>
<listitem>
@ -1098,6 +1123,24 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-schema</option></term>
<listitem>
<para>
Do not dump schema (data definitions).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
<para>
Do not dump statistics.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-subscriptions</option></term>
<listitem>
@ -1236,9 +1279,11 @@ PostgreSQL documentation
</para>
<para>
The data section contains actual table data, large-object
contents, and sequence values.
contents, statitistics for tables and materialized views and
sequence values.
Post-data items include definitions of indexes, triggers, rules,
and constraints other than validated check constraints.
statistics for indexes, and constraints other than validated check
constraints.
Pre-data items include all other data definition items.
</para>
</listitem>
@ -1581,7 +1626,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
</para>
<para>
When a data-only dump is chosen and the option <option>--disable-triggers</option>
When a dump without schema is chosen and the option <option>--disable-triggers</option>
is used, <application>pg_dump</application> emits commands
to disable triggers on user tables before inserting the data,
and then commands to re-enable them after the data has been

View File

@ -81,7 +81,7 @@ PostgreSQL documentation
<term><option>--data-only</option></term>
<listitem>
<para>
Dump only the data, not the schema (data definitions).
Dump only the data, not the schema (data definitions) or statistics.
</para>
</listitem>
</varlistentry>
@ -265,6 +265,16 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--statistics-only</option></term>
<listitem>
<para>
Dump only the statistics, not the schema (data definitions) or data.
Statistics for tables, materialized views, and indexes are dumped.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--binary-upgrade</option></term>
<listitem>
@ -307,7 +317,7 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
<term><option>--disable-triggers</option></term>
<listitem>
<para>
This option is relevant only when creating a data-only dump.
This option is relevant only when creating a dump with data and without schema.
It instructs <application>pg_dumpall</application> to include commands
to temporarily disable triggers on the target tables while
the data is restored. Use this if you have referential
@ -422,6 +432,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-data</option></term>
<listitem>
<para>
Do not dump data.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-publications</option></term>
<listitem>
@ -447,6 +466,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-schema</option></term>
<listitem>
<para>
Do not dump schema (data definitions).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-security-labels</option></term>
<listitem>
@ -456,6 +484,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
<para>
Do not dump statistics.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-subscriptions</option></term>
<listitem>

View File

@ -94,7 +94,7 @@ PostgreSQL documentation
<term><option>--data-only</option></term>
<listitem>
<para>
Restore only the data, not the schema (data definitions).
Restore only the data, not the schema (data definitions) or statistics.
Table data, large objects, and sequence values are restored,
if present in the archive.
</para>
@ -483,10 +483,11 @@ PostgreSQL documentation
to the extent that schema entries are present in the archive.
</para>
<para>
This option is the inverse of <option>--data-only</option>.
This option is mutually exclusive of <option>--data-only</option>
and <option>--statistics-only</option>.
It is similar to, but for historical reasons not identical to,
specifying
<option>--section=pre-data --section=post-data</option>.
<option>--section=pre-data --section=post-data --no-statistics</option>.
</para>
<para>
(Do not confuse this with the <option>--schema</option> option, which
@ -599,6 +600,15 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--statistics-only</option></term>
<listitem>
<para>
Restore only the statistics, not schema (data definitions) or data.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-1</option></term>
<term><option>--single-transaction</option></term>
@ -617,7 +627,7 @@ PostgreSQL documentation
<term><option>--disable-triggers</option></term>
<listitem>
<para>
This option is relevant only when performing a data-only restore.
This option is relevant only when performing a restore without schema.
It instructs <application>pg_restore</application> to execute commands
to temporarily disable triggers on the target tables while
the data is restored. Use this if you have referential
@ -681,6 +691,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-data</option></term>
<listitem>
<para>
Do not output commands to restore data, even if the archive
contains them.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-data-for-failed-tables</option></term>
<listitem>
@ -713,6 +733,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-schema</option></term>
<listitem>
<para>
Do not output commands to restore schema (data definitions), even if
the archive contains them.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-security-labels</option></term>
<listitem>
@ -723,6 +753,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
<para>
Do not output commands to restore statistics, even if the archive
contains them.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-subscriptions</option></term>
<listitem>

View File

@ -145,6 +145,15 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
<para>
Do not restore statistics from the old cluster into the new cluster.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-o</option> <replaceable class="parameter">options</replaceable></term>
<term><option>--old-options</option> <replaceable class="parameter">options</replaceable></term>