Re: pg_dump without explicit table locking

Lists: pgsql-hackers
From: Jürgen Strobel <juergen+pg(at)strobel(dot)info>
To: pgsql-hackers(at)postgresql(dot)org
Subject: pg_dump without explicit table locking
Date: 2014-03-17 11:52:19
Message-ID: 5326E1F3.7060008@strobel.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Hi,

at work at my company I inherited responsibility for a large PG 8.1 DB,
with a an extreme number of tables (~300000). Surprisingly this is
working quite well, except for maintenance and backup. I am tasked with
finding a way to do dump & restore to 9.3 with as little downtime as
possible.

Using 9.3's pg_dump with -j12 I found out that pg_dump takes 6 hours to
lock tables using a single thread, then does the data dump in 1 more
hour using 12 workers. However if I patch out the explicit LOCK TABLE
statements this only takes 1 hour total. Of course no one else is using
the DB at this time. In a pathological test case scenario in a staging
environment the dump time decreased from 5 hours to 5 minutes.

I've googled the problem and there seem to be more people with similar
problems, so I made this a command line option --no-table-locks and
wrapped it up in as nice a patch against github/master as I can manage
(and I didn't use C for a long time). I hope you find it useful.

regards,
Jürgen Strobel

Attachment Content-Type Size
pg_dump_nolock.diff text/plain 4.5 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jürgen Strobel <juergen+pg(at)strobel(dot)info>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 12:02:32
Message-ID: CA+TgmoaEZoOPUCpdV5Fh1Ef3CDzPuSkeTcDuiBEC+AvdkCysmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Mar 17, 2014 at 7:52 AM, Jürgen Strobel <juergen+pg(at)strobel(dot)info> wrote:
> at work at my company I inherited responsibility for a large PG 8.1 DB,
> with a an extreme number of tables (~300000). Surprisingly this is
> working quite well, except for maintenance and backup. I am tasked with
> finding a way to do dump & restore to 9.3 with as little downtime as
> possible.
>
> Using 9.3's pg_dump with -j12 I found out that pg_dump takes 6 hours to
> lock tables using a single thread, then does the data dump in 1 more
> hour using 12 workers. However if I patch out the explicit LOCK TABLE
> statements this only takes 1 hour total. Of course no one else is using
> the DB at this time. In a pathological test case scenario in a staging
> environment the dump time decreased from 5 hours to 5 minutes.
>
> I've googled the problem and there seem to be more people with similar
> problems, so I made this a command line option --no-table-locks and
> wrapped it up in as nice a patch against github/master as I can manage
> (and I didn't use C for a long time). I hope you find it useful.

Fascinating report. Whether we use your patch or not, that's
interesting to know about. Please add your patch here so we don't
forget about it:

https://commitfest.postgresql.org/action/commitfest_view/open

See also https://wiki.postgresql.org/wiki/Submitting_a_Patch

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jürgen Strobel <juergen+pg(at)strobel(dot)info>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 12:21:25
Message-ID: CAFj8pRA_eSJR6FO6-47xc22SipB+W2i55p4uJc46YXLO0=RKuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2014-03-17 12:52 GMT+01:00 Jürgen Strobel <juergen+pg(at)strobel(dot)info>:

>
> Hi,
>
> at work at my company I inherited responsibility for a large PG 8.1 DB,
> with a an extreme number of tables (~300000). Surprisingly this is
> working quite well, except for maintenance and backup. I am tasked with
> finding a way to do dump & restore to 9.3 with as little downtime as
> possible.
>
> Using 9.3's pg_dump with -j12 I found out that pg_dump takes 6 hours to
> lock tables using a single thread, then does the data dump in 1 more
> hour using 12 workers. However if I patch out the explicit LOCK TABLE
> statements this only takes 1 hour total. Of course no one else is using
> the DB at this time. In a pathological test case scenario in a staging
> environment the dump time decreased from 5 hours to 5 minutes.
>
> I've googled the problem and there seem to be more people with similar
> problems, so I made this a command line option --no-table-locks and
> wrapped it up in as nice a patch against github/master as I can manage
> (and I didn't use C for a long time). I hope you find it useful.
>

Joe Conway sent me a tip so commit eeb6f37d89fc60c6449ca12ef9e914
91069369cb significantly decrease a time necessary for locking. So it can
help to.

I am not sure, if missing lock is fully correct. In same situation I though
about some form of database level lock. So you can get a protected access
by one statement.

Regards

Pavel Stehule

>
> regards,
> Jürgen Strobel
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 13:47:43
Message-ID: 6388.1395064063@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> 2014-03-17 12:52 GMT+01:00 Jrgen Strobel <juergen+pg(at)strobel(dot)info>:
>> I've googled the problem and there seem to be more people with similar
>> problems, so I made this a command line option --no-table-locks and
>> wrapped it up in as nice a patch against github/master as I can manage
>> (and I didn't use C for a long time). I hope you find it useful.

> Joe Conway sent me a tip so commit eeb6f37d89fc60c6449ca12ef9e914
> 91069369cb significantly decrease a time necessary for locking. So it can
> help to.

Indeed. I think there's zero chance that we'd accept the patch as
proposed. If there's still a performance problem in HEAD, we'd look
for some other way to improve matters more.

(Note that this is only one of assorted O(N^2) behaviors in older versions
of pg_dump; we've gradually stamped them out over time.)

regards, tom lane


From: Jim Nasby <jim(at)nasby(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 22:51:03
Message-ID: 53277C57.4040404@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/17/14, 8:47 AM, Tom Lane wrote:
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>> 2014-03-17 12:52 GMT+01:00 Jürgen Strobel <juergen+pg(at)strobel(dot)info>:
>>> I've googled the problem and there seem to be more people with similar
>>> problems, so I made this a command line option --no-table-locks and
>>> wrapped it up in as nice a patch against github/master as I can manage
>>> (and I didn't use C for a long time). I hope you find it useful.
>
>> Joe Conway sent me a tip so commit eeb6f37d89fc60c6449ca12ef9e914
>> 91069369cb significantly decrease a time necessary for locking. So it can
>> help to.
>
> Indeed. I think there's zero chance that we'd accept the patch as
> proposed. If there's still a performance problem in HEAD, we'd look
> for some other way to improve matters more.
>
> (Note that this is only one of assorted O(N^2) behaviors in older versions
> of pg_dump; we've gradually stamped them out over time.)

On that note, it's recommended that when you are taking a backup to restore into a newer version of Postgres you create the dump using the NEWER version of pg_dump, not the old one.
--
Jim C. Nasby, Data Architect jim(at)nasby(dot)net
512.569.9461 (cell) http://jim.nasby.net


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Nasby <jim(at)nasby(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 23:15:50
Message-ID: 10756.1395098150@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jim Nasby <jim(at)nasby(dot)net> writes:
> On 3/17/14, 8:47 AM, Tom Lane wrote:
>> (Note that this is only one of assorted O(N^2) behaviors in older versions
>> of pg_dump; we've gradually stamped them out over time.)

> On that note, it's recommended that when you are taking a backup to restore into a newer version of Postgres you create the dump using the NEWER version of pg_dump, not the old one.

Right. IIRC, the OP said he *did* use a recent pg_dump ... but this
particular issue got fixed server-side, so the new pg_dump didn't help
against an 8.1 server :-(

regards, tom lane


From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-17 23:20:27
Message-ID: 5327833B.4060205@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/17/2014 04:15 PM, Tom Lane wrote:
> Jim Nasby <jim(at)nasby(dot)net> writes:
>> On 3/17/14, 8:47 AM, Tom Lane wrote:
>>> (Note that this is only one of assorted O(N^2) behaviors in
>>> older versions of pg_dump; we've gradually stamped them out
>>> over time.)
>
>> On that note, it's recommended that when you are taking a backup
>> to restore into a newer version of Postgres you create the dump
>> using the NEWER version of pg_dump, not the old one.
>
> Right. IIRC, the OP said he *did* use a recent pg_dump ... but
> this particular issue got fixed server-side, so the new pg_dump
> didn't help against an 8.1 server :-(

Exactly. I backported the patch from 9.3 to 8.4 and saw a schema-only
dump time go from <give-up-and-kill-it-after-5-days> to 1 hour. This
was for a database with about 500k tables.

Joe

- --
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJTJ4M7AAoJEDfy90M199hlLzUQAIpprlGDB2lAwgaMD9CYiko4
xJKCWPE9FH3zd5D4hoWfzI3rTudP+wr5VHGncJHKFcarVC3RFwlDcwYFZVFbzVfr
IcKxQjiwYJfi30/sjClnXeaqyQCeurolKwkLXiSLbmVvi7edtlYPN4WEBrEojKCS
AUQtVqbtlSWhCMmTWnYAn2uejuXK5wZnOvjQZzhTpTuYsMZ1uKhuAb/ir3/PPiVA
qGax6QLKfJ1SLOlMtLRWTo8jYH82s9QNRNv2kvaiQILXgkmTQ3Z79aYrq5BrCeVL
dn5vHwkGXyYfZ3XuuaomspB9+kUleNsvWWWfBWKJVw129WFbwYqqFF6GX0q1vLzb
+Le2tMmvIUxFAaJle9usS9REa6lyJr5RiLPq+q0DA/oTx/na7O9DdJzfjIzhsKTK
ghRyhUyIafPDPgAMSahh1vWlHdOE9wy+8GYcRKkfLiZKFO24DVknHcDWCFa22uBH
b5BZCV0AgJwWTFcBjpQ/Nz8+0ykGx69B9RswUXtqXoRpak9kvvCbtqCyN15MRUSG
t5Bfr5RPGmL8TFZWKsgGeg8cWRFra3P4WktDB9d1tq8qfcKDPENlEkUEC/bc5D0M
OFoaNoSVCiK2uoFInxtGujFuQxlxtAgbN8PkkCrqHwkU/tmWSzQljaaHx3AKY8iM
Bgr493yOFPDVcESQ1pSa
=PV6q
-----END PGP SIGNATURE-----


From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-18 00:48:41
Message-ID: 532797E9.6080907@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/18/2014 07:20 AM, Joe Conway wrote:
> On 03/17/2014 04:15 PM, Tom Lane wrote:
>> Jim Nasby <jim(at)nasby(dot)net> writes:
>>> On 3/17/14, 8:47 AM, Tom Lane wrote:
>>>> (Note that this is only one of assorted O(N^2) behaviors in
>>>> older versions of pg_dump; we've gradually stamped them out
>>>> over time.)
>
>>> On that note, it's recommended that when you are taking a
>>> backup to restore into a newer version of Postgres you create
>>> the dump using the NEWER version of pg_dump, not the old one.
>
>> Right. IIRC, the OP said he *did* use a recent pg_dump ... but
>> this particular issue got fixed server-side, so the new pg_dump
>> didn't help against an 8.1 server :-(
>
> Exactly. I backported the patch from 9.3 to 8.4 and saw a
> schema-only dump time go from <give-up-and-kill-it-after-5-days> to
> 1 hour. This was for a database with about 500k tables.

I wonder if doing large batches of

LOCK TABLE table1, table2, table3, ...

would help, instead of doing individual statements?

- --
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTJ5fpAAoJELBXNkqjr+S2XMkH/jhhyET40uuc+zkwpJzW6j7x
o6x2VsaME0PpFUZE5iRL0FDEbHovwznZsQFOPFaCOqZ9vCL1P0JWl6Wf1JNZPJSr
NkwT08PsiOFmtXvnGh5109z3Of6ADGyEKCWHp7msxokzj1whJqzcIbyjAajUq21K
wgnYksH6TUVuutDg6r6PPaNTbmIvcxHwRs58hYi8JUIXdzIyYSlLdPezAo0VjwGw
8GHUQYy4r/hkSDWA4ViZ6ZjDIIgzT46nrTdxkGNPZn4Oz8k6nASnFFZhLfanytQI
YQhqlmIa/jievlZX5Q38snIPE+KYEq3buYK/OmbKuDCfHotC9nNNDCHdop7Qs4c=
=zQoC
-----END PGP SIGNATURE-----


From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-18 00:55:39
Message-ID: CAMkU=1xox5YcFOh5P_hNzxcNeVpGTu8N3ii6hfqGCdTFB5wBSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Mar 17, 2014 at 5:48 PM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 03/18/2014 07:20 AM, Joe Conway wrote:
> > On 03/17/2014 04:15 PM, Tom Lane wrote:
> >> Jim Nasby <jim(at)nasby(dot)net> writes:
> >>> On 3/17/14, 8:47 AM, Tom Lane wrote:
> >>>> (Note that this is only one of assorted O(N^2) behaviors in
> >>>> older versions of pg_dump; we've gradually stamped them out
> >>>> over time.)
> >
> >>> On that note, it's recommended that when you are taking a
> >>> backup to restore into a newer version of Postgres you create
> >>> the dump using the NEWER version of pg_dump, not the old one.
> >
> >> Right. IIRC, the OP said he *did* use a recent pg_dump ... but
> >> this particular issue got fixed server-side, so the new pg_dump
> >> didn't help against an 8.1 server :-(
> >
> > Exactly. I backported the patch from 9.3 to 8.4 and saw a
> > schema-only dump time go from <give-up-and-kill-it-after-5-days> to
> > 1 hour. This was for a database with about 500k tables.
>
> I wonder if doing large batches of
>
> LOCK TABLE table1, table2, table3, ...
>
> would help, instead of doing individual statements?
>

If I recall correctly, someone did submit a patch to do that. It helped
when dumping schema only, but not much when dumping data.

Cheers,

Jeff


From: Joe Conway <mail(at)joeconway(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jürgen Strobel <juergen+pg(at)strobel(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-18 01:32:37
Message-ID: 5327A235.9040001@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/17/2014 05:55 PM, Jeff Janes wrote:
> On Mon, Mar 17, 2014 at 5:48 PM, Craig Ringer
> <craig(at)2ndquadrant(dot)com I wonder if doing large batches of
>
> LOCK TABLE table1, table2, table3, ...
>
> would help, instead of doing individual statements?
>
> If I recall correctly, someone did submit a patch to do that. It
> helped when dumping schema only, but not much when dumping data.

Not surprising at all. The huge time is incurred in taking the locks,
but if you are trying to use pg_upgrade in link mode to speed your
upgrade, you are totally hosed by the time it takes to grab those locks.

This patch applied to 9.3 substantially fixes the issue:
8<-----------------------
commit eeb6f37d89fc60c6449ca12ef9e91491069369cb
Author: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
Date: Thu Jun 21 15:01:17 2012 +0300

Add a small cache of locks owned by a resource owner in ResourceOwner.
8<-----------------------

On my 8.4 database, with 500,000 tables there were about 2.5 million
locks taken including toast tables and indexes during the schema dump.
Without the patch grabbing locks took many, many days with that many
objects to lock. With a backported version of the patch, one hour.

So if you have a problem due to many tables on an older than 9.3
version of Postgres, this is the direction to head (a custom patch
applied to your old version just long enough to get successfully
upgraded).

Joe

- --
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJTJ6I1AAoJEDfy90M199hlDsAP/320vLhjKRjaxulBmcESmuze
LUoIOHLS2ZacybTjcMlZSoTBSzf6iXzc3A84ROhQ0c7ASYzWtF/YFkd039FzHz+e
TxtuodZd+CO18f1ZYBR5S7AhXhsA7oviXXdgPhqwb14mIqGAlvblTp9cvMODK+OS
O96NSLe2qe1AvmxwwthcKzhlXBChzoRvT8jXeS5A/G+VfM7UV1HApGmklJE0oe9+
ZaXhxQWGecKqZgkPwfZzIzOz9qQITDb3woi7GxbiXLv8Ds1lgAxPRz26qJB/mKBC
NqxQHViyty79TA8EFV8DrE0g++CUz33rSs1suY5Z1yzsQ7iEFBP1U52BJE5ZdB0J
8Zpz1eLT15fEIuV+64MeXN47U2refJdEjw9Ozx788MgDOu43k9m4+VHjzcH1AO2l
qfp0eqxpIjDpqH4Lu/0DAzl86yEW76tJX+pdieICGOHLdruLS/984gZGtDpjclNE
l/FaliLQQ4Bvqg8tMmmq/dyTxBG+BRmfCBbaBRdtQA762P9Lh7QsL/mGHukwRNVb
M5Ve7i/1HT7ZrazEnMkAotnYMrH5QTy1qTVfjiR0gjXzccdMXSOT8NN/yiWwOq6d
ZRuBvr8Ws+xCDDWwABj8Oh2mKpupy04/87EaTy2+sh6yJaIZPPV+n4ftjF4NF/gP
zBhXxMpFalKDqevkp52Z
=/Nl7
-----END PGP SIGNATURE-----


From: Jürgen Strobel <juergen+pg(at)strobel(dot)info>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-18 10:02:38
Message-ID: 532819BE.2090901@strobel.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 18.03.14 00:15, Tom Lane wrote:
> Jim Nasby <jim(at)nasby(dot)net> writes:
>> On 3/17/14, 8:47 AM, Tom Lane wrote:
>>> (Note that this is only one of assorted O(N^2) behaviors in older versions
>>> of pg_dump; we've gradually stamped them out over time.)
>
>> On that note, it's recommended that when you are taking a backup to restore into a newer version of Postgres you create the dump using the NEWER version of pg_dump, not the old one.
>
> Right. IIRC, the OP said he *did* use a recent pg_dump ... but this
> particular issue got fixed server-side, so the new pg_dump didn't help
> against an 8.1 server :-(

Yes, I did use 9.3's pg_dump against my 8.1 DB initially.

The patch was created against github's master.

-Jürgen


From: Jürgen Strobel <juergen+pg(at)strobel(dot)info>
To: Joe Conway <mail(at)joeconway(dot)com>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <jim(at)nasby(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_dump without explicit table locking
Date: 2014-03-18 12:25:50
Message-ID: 53283B4E.40502@strobel.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 18.03.14 02:32, Joe Conway wrote:
> On 03/17/2014 05:55 PM, Jeff Janes wrote:
>> On Mon, Mar 17, 2014 at 5:48 PM, Craig Ringer
>> <craig(at)2ndquadrant(dot)com I wonder if doing large batches of
>
>> LOCK TABLE table1, table2, table3, ...
>
>> would help, instead of doing individual statements?
>
>> If I recall correctly, someone did submit a patch to do that. It
>> helped when dumping schema only, but not much when dumping data.
>
> Not surprising at all. The huge time is incurred in taking the locks,
> but if you are trying to use pg_upgrade in link mode to speed your
> upgrade, you are totally hosed by the time it takes to grab those locks.
>
> This patch applied to 9.3 substantially fixes the issue:
> 8<-----------------------
> commit eeb6f37d89fc60c6449ca12ef9e91491069369cb
> Author: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
> Date: Thu Jun 21 15:01:17 2012 +0300
>
> Add a small cache of locks owned by a resource owner in ResourceOwner.
> 8<-----------------------
>
> On my 8.4 database, with 500,000 tables there were about 2.5 million
> locks taken including toast tables and indexes during the schema dump.
> Without the patch grabbing locks took many, many days with that many
> objects to lock. With a backported version of the patch, one hour.
>
> So if you have a problem due to many tables on an older than 9.3
> version of Postgres, this is the direction to head (a custom patch
> applied to your old version just long enough to get successfully
> upgraded).
>

In a testing environment I restored my 8.1 DB with 300,000 tables to a
9.3 server (using my patched pg_dump).

Then I ran the original 9.3 pg_dump against the 9.3 DB again, and it
works reasonably well. So I can confirm the server side improvements in
9.3 do to work for my test case.

Still when I finally get around to do this on production I plan to use
my patched pg_dump rather than backporting the server fix to 8.1, as I'd
rather not touch our already-patched-for-something-else 8.1 server.

I can't wait to get my hand on 9.x replication features and other stuff :-)

-Jürgen