pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_upgrade and wraparound
30+ messages / 9 participants
[nested] [flat]
* pg_upgrade and wraparound
@ 2018-06-09 10:46 Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 2 replies; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-09 10:46 UTC (permalink / raw)
To: pgsql-general
Hello!
I've been trying to upgrade a postgresql cluster from 9.6 to 10. I've
executed the pg_upgrade with the following options:
/usr/lib/postgresql/10/bin/pg_upgrade -b /usr/lib/postgresql/9.6/bin/ -B
/usr/lib/postgresql/10/bin/ -d /var/lib/postgresql/9.6/main -D
/var/lib/postgresql/10/main -o ' -c
config_file=/etc/postgresql/9.6/main/postgresql.conf' -O ' -c
config_file=/etc/postgresql/10/main/postgresql.conf'
The upgrade operation failed after several hours with the following error:
database is not accepting commands to avoid wraparound data loss in
database with OID 0
Earlier in the log there are a lot of messages like
pg_restore: executing BLOB 1740736966
pg_restore: WARNING: database with OID 0 must be vacuumed within 1000279
transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
database.
You might also need to commit or roll back old prepared transactions.
pg_restore: WARNING: database with OID 0 must be vacuumed within 1000278
transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
database.
You might also need to commit or roll back old prepared transactions.
I've tried to do VACUUM FULL on my 9.6 cluster on all databases and then
retried the pg_upgrade - it failed in the same way.
Also to be noted, earlier this cluster was succesfully upgraded with
pg_upgrade using similar parameters from older versions (at least 2 times,
something like 9.1 -> 9.3, 9.3 -> 9.6). The database is around 700 GB and
has very many pg_largeobjects in it.
What could be the reason of this and how can I perform my upgrade?
Thanks in advance,
Alexander
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-09 19:41 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
1 sibling, 1 reply; 30+ messages in thread
From: Adrian Klaver @ 2018-06-09 19:41 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 06/09/2018 03:46 AM, Alexander Shutyaev wrote:
> Hello!
>
> I've been trying to upgrade a postgresql cluster from 9.6 to 10. I've
> executed the pg_upgrade with the following options:
>
> /usr/lib/postgresql/10/bin/pg_upgrade -b /usr/lib/postgresql/9.6/bin/
> -B /usr/lib/postgresql/10/bin/ -d /var/lib/postgresql/9.6/main -D
> /var/lib/postgresql/10/main -o ' -c
> config_file=/etc/postgresql/9.6/main/postgresql.conf' -O ' -c
> config_file=/etc/postgresql/10/main/postgresql.conf'
>
> The upgrade operation failed after several hours with the following error:
>
> database is not accepting commands to avoid wraparound data loss in
> database with OID 0
Do you know which database has an OID of 0?
>
> Earlier in the log there are a lot of messages like
>
> pg_restore: executing BLOB 1740736966
> pg_restore: WARNING: database with OID 0 must be vacuumed within
> 1000279 transactions
> HINT: To avoid a database shutdown, execute a database-wide VACUUM in
> that database.
> You might also need to commit or roll back old prepared transactions.
> pg_restore: WARNING: database with OID 0 must be vacuumed within
> 1000278 transactions
> HINT: To avoid a database shutdown, execute a database-wide VACUUM in
> that database.
> You might also need to commit or roll back old prepared transactions.
>
> I've tried to do VACUUM FULL on my 9.6 cluster on all databases and then
> retried the pg_upgrade - it failed in the same way.
>
> Also to be noted, earlier this cluster was succesfully upgraded with
> pg_upgrade using similar parameters from older versions (at least 2
> times, something like 9.1 -> 9.3, 9.3 -> 9.6). The database is around
> 700 GB and has very many pg_largeobjects in it.
>
> What could be the reason of this and how can I perform my upgrade?
>
> Thanks in advance,
> Alexander
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-09 19:52 Tom Lane <tgl@sss.pgh.pa.us>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 3 replies; 30+ messages in thread
From: Tom Lane @ 2018-06-09 19:52 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 06/09/2018 03:46 AM, Alexander Shutyaev wrote:
>> The upgrade operation failed after several hours with the following error:
>> database is not accepting commands to avoid wraparound data loss in
>> database with OID 0
> Do you know which database has an OID of 0?
Well, none do, so the correct question is what is passing an invalid
database OID to the code that's complaining. This sure looks like a
bug, though I'm not sure we have enough info to locate it.
regards, tom lane
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 20:46 Alexander Shutyaev <shutyaev@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-10 20:46 UTC (permalink / raw)
To: pgsql-general
I can provide you with more info. Please tell me what you need. I really hope
someone here can help me somehow solve or workaround this, because I really
need to migrate to v10 for its features.
Thanks in advance,
Alexander
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 20:48 Alexander Shutyaev <shutyaev@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 0 replies; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-10 20:48 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
I can provide you with more info. Please tell me what you need. I really
hope someone here can help me somehow solve or workaround this, because I
really need to migrate to v10 for its features.
Thanks in advance,
Alexander
2018-06-09 22:52 GMT+03:00 Tom Lane <tgl@sss.pgh.pa.us>:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 06/09/2018 03:46 AM, Alexander Shutyaev wrote:
> >> The upgrade operation failed after several hours with the following
> error:
> >> database is not accepting commands to avoid wraparound data loss in
> >> database with OID 0
>
> > Do you know which database has an OID of 0?
>
> Well, none do, so the correct question is what is passing an invalid
> database OID to the code that's complaining. This sure looks like a
> bug, though I'm not sure we have enough info to locate it.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 20:55 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 1 reply; 30+ messages in thread
From: Adrian Klaver @ 2018-06-10 20:55 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 06/10/2018 01:46 PM, Alexander Shutyaev wrote:
> I can provide you with more info. Please tell me what you need. I really hope
> someone here can help me somehow solve or workaround this, because I really
> need to migrate to v10 for its features.
Well as Tom Lane said a database will not have an OID of 0, so we need
to know where that is coming from. On the oft chance it occurred in your
9.6 cluster can you see if:
select oid, datname from pg_database;
in the 9.6 cluster shows an OID of 0.
Also:
1) OS and version you are using?
2) Where are you getting you Postgres from?:
a) Package
Repo?
b) Source
File source?
3) Where there any issues with 9.6 cluster before you tried to upgrade
from it?
>
> Thanks in advance,
> Alexander
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 21:03 Alexander Shutyaev <shutyaev@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-10 21:03 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general
No database with oid 0 in 9.6 cluster:
postgres=# select oid, datname from pg_database;
oid | datname
------------+-----------
1 | template1
12438 | template0
16400 | bof
12439 | postgres
1016305714 | sslentry
(5 rows)
>> 1) OS and version you are using?
Ubuntu 16.04.4
>> 2) Where are you getting you Postgres from?:
>> a) Package
>> Repo?
>> b) Source
>> File source?
I've installed it from postgresql repo -
http://apt.postgresql.org/pub/repos/apt/
>> 3) Where there any issues with 9.6 cluster before you tried to upgrade
from it?
No, I don't remember anything specific about it.
2018-06-10 23:55 GMT+03:00 Adrian Klaver <adrian.klaver@aklaver.com>:
> On 06/10/2018 01:46 PM, Alexander Shutyaev wrote:
>
>> I can provide you with more info. Please tell me what you need. I really
>> hope
>> someone here can help me somehow solve or workaround this, because I
>> really
>> need to migrate to v10 for its features.
>>
>
> Well as Tom Lane said a database will not have an OID of 0, so we need to
> know where that is coming from. On the oft chance it occurred in your 9.6
> cluster can you see if:
>
> select oid, datname from pg_database;
>
> in the 9.6 cluster shows an OID of 0.
>
> Also:
>
> 1) OS and version you are using?
>
> 2) Where are you getting you Postgres from?:
> a) Package
> Repo?
> b) Source
> File source?
>
> 3) Where there any issues with 9.6 cluster before you tried to upgrade
> from it?
>
>
>
>> Thanks in advance,
>> Alexander
>>
>>
>>
>> --
>> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f184378
>> 0.html
>>
>>
>>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 21:09 Alexander Shutyaev <shutyaev@gmail.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-10 21:09 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general
Some more notes on databses.
Although the pg_upgrade failed, I've decided to check the databases in the
new cluster (10.4). There is no database with oid 0 either. Also to be
noted that some system databases changed the oids while others retained
them.
And of my databases - sslentry. It had a very big oid (can that seem
strange?) and its oid has changed.
select oid, datname from pg_database;
oid | datname
-------+-----------
13011 | template0
16400 | bof
13012 | postgres
16401 | sslentry
1 | template1
(5 rows)
2018-06-11 0:03 GMT+03:00 Alexander Shutyaev <shutyaev@gmail.com>:
> No database with oid 0 in 9.6 cluster:
>
> postgres=# select oid, datname from pg_database;
> oid | datname
> ------------+-----------
> 1 | template1
> 12438 | template0
> 16400 | bof
> 12439 | postgres
> 1016305714 | sslentry
> (5 rows)
>
> >> 1) OS and version you are using?
>
> Ubuntu 16.04.4
>
> >> 2) Where are you getting you Postgres from?:
> >> a) Package
> >> Repo?
> >> b) Source
> >> File source?
>
> I've installed it from postgresql repo - http://apt.postgresql.org/
> pub/repos/apt/
>
> >> 3) Where there any issues with 9.6 cluster before you tried to upgrade
> from it?
>
> No, I don't remember anything specific about it.
>
> 2018-06-10 23:55 GMT+03:00 Adrian Klaver <adrian.klaver@aklaver.com>:
>
>> On 06/10/2018 01:46 PM, Alexander Shutyaev wrote:
>>
>>> I can provide you with more info. Please tell me what you need. I really
>>> hope
>>> someone here can help me somehow solve or workaround this, because I
>>> really
>>> need to migrate to v10 for its features.
>>>
>>
>> Well as Tom Lane said a database will not have an OID of 0, so we need to
>> know where that is coming from. On the oft chance it occurred in your 9.6
>> cluster can you see if:
>>
>> select oid, datname from pg_database;
>>
>> in the 9.6 cluster shows an OID of 0.
>>
>> Also:
>>
>> 1) OS and version you are using?
>>
>> 2) Where are you getting you Postgres from?:
>> a) Package
>> Repo?
>> b) Source
>> File source?
>>
>> 3) Where there any issues with 9.6 cluster before you tried to upgrade
>> from it?
>>
>>
>>
>>> Thanks in advance,
>>> Alexander
>>>
>>>
>>>
>>> --
>>> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f184378
>>> 0.html
>>>
>>>
>>>
>>
>> --
>> Adrian Klaver
>> adrian.klaver@aklaver.com
>>
>
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 21:34 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 1 reply; 30+ messages in thread
From: Adrian Klaver @ 2018-06-10 21:34 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; +Cc: pgsql-general
On 06/10/2018 02:09 PM, Alexander Shutyaev wrote:
> Some more notes on databses.
>
> Although the pg_upgrade failed, I've decided to check the databases in
> the new cluster (10.4). There is no database with oid 0 either. Also to
> be noted that some system databases changed the oids while others
> retained them.
If I am following the source code for pg_upgrade correctly that is
expected. Pretty sure because the order of object creation is different.
>
> And of my databases - sslentry. It had a very big oid (can that seem
> strange?) and its oid has changed.
OID's are added at time of object creation so I would say the ssslentry
database was created some time after the other databases in the 9.6
cluster. Actually probably more accurate to say after 1016305714 -
16400(bof db) objects that have OID's where created.
When the upgrade failed pg_upgrade should have pointed you at an error log.
Did it and is there anything useful there?
From your OP post:
"You might also need to commit or roll back old prepared transactions."
Do you have any of those in the 9.6 cluster?
See:
https://www.postgresql.org/docs/10/static/view-pg-prepared-xacts.html
>
> select oid, datname from pg_database;
> oid | datname
> -------+-----------
> 13011 | template0
> 16400 | bof
> 13012 | postgres
> 16401 | sslentry
> 1 | template1
> (5 rows)
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-10 21:45 Alexander Shutyaev <shutyaev@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-10 21:45 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general
The error log is like this. Here's its tail:
pg_restore: executing BLOB 1740737401
pg_restore: WARNING: database with OID 0 must be vacuumed within 1000003
transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
database.
You might also need to commit or roll back old prepared transactions.
pg_restore: WARNING: database with OID 0 must be vacuumed within 1000002
transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
database.
You might also need to commit or roll back old prepared transactions.
pg_restore: executing BLOB 1740737402
pg_restore: WARNING: database with OID 0 must be vacuumed within 1000001
transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
database.
You might also need to commit or roll back old prepared transactions.
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 9759463; 2613 1740737402
BLOB 1740737402 bof_user
pg_restore: [archiver (db)] could not execute query: ERROR: database is
not accepting commands to avoid wraparound data loss in database with OID 0
HINT: Stop the postmaster and vacuum that database in single-user mode.
You might also need to commit or roll back old prepared transactions.
Command was: ALTER LARGE OBJECT 1740737402 OWNER TO bof_user;
Before that there is a lot of similar messages - the only things chainging
are the "executing BLOB nnn" number and "must be vacuumed within nnn
transactions" number.
As for the prepared transactions - no, I don't have them, our application
doesn't use this functionality.
2018-06-11 0:34 GMT+03:00 Adrian Klaver <adrian.klaver@aklaver.com>:
> On 06/10/2018 02:09 PM, Alexander Shutyaev wrote:
>
>> Some more notes on databses.
>>
>> Although the pg_upgrade failed, I've decided to check the databases in
>> the new cluster (10.4). There is no database with oid 0 either. Also to be
>> noted that some system databases changed the oids while others retained
>> them.
>>
>
> If I am following the source code for pg_upgrade correctly that is
> expected. Pretty sure because the order of object creation is different.
>
>
>> And of my databases - sslentry. It had a very big oid (can that seem
>> strange?) and its oid has changed.
>>
>
> OID's are added at time of object creation so I would say the ssslentry
> database was created some time after the other databases in the 9.6
> cluster. Actually probably more accurate to say after 1016305714 -
> 16400(bof db) objects that have OID's where created.
>
> When the upgrade failed pg_upgrade should have pointed you at an error log.
>
> Did it and is there anything useful there?
>
> From your OP post:
>
> "You might also need to commit or roll back old prepared transactions."
>
> Do you have any of those in the 9.6 cluster?
>
> See:
>
> https://www.postgresql.org/docs/10/static/view-pg-prepared-xacts.html
>
>
>
>> select oid, datname from pg_database;
>> oid | datname
>> -------+-----------
>> 13011 | template0
>> 16400 | bof
>> 13012 | postgres
>> 16401 | sslentry
>> 1 | template1
>> (5 rows)
>>
>>
>>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 00:15 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 1 reply; 30+ messages in thread
From: Adrian Klaver @ 2018-06-11 00:15 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; +Cc: pgsql-general
On 06/10/2018 02:45 PM, Alexander Shutyaev wrote:
Comments inline.
> The error log is like this. Here's its tail:
Is this the regular Postgres log or the pg_upgrade log which should be
something like pg_upgrade_server.log?
> pg_restore: [archiver (db)] could not execute query: ERROR: database is
> not accepting commands to avoid wraparound data loss in database with OID 0
> HINT: Stop the postmaster and vacuum that database in single-user mode.
How did you get into the 10 cluster to report on the database OID's and
names?
> You might also need to commit or roll back old prepared transactions.
> Command was: ALTER LARGE OBJECT 1740737402 OWNER TO bof_user;
>
> Before that there is a lot of similar messages - the only things
> chainging are the "executing BLOB nnn" number and "must be vacuumed
> within nnn transactions" number.
>
Which database has the large objects?
> As for the prepared transactions - no, I don't have them, our
> application doesn't use this functionality.
Did you check this view to confirm?:
https://www.postgresql.org/docs/10/static/view-pg-prepared-xacts.html
Just trying to eliminate possibilities.
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 06:46 Alexander Shutyaev <shutyaev@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-11 06:46 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general
>> Is this the regular Postgres log or the pg_upgrade log which should be
something like pg_upgrade_server.log?
This is the pg_upgrade_dump_16400.log.
>> How did you get into the 10 cluster to report on the database OID's and
names?
After the pg_upgrade failed I was able to start both clusters, so I
connected to the new 10.4 cluster and ran the query.
>> Which database has the large objects?
bof (OID=16400). It is also effectively the only database that matters
here. The other one - sslentry only contains a couple of tables and a dozen
of records.
>> Did you check this view to confirm?
Yes, I did:
select * from pg_prepared_xacts;
transaction | gid | prepared | owner | database
-------------+-----+----------+-------+----------
(0 rows)
2018-06-11 3:15 GMT+03:00 Adrian Klaver <adrian.klaver@aklaver.com>:
> On 06/10/2018 02:45 PM, Alexander Shutyaev wrote:
>
> Comments inline.
>
> The error log is like this. Here's its tail:
>>
>
> Is this the regular Postgres log or the pg_upgrade log which should be
> something like pg_upgrade_server.log?
>
>
> pg_restore: [archiver (db)] could not execute query: ERROR: database is
>> not accepting commands to avoid wraparound data loss in database with OID 0
>> HINT: Stop the postmaster and vacuum that database in single-user mode.
>>
>
> How did you get into the 10 cluster to report on the database OID's and
> names?
>
> You might also need to commit or roll back old prepared transactions.
>> Command was: ALTER LARGE OBJECT 1740737402 OWNER TO bof_user;
>>
>> Before that there is a lot of similar messages - the only things
>> chainging are the "executing BLOB nnn" number and "must be vacuumed within
>> nnn transactions" number.
>>
>>
> Which database has the large objects?
>
> As for the prepared transactions - no, I don't have them, our application
>> doesn't use this functionality.
>>
>
> Did you check this view to confirm?:
>
> https://www.postgresql.org/docs/10/static/view-pg-prepared-xacts.html
>
> Just trying to eliminate possibilities.
>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 13:12 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 0 replies; 30+ messages in thread
From: Adrian Klaver @ 2018-06-11 13:12 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; +Cc: pgsql-general
On 06/10/2018 11:46 PM, Alexander Shutyaev wrote:
> >> Is this the regular Postgres log or the pg_upgrade log which should
> be something like pg_upgrade_server.log?
>
> This is the pg_upgrade_dump_16400.log.
>
>>> How did you get into the 10 cluster to report on the database OID's and
> names?
>
> After the pg_upgrade failed I was able to start both clusters, so I
> connected to the new 10.4 cluster and ran the query.
I am at a loss for an explanation. My thoughts:
1) The database with an OID of 0 is a mystery, though it does not seem
to be stopping the upgrade by itself.
2) The upgrade stops because of transaction ID wraparound, which is
strange as that is not showing up in the 9.6 cluster I presume. You
might want the queries found below on the 9.6 and 10 clusters to help
figure this out:
https://www.postgresql.org/docs/10/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND
SELECT c.oid::regclass as table_name,
greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
FROM pg_class c
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
WHERE c.relkind IN ('r', 'm');
SELECT datname, age(datfrozenxid) FROM pg_database;
>
>>> Which database has the large objects?
>
> bof (OID=16400). It is also effectively the only database that matters
> here. The other one - sslentry only contains a couple of tables and a
> dozen of records.
>
>>> Did you check this view to confirm?
>
> Yes, I did:
>
> select * from pg_prepared_xacts;
> transaction | gid | prepared | owner | database
> -------------+-----+----------+-------+----------
> (0 rows)
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 17:03 Andres Freund <andres@anarazel.de>
parent: Alexander Shutyaev <shutyaev@gmail.com>
1 sibling, 0 replies; 30+ messages in thread
From: Andres Freund @ 2018-06-11 17:03 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; +Cc: pgsql-general
Hi,
On 2018-06-09 13:46:16 +0300, Alexander Shutyaev wrote:
> Hello!
>
> I've been trying to upgrade a postgresql cluster from 9.6 to 10. I've
> executed the pg_upgrade with the following options:
>
> /usr/lib/postgresql/10/bin/pg_upgrade -b /usr/lib/postgresql/9.6/bin/ -B
> /usr/lib/postgresql/10/bin/ -d /var/lib/postgresql/9.6/main -D
> /var/lib/postgresql/10/main -o ' -c
> config_file=/etc/postgresql/9.6/main/postgresql.conf' -O ' -c
> config_file=/etc/postgresql/10/main/postgresql.conf'
>
> The upgrade operation failed after several hours with the following error:
>
> database is not accepting commands to avoid wraparound data loss in
> database with OID 0
>
> Earlier in the log there are a lot of messages like
>
> pg_restore: executing BLOB 1740736966
> pg_restore: WARNING: database with OID 0 must be vacuumed within 1000279
> transactions
> HINT: To avoid a database shutdown, execute a database-wide VACUUM in that
> database.
> You might also need to commit or roll back old prepared transactions.
Since this happens in the version you're migrating too, I suggest
replacing the warning with a PANIC and then using the debugger to look
at the corefile generated (when using an appropriate ulimit). It's not
immediately obvious why there'd not be correct knowledge about the
oldest database around. If you do so, please include 'p *ShmemVariableCache'
output.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 17:08 Andres Freund <andres@anarazel.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 30+ messages in thread
From: Andres Freund @ 2018-06-11 17:08 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 2018-06-09 15:52:26 -0400, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 06/09/2018 03:46 AM, Alexander Shutyaev wrote:
> >> The upgrade operation failed after several hours with the following error:
> >> database is not accepting commands to avoid wraparound data loss in
> >> database with OID 0
>
> > Do you know which database has an OID of 0?
>
> Well, none do, so the correct question is what is passing an invalid
> database OID to the code that's complaining. This sure looks like a
> bug, though I'm not sure we have enough info to locate it.
It sure looks like ShmemVariableCache->oldestXidDB isn't initialized.
As far as I remember we just initialize that from a checkpoint at
startup. I suspect the issue is that pg_resetwal does:
if (set_xid != 0)
{
ControlFile.checkPointCopy.nextXid = set_xid;
/*
* For the moment, just set oldestXid to a value that will force
* immediate autovacuum-for-wraparound. It's not clear whether adding
* user control of this is useful, so let's just do something that's
* reasonably safe. The magic constant here corresponds to the
* maximum allowed value of autovacuum_freeze_max_age.
*/
ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
}
but we have codepath that doesn't check for oldestXidDB being
InvalidOid. Not great.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 17:14 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 30+ messages in thread
From: Tom Lane @ 2018-06-11 17:14 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
Andres Freund <andres@anarazel.de> writes:
> I suspect the issue is that pg_resetwal does:
> if (set_xid != 0)
> {
> ControlFile.checkPointCopy.nextXid = set_xid;
> /*
> * For the moment, just set oldestXid to a value that will force
> * immediate autovacuum-for-wraparound. It's not clear whether adding
> * user control of this is useful, so let's just do something that's
> * reasonably safe. The magic constant here corresponds to the
> * maximum allowed value of autovacuum_freeze_max_age.
> */
> ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
> if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
> ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
> ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
> }
> but we have codepath that doesn't check for oldestXidDB being
> InvalidOid. Not great.
Hm, I think I'd define the problem as "pg_resetwal is violating the
expectation that oldestXidDB be valid".
However, this just explains the basically-cosmetic issue that the
complaint message mentions OID 0. It doesn't really get us to the
answer to why Alexander is seeing a failure. It might be useful
to see pg_controldata output for the old cluster, as well as
"select datname, datfrozenxid from pg_database" output from the
old cluster.
regards, tom lane
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 17:29 Andres Freund <andres@anarazel.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 2 replies; 30+ messages in thread
From: Andres Freund @ 2018-06-11 17:29 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 2018-06-11 13:14:12 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > I suspect the issue is that pg_resetwal does:
> > if (set_xid != 0)
> > {
> > ControlFile.checkPointCopy.nextXid = set_xid;
>
> > /*
> > * For the moment, just set oldestXid to a value that will force
> > * immediate autovacuum-for-wraparound. It's not clear whether adding
> > * user control of this is useful, so let's just do something that's
> > * reasonably safe. The magic constant here corresponds to the
> > * maximum allowed value of autovacuum_freeze_max_age.
> > */
> > ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
> > if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
> > ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
> > ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
> > }
>
> > but we have codepath that doesn't check for oldestXidDB being
> > InvalidOid. Not great.
>
> Hm, I think I'd define the problem as "pg_resetwal is violating the
> expectation that oldestXidDB be valid".
Well, what could it do otherwise? ForceTransactionIdLimitUpdate()
currently does a syscache check for database existence. That'll just
return a lookup failure for InvalidOid, so we're reasonably good on that
front.
Using a hardcoded 2000000000 seems worse, will have funny results if
running with a smaller autovacuum_freeze_max_age...
> However, this just explains the basically-cosmetic issue that the
> complaint message mentions OID 0. It doesn't really get us to the
> answer to why Alexander is seeing a failure. It might be useful
> to see pg_controldata output for the old cluster, as well as
> "select datname, datfrozenxid from pg_database" output from the
> old cluster.
pg_upgrade starts the server with autovacuum disabled, I suspect
restoring all the large objects ends up using a lot of transaction
ids. GetNewTransactionId() should start autovacuum, but I'd guess that's
where things are going wrong for some reason.
Alexander, could you hack things up so autovacuum logging is enabled
(log_autovacuum_min_duration=0), and see whether it's triggered?
I'm not entirely clear why pg_restore appears to use a separate
transaction for each large object, surely exascerbating the problem.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 18:32 Alexander Shutyaev <shutyaev@gmail.com>
parent: Andres Freund <andres@anarazel.de>
1 sibling, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-11 18:32 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
I'm back with more details.
First, I've deleted the smaller sslentry database, since I don't need it,
just so that it doesn't somehow spoil the picture. Now there is only 1 user
database - bof (OID=16400). After that I've ran the pg_upgrade on a clean
10.4 cluster and it failed in the same way.
Now, the answers to your queries.
>> 2) The upgrade stops because of transaction ID wraparound, which is
strange as that is not showing up in the 9.6 cluster I presume. You might
want the queries found below on the 9.6 and 10 clusters to help figure this
out:
>> SELECT c.oid::regclass as table_name,
>> greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
>> FROM pg_class c
>> LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
>> WHERE c.relkind IN ('r', 'm');
9.6 result - see attached 96-query1.txt
10.4 result - see attached 104-query1.txt
>> SELECT datname, age(datfrozenxid) FROM pg_database;
9.6 result - see attached 96-query2.txt
10.4 result - see attached 104-query2.txt
>> It might be useful
>> to see pg_controldata output for the old cluster, as well as
>> "select datname, datfrozenxid from pg_database" output from the
>> old cluster.
for the query - see above, for pg_controldata:
9.6 - see attached 96-pg_controldata.txt
10.4 - see attached 104-pg_controldata.txt
>> Alexander, could you hack things up so autovacuum logging is enabled
>> (log_autovacuum_min_duration=0), and see whether it's triggered?
I'll be happy to, but that will require to run pg_upgrade once more and
that takes more that half a day and during this time clusters are not
available to me. Given the data I'm attaching it may happen that the
colleagues will want to see something else from my clusters or maybe change
some settings before running the pg_upgrade again. Therefore, I'll wait 12
hours after this message in case there will be any more requests and the
I'll run the pg_upgrade again.
Thank you all for trying to solve this matter, this is much appreciated! :)
2018-06-11 20:29 GMT+03:00 Andres Freund <andres@anarazel.de>:
> On 2018-06-11 13:14:12 -0400, Tom Lane wrote:
> > Andres Freund <andres@anarazel.de> writes:
> > > I suspect the issue is that pg_resetwal does:
> > > if (set_xid != 0)
> > > {
> > > ControlFile.checkPointCopy.nextXid = set_xid;
> >
> > > /*
> > > * For the moment, just set oldestXid to a value that will
> force
> > > * immediate autovacuum-for-wraparound. It's not clear
> whether adding
> > > * user control of this is useful, so let's just do
> something that's
> > > * reasonably safe. The magic constant here corresponds
> to the
> > > * maximum allowed value of autovacuum_freeze_max_age.
> > > */
> > > ControlFile.checkPointCopy.oldestXid = set_xid -
> 2000000000;
> > > if (ControlFile.checkPointCopy.oldestXid <
> FirstNormalTransactionId)
> > > ControlFile.checkPointCopy.oldestXid +=
> FirstNormalTransactionId;
> > > ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
> > > }
> >
> > > but we have codepath that doesn't check for oldestXidDB being
> > > InvalidOid. Not great.
> >
> > Hm, I think I'd define the problem as "pg_resetwal is violating the
> > expectation that oldestXidDB be valid".
>
> Well, what could it do otherwise? ForceTransactionIdLimitUpdate()
> currently does a syscache check for database existence. That'll just
> return a lookup failure for InvalidOid, so we're reasonably good on that
> front.
>
> Using a hardcoded 2000000000 seems worse, will have funny results if
> running with a smaller autovacuum_freeze_max_age...
>
>
> > However, this just explains the basically-cosmetic issue that the
> > complaint message mentions OID 0. It doesn't really get us to the
> > answer to why Alexander is seeing a failure. It might be useful
> > to see pg_controldata output for the old cluster, as well as
> > "select datname, datfrozenxid from pg_database" output from the
> > old cluster.
>
> pg_upgrade starts the server with autovacuum disabled, I suspect
> restoring all the large objects ends up using a lot of transaction
> ids. GetNewTransactionId() should start autovacuum, but I'd guess that's
> where things are going wrong for some reason.
>
> Alexander, could you hack things up so autovacuum logging is enabled
> (log_autovacuum_min_duration=0), and see whether it's triggered?
>
> I'm not entirely clear why pg_restore appears to use a separate
> transaction for each large object, surely exascerbating the problem.
>
> Greetings,
>
> Andres Freund
>
Attachments:
96-pg_controldata.txt (text/plain, 2.3K) download
pg_control version number: 960
Catalog version number: 201608131
Database system identifier: 6341258630649216079
Database cluster state: in production
pg_control last modified: Mon 11 Jun 2018 09:10:28 PM MSK
Latest checkpoint location: 811B/24CA0B40
Prior checkpoint location: 811B/24CA0AD0
Latest checkpoint's REDO location: 811B/24CA0B40
Latest checkpoint's REDO WAL file: 000000030000811B00000024
Latest checkpoint's TimeLineID: 3
Latest checkpoint's PrevTimeLineID: 3
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:1982110603
Latest checkpoint's NextOID: 1763738656
Latest checkpoint's NextMultiXactId: 78
Latest checkpoint's NextMultiOffset: 136
Latest checkpoint's oldestXID: 1871522205
Latest checkpoint's oldestXID's DB: 12438
Latest checkpoint's oldestActiveXID: 0
Latest checkpoint's oldestMultiXid: 78
Latest checkpoint's oldestMulti's DB: 12439
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Mon 11 Jun 2018 11:54:29 AM MSK
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: minimal
wal_log_hints setting: off
max_connections setting: 1500
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 1024
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
96-query1.txt (text/plain, 19.6K) download
table_name | age
-----------------------------------------------------+-----
pg_authid | 771
pg_shseclabel | 767
pg_transform | 766
information_schema.sql_languages | 765
information_schema.sql_packages | 763
pg_description | 761
pg_cast | 759
pg_largeobject | 757
pg_largeobject_metadata | 755
pg_amop | 753
pg_amproc | 751
pg_language | 749
pg_aggregate | 747
pg_rewrite | 745
pg_trigger | 743
pg_event_trigger | 741
pg_enum | 740
pg_namespace | 739
pg_conversion | 737
pg_depend | 735
pg_database | 733
pg_auth_members | 729
pg_shdepend | 728
pg_shdescription | 726
pg_ts_config_map | 722
pg_ts_dict | 720
pg_ts_parser | 718
pg_ts_template | 716
pg_extension | 714
pg_foreign_data_wrapper | 712
pg_foreign_server | 710
pg_foreign_table | 708
pg_policy | 706
information_schema.sql_parts | 705
alfastrahexchangedocumentindexdata | 703
information_schema.sql_sizing | 701
information_schema.sql_sizing_profiles | 699
pg_user_mapping | 698
pg_index | 696
pg_operator | 694
pg_opfamily | 692
pg_opclass | 690
pg_am | 688
aclroleindexdata | 686
acluserdata | 684
pg_statistic | 682
cluster_qrtz_simple_triggers | 679
cluster_qrtz_job_details | 677
cluster_qrtz_simprop_triggers | 675
financedocumentrecordindexdata | 672
farerulesdocumentindexdata | 670
gdsbookabilityitemindexdata | 668
locks | 664
notificationmaildocumenttemplateindexdata | 663
notificationschemeindexdata | 661
amadeusexchangedocumentindexdata | 658
ssodexchangedocumentindexdata | 656
templatereportdescriptionindexdata | 655
userwebsettingsdata | 653
pg_constraint | 649
productvoidingindexdata | 647
debitslipindexdata | 645
teletrainexchangedocumentindexdata | 644
suxmlexchangedocumentindexdata | 643
commissionpropertiesindexdata | 642
vctcostsexchangedocumentindexdata | 640
aclregistryassetdata | 638
inmobexchangedocumentindexdata | 636
creditslipindexdata | 635
aeroexpressticketindexdata | 633
aclaspectindexdata | 630
aclgroupdata | 628
agencymemoproductitemgroupindexdata | 626
aclmodificatorindexdata | 625
basicdocumentindexdata | 623
agencymemoindexdata | 621
agentgroupindexdata | 620
acquainteddata | 618
aeroexpressreportdocumentindexdata | 615
athxmlorganizationexchangedocumentindexdata | 614
airlinecardcodesexchangedocumentindexdata | 613
agencymemoproductindexdata | 612
basicbugreportindexdata | 611
agenttemplatereportdocumentindexdata | 609
archivedproductindexdata | 608
baggagelimitsstatisticsdata | 606
basiccommonconnectionsettingsindexdata | 604
cluster_qrtz_calendars | 602
bookabilityreportdocumentindexdata | 601
bookingfileexchangedocumentindexdata | 600
basiccommonexportsettingsindexdata | 599
billingtransactionchangeindexdata | 597
cluster_qrtz_blob_triggers | 596
aviacentrconsolidatedreportdocumentindexdata | 595
brandedfareinformationindexdata | 593
cashindexdata | 592
billingtransactionindexdata | 591
basicexportsettingsindexdata | 589
blockcharterappendixindexdata | 587
mcoexchangedocumentindexdata | 585
branchexchangedocumentindexdata | 584
billing1cexchangedocumentindexdata | 583
chartofaccountselementindexdata | 580
cashregisterindexdata | 578
bulklongrunningtaskentrydata | 577
charterscitypairsexchangedocumentindexdata | 576
clientexchangedocumentindexdata | 574
cccexchangedocumentindexdata | 573
charterstraveldocumentexchangedocumentindexdata | 572
cluster_qrtz_cron_triggers | 570
cluster_qrtz_fired_triggers | 568
contractordescriptionindexdata | 566
cluster_qrtz_triggers | 564
combdata | 562
complexorderindexdata | 560
deliveryitemindexdata | 558
combincrementdata | 557
contractrelationdescriptionindexdata | 555
deletedobjectreferencedata | 553
dictionarydata | 551
credithistorydata | 549
deskentrydata | 547
bnch2exchangedocumentindexdata | 545
insuranceaccidentindexdata | 543
deliveryindexdata | 541
dbexchangedocumentindexdata | 540
dictupdateitemindexdata | 539
divergencereportdocumentindexdata | 537
discountpropertiesindexdata | 536
hotelproductreportdocumentindexdata | 534
excessbagageexchangedocumentindexdata | 533
exportdocumentindexdata | 532
financedocumentstemplatereportdocumentindexdata | 530
gdsaccountindexdata | 529
gdstracingdocumentindexdata | 527
gabrielmaskexchangedocumentindexdata | 525
openingbalancedata | 523
mainhotelproductguestindexdata | 521
hotexchangedocumentindexdata | 519
geoiprangedata | 518
hotelproductindexdata | 516
holdingexchangedocumentindexdata | 514
ibankexportdataindexdata | 513
insuranceaccidentreportdocumentindexdata | 511
insurancetripcancelindexdata | 510
issuetemplatesindexdata | 508
penaltypropertiesindexdata | 506
organizationexchangedocumentindexdata | 504
iurexchangedocumentindexdata | 503
gdsreferenceindexdata | 501
organizationbalanceindexdata | 499
personmetadataindexdata | 498
modifiedobjectreferencedata | 496
payment1cexchangedocumentindexdata | 494
mcofeesindexdata | 493
mytable | 492
mytmptable | 490
paytureregistryexchangedocumentindexdata | 488
notificationtemplategroupindexdata | 486
personexchangedocumentindexdata | 484
passnflycheckinproductindexdata | 482
pgpaymentindexdata | 481
retexchangedocumentindexdata | 479
refundeventindexdata | 478
userotpassetdata | 477
pg_db_role_setting | 772
productreportdocumentindexdata | 475
renaissanceinsuranceexchangedocumentindexdata | 474
s7excelexchangedocumentindexdata | 473
reportassetdata | 472
rootagentindexdata | 470
rulesmigrationexchangedocumentindexdata | 468
railwayreportdocumentindexdata | 466
retarchiveexchangedocumentindexdata | 465
rapidaexchangedocumentindexdata | 464
scheduledtasksettingsindexdata | 463
sirenamtdfaresettingsindexdata | 461
sabrecsvexchangedocumentindexdata | 458
searchcityfilterassetdata | 457
transactionsplitindexdata | 456
saleschaindescriptionindexdata | 454
salesreportdocumentindexdata | 452
sequencenumbersdata | 450
sirenaxmlexchangedocumentindexdata | 448
skyagentexchangedocumentindexdata | 446
soficlientsexchangedocumentindexdata | 445
travelpolicyauthorizationschemeindexdata | 444
terminalcreditreportdocumentindexdata | 442
spgdarchiveexchangedocumentindexdata | 441
subagentbalancereportdocumentindexdata | 440
tchdirectcontractindexdata | 439
subagentreportdocumentindexdata | 438
productsearchindexdata | 437
bulkdictionarydata | 411
sslentrylockassetdata | 435
stockblankreportdocumentindexdata | 434
tmp | 433
tchxmlcommissionsexchangedocumentindexdata | 431
tripartitereportdocumentindexdata | 429
trashbinitemindexdata | 428
triprequestindexdata | 426
shipmentautoprocessingexchangedocumentindexdata | 424
stockorderindexdata | 422
pg_inherits | 421
universalproductdescriptionindexdata | 420
utsitineraryexchangedocumentindexdata | 418
validatorindexdata | 417
vctpassengersexchangedocumentindexdata | 415
vip1cudidsexchangedocumentindexdata | 413
worklogindexdata | 412
cluster_qrtz_scheduler_state | 410
deletedassetreferencedata | 408
ufsexchangedocumentindexdata | 406
sabretokenindexdata | 405
accountingentryindexdata | 403
basemtdfaresettingsindexdata | 402
agentreportdocumentindexdata | 400
holdingindexdata | 399
personemploymentindexdata | 397
auraexchangedocumentindexdata | 395
rulesmigrationsettingsindexdata | 394
termindexdata | 390
paymentfeepropertiesindexdata | 388
paymentindexdata | 383
noticeindexdata | 392
organizationcontractindexdata | 386
hotelbookexchangedocumentindexdata | 384
tripartitecontractindexdata | 381
loginhistorydata | 379
pg_init_privs | 769
cluster_qrtz_paused_trigger_grps | 378
agencymemoitemindexdata | 377
organizationmetadataindexdata | 376
specialtariffindexdata | 374
templatereportdocumentindexdata | 372
branchindexdata | 370
avianovaitineraryreceiptexchangedocindexdata | 369
eticketquotaindexdata | 368
requestindexdata | 367
pg_replication_origin | 365
pg_collation | 364
pg_tablespace | 362
information_schema.sql_implementation_info | 360
pg_attrdef | 358
dbproperties | 356
crmaccountsexchangedocumentindexdata | 354
placeofsalesindexdata | 352
directcontractindexdata | 350
stockblankindexdata | 348
passengerpassportindexdata | 345
bookingfileindexdata | 343
liaisonexchangedocumentindexdata | 341
issueindexdata | 347
ssodarchiveexchangedocumentindexdata | 340
pg_default_acl | 339
tripindexdata | 337
railwayproductindexdata | 335
insurancetouristicindexdata | 333
commonproductfopindexdata | 331
universalproductindexdata | 329
entityeventnotificationindexdata | 327
pg_range | 325
pg_seclabel | 323
pg_attribute | 322
pg_proc | 320
productindexdata | 314
feepropertiesindexdata | 312
pg_type | 318
sftppersonsexchangedocumentindexdata | 310
personindexdata | 308
portraitpersonsexchangedocumentindexdata | 306
visaproductindexdata | 305
personbalanceindexdata | 303
invoiceexchangedocumentindexdata | 301
cwtgeneralproductindexdata | 299
seatblocksindexdata | 297
contractindexdata | 295
bronevikexchangedocumentindexdata | 293
mainhotelproductindexdata | 292
taisexchangedocumentindexdata | 290
contractcustomerindexdata | 289
pg_pltemplate | 731
pg_ts_config | 724
financeinitializationdataindexdata | 287
cardindexdata | 285
carrentalproductindexdata | 283
modelcontractindexdata | 281
basicsystemsettingsindexdata | 279
salespointindexdata | 277
basicpaymentdocumentindexdata | 275
transferproductindexdata | 273
cluster_qrtz_locks | 681
pccindexdata | 674
financedocumentindexdata | 666
statisticsdocumentindexdata | 659
information_schema.sql_features | 651
entitydata | 269
asynccommandinfodata | 267
versiondata | 266
vipstatisticspdoassetdata | 264
temporalobjectdata | 263
aclassetdata | 261
keypairentrydata | 259
fxworkspacedata | 257
aclentrydata | 255
exportreferencedata | 253
templatedocumentindexdata | 251
longrunningtaskinfodata | 249
syslogitemdata | 247
workspacedata | 245
activityitemdata | 243
shipmentautoprocessingexchangedocumentreferencedata | 241
phonecalldata | 240
keybindingsdata | 239
gdsstatentrydata | 235
storagesyncrecorddata | 234
asynctaskassignmentdata | 233
sslsessionentryassetdata | 231
transferindexdata | 230
iwayexchangedocumentindexdata | 229
shipmentindexdata | 228
questionrecorddata | 226
carlson1cinvoicerecordindexdata | 225
commonproductindexdata | 223
expressexchangedocumentindexdata | 646
athxmlpersonexchangedocumentindexdata | 631
aggregatedentityindexdata | 616
clientdebtreportdocumentindexdata | 594
cashregisterworkplaceindexdata | 581
spgdexchangedocumentindexdata | 459
pg_class | 316
organizationindexdata | 271
useraccountdata | 237
(333 rows)
96-query2.txt (text/plain, 152B) download
datname | age
-----------+-----------
template1 | 216
template0 | 110588398
bof | 772
postgres | 110
(4 rows)
104-pg_controldata.txt (text/plain, 2.4K) download
pg_control version number: 1002
Catalog version number: 201707211
Database system identifier: 6565566377704503227
Database cluster state: in production
pg_control last modified: Mon 11 Jun 2018 09:20:32 PM MSK
Latest checkpoint location: 8125/B7DEC5C0
Prior checkpoint location: 8125/8877C950
Latest checkpoint's REDO location: 8125/B738E100
Latest checkpoint's REDO WAL file: 0000000100008125000000B7
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:2128594259
Latest checkpoint's NextOID: 24781
Latest checkpoint's NextMultiXactId: 78
Latest checkpoint's NextMultiOffset: 136
Latest checkpoint's oldestXID: 1982109846
Latest checkpoint's oldestXID's DB: 16400
Latest checkpoint's oldestActiveXID: 2128594259
Latest checkpoint's oldestMultiXid: 78
Latest checkpoint's oldestMulti's DB: 16400
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Mon 11 Jun 2018 09:20:28 PM MSK
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: replica
wal_log_hints setting: off
max_connections setting: 1500
max_worker_processes setting: 20
max_prepared_xacts setting: 0
max_locks_per_xact setting: 1024
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
Mock authentication nonce: 2535ee631c6be3ddcf78f52d21a10ba1694e4d96a396f265f5a6013b2c5931ee
104-query1.txt (text/plain, 22.1K) download
table_name | age
-----------------------------------------------------+-----------
pg_statistic | 146483656
pg_type | 146483656
amadeusexchangedocumentindexdata | 146484314
agenttemplatereportdocumentindexdata | 146484265
aggregatedentityindexdata | 146484272
airlinecardcodesexchangedocumentindexdata | 146484269
archivedproductindexdata | 146484264
alfastrahexchangedocumentindexdata | 146484359
asynctaskassignmentdata | 146483889
asynccommandinfodata | 146483923
athxmlorganizationexchangedocumentindexdata | 146484270
auraexchangedocumentindexdata | 146484051
athxmlpersonexchangedocumentindexdata | 146484287
aviacentrconsolidatedreportdocumentindexdata | 146484251
avianovaitineraryreceiptexchangedocindexdata | 146484025
pg_policy | 146483656
pg_authid | 146483656
pg_largeobject_metadata | 146484411
baggagelimitsstatisticsdata | 146484262
pg_amop | 146483656
pg_amproc | 146483656
pg_language | 146483656
pg_aggregate | 146483656
pg_user_mapping | 146483656
pg_subscription | 146483656
pg_attribute | 146483656
pg_proc | 146483656
pg_class | 146483656
pg_attrdef | 146483656
pg_constraint | 146483656
basiccommonexportsettingsindexdata | 146484255
basemtdfaresettingsindexdata | 146484058
basicbugreportindexdata | 146484267
basiccommonconnectionsettingsindexdata | 146484260
basicdocumentindexdata | 146484279
pg_inherits | 146483656
aeroexpressreportdocumentindexdata | 146484271
activityitemdata | 146483899
agencymemoindexdata | 146484277
aeroexpressticketindexdata | 146484289
agencymemoitemindexdata | 146484033
agencymemoproductindexdata | 146484268
agentgroupindexdata | 146484276
agencymemoproductitemgroupindexdata | 146484282
agentreportdocumentindexdata | 146484056
pg_index | 146483656
pg_operator | 146483656
pg_opfamily | 146483656
pg_opclass | 146483656
pg_am | 146483656
pg_statistic_ext | 146483656
pg_rewrite | 146483656
pg_trigger | 146483656
pg_event_trigger | 146483656
pg_description | 146483656
pg_cast | 146483656
pg_enum | 146483656
pg_namespace | 146483656
pg_conversion | 146483656
pg_depend | 146483656
pg_database | 146483656
pg_db_role_setting | 146483656
pg_tablespace | 146483656
pg_pltemplate | 146483656
pg_auth_members | 146483656
pg_shdepend | 146483656
pg_shdescription | 146483656
pg_ts_config | 146483656
pg_ts_config_map | 146483656
pg_ts_dict | 146483656
pg_ts_parser | 146483656
pg_ts_template | 146483656
pg_extension | 146483656
pg_foreign_data_wrapper | 146483656
pg_foreign_server | 146483656
pg_foreign_table | 146483656
pg_replication_origin | 146483656
pg_default_acl | 146483656
pg_init_privs | 146483656
pg_seclabel | 146483656
pg_shseclabel | 146483656
pg_collation | 146483656
pg_partitioned_table | 146483656
pg_range | 146483656
pg_transform | 146483656
pg_sequence | 146483656
pg_publication | 146483656
pg_publication_rel | 146483656
pg_subscription_rel | 146483656
information_schema.sql_parts | 146483656
information_schema.sql_languages | 146483656
information_schema.sql_features | 146483656
information_schema.sql_implementation_info | 146483656
information_schema.sql_packages | 146483656
information_schema.sql_sizing | 146483656
information_schema.sql_sizing_profiles | 146483656
pg_largeobject | 146484413
aclentrydata | 146483911
accountingentryindexdata | 146484059
aclaspectindexdata | 146484286
aclassetdata | 146483917
aclmodificatorindexdata | 146484281
aclgroupdata | 146484284
aclregistryassetdata | 146484294
acluserdata | 146484340
aclroleindexdata | 146484342
acquainteddata | 146484274
basicexportsettingsindexdata | 146484245
basicpaymentdocumentindexdata | 146483931
billingtransactionindexdata | 146484247
basicsystemsettingsindexdata | 146483935
billing1cexchangedocumentindexdata | 146484239
branchexchangedocumentindexdata | 146484240
bookabilityreportdocumentindexdata | 146484257
billingtransactionchangeindexdata | 146484253
blockcharterappendixindexdata | 146484243
bnch2exchangedocumentindexdata | 146484201
bookingfileindexdata | 146483999
bookingfileexchangedocumentindexdata | 146484256
branchindexdata | 146484026
brandedfareinformationindexdata | 146484249
bronevikexchangedocumentindexdata | 146483949
bulkdictionarydata | 146484067
bulklongrunningtaskentrydata | 146484233
cashindexdata | 146484248
cardindexdata | 146483941
carlson1cinvoicerecordindexdata | 146483881
chartofaccountselementindexdata | 146484236
cccexchangedocumentindexdata | 146484229
carrentalproductindexdata | 146483939
cashregisterindexdata | 146484234
cashregisterworkplaceindexdata | 146484237
charterstraveldocumentexchangedocumentindexdata | 146484228
charterscitypairsexchangedocumentindexdata | 146484232
clientdebtreportdocumentindexdata | 146484250
clientexchangedocumentindexdata | 146484230
cluster_qrtz_blob_triggers | 146484252
cluster_qrtz_paused_trigger_grps | 146484034
cluster_qrtz_triggers | 146484220
cluster_qrtz_calendars | 146484258
cluster_qrtz_scheduler_state | 146484066
cluster_qrtz_cron_triggers | 146484226
cluster_qrtz_fired_triggers | 146484224
cluster_qrtz_simple_triggers | 146484335
cluster_qrtz_job_details | 146484333
cluster_qrtz_locks | 146484337
combincrementdata | 146484213
cluster_qrtz_simprop_triggers | 146484331
combdata | 146484218
commonproductfopindexdata | 146483987
commissionpropertiesindexdata | 146484298
commonproductindexdata | 146483879
complexorderindexdata | 146484216
contractcustomerindexdata | 146483945
contractindexdata | 146483951
creditslipindexdata | 146484291
contractordescriptionindexdata | 146484222
contractrelationdescriptionindexdata | 146484211
credithistorydata | 146484205
crmaccountsexchangedocumentindexdata | 146484010
dbexchangedocumentindexdata | 146484196
cwtgeneralproductindexdata | 146483955
dbproperties | 146484012
deletedobjectreferencedata | 146484209
debitslipindexdata | 146484301
deletedassetreferencedata | 146484064
deliveryindexdata | 146484197
deliveryitemindexdata | 146484214
discountpropertiesindexdata | 146484192
deskentrydata | 146484203
dictionarydata | 146484207
dictupdateitemindexdata | 146484195
entityeventnotificationindexdata | 146483983
divergencereportdocumentindexdata | 146484193
directcontractindexdata | 146484006
entitydata | 146483925
exportdocumentindexdata | 146484188
excessbagageexchangedocumentindexdata | 146484189
eticketquotaindexdata | 146484024
exportreferencedata | 146483909
expressexchangedocumentindexdata | 146484302
farerulesdocumentindexdata | 146484326
gdsstatentrydata | 146483891
financeinitializationdataindexdata | 146483943
feepropertiesindexdata | 146483968
financedocumentindexdata | 146484322
financedocumentrecordindexdata | 146484328
gdsaccountindexdata | 146484185
fxworkspacedata | 146483913
financedocumentstemplatereportdocumentindexdata | 146484186
gabrielmaskexchangedocumentindexdata | 146484181
gdsreferenceindexdata | 146484157
gdsbookabilityitemindexdata | 146484324
gdstracingdocumentindexdata | 146484183
geoiprangedata | 146484174
holdingexchangedocumentindexdata | 146484170
holdingindexdata | 146484055
hotelbookexchangedocumentindexdata | 146484040
ibankexportdataindexdata | 146484169
hotelproductindexdata | 146484172
hotelproductreportdocumentindexdata | 146484190
hotexchangedocumentindexdata | 146484175
inmobexchangedocumentindexdata | 146484292
insuranceaccidentreportdocumentindexdata | 146484167
insuranceaccidentindexdata | 146484199
insurancetouristicindexdata | 146483989
issueindexdata | 146484003
insurancetripcancelindexdata | 146484166
invoiceexchangedocumentindexdata | 146483957
issuetemplatesindexdata | 146484164
iurexchangedocumentindexdata | 146484159
iwayexchangedocumentindexdata | 146483885
keybindingsdata | 146483895
loginhistorydata | 146484035
keypairentrydata | 146483915
liaisonexchangedocumentindexdata | 146483997
locks | 146484320
mainhotelproductindexdata | 146483948
longrunningtaskinfodata | 146483905
mainhotelproductguestindexdata | 146484177
mcoexchangedocumentindexdata | 146484241
modifiedobjectreferencedata | 146484152
mcofeesindexdata | 146484149
modelcontractindexdata | 146483937
mytable | 146484148
mytmptable | 146484146
noticeindexdata | 146484048
notificationmaildocumenttemplateindexdata | 146484319
organizationbalanceindexdata | 146484155
notificationschemeindexdata | 146484317
notificationtemplategroupindexdata | 146484142
passnflycheckinproductindexdata | 146484138
organizationindexdata | 146483927
openingbalancedata | 146484179
organizationcontractindexdata | 146484042
organizationexchangedocumentindexdata | 146484160
passengerpassportindexdata | 146484001
organizationmetadataindexdata | 146484032
payment1cexchangedocumentindexdata | 146484150
paymentfeepropertiesindexdata | 146484044
paymentindexdata | 146484039
placeofsalesindexdata | 146484008
personemploymentindexdata | 146484053
paytureregistryexchangedocumentindexdata | 146484144
pccindexdata | 146484330
penaltypropertiesindexdata | 146484162
personmetadataindexdata | 146484154
personexchangedocumentindexdata | 146484140
personbalanceindexdata | 146483959
personindexdata | 146483964
phonecalldata | 146483896
pgpaymentindexdata | 146484137
portraitpersonsexchangedocumentindexdata | 146483962
productindexdata | 146483970
productreportdocumentindexdata | 146484131
productsearchindexdata | 146484093
productvoidingindexdata | 146484303
rapidaexchangedocumentindexdata | 146484120
questionrecorddata | 146483882
railwayproductindexdata | 146483991
railwayreportdocumentindexdata | 146484122
refundeventindexdata | 146484134
reportassetdata | 146484128
renaissanceinsuranceexchangedocumentindexdata | 146484130
requestindexdata | 146484023
rootagentindexdata | 146484126
retarchiveexchangedocumentindexdata | 146484121
retexchangedocumentindexdata | 146484135
rulesmigrationexchangedocumentindexdata | 146484124
rulesmigrationsettingsindexdata | 146484050
s7excelexchangedocumentindexdata | 146484129
salespointindexdata | 146483933
sabrecsvexchangedocumentindexdata | 146484114
sabretokenindexdata | 146484061
sftppersonsexchangedocumentindexdata | 146483966
searchcityfilterassetdata | 146484113
saleschaindescriptionindexdata | 146484110
salesreportdocumentindexdata | 146484108
scheduledtasksettingsindexdata | 146484119
sequencenumbersdata | 146484106
seatblocksindexdata | 146483953
shipmentautoprocessingexchangedocumentindexdata | 146484080
shipmentautoprocessingexchangedocumentreferencedata | 146483897
shipmentindexdata | 146483884
ssodexchangedocumentindexdata | 146484312
specialtariffindexdata | 146484030
sirenamtdfaresettingsindexdata | 146484117
sirenaxmlexchangedocumentindexdata | 146484104
skyagentexchangedocumentindexdata | 146484102
sslentrylockassetdata | 146484091
spgdarchiveexchangedocumentindexdata | 146484097
soficlientsexchangedocumentindexdata | 146484101
spgdexchangedocumentindexdata | 146484115
ssodarchiveexchangedocumentindexdata | 146483996
sslsessionentryassetdata | 146483887
statisticsdocumentindexdata | 146484315
stockblankindexdata | 146484004
stockblankreportdocumentindexdata | 146484090
stockorderindexdata | 146484078
storagesyncrecorddata | 146483890
syslogitemdata | 146483903
subagentbalancereportdocumentindexdata | 146484096
subagentreportdocumentindexdata | 146484094
suxmlexchangedocumentindexdata | 146484299
taisexchangedocumentindexdata | 146483946
tchxmlcommissionsexchangedocumentindexdata | 146484087
tchdirectcontractindexdata | 146484095
teletrainexchangedocumentindexdata | 146484300
templatereportdocumentindexdata | 146484028
templatedocumentindexdata | 146483907
templatereportdescriptionindexdata | 146484311
temporalobjectdata | 146483919
terminalcreditreportdocumentindexdata | 146484098
transferproductindexdata | 146483929
termindexdata | 146484046
tmp | 146484089
transactionsplitindexdata | 146484112
tripartitecontractindexdata | 146484037
trashbinitemindexdata | 146484084
transferindexdata | 146483886
travelpolicyauthorizationschemeindexdata | 146484100
triprequestindexdata | 146484082
tripindexdata | 146483993
tripartitereportdocumentindexdata | 146484085
ufsexchangedocumentindexdata | 146484062
universalproductdescriptionindexdata | 146484076
universalproductindexdata | 146483985
visaproductindexdata | 146483961
validatorindexdata | 146484073
useraccountdata | 146483893
userotpassetdata | 146484133
userwebsettingsdata | 146484309
versiondata | 146483922
vctcostsexchangedocumentindexdata | 146484296
utsitineraryexchangedocumentindexdata | 146484074
vctpassengersexchangedocumentindexdata | 146484071
vipstatisticspdoassetdata | 146483920
vip1cudidsexchangedocumentindexdata | 146484069
worklogindexdata | 146484068
workspacedata | 146483901
(340 rows)
104-query2.txt (text/plain, 152B) download
datname | age
-----------+-----------
template0 | 146483656
bof | 146484413
postgres | 146483656
template1 | 146483656
(4 rows)
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 19:10 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 1 reply; 30+ messages in thread
From: Adrian Klaver @ 2018-06-11 19:10 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; Andres Freund <andres@anarazel.de>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
On 06/11/2018 11:32 AM, Alexander Shutyaev wrote:
> I'm back with more details.
>
> First, I've deleted the smaller sslentry database, since I don't need
> it, just so that it doesn't somehow spoil the picture. Now there is only
> 1 user database - bof (OID=16400). After that I've ran the pg_upgrade on
> a clean 10.4 cluster and it failed in the same way.
>
> Now, the answers to your queries.
>
> >> 2) The upgrade stops because of transaction ID wraparound, which is
> strange as that is not showing up in the 9.6 cluster I presume. You
> might want the queries found below on the 9.6 and 10 clusters to help
> figure this out:
>
> >> SELECT c.oid::regclass as table_name,
> >> greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
> >> FROM pg_class c
> >> LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
> >> WHERE c.relkind IN ('r', 'm');
>
> 9.6 result - see attached 96-query1.txt
> 10.4 result - see attached 104-query1.txt
I should have been clearer in my previous post, the above query is per
database. From the query below I am going to say the above query was
done on the bof database. Is that correct?
Given the below from 96-query2.txt:
template0 | 110588398
Can you run the table_name query in template0 in the 9.6 cluster?
>
> >> SELECT datname, age(datfrozenxid) FROM pg_database;
>
> 9.6 result - see attached 96-query2.txt
> 10.4 result - see attached 104-query2.txt
>
> >> It might be useful
> >> to see pg_controldata output for the old cluster, as well as
> >> "select datname, datfrozenxid from pg_database" output from the
> >> old cluster.
>
> for the query - see above, for pg_controldata:
>
> 9.6 - see attached 96-pg_controldata.txt
> 10.4 - see attached 104-pg_controldata.txt
>
> >> Alexander, could you hack things up so autovacuum logging is enabled
> >> (log_autovacuum_min_duration=0), and see whether it's triggered?
>
> I'll be happy to, but that will require to run pg_upgrade once more and
> that takes more that half a day and during this time clusters are not
> available to me. Given the data I'm attaching it may happen that the
> colleagues will want to see something else from my clusters or maybe
> change some settings before running the pg_upgrade again. Therefore,
> I'll wait 12 hours after this message in case there will be any more
> requests and the I'll run the pg_upgrade again.
>
> Thank you all for trying to solve this matter, this is much appreciated! :)
>
> 2018-06-11 20:29 GMT+03:00 Andres Freund <andres@anarazel.de
> <mailto:andres@anarazel.de>>:
>
> On 2018-06-11 13:14:12 -0400, Tom Lane wrote:
> > Andres Freund <andres@anarazel.de <mailto:andres@anarazel.de>> writes:
> > > I suspect the issue is that pg_resetwal does:
> > > if (set_xid != 0)
> > > {
> > > ControlFile.checkPointCopy.nextXid = set_xid;
> >
> > > /*
> > > * For the moment, just set oldestXid to a value that will force
> > > * immediate autovacuum-for-wraparound. It's not clear whether adding
> > > * user control of this is useful, so let's just do something that's
> > > * reasonably safe. The magic constant here corresponds to the
> > > * maximum allowed value of autovacuum_freeze_max_age.
> > > */
> > > ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
> > > if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
> > > ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
> > > ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
> > > }
> >
> > > but we have codepath that doesn't check for oldestXidDB being
> > > InvalidOid. Not great.
> >
> > Hm, I think I'd define the problem as "pg_resetwal is violating the
> > expectation that oldestXidDB be valid".
>
> Well, what could it do otherwise? ForceTransactionIdLimitUpdate()
> currently does a syscache check for database existence. That'll just
> return a lookup failure for InvalidOid, so we're reasonably good on that
> front.
>
> Using a hardcoded 2000000000 seems worse, will have funny results if
> running with a smaller autovacuum_freeze_max_age...
>
>
> > However, this just explains the basically-cosmetic issue that the
> > complaint message mentions OID 0. It doesn't really get us to the
> > answer to why Alexander is seeing a failure. It might be useful
> > to see pg_controldata output for the old cluster, as well as
> > "select datname, datfrozenxid from pg_database" output from the
> > old cluster.
>
> pg_upgrade starts the server with autovacuum disabled, I suspect
> restoring all the large objects ends up using a lot of transaction
> ids. GetNewTransactionId() should start autovacuum, but I'd guess that's
> where things are going wrong for some reason.
>
> Alexander, could you hack things up so autovacuum logging is enabled
> (log_autovacuum_min_duration=0), and see whether it's triggered?
>
> I'm not entirely clear why pg_restore appears to use a separate
> transaction for each large object, surely exascerbating the problem.
>
> Greetings,
>
> Andres Freund
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-11 19:19 Alexander Shutyaev <shutyaev@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-11 19:19 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
>> From the query below I am going to say the above query was done on the
bof database. Is that correct?
Yes, it is.
>> Can you run the table_name query in template0 in the 9.6 cluster?
At first I couldn't. There was an error:
psql: FATAL: database "template0" is not currently accepting connections
I've googled for it and found out that template0 is some special system
database that is protected from connections, but that can be changed (see
https://wiki.postgresql.org/wiki/Adventures_in_PostgreSQL,_Episode_1)
I've changed that and connected to this database and ran your query. The
result is attached in 96-query1-template0.txt.
2018-06-11 22:10 GMT+03:00 Adrian Klaver <adrian.klaver@aklaver.com>:
> On 06/11/2018 11:32 AM, Alexander Shutyaev wrote:
>
>> I'm back with more details.
>>
>> First, I've deleted the smaller sslentry database, since I don't need it,
>> just so that it doesn't somehow spoil the picture. Now there is only 1 user
>> database - bof (OID=16400). After that I've ran the pg_upgrade on a clean
>> 10.4 cluster and it failed in the same way.
>>
>> Now, the answers to your queries.
>>
>> >> 2) The upgrade stops because of transaction ID wraparound, which is
>> strange as that is not showing up in the 9.6 cluster I presume. You might
>> want the queries found below on the 9.6 and 10 clusters to help figure this
>> out:
>>
>> >> SELECT c.oid::regclass as table_name,
>> >> greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
>> >> FROM pg_class c
>> >> LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
>> >> WHERE c.relkind IN ('r', 'm');
>>
>> 9.6 result - see attached 96-query1.txt
>> 10.4 result - see attached 104-query1.txt
>>
>
> I should have been clearer in my previous post, the above query is per
> database. From the query below I am going to say the above query was done
> on the bof database. Is that correct?
>
> Given the below from 96-query2.txt:
>
> template0 | 110588398
>
> Can you run the table_name query in template0 in the 9.6 cluster?
>
>
>
>> >> SELECT datname, age(datfrozenxid) FROM pg_database;
>>
>> 9.6 result - see attached 96-query2.txt
>> 10.4 result - see attached 104-query2.txt
>>
>> >> It might be useful
>> >> to see pg_controldata output for the old cluster, as well as
>> >> "select datname, datfrozenxid from pg_database" output from the
>> >> old cluster.
>>
>> for the query - see above, for pg_controldata:
>>
>> 9.6 - see attached 96-pg_controldata.txt
>> 10.4 - see attached 104-pg_controldata.txt
>>
>> >> Alexander, could you hack things up so autovacuum logging is enabled
>> >> (log_autovacuum_min_duration=0), and see whether it's triggered?
>>
>> I'll be happy to, but that will require to run pg_upgrade once more and
>> that takes more that half a day and during this time clusters are not
>> available to me. Given the data I'm attaching it may happen that the
>> colleagues will want to see something else from my clusters or maybe change
>> some settings before running the pg_upgrade again. Therefore, I'll wait 12
>> hours after this message in case there will be any more requests and the
>> I'll run the pg_upgrade again.
>>
>> Thank you all for trying to solve this matter, this is much appreciated!
>> :)
>>
>> 2018-06-11 20:29 GMT+03:00 Andres Freund <andres@anarazel.de <mailto:
>> andres@anarazel.de>>:
>>
>> On 2018-06-11 13:14:12 -0400, Tom Lane wrote:
>> > Andres Freund <andres@anarazel.de <mailto:andres@anarazel.de>>
>> writes:
>> > > I suspect the issue is that pg_resetwal does:
>> > > if (set_xid != 0)
>> > > {
>> > > ControlFile.checkPointCopy.nextXid = set_xid;
>> > > > /*
>> > > * For the moment, just set oldestXid to a value that
>> will force
>> > > * immediate autovacuum-for-wraparound. It's not
>> clear whether adding
>> > > * user control of this is useful, so let's just do
>> something that's
>> > > * reasonably safe. The magic constant here
>> corresponds to the
>> > > * maximum allowed value of autovacuum_freeze_max_age.
>> > > */
>> > > ControlFile.checkPointCopy.oldestXid = set_xid -
>> 2000000000;
>> > > if (ControlFile.checkPointCopy.oldestXid <
>> FirstNormalTransactionId)
>> > > ControlFile.checkPointCopy.oldestXid +=
>> FirstNormalTransactionId;
>> > > ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
>> > > }
>> > > > but we have codepath that doesn't check for oldestXidDB
>> being
>> > > InvalidOid. Not great.
>> > > Hm, I think I'd define the problem as "pg_resetwal is
>> violating the
>> > expectation that oldestXidDB be valid".
>>
>> Well, what could it do otherwise? ForceTransactionIdLimitUpdate()
>> currently does a syscache check for database existence. That'll just
>> return a lookup failure for InvalidOid, so we're reasonably good on
>> that
>> front.
>>
>> Using a hardcoded 2000000000 seems worse, will have funny results if
>> running with a smaller autovacuum_freeze_max_age...
>>
>>
>> > However, this just explains the basically-cosmetic issue that the
>> > complaint message mentions OID 0. It doesn't really get us to the
>> > answer to why Alexander is seeing a failure. It might be useful
>> > to see pg_controldata output for the old cluster, as well as
>> > "select datname, datfrozenxid from pg_database" output from the
>> > old cluster.
>>
>> pg_upgrade starts the server with autovacuum disabled, I suspect
>> restoring all the large objects ends up using a lot of transaction
>> ids. GetNewTransactionId() should start autovacuum, but I'd guess
>> that's
>> where things are going wrong for some reason.
>>
>> Alexander, could you hack things up so autovacuum logging is enabled
>> (log_autovacuum_min_duration=0), and see whether it's triggered?
>>
>> I'm not entirely clear why pg_restore appears to use a separate
>> transaction for each large object, surely exascerbating the problem.
>>
>> Greetings,
>>
>> Andres Freund
>>
>>
>>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
Attachments:
96-query1-template0.txt (text/plain, 3.6K) download
table_name | age
--------------------------------------------+-----------
pg_statistic | 110588399
pg_type | 110588399
pg_authid | 110588399
pg_replication_origin | 110588399
pg_default_acl | 110588399
pg_init_privs | 110588399
pg_seclabel | 110588399
pg_shseclabel | 110588399
pg_collation | 110588399
pg_range | 110588399
pg_transform | 110588399
information_schema.sql_features | 110588399
information_schema.sql_languages | 110588399
information_schema.sql_packages | 110588399
pg_amop | 110588399
pg_amproc | 110588399
pg_language | 110588399
pg_largeobject_metadata | 110588399
pg_aggregate | 110588399
pg_rewrite | 110588399
pg_largeobject | 110588399
pg_trigger | 110588399
pg_event_trigger | 110588399
pg_description | 110588399
pg_cast | 110588399
pg_enum | 110588399
pg_namespace | 110588399
pg_conversion | 110588399
pg_depend | 110588399
pg_database | 110588399
information_schema.sql_implementation_info | 110588399
pg_db_role_setting | 110588399
pg_tablespace | 110588399
pg_pltemplate | 110588399
pg_auth_members | 110588399
pg_shdepend | 33255025
pg_shdescription | 110588399
pg_ts_config | 110588399
pg_ts_config_map | 110588399
pg_ts_dict | 110588399
pg_ts_parser | 110588399
pg_ts_template | 110588399
pg_extension | 110588399
pg_foreign_data_wrapper | 110588399
pg_foreign_server | 110588399
pg_foreign_table | 110588399
pg_policy | 110588399
information_schema.sql_parts | 110588399
information_schema.sql_sizing | 110588399
information_schema.sql_sizing_profiles | 110588399
pg_user_mapping | 110588399
pg_attribute | 110588399
pg_proc | 110588399
pg_class | 110588399
pg_attrdef | 110588399
pg_constraint | 110588399
pg_inherits | 110588399
pg_index | 110588399
pg_operator | 110588399
pg_opfamily | 110588399
pg_opclass | 110588399
pg_am | 110588399
(62 rows)
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-12 11:32 Daniel Verite <daniel@manitou-mail.org>
parent: Andres Freund <andres@anarazel.de>
1 sibling, 1 reply; 30+ messages in thread
From: Daniel Verite @ 2018-06-12 11:32 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
Andres Freund wrote:
> I'm not entirely clear why pg_restore appears to use a separate
> transaction for each large object, surely exascerbating the problem.
To make sure that per-object locks don't fill up the shared
lock table?
There might be hundreds of thousands of large objects.
If it had to restore N objects per transaction, would it know
how to compute N that is large enough to be effective
and small enough not to exhaust the shared table?
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-12 21:11 Alexander Shutyaev <shutyaev@gmail.com>
parent: Daniel Verite <daniel@manitou-mail.org>
0 siblings, 1 reply; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-12 21:11 UTC (permalink / raw)
To: Daniel Verite <daniel@manitou-mail.org>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
Back again,
>> Alexander, could you hack things up so autovacuum logging is enabled
>> (log_autovacuum_min_duration=0), and see whether it's triggered?
I've changed this config setting in both 9.6 and 10.4 postgresql.conf, then
I've ran pg_upgrade once more.
However I'm not sure how can I see whether autovacuum was triggered or not.
I've tried grepping the logs for lines containing both 'vacuum' and 'auto'
(case-insensitive) - there were none. If you can be more specific, I can
look for anything else.
I've googled on how can one see that the autovacuum is working, and found
out this query, which I ran on the 10.4 cluster:
select count(*) from pg_stat_all_tables where last_autovacuum is not null;
count
-------
0
(1 row)
So it seems autovacuum is indeed not working, just as you proposed.
If I correctly summarized all your responses, the problem is that:
1) pg_restore (as part of pg_upgrade) inserts each large object in a
different transaction
That seems true to me given the log output - each time an object is
inserted the wraparound warning decrements by 1
2) the autovacuum doesn't work while the database is restored
That also seems true (see above)
3) the number of large objects is so big that as they are restored the
transaction wraparound occurs
Here's the number of large objects taken from the 9.6 cluster (spaces added
manually for clarity):
select count(*) from pg_largeobject_metadata ;
count
-----------
133 635 871
(1 row)
If I've googled correctly - the transaction number is a 32bit integer so
it's limit is 2 147 483 647 which is a lot more. I guess I'm missing
something.
This is just my attempt to summarize our progress so far.
I'm further open to your suggestions.
2018-06-12 14:32 GMT+03:00 Daniel Verite <daniel@manitou-mail.org>:
> Andres Freund wrote:
>
> > I'm not entirely clear why pg_restore appears to use a separate
> > transaction for each large object, surely exascerbating the problem.
>
> To make sure that per-object locks don't fill up the shared
> lock table?
> There might be hundreds of thousands of large objects.
> If it had to restore N objects per transaction, would it know
> how to compute N that is large enough to be effective
> and small enough not to exhaust the shared table?
>
> Best regards,
> --
> Daniel Vérité
> PostgreSQL-powered mailer: http://www.manitou-mail.org
> Twitter: @DanielVerite
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-26 06:38 Alexander Shutyaev <shutyaev@gmail.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
0 siblings, 2 replies; 30+ messages in thread
From: Alexander Shutyaev @ 2018-06-26 06:38 UTC (permalink / raw)
To: Daniel Verite <daniel@manitou-mail.org>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
Hello again,
I've performed another test - I've migrated to the new cluster using dump
restore: pg_dumpall | psql. It went well, although it took 6 days while
pg_upgrade usually took a night.
Is there any hope the issue with pg_upgrade can be resolved? If not, could
you give me some hints as to how can I decrease time needed for pg_dumpall
| psql?
Thanks in advance!
2018-06-13 0:11 GMT+03:00 Alexander Shutyaev <shutyaev@gmail.com>:
> Back again,
>
> >> Alexander, could you hack things up so autovacuum logging is enabled
> >> (log_autovacuum_min_duration=0), and see whether it's triggered?
>
> I've changed this config setting in both 9.6 and 10.4 postgresql.conf,
> then I've ran pg_upgrade once more.
>
> However I'm not sure how can I see whether autovacuum was triggered or
> not. I've tried grepping the logs for lines containing both 'vacuum' and
> 'auto' (case-insensitive) - there were none. If you can be more specific, I
> can look for anything else.
>
> I've googled on how can one see that the autovacuum is working, and found
> out this query, which I ran on the 10.4 cluster:
>
> select count(*) from pg_stat_all_tables where last_autovacuum is not null;
> count
> -------
> 0
> (1 row)
>
> So it seems autovacuum is indeed not working, just as you proposed.
>
> If I correctly summarized all your responses, the problem is that:
>
> 1) pg_restore (as part of pg_upgrade) inserts each large object in a
> different transaction
>
> That seems true to me given the log output - each time an object is
> inserted the wraparound warning decrements by 1
>
> 2) the autovacuum doesn't work while the database is restored
>
> That also seems true (see above)
>
> 3) the number of large objects is so big that as they are restored the
> transaction wraparound occurs
>
> Here's the number of large objects taken from the 9.6 cluster (spaces
> added manually for clarity):
>
> select count(*) from pg_largeobject_metadata ;
> count
> -----------
> 133 635 871
> (1 row)
>
> If I've googled correctly - the transaction number is a 32bit integer so
> it's limit is 2 147 483 647 which is a lot more. I guess I'm missing
> something.
>
> This is just my attempt to summarize our progress so far.
>
> I'm further open to your suggestions.
>
> 2018-06-12 14:32 GMT+03:00 Daniel Verite <daniel@manitou-mail.org>:
>
>> Andres Freund wrote:
>>
>> > I'm not entirely clear why pg_restore appears to use a separate
>> > transaction for each large object, surely exascerbating the problem.
>>
>> To make sure that per-object locks don't fill up the shared
>> lock table?
>> There might be hundreds of thousands of large objects.
>> If it had to restore N objects per transaction, would it know
>> how to compute N that is large enough to be effective
>> and small enough not to exhaust the shared table?
>>
>> Best regards,
>> --
>> Daniel Vérité
>> PostgreSQL-powered mailer: http://www.manitou-mail.org
>> Twitter: @DanielVerite
>>
>
>
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-26 07:57 Arjen Nienhuis <a.g.nienhuis@gmail.com>
parent: Alexander Shutyaev <shutyaev@gmail.com>
1 sibling, 0 replies; 30+ messages in thread
From: Arjen Nienhuis @ 2018-06-26 07:57 UTC (permalink / raw)
To: shutyaev@gmail.com; +Cc: daniel@manitou-mail.org, andres@anarazel.de, Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
On Tue, Jun 26, 2018 at 8:38 AM Alexander Shutyaev <shutyaev@gmail.com> wrote:
>
> Hello again,
>
> I've performed another test - I've migrated to the new cluster using dump restore: pg_dumpall | psql. It went well, although it took 6 days while pg_upgrade usually took a night.
>
> Is there any hope the issue with pg_upgrade can be resolved? If not, could you give me some hints as to how can I decrease time needed for pg_dumpall | psql?
If you use pg_dump with the custom format you can use pg_restore
--jobs=n to do a parallel restore.
I think you can do pg_dumpall --globals-only to restore users, and
then do a pg_dump per database.
Groeten, Arjen
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2018-06-27 09:43 Daniel Verite <daniel@manitou-mail.org>
parent: Alexander Shutyaev <shutyaev@gmail.com>
1 sibling, 0 replies; 30+ messages in thread
From: Daniel Verite @ 2018-06-27 09:43 UTC (permalink / raw)
To: Alexander Shutyaev <shutyaev@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
Alexander Shutyaev wrote:
> Is there any hope the issue with pg_upgrade can be resolved? If not,
> could you give me some hints as to how can I decrease time needed
> for pg_dumpall | psql?
Not sure about the larger problem, but for the part about having more
than 1 million large objects that get committed individually, setting
fsync=off for the reload phase is likely to help a lot.
Just don't forget to turn it on again when it's done. See
https://blog.2ndquadrant.com/postgresql-fsync-off-warning-in-config-file/
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2021-03-12 23:13 Jan Wieck <jan@wi3ck.info>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 30+ messages in thread
From: Jan Wieck @ 2021-03-12 23:13 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Andres Freund <andres@anarazel.de>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
Resurrecting an old thread.
We (AWS) have seen this wraparound during pg_upgrade more often recently
with customers who have millions of large objects in their databases.
On 6/11/18 1:14 PM, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
>> I suspect the issue is that pg_resetwal does:
>> if (set_xid != 0)
>> {
>> ControlFile.checkPointCopy.nextXid = set_xid;
>
>> /*
>> * For the moment, just set oldestXid to a value that will force
>> * immediate autovacuum-for-wraparound. It's not clear whether adding
>> * user control of this is useful, so let's just do something that's
>> * reasonably safe. The magic constant here corresponds to the
>> * maximum allowed value of autovacuum_freeze_max_age.
>> */
>> ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
>> if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
>> ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
>> ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
>> }
>
>> but we have codepath that doesn't check for oldestXidDB being
>> InvalidOid. Not great.
>
> Hm, I think I'd define the problem as "pg_resetwal is violating the
> expectation that oldestXidDB be valid".
>
> However, this just explains the basically-cosmetic issue that the
> complaint message mentions OID 0. It doesn't really get us to the
> answer to why Alexander is seeing a failure. It might be useful
> to see pg_controldata output for the old cluster, as well as
> "select datname, datfrozenxid from pg_database" output from the
> old cluster.
Unfortunately I don't have pg_controldata output from the old clusters
either. I would like to be able to artificially create an "old" cluster
that fails during pg_upgrade in that way.
One of the things in my way is that when using pg_resetwal to put the
NextXID way into the future (to push the old cluster close to wraparound
for example), the postmaster won't start because it doesn't have the
pg_xact files for that around. Should pg_resetwal create the files in
the gap between the old NextXID and the new one?
Onw thing I do have is a patch that provides a workaround for the
problem as well as a substantial speed improvement for the case at hand.
This patch adds some options to pg_upgrade, pg_dump and pg_restore.
Option added to pg_dump:
--blob-in-parallel
This option requires --schema-only. It causes pg_dump to emit the BLOB
metadata with SECTION_DATA instead of SECTION_PRE_DATA. This causes the
statements for creating the large object metadata (lo_create(OID) and
ALTER LARGE OBJECT) to move into the parallel phase of pg_restore, which
means that their metadata will be created in parallel. In my tests a
database containing large objects only is upgraded in 1/#cores the time.
Option added to pg_restore:
--blob-batch-size=N
With this option pg_restore tries to put N BLOB TOC entries into one
transaction. This is per parallel worker and it will commit those
batches if there is a change in object type, so only BLOB TOC entries
will ever be batched at all. With a sufficient
'max_locks_per_transation' a --blob-batch-size=1000 nicely reduces the
number of XIDs consumed for upgrading 10M large objects from 20M to 10K.
Options added to pg_upgrade:
--blob-in-parallel forwarded to pg_dump
--blob-batch-size=N forwarded to pg_restore
--restore-jobs=N forwarded as --jobs=N to pg_restore
Patch is attached.
Regards, Jan
--
Jan Wieck
Principle Database Engineer
Amazon Web Services
Attachments:
pg_upgrade_improvements.v1.diff (text/x-patch, 12.6K) download
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index c6059fc..fdcb5e7 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -865,6 +865,11 @@ RunWorker(ArchiveHandle *AH, ParallelSlot *slot)
WaitForCommands(AH, pipefd);
/*
+ * Close an eventually open BLOB batch transaction.
+ */
+ CommitBlobTransaction((Archive *)AH);
+
+ /*
* Disconnect from database and clean up.
*/
set_cancel_slot_archive(slot, NULL);
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 97941fa..2bedd02 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -201,6 +201,8 @@ typedef struct Archive
int numWorkers; /* number of parallel processes */
char *sync_snapshot_id; /* sync snapshot id for parallel operation */
+ int blobBatchSize; /* # of blob to restore per transaction */
+ bool blobInParallel; /* place "BLOB" TEs in SECTION_DATA */
/* info needed for string escaping */
int encoding; /* libpq code for client_encoding */
@@ -268,6 +270,7 @@ extern void WriteData(Archive *AH, const void *data, size_t dLen);
extern int StartBlob(Archive *AH, Oid oid);
extern int EndBlob(Archive *AH, Oid oid);
+extern void CommitBlobTransaction(Archive *AH);
extern void CloseArchive(Archive *AH);
extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 5b9fbe8..f772410 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -68,6 +68,10 @@ typedef struct _parallelReadyList
} ParallelReadyList;
+static int blobBatchCount = 0;
+static bool blobInXact = false;
+
+
static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
const int compression, bool dosync, ArchiveMode mode,
SetupWorkerPtrType setupWorkerPtr);
@@ -259,6 +263,23 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
return (Archive *) AH;
}
+void
+CommitBlobTransaction(Archive *AHX)
+{
+ ArchiveHandle *AH = (ArchiveHandle *) AHX;
+
+ if (blobInXact)
+ {
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "-- End BLOB restore batch\n");
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "COMMIT;\n\n");
+
+ blobBatchCount = 0;
+ blobInXact = false;
+ }
+}
+
/* Public */
void
CloseArchive(Archive *AHX)
@@ -266,6 +287,8 @@ CloseArchive(Archive *AHX)
int res = 0;
ArchiveHandle *AH = (ArchiveHandle *) AHX;
+ CommitBlobTransaction(AHX);
+
AH->ClosePtr(AH);
/* Close the output */
@@ -3546,6 +3569,59 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
{
RestoreOptions *ropt = AH->public.ropt;
+ /* We restore BLOBs in batches to reduce XID consumption */
+ if (strcmp(te->desc, "BLOB") == 0 && AH->public.blobBatchSize > 0)
+ {
+ if (blobInXact)
+ {
+ /* We are inside a BLOB restore transaction */
+ if (blobBatchCount >= AH->public.blobBatchSize)
+ {
+ /*
+ * We did reach the batch size with the previous BLOB.
+ * Commit and start a new batch.
+ */
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "-- BLOB batch size reached\n");
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "COMMIT;\n");
+ ahprintf(AH, "BEGIN;\n\n");
+
+ blobBatchCount = 1;
+ }
+ else
+ {
+ /* This one still fits into the current batch */
+ blobBatchCount++;
+ }
+ }
+ else
+ {
+ /* Not inside a transaction, start a new batch */
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "-- Start BLOB restore batch\n");
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "BEGIN;\n\n");
+
+ blobBatchCount = 1;
+ blobInXact = true;
+ }
+ }
+ else
+ {
+ /* Not a BLOB. If we have a BLOB batch open, close it. */
+ if (blobInXact)
+ {
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "-- End BLOB restore batch\n");
+ ahprintf(AH, "--\n");
+ ahprintf(AH, "COMMIT;\n\n");
+
+ blobBatchCount = 0;
+ blobInXact = false;
+ }
+ }
+
/* Select owner, schema, tablespace and default AM as necessary */
_becomeOwner(AH, te);
_selectOutputSchema(AH, te->namespace);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index bce8d54..b327e89 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -323,6 +323,7 @@ main(int argc, char **argv)
int numWorkers = 1;
int compressLevel = -1;
int plainText = 0;
+ bool blobInParallel = false;
ArchiveFormat archiveFormat = archUnknown;
ArchiveMode archiveMode;
@@ -391,6 +392,7 @@ main(int argc, char **argv)
{"no-sync", no_argument, NULL, 7},
{"on-conflict-do-nothing", no_argument, &dopt.do_nothing, 1},
{"rows-per-insert", required_argument, NULL, 10},
+ {"blob-in-parallel", no_argument, NULL, 11},
{NULL, 0, NULL, 0}
};
@@ -607,6 +609,10 @@ main(int argc, char **argv)
dopt.dump_inserts = (int) rowsPerInsert;
break;
+ case 11: /* place "BLOB" TEs in SECTION_DATA */
+ blobInParallel = true;
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit_nicely(1);
@@ -711,6 +717,10 @@ main(int argc, char **argv)
if (archiveFormat != archDirectory && numWorkers > 1)
fatal("parallel backup only supported by the directory format");
+ /* blobInParallel is only possible with schemaOnly */
+ if (!dopt.schemaOnly && blobInParallel)
+ fatal("blob-in-parallel only supported in schema-only dump");
+
/* Open the output file */
fout = CreateArchive(filename, archiveFormat, compressLevel, dosync,
archiveMode, setupDumpWorker);
@@ -733,6 +743,7 @@ main(int argc, char **argv)
fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99;
fout->numWorkers = numWorkers;
+ fout->blobInParallel = blobInParallel;
/*
* Open the database using the Archiver, so it knows about it. Errors mean
@@ -1043,6 +1054,8 @@ help(const char *progname)
printf(_(" --use-set-session-authorization\n"
" use SET SESSION AUTHORIZATION commands instead of\n"
" ALTER OWNER commands to set ownership\n"));
+ printf(_(" --blob-in-parallel dump blob metadata in the parallel section\n"
+ " (requires --schema-only)\n"));
printf(_("\nConnection options:\n"));
printf(_(" -d, --dbname=DBNAME database to dump\n"));
@@ -3400,7 +3413,8 @@ dumpBlob(Archive *fout, BlobInfo *binfo)
ARCHIVE_OPTS(.tag = binfo->dobj.name,
.owner = binfo->rolname,
.description = "BLOB",
- .section = SECTION_PRE_DATA,
+ .section = fout->blobInParallel ?
+ SECTION_DATA : SECTION_PRE_DATA,
.createStmt = cquery->data,
.dropStmt = dquery->data));
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index e47d0b8..43d5507 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -63,6 +63,7 @@ main(int argc, char **argv)
int c;
int exit_code;
int numWorkers = 1;
+ int blobBatchSize = 0;
Archive *AH;
char *inputFileSpec;
static int disable_triggers = 0;
@@ -124,6 +125,7 @@ main(int argc, char **argv)
{"no-publications", no_argument, &no_publications, 1},
{"no-security-labels", no_argument, &no_security_labels, 1},
{"no-subscriptions", no_argument, &no_subscriptions, 1},
+ {"blob-batch-size", required_argument, NULL, 4},
{NULL, 0, NULL, 0}
};
@@ -249,7 +251,7 @@ main(int argc, char **argv)
case 'v': /* verbose */
opts->verbose = 1;
- pg_logging_set_level(PG_LOG_INFO);
+ pg_logging_set_level(PG_LOG_DEBUG);
break;
case 'w':
@@ -284,6 +286,10 @@ main(int argc, char **argv)
set_dump_section(optarg, &(opts->dumpSections));
break;
+ case 4: /* # of blobs to restore per transaction */
+ blobBatchSize = atoi(optarg);
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit_nicely(1);
@@ -371,6 +377,12 @@ main(int argc, char **argv)
exit_nicely(1);
}
+ if (blobBatchSize < 0)
+ {
+ pg_log_error("invalid blob batch size");
+ exit(1);
+ }
+
opts->disable_triggers = disable_triggers;
opts->enable_row_security = enable_row_security;
opts->noDataForFailedTables = no_data_for_failed_tables;
@@ -438,6 +450,7 @@ main(int argc, char **argv)
SortTocFromFile(AH);
AH->numWorkers = numWorkers;
+ AH->blobBatchSize = blobBatchSize;
if (opts->tocSummary)
PrintTOCSummary(AH);
@@ -510,6 +523,7 @@ usage(const char *progname)
printf(_(" --use-set-session-authorization\n"
" use SET SESSION AUTHORIZATION commands instead of\n"
" ALTER OWNER commands to set ownership\n"));
+ printf(_(" --blob-batch-size=NUM attempt to restore NUM BLOBs per transaction\n"));
printf(_("\nConnection options:\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index 0ffe171..975da00 100644
--- a/src/bin/pg_upgrade/dump.c
+++ b/src/bin/pg_upgrade/dump.c
@@ -54,8 +54,9 @@ generate_old_dump(void)
parallel_exec_prog(log_file_name, NULL,
"\"%s/pg_dump\" %s --schema-only --quote-all-identifiers "
- "--binary-upgrade --format=custom %s --file=\"%s\" %s",
+ "--binary-upgrade --format=custom %s %s --file=\"%s\" %s",
new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ user_opts.blob_in_parallel ? "--blob-in-parallel " : "",
log_opts.verbose ? "--verbose" : "",
sql_file_name, escaped_connstr.data);
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index a05675c..3e6c08d 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -56,6 +56,9 @@ parseCommandLine(int argc, char *argv[])
{"socketdir", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"clone", no_argument, NULL, 1},
+ {"blob-batch-size", required_argument, NULL, 2},
+ {"blob-in-parallel", no_argument, NULL, 3},
+ {"restore-jobs", required_argument, NULL, 4},
{NULL, 0, NULL, 0}
};
@@ -67,6 +70,7 @@ parseCommandLine(int argc, char *argv[])
time_t run_time = time(NULL);
user_opts.transfer_mode = TRANSFER_MODE_COPY;
+ user_opts.restore_jobs = 1;
os_info.progname = get_progname(argv[0]);
@@ -209,6 +213,18 @@ parseCommandLine(int argc, char *argv[])
user_opts.transfer_mode = TRANSFER_MODE_CLONE;
break;
+ case 2:
+ user_opts.blob_batch_size = atoi(optarg);
+ break;
+
+ case 3:
+ user_opts.blob_in_parallel = true;
+ break;
+
+ case 4:
+ user_opts.restore_jobs = atoi(optarg);
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
os_info.progname);
@@ -309,6 +325,10 @@ usage(void)
printf(_(" -v, --verbose enable verbose internal logging\n"));
printf(_(" -V, --version display version information, then exit\n"));
printf(_(" --clone clone instead of copying files to new cluster\n"));
+ printf(_(" --blob-batch-size=NUM number of blobs to restore per transaction\n"));
+ printf(_(" --blob-in-parallel have pg_dump put the BLOB metadata into the\n"
+ "parallel section\n"));
+ printf(_(" --restore-jobs=NUM number of simultaneous processes or threads to use for pg_restore\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\n"
"Before running pg_upgrade you must:\n"
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index cb0aff3..c6310ed 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -388,10 +388,14 @@ create_new_objects(void)
parallel_exec_prog(log_file_name,
NULL,
"\"%s/pg_restore\" %s %s --exit-on-error --verbose "
+ "--blob-batch-size %d "
+ "--jobs %d --verbose "
"--dbname template1 \"%s\"",
new_cluster.bindir,
cluster_conn_opts(&new_cluster),
create_opts,
+ user_opts.blob_batch_size,
+ user_opts.restore_jobs,
sql_file_name);
}
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 63574b5..32c0abe 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -299,6 +299,9 @@ typedef struct
* changes */
transferMode transfer_mode; /* copy files or link them? */
int jobs; /* number of processes/threads to use */
+ int blob_batch_size;/* number of BLOBs to restore per xact */
+ bool blob_in_parallel; /* dump BLOB metadata in data section */
+ int restore_jobs; /* number of procs/threads for pg_restore */
char *socketdir; /* directory to use for Unix sockets */
} UserOpts;
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2021-03-13 01:30 Michael Paquier <michael@paquier.xyz>
parent: Jan Wieck <jan@wi3ck.info>
0 siblings, 1 reply; 30+ messages in thread
From: Michael Paquier @ 2021-03-13 01:30 UTC (permalink / raw)
To: Jan Wieck <jan@wi3ck.info>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Andres Freund <andres@anarazel.de>; Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
Hi Jan,
On Fri, Mar 12, 2021 at 06:13:33PM -0500, Jan Wieck wrote:
> One of the things in my way is that when using pg_resetwal to put the
> NextXID way into the future (to push the old cluster close to wraparound for
> example), the postmaster won't start because it doesn't have the pg_xact
> files for that around. Should pg_resetwal create the files in the gap
> between the old NextXID and the new one?
I think that you should add this patch to the next commit fest to
track it properly:
https://commitfest.postgresql.org/33/
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2021-03-13 13:43 Jan Wieck <jan@wi3ck.info>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 30+ messages in thread
From: Jan Wieck @ 2021-03-13 13:43 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Andres Freund <andres@anarazel.de>; Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 3/12/21 8:30 PM, Michael Paquier wrote:
> Hi Jan,
>
> On Fri, Mar 12, 2021 at 06:13:33PM -0500, Jan Wieck wrote:
>> One of the things in my way is that when using pg_resetwal to put the
>> NextXID way into the future (to push the old cluster close to wraparound for
>> example), the postmaster won't start because it doesn't have the pg_xact
>> files for that around. Should pg_resetwal create the files in the gap
>> between the old NextXID and the new one?
>
> I think that you should add this patch to the next commit fest to
> track it properly:
> https://commitfest.postgresql.org/33/
> --
> Michael
>
Actually this is the wrong patch (this one is for PG-12, not for HEAD).
Will update later today.
But yes, putting it into the next commitfest after initial discussion is
the plan.
Regards, Jan
--
Jan Wieck
Principle Database Engineer
Amazon Web Services
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2021-04-30 19:32 Bruce Momjian <bruce@momjian.us>
parent: Jan Wieck <jan@wi3ck.info>
0 siblings, 1 reply; 30+ messages in thread
From: Bruce Momjian @ 2021-04-30 19:32 UTC (permalink / raw)
To: Jan Wieck <jan@wi3ck.info>; +Cc: Michael Paquier <michael@paquier.xyz>; Tom Lane <tgl@sss.pgh.pa.us>; Andres Freund <andres@anarazel.de>; Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On Sat, Mar 13, 2021 at 08:43:54AM -0500, Jan Wieck wrote:
> On 3/12/21 8:30 PM, Michael Paquier wrote:
> > Hi Jan,
> >
> > On Fri, Mar 12, 2021 at 06:13:33PM -0500, Jan Wieck wrote:
> > > One of the things in my way is that when using pg_resetwal to put the
> > > NextXID way into the future (to push the old cluster close to wraparound for
> > > example), the postmaster won't start because it doesn't have the pg_xact
> > > files for that around. Should pg_resetwal create the files in the gap
> > > between the old NextXID and the new one?
> >
> > I think that you should add this patch to the next commit fest to
> > track it properly:
> > https://commitfest.postgresql.org/33/
> > --
> > Michael
> >
>
> Actually this is the wrong patch (this one is for PG-12, not for HEAD). Will
> update later today.
>
> But yes, putting it into the next commitfest after initial discussion is the
> plan.
Uh, were either of these things done?
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 30+ messages in thread
* Re: pg_upgrade and wraparound
@ 2021-05-03 15:10 Jan Wieck <jan@wi3ck.info>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 0 replies; 30+ messages in thread
From: Jan Wieck @ 2021-05-03 15:10 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Michael Paquier <michael@paquier.xyz>; Tom Lane <tgl@sss.pgh.pa.us>; Andres Freund <andres@anarazel.de>; Adrian Klaver <adrian.klaver@aklaver.com>; Alexander Shutyaev <shutyaev@gmail.com>; pgsql-general
On 4/30/21 3:32 PM, Bruce Momjian wrote:
> On Sat, Mar 13, 2021 at 08:43:54AM -0500, Jan Wieck wrote:
>> On 3/12/21 8:30 PM, Michael Paquier wrote:
>> > Hi Jan,
>> >
>> > On Fri, Mar 12, 2021 at 06:13:33PM -0500, Jan Wieck wrote:
>> > > One of the things in my way is that when using pg_resetwal to put the
>> > > NextXID way into the future (to push the old cluster close to wraparound for
>> > > example), the postmaster won't start because it doesn't have the pg_xact
>> > > files for that around. Should pg_resetwal create the files in the gap
>> > > between the old NextXID and the new one?
>> >
>> > I think that you should add this patch to the next commit fest to
>> > track it properly:
>> > https://commitfest.postgresql.org/33/
>> > --
>> > Michael
>> >
>>
>> Actually this is the wrong patch (this one is for PG-12, not for HEAD). Will
>> update later today.
>>
>> But yes, putting it into the next commitfest after initial discussion is the
>> plan.
>
> Uh, were either of these things done?
>
Not yet, but I will enter it so that we can get it into 15 for sure.
Regards, Jan
--
Jan Wieck
Postgres User since 1994
^ permalink raw reply [nested|flat] 30+ messages in thread
end of thread, other threads:[~2021-05-03 15:10 UTC | newest]
Thread overview: 30+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-09 10:46 pg_upgrade and wraparound Alexander Shutyaev <shutyaev@gmail.com>
2018-06-09 19:41 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-09 19:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-06-10 20:46 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-10 20:55 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-10 21:03 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-10 21:09 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-10 21:34 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-10 21:45 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-11 00:15 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-11 06:46 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-11 13:12 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-10 20:48 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-11 17:08 ` Andres Freund <andres@anarazel.de>
2018-06-11 17:14 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-06-11 17:29 ` Andres Freund <andres@anarazel.de>
2018-06-11 18:32 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-11 19:10 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-11 19:19 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-12 11:32 ` Daniel Verite <daniel@manitou-mail.org>
2018-06-12 21:11 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-26 06:38 ` Alexander Shutyaev <shutyaev@gmail.com>
2018-06-26 07:57 ` Arjen Nienhuis <a.g.nienhuis@gmail.com>
2018-06-27 09:43 ` Daniel Verite <daniel@manitou-mail.org>
2021-03-12 23:13 ` Jan Wieck <jan@wi3ck.info>
2021-03-13 01:30 ` Michael Paquier <michael@paquier.xyz>
2021-03-13 13:43 ` Jan Wieck <jan@wi3ck.info>
2021-04-30 19:32 ` Bruce Momjian <bruce@momjian.us>
2021-05-03 15:10 ` Jan Wieck <jan@wi3ck.info>
2018-06-11 17:03 ` Andres Freund <andres@anarazel.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox