diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-04-01 16:46:24 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-04-01 16:46:24 -0400 |
commit | 959b38d770ba1f8f35edab27ef3ccf8b1d99f5dd (patch) | |
tree | e1396f20b9672178d2ff3d452851078bc7b12202 /doc/src | |
parent | a45c78e3284b269085e9a0cbd0ea3b236b7180fa (diff) | |
download | postgresql-959b38d770ba1f8f35edab27ef3ccf8b1d99f5dd.tar.gz postgresql-959b38d770ba1f8f35edab27ef3ccf8b1d99f5dd.zip |
Invent --transaction-size option for pg_restore.
This patch allows pg_restore to wrap its commands into transaction
blocks, somewhat like --single-transaction, except that we commit
and start a new block after every N objects. Using this mode
with a size limit of 1000 or so objects greatly reduces the number
of transactions consumed by the restore, while preventing any
one transaction from taking enough locks to overrun the receiving
server's shared lock table.
(A value of 1000 works well with the default lock table size of
around 6400 locks. Higher --transaction-size values can be used
if one has increased the receiving server's lock table size.)
Excessive consumption of XIDs has been reported as a problem for
pg_upgrade in particular, but it could be bad for any restore; and the
change also reduces the number of fsyncs and amount of WAL generated,
so it should provide speed benefits too.
This patch does not try to make parallel workers batch the SQL
commands they issue. The trouble with doing that is that other
workers may need to see the objects a worker creates right away.
Possibly this can be improved later.
In this patch I have hard-wired pg_upgrade to use a transaction size
of 1000 divided by the number of parallel restore jobs allowed
(without that, we'd still be at risk of overrunning the shared lock
table). Perhaps there would be value in adding another pg_upgrade
option to allow user control of that, but I'm unsure that it's worth
the trouble; I think few users would use it, and any who did would see
not that much benefit compared to the default.
Patch by me, but the original idea to batch SQL commands during
restore is due to Robins Tharakan.
Discussion: https://postgr.es/m/a9f9376f1c3343a6bb319dce294e20ac@EX13D05UWC001.ant.amazon.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/ref/pg_restore.sgml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index 1a23874da68..2e3ba802581 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -787,6 +787,30 @@ PostgreSQL documentation </varlistentry> <varlistentry> + <term><option>--transaction-size=<replaceable class="parameter">N</replaceable></option></term> + <listitem> + <para> + Execute the restore as a series of transactions, each processing + up to <replaceable class="parameter">N</replaceable> database + objects. This option implies <option>--exit-on-error</option>. + </para> + <para> + <option>--transaction-size</option> offers an intermediate choice + between the default behavior (one transaction per SQL command) + and <option>-1</option>/<option>--single-transaction</option> + (one transaction for all restored objects). + While <option>--single-transaction</option> has the least + overhead, it may be impractical for large databases because the + transaction will take a lock on each restored object, possibly + exhausting the server's lock table space. + Using <option>--transaction-size</option> with a size of a few + thousand objects offers nearly the same performance benefits while + capping the amount of lock table space needed. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>--use-set-session-authorization</option></term> <listitem> <para> |