pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedDoes PostgreSQL check database integrity at startup?
51+ messages / 14 participants
[nested] [flat]
* Does PostgreSQL check database integrity at startup?
@ 2017-12-26 12:52 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 1 reply; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-26 12:52 UTC (permalink / raw)
To: pgsql-general
Recently I had a problem with a base file with size 0 in a standby server.
This raised one question: does PostgreSQL (9.6.6) check base integrity
at startup?
At least if there are 0 byte size files in base dir? Or CRC? Something?
Regards,
--
*Edson Carlos Ericksson Richter*
/SimKorp Ltda/
Fone: (51) 3366-7964
Embedded Image
/"A mente que se abre a uma nova ideia jamais voltará ao seu tamanho
original"/
- Albert Einstein
Attachments:
edeiknjfgmlphknm.png (image/png, 3.9K) download
view image
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 13:44 Martin Marques <martin.marques@2ndquadrant.com>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 1 reply; 51+ messages in thread
From: Martin Marques @ 2017-12-26 13:44 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general
El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
> Recently I had a problem with a base file with size 0 in a standby server.
>
> This raised one question: does PostgreSQL (9.6.6) check base integrity
> at startup?
>
> At least if there are 0 byte size files in base dir? Or CRC? Something?
Yes it has CRC check, but only if you initialize the cluster with
--data-checksums, and there's a price to pay in performance.
--
Martín Marqués http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 14:25 Pavel Stehule <pavel.stehule@gmail.com>
parent: Martin Marques <martin.marques@2ndquadrant.com>
0 siblings, 1 reply; 51+ messages in thread
From: Pavel Stehule @ 2017-12-26 14:25 UTC (permalink / raw)
To: Martin Marques <martin.marques@2ndquadrant.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general
2017-12-26 14:44 GMT+01:00 Martin Marques <martin.marques@2ndquadrant.com>:
> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
> > Recently I had a problem with a base file with size 0 in a standby
> server.
> >
> > This raised one question: does PostgreSQL (9.6.6) check base integrity
> > at startup?
> >
> > At least if there are 0 byte size files in base dir? Or CRC? Something?
>
> Yes it has CRC check, but only if you initialize the cluster with
> --data-checksums, and there's a price to pay in performance.
>
>
It has CRC check, but it is used in runtime - when data are necessary
So Postgres usually check nothing on start - few system tables and indexes
Regards
Pavel
>
> --
> Martín Marqués http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 15:37 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 2 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-26 15:37 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; Martin Marques <martin.marques@2ndquadrant.com>; +Cc: pgsql-general
Em 26/12/2017 12:25, Pavel Stehule escreveu:
>
>
> 2017-12-26 14:44 GMT+01:00 Martin Marques
> <martin.marques@2ndquadrant.com <mailto:martin.marques@2ndquadrant.com>>:
>
> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
> > Recently I had a problem with a base file with size 0 in a
> standby server.
> >
> > This raised one question: does PostgreSQL (9.6.6) check base
> integrity
> > at startup?
> >
> > At least if there are 0 byte size files in base dir? Or CRC?
> Something?
>
> Yes it has CRC check, but only if you initialize the cluster with
> --data-checksums, and there's a price to pay in performance.
>
>
> It has CRC check, but it is used in runtime - when data are necessary
>
> So Postgres usually check nothing on start - few system tables and indexes
>
> Regards
>
> Pavel
>
>
> --
> Martín Marqués http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
Any tips to make database server don't start if corrupt?
If I can change the startup script to make some checks before
effectively starting the database, what would be the recommendations?
One that seems obvious to me are empty data files (something like "find
-size 0 $PG_DATA/base")...
But I'm sure that more experienced PostgreSQL DBA would have more tests
to check before startup.
Thanks,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 15:39 Peter Geoghegan <pg@bowt.ie>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 0 replies; 51+ messages in thread
From: Peter Geoghegan @ 2017-12-26 15:39 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
Look into amcheck:
https://github.com/petergeoghegan/amcheck
--
Peter Geoghegan
(Sent from my phone)
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 15:40 Pavel Stehule <pavel.stehule@gmail.com>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 1 reply; 51+ messages in thread
From: Pavel Stehule @ 2017-12-26 15:40 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
2017-12-26 16:37 GMT+01:00 Edson Carlos Ericksson Richter <
richter@simkorp.com.br>:
> Em 26/12/2017 12:25, Pavel Stehule escreveu:
>
>
>
> 2017-12-26 14:44 GMT+01:00 Martin Marques <martin.marques@2ndquadrant.com>
> :
>
>> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
>> > Recently I had a problem with a base file with size 0 in a standby
>> server.
>> >
>> > This raised one question: does PostgreSQL (9.6.6) check base integrity
>> > at startup?
>> >
>> > At least if there are 0 byte size files in base dir? Or CRC? Something?
>>
>> Yes it has CRC check, but only if you initialize the cluster with
>> --data-checksums, and there's a price to pay in performance.
>>
>>
> It has CRC check, but it is used in runtime - when data are necessary
>
> So Postgres usually check nothing on start - few system tables and indexes
>
> Regards
>
> Pavel
>
>>
>> --
>> Martín Marqués http://www.2ndQuadrant.com/
>> PostgreSQL Development, 24x7 Support, Training & Services
>>
>>
>
> Any tips to make database server don't start if corrupt?
> If I can change the startup script to make some checks before effectively
> starting the database, what would be the recommendations?
>
> One that seems obvious to me are empty data files (something like "find
> -size 0 $PG_DATA/base")...
> But I'm sure that more experienced PostgreSQL DBA would have more tests to
> check before startup.
>
I don't think so anybody does it. Reading 1TB database needs more then few
hours.
Regards
>
> Thanks,
>
> Edson
>
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 15:50 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 2 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-26 15:50 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
Em 26/12/2017 13:40, Pavel Stehule escreveu:
>
>
> 2017-12-26 16:37 GMT+01:00 Edson Carlos Ericksson Richter
> <richter@simkorp.com.br <mailto:richter@simkorp.com.br>>:
>
> Em 26/12/2017 12:25, Pavel Stehule escreveu:
>>
>>
>> 2017-12-26 14:44 GMT+01:00 Martin Marques
>> <martin.marques@2ndquadrant.com
>> <mailto:martin.marques@2ndquadrant.com>>:
>>
>> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
>> > Recently I had a problem with a base file with size 0 in a
>> standby server.
>> >
>> > This raised one question: does PostgreSQL (9.6.6) check
>> base integrity
>> > at startup?
>> >
>> > At least if there are 0 byte size files in base dir? Or
>> CRC? Something?
>>
>> Yes it has CRC check, but only if you initialize the cluster with
>> --data-checksums, and there's a price to pay in performance.
>>
>>
>> It has CRC check, but it is used in runtime - when data are
>> necessary
>>
>> So Postgres usually check nothing on start - few system tables
>> and indexes
>>
>> Regards
>>
>> Pavel
>>
>>
>> --
>> Martín Marqués http://www.2ndQuadrant.com/
>> PostgreSQL Development, 24x7 Support, Training & Services
>>
>>
>
> Any tips to make database server don't start if corrupt?
> If I can change the startup script to make some checks before
> effectively starting the database, what would be the recommendations?
>
> One that seems obvious to me are empty data files (something like
> "find -size 0 $PG_DATA/base")...
> But I'm sure that more experienced PostgreSQL DBA would have more
> tests to check before startup.
>
>
> I don't think so anybody does it. Reading 1TB database needs more then
> few hours.
>
> Regards
>
>
>
> Thanks,
>
> Edson
>
>
I'm rebuilding the standby server for two days already, with 23% of
completion status...
If lost the database and backups because of that failure, it would be a
giant disaster.
Few hours checking integrity would be acceptable... Specially if I can
run it on standby only.
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 15:57 Pavel Stehule <pavel.stehule@gmail.com>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 2 replies; 51+ messages in thread
From: Pavel Stehule @ 2017-12-26 15:57 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
2017-12-26 16:50 GMT+01:00 Edson Carlos Ericksson Richter <
richter@simkorp.com.br>:
> Em 26/12/2017 13:40, Pavel Stehule escreveu:
>
>
>
> 2017-12-26 16:37 GMT+01:00 Edson Carlos Ericksson Richter <
> richter@simkorp.com.br>:
>
>> Em 26/12/2017 12:25, Pavel Stehule escreveu:
>>
>>
>>
>> 2017-12-26 14:44 GMT+01:00 Martin Marques <martin.marques@2ndquadrant.com
>> >:
>>
>>> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter escribió:
>>> > Recently I had a problem with a base file with size 0 in a standby
>>> server.
>>> >
>>> > This raised one question: does PostgreSQL (9.6.6) check base integrity
>>> > at startup?
>>> >
>>> > At least if there are 0 byte size files in base dir? Or CRC? Something?
>>>
>>> Yes it has CRC check, but only if you initialize the cluster with
>>> --data-checksums, and there's a price to pay in performance.
>>>
>>>
>> It has CRC check, but it is used in runtime - when data are necessary
>>
>> So Postgres usually check nothing on start - few system tables and indexes
>>
>> Regards
>>
>> Pavel
>>
>>>
>>> --
>>> Martín Marqués http://www.2ndQuadrant.com/
>>> PostgreSQL Development, 24x7 Support, Training & Services
>>>
>>>
>>
>> Any tips to make database server don't start if corrupt?
>> If I can change the startup script to make some checks before effectively
>> starting the database, what would be the recommendations?
>>
>> One that seems obvious to me are empty data files (something like "find
>> -size 0 $PG_DATA/base")...
>> But I'm sure that more experienced PostgreSQL DBA would have more tests
>> to check before startup.
>>
>
> I don't think so anybody does it. Reading 1TB database needs more then few
> hours.
>
> Regards
>
>
>
>>
>> Thanks,
>>
>> Edson
>>
>
> I'm rebuilding the standby server for two days already, with 23% of
> completion status...
> If lost the database and backups because of that failure, it would be a
> giant disaster.
> Few hours checking integrity would be acceptable... Specially if I can run
> it on standby only.
>
very simple check
pgdumpall > /dev/null
but this doesn't check indexes.
Regards
Pavel
> Regards,
>
> Edson
>
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 17:06 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Pavel Stehule <pavel.stehule@gmail.com>
1 sibling, 0 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-26 17:06 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
Em 26/12/2017 13:57, Pavel Stehule escreveu:
>
>
> 2017-12-26 16:50 GMT+01:00 Edson Carlos Ericksson Richter
> <richter@simkorp.com.br <mailto:richter@simkorp.com.br>>:
>
> Em 26/12/2017 13:40, Pavel Stehule escreveu:
>>
>>
>> 2017-12-26 16:37 GMT+01:00 Edson Carlos Ericksson Richter
>> <richter@simkorp.com.br <mailto:richter@simkorp.com.br>>:
>>
>> Em 26/12/2017 12:25, Pavel Stehule escreveu:
>>>
>>>
>>> 2017-12-26 14:44 GMT+01:00 Martin Marques
>>> <martin.marques@2ndquadrant.com
>>> <mailto:martin.marques@2ndquadrant.com>>:
>>>
>>> El 26/12/17 a las 09:52, Edson Carlos Ericksson Richter
>>> escribió:
>>> > Recently I had a problem with a base file with size 0
>>> in a standby server.
>>> >
>>> > This raised one question: does PostgreSQL (9.6.6)
>>> check base integrity
>>> > at startup?
>>> >
>>> > At least if there are 0 byte size files in base dir?
>>> Or CRC? Something?
>>>
>>> Yes it has CRC check, but only if you initialize the
>>> cluster with
>>> --data-checksums, and there's a price to pay in performance.
>>>
>>>
>>> It has CRC check, but it is used in runtime - when data are
>>> necessary
>>>
>>> So Postgres usually check nothing on start - few system
>>> tables and indexes
>>>
>>> Regards
>>>
>>> Pavel
>>>
>>>
>>> --
>>> Martín Marqués http://www.2ndQuadrant.com/
>>> PostgreSQL Development, 24x7 Support, Training & Services
>>>
>>>
>>
>> Any tips to make database server don't start if corrupt?
>> If I can change the startup script to make some checks before
>> effectively starting the database, what would be the
>> recommendations?
>>
>> One that seems obvious to me are empty data files (something
>> like "find -size 0 $PG_DATA/base")...
>> But I'm sure that more experienced PostgreSQL DBA would have
>> more tests to check before startup.
>>
>>
>> I don't think so anybody does it. Reading 1TB database needs more
>> then few hours.
>>
>> Regards
>>
>>
>>
>> Thanks,
>>
>> Edson
>>
>>
> I'm rebuilding the standby server for two days already, with 23%
> of completion status...
> If lost the database and backups because of that failure, it would
> be a giant disaster.
> Few hours checking integrity would be acceptable... Specially if I
> can run it on standby only.
>
>
> very simple check
>
> pgdumpall > /dev/null
>
> but this doesn't check indexes.
>
> Regards
>
> Pavel
>
>
>
I'll check it and make some tests.
Thanks!
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 17:13 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 1 reply; 51+ messages in thread
From: Alvaro Herrera @ 2017-12-26 17:13 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
Edson Carlos Ericksson Richter wrote:
> I'm rebuilding the standby server for two days already, with 23% of
> completion status...
So how do you build your standbys, exactly? Maybe there's a bug in your
procedure, rather than a bug in the software.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 17:46 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-26 17:46 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 26/12/2017 15:13, Alvaro Herrera escreveu:
> Edson Carlos Ericksson Richter wrote:
>
>> I'm rebuilding the standby server for two days already, with 23% of
>> completion status...
> So how do you build your standbys, exactly? Maybe there's a bug in your
> procedure, rather than a bug in the software.
>
Usually, or by "pg_basebackup" or by "rsync" as described in PostgreSQL
Wiki.
Right now, I'm doing via pg_basebackup.
Nothing extraordinary.
When using rsync:
rsync -e "ssh -2 -C -p slave_ssh_port" --progress --partial -az
/pgsql/9.6/master_data_folder/*
superuser_name@$slave_host:/home/pgsql/9.6/slave_data_folder/ --exclude
postmaster.pid --exclude postgresql.conf --exclude pg_log
When using pg_basebackup:
/usr/pgsql-9.6/bin/pg_basebackup -h master_host -p master_port -D
/home/pgsql/9.6/master_data_folder -R -S slot_name -X stream -P -d "
user=superuser_name password=superuser_pass sslmode=require "
Of course, this is inside a bash script with variables at right places
to make script generic as needed to make it works with dozens of
databases...
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 21:42 David Steele <david@pgmasters.net>
parent: Pavel Stehule <pavel.stehule@gmail.com>
1 sibling, 1 reply; 51+ messages in thread
From: David Steele @ 2017-12-26 21:42 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
On 12/26/17 10:57 AM, Pavel Stehule wrote:
> 2017-12-26 16:50 GMT+01:00 Edson Carlos Ericksson Richter
>>
> I'm rebuilding the standby server for two days already, with 23% of
> completion status...
> If lost the database and backups because of that failure, it would
> be a giant disaster.
> Few hours checking integrity would be acceptable... Specially if I
> can run it on standby only.
>
>
> very simple check
>
> pgdumpall > /dev/null
>
> but this doesn't check indexes.
pgBackRest will validate all page checksums (including indexes, etc.) in
the cluster during backup. Full backups check everything,
incr/differential backups check only the files that have changed.
--
-David
david@pgmasters.net
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 21:58 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: David Steele <david@pgmasters.net>
0 siblings, 2 replies; 51+ messages in thread
From: Alvaro Herrera @ 2017-12-26 21:58 UTC (permalink / raw)
To: David Steele <david@pgmasters.net>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
David Steele wrote:
> pgBackRest will validate all page checksums (including indexes, etc.) in the
> cluster during backup. Full backups check everything, incr/differential
> backups check only the files that have changed.
If a table or index file is of zero length when backed up, as in the
described case, nothing will be checked, right? I mean, there is
nothing externally indicating that the file ought to be of a different
size. Am I wrong? So Edson's situation here would not raise any red
flags.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 22:11 rob stone <floriparob@gmail.com>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
1 sibling, 1 reply; 51+ messages in thread
From: rob stone @ 2017-12-26 22:11 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; David Steele <david@pgmasters.net>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
Hello,
On Tue, 2017-12-26 at 18:58 -0300, Alvaro Herrera wrote:Hello,
> David Steele wrote:
>
> > pgBackRest will validate all page checksums (including indexes,
> > etc.) in the
> > cluster during backup. Full backups check everything,
> > incr/differential
> > backups check only the files that have changed.
>
> If a table or index file is of zero length when backed up, as in the
> described case, nothing will be checked, right? I mean, there is
> nothing externally indicating that the file ought to be of a
> different
> size. Am I wrong? So Edson's situation here would not raise any red
> flags.
>
Could the following occur:-
1) Your app. issues a BEGIN followed by an INSERT.
2) Postgres decides to open a new file in order to store the new row.
3) Your app. then does a ROLLBACK.
Wouldn't that leave you with a zero length file on disk?
There's no reason for Postgres to delete the file just because a
rollback was issued. All it has to do is clear the buffer in memory.
My 2 cents.
Rob
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-26 22:42 Martin Marques <martin.marques@2ndquadrant.com>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 1 reply; 51+ messages in thread
From: Martin Marques @ 2017-12-26 22:42 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
El 26/12/17 a las 14:46, Edson Carlos Ericksson Richter escribió:
>
> Usually, or by "pg_basebackup" or by "rsync" as described in PostgreSQL
> Wiki.
> Right now, I'm doing via pg_basebackup.
> Nothing extraordinary.
>
> When using rsync:
>
> rsync -e "ssh -2 -C -p slave_ssh_port" --progress --partial -az
> /pgsql/9.6/master_data_folder/*
> superuser_name@$slave_host:/home/pgsql/9.6/slave_data_folder/ --exclude
> postmaster.pid --exclude postgresql.conf --exclude pg_log
You don't say so anywhere, but I suspect you run the rsync between a
pg_start_backup() and pg_stop_backup(), right?
That is the way it's described in the wiki.
Regards,
--
Martín Marqués http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 12:25 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Martin Marques <martin.marques@2ndquadrant.com>
0 siblings, 1 reply; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-27 12:25 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 26/12/2017 20:42, Martin Marques escreveu:
> El 26/12/17 a las 14:46, Edson Carlos Ericksson Richter escribió:
>> Usually, or by "pg_basebackup" or by "rsync" as described in PostgreSQL
>> Wiki.
>> Right now, I'm doing via pg_basebackup.
>> Nothing extraordinary.
>>
>> When using rsync:
>>
>> rsync -e "ssh -2 -C -p slave_ssh_port" --progress --partial -az
>> /pgsql/9.6/master_data_folder/*
>> superuser_name@$slave_host:/home/pgsql/9.6/slave_data_folder/ --exclude
>> postmaster.pid --exclude postgresql.conf --exclude pg_log
> You don't say so anywhere, but I suspect you run the rsync between a
> pg_start_backup() and pg_stop_backup(), right?
>
> That is the way it's described in the wiki.
>
> Regards,
>
Yes, sure. When using wiki, I'm following all instructions. Process
revisited many times do check if something changed (since 9.0 days :-) )
Right now, I do prefer to use pg_basebackup instead - but sometimes
(when database is just too large), rsync seems more reliable (maybe it
is the cause of the problem).
Anyway, instead digging into rsync functionality (or bugs - I doubt, but
who knows?), I do prefer to have a script I can run to check if there is
obvious failures in standby servers.
Looking for empty files would be a start point.
I'm learning from experienced people from the list that are other points
I would like to check as well.
Regards,
Edson.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 12:31 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: rob stone <floriparob@gmail.com>
0 siblings, 0 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-27 12:31 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 26/12/2017 20:11, rob stone escreveu:
> Hello,
>
>
> On Tue, 2017-12-26 at 18:58 -0300, Alvaro Herrera wrote:Hello,
>> David Steele wrote:
>>
>>> pgBackRest will validate all page checksums (including indexes,
>>> etc.) in the
>>> cluster during backup. Full backups check everything,
>>> incr/differential
>>> backups check only the files that have changed.
>> If a table or index file is of zero length when backed up, as in the
>> described case, nothing will be checked, right? I mean, there is
>> nothing externally indicating that the file ought to be of a
>> different
>> size. Am I wrong? So Edson's situation here would not raise any red
>> flags.
>>
>
> Could the following occur:-
> 1) Your app. issues a BEGIN followed by an INSERT.
> 2) Postgres decides to open a new file in order to store the new row.
> 3) Your app. then does a ROLLBACK.
>
> Wouldn't that leave you with a zero length file on disk?
>
> There's no reason for Postgres to delete the file just because a
> rollback was issued. All it has to do is clear the buffer in memory.
>
> My 2 cents.
>
> Rob
>
>
You are right, in several databases I've looked there are many files
with 0 byte size in ./base folder.
This is not a good quest.
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 14:49 Stephen Frost <sfrost@snowman.net>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 1 reply; 51+ messages in thread
From: Stephen Frost @ 2017-12-27 14:49 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: pgsql-general@lists.postgresql.org
Greetings,
* Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> Right now, I do prefer to use pg_basebackup instead - but sometimes
> (when database is just too large), rsync seems more reliable (maybe
> it is the cause of the problem).
I don't generally recommend rsync for various reasons, but if you make
sure to call pg_start/stop_backup(), keep track of all your WAL and
verify everything ends up written to disk then it should work. Don't
use it for incrementals though- there are cases where that can fail.
> Anyway, instead digging into rsync functionality (or bugs - I doubt,
> but who knows?), I do prefer to have a script I can run to check if
> there is obvious failures in standby servers.
As mentioned, zero-byte files can be perfectly valid. PostgreSQL does
have page-level CRCs, if you initialized your database with them (which
I would strongly recommend). There are also backup tools which will
verify those checksums when performing a backup of the system. In
addition to that, you can do parallel backup and restore which can
reduce the downtime for doing restores quite a bit (though this will
depend on what you're bottleneck is, of course). I'd suggest you take a
look at pgBackRest, though I think that other solutions now also have
all of these features (though they all have their own features too).
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 16:47 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 51+ messages in thread
From: Alvaro Herrera @ 2017-12-27 16:47 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Stephen Frost wrote:
> * Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> > Anyway, instead digging into rsync functionality (or bugs - I doubt,
> > but who knows?), I do prefer to have a script I can run to check if
> > there is obvious failures in standby servers.
>
> As mentioned, zero-byte files can be perfectly valid. PostgreSQL does
> have page-level CRCs, if you initialized your database with them (which
> I would strongly recommend).
Page-level checksums would not detect the problem being complained in
this thread, however.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 17:02 Stephen Frost <sfrost@snowman.net>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 2 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-27 17:02 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Alvaro,
* Alvaro Herrera (alvherre@2ndquadrant.com) wrote:
> Stephen Frost wrote:
>
> > * Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
>
> > > Anyway, instead digging into rsync functionality (or bugs - I doubt,
> > > but who knows?), I do prefer to have a script I can run to check if
> > > there is obvious failures in standby servers.
> >
> > As mentioned, zero-byte files can be perfectly valid. PostgreSQL does
> > have page-level CRCs, if you initialized your database with them (which
> > I would strongly recommend).
>
> Page-level checksums would not detect the problem being complained in
> this thread, however.
It's entirely unclear to me what the problem being complained about in
this thread actually is. The complaint so far was about zero-byte
files, but those are entirely valid, so that isn't a problem that anyone
can solve..
Given the thread subject, if someone actually wanted to do a database
integrity check before startup, they could use pgBackRest to perform a
backup with a CRC-enabled database and at least verify that all of the
checksums are valid.
We could possibly look into adding some set of additional checks for
files which can't actually be zero-byte, perhaps.. I know we have some
other one-off checks already.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 17:30 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-27 17:30 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 27/12/2017 15:02, Stephen Frost escreveu:
> Alvaro,
>
> * Alvaro Herrera (alvherre@2ndquadrant.com) wrote:
>> Stephen Frost wrote:
>>
>>> * Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
>>>> Anyway, instead digging into rsync functionality (or bugs - I doubt,
>>>> but who knows?), I do prefer to have a script I can run to check if
>>>> there is obvious failures in standby servers.
>>> As mentioned, zero-byte files can be perfectly valid. PostgreSQL does
>>> have page-level CRCs, if you initialized your database with them (which
>>> I would strongly recommend).
>> Page-level checksums would not detect the problem being complained in
>> this thread, however.
> It's entirely unclear to me what the problem being complained about in
> this thread actually is. The complaint so far was about zero-byte
> files, but those are entirely valid, so that isn't a problem that anyone
> can solve..
>
> Given the thread subject, if someone actually wanted to do a database
> integrity check before startup, they could use pgBackRest to perform a
> backup with a CRC-enabled database and at least verify that all of the
> checksums are valid.
>
> We could possibly look into adding some set of additional checks for
> files which can't actually be zero-byte, perhaps.. I know we have some
> other one-off checks already.
>
> Thanks!
>
> Stephen
Actually, the problem is:
Master => Slave => Backup
In the master server everything is fine.
But at some point in time, slave became corrupt (one of the base files
are zero size where it should be 16Mb in size), and IMHO a "red alert"
should arise - Slave server shall not even startup at all.
Since backups are taken from slave server, all backups are also corrupt.
I've detected the problem just because I've restored a backup (excellent
practice perhaps - nobody should take backups if not testing it with the
restore procedure).
In slave server there is no indication that the database is corrupt (not
in logs, it starts normally and show it is applying stream changes
regularly).
So that is the point: how to detect that a database is corrupt so
cluster doesn't even start...
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 20:11 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Alvaro Herrera @ 2017-12-27 20:11 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Stephen Frost wrote:
> It's entirely unclear to me what the problem being complained about in
> this thread actually is.
As Edson explained, a relfilenode in the standby server is zero bytes
long when it is not that size in the primary server, and it corresponds
to a persistent table. I don't have any satisfactory explanation for
that.
> Given the thread subject, if someone actually wanted to do a database
> integrity check before startup, they could use pgBackRest to perform a
> backup with a CRC-enabled database and at least verify that all of the
> checksums are valid.
That's not a complete solution, because a zero-byte file does not
contain any CRC. CRCs may detect some problems, but they will not
detect this particular kind of corruption.
> We could possibly look into adding some set of additional checks for
> files which can't actually be zero-byte, perhaps.. I know we have some
> other one-off checks already.
Some possibilities, from the realm of haven't-had-coffee-yet-after-lunch:
* the length of the FSM fork can let you infer something about the
length that the main fork ought to have. Maybe the VM fork too? not sure.
(Easy to check: just some math on the size of the FSM/VM forks)
* the largest block number in any item pointer in any index of a table
can tell you what's the latest page that should appear in the table.
(Expensive: need to scan the indexes completely)
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 20:24 Stephen Frost <sfrost@snowman.net>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-27 20:24 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Alvaro,
* Alvaro Herrera (alvherre@alvh.no-ip.org) wrote:
> Stephen Frost wrote:
>
> > It's entirely unclear to me what the problem being complained about in
> > this thread actually is.
>
> As Edson explained, a relfilenode in the standby server is zero bytes
> long when it is not that size in the primary server, and it corresponds
> to a persistent table. I don't have any satisfactory explanation for
> that.
Somehow I missed the discussion of it being zero bytes for a long time
after it's non-zero on the primary (I take the to main that it's longer
than whatever checkpoint timeout is set to..?). That does sound like
there might be an actual issue/bug here.
> > Given the thread subject, if someone actually wanted to do a database
> > integrity check before startup, they could use pgBackRest to perform a
> > backup with a CRC-enabled database and at least verify that all of the
> > checksums are valid.
>
> That's not a complete solution, because a zero-byte file does not
> contain any CRC. CRCs may detect some problems, but they will not
> detect this particular kind of corruption.
I agree that we can certainly have bugs which will cause corruption
that's not detectable by our CRCs. Validating CRCs is just checking for
one kind of corruption; using amcheck would provide another level,
though it's unclear if that would help in this specific case if it's
really just files on the standby (but not the primary) being zero-length
long after they should be written out.
> > We could possibly look into adding some set of additional checks for
> > files which can't actually be zero-byte, perhaps.. I know we have some
> > other one-off checks already.
>
> Some possibilities, from the realm of haven't-had-coffee-yet-after-lunch:
>
> * the length of the FSM fork can let you infer something about the
> length that the main fork ought to have. Maybe the VM fork too? not sure.
> (Easy to check: just some math on the size of the FSM/VM forks)
I was just chatting with David over lunch specifically about checking
that the number of forks was valid and looking at their lengths also
makes sense, but the VM is only created/updated based on VACUUM runs, so
checking that is a bit tricky. David has ideas about how to handle
various races when it comes to forks (in particular by building a
manifest once and then seeing if anything in the relation has changed
since the manifest was built- if so, assume that WAL has the necessary
info and if not then raise a flag) but it's all a bit tricky when the
system is running. We might be able to do more checks if we're serious
about supporting pre-startup checks though. We were also thinking about
having a set of catalog tables that must not be zero and checking for
those.
> * the largest block number in any item pointer in any index of a table
> can tell you what's the latest page that should appear in the table.
> (Expensive: need to scan the indexes completely)
This is something that I'd expect amcheck to handle; I'm not sure it
makes sense to invent something else. David and I have chatted a little
bit a while ago about trying to incorporate amcheck but it's rather
complicated and not something we plan to do in the near-term. Still, it
does seem like it'd be a nice capability to have. I wish it was
possible to do off-line though. Of course, a user could do a restore
and then run amcheck on the result themselves.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 21:33 Stephen Frost <sfrost@snowman.net>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 1 reply; 51+ messages in thread
From: Stephen Frost @ 2017-12-27 21:33 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: pgsql-general@lists.postgresql.org
Edson,
* Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> Em 27/12/2017 15:02, Stephen Frost escreveu:
> >* Alvaro Herrera (alvherre@2ndquadrant.com) wrote:
> >>Stephen Frost wrote:
> >>
> >>>* Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> >>>>Anyway, instead digging into rsync functionality (or bugs - I doubt,
> >>>>but who knows?), I do prefer to have a script I can run to check if
> >>>>there is obvious failures in standby servers.
> >>>As mentioned, zero-byte files can be perfectly valid. PostgreSQL does
> >>>have page-level CRCs, if you initialized your database with them (which
> >>>I would strongly recommend).
> >>Page-level checksums would not detect the problem being complained in
> >>this thread, however.
> >It's entirely unclear to me what the problem being complained about in
> >this thread actually is. The complaint so far was about zero-byte
> >files, but those are entirely valid, so that isn't a problem that anyone
> >can solve..
> >
> >Given the thread subject, if someone actually wanted to do a database
> >integrity check before startup, they could use pgBackRest to perform a
> >backup with a CRC-enabled database and at least verify that all of the
> >checksums are valid.
> >
> >We could possibly look into adding some set of additional checks for
> >files which can't actually be zero-byte, perhaps.. I know we have some
> >other one-off checks already.
>
> Actually, the problem is:
>
> Master => Slave => Backup
>
> In the master server everything is fine.
Alright..
> But at some point in time, slave became corrupt (one of the base
> files are zero size where it should be 16Mb in size), and IMHO a
> "red alert" should arise - Slave server shall not even startup at
> all.
How do you know it should be 16Mb in size...? That sounds like you're
describing a WAL file, but you should be archiving your WAL files during
a backup, not just using whatever is in pg_xlog/pg_wal..
> Since backups are taken from slave server, all backups are also corrupt.
If you aren't following the appropriate process to perform a backup
then, yes, you're going to end up with corrupt and useless/bad backups.
Backing up from a replica has only been officially supported using the
pg_start/stop_backup methods as of 9.6 and only when doing a
non-exclusive backup.
Note that the wiki page you're talking about (I think, anyway...) is
describing *exclusive* backup, not non-exclusive, and the two are not
the same.
> I've detected the problem just because I've restored a backup
> (excellent practice perhaps - nobody should take backups if not
> testing it with the restore procedure).
Yes, restoring a backup is excellent practice and something that
everyone really should be doing. In my view, at least, everyone should
also be using well tested backup tools instead of trying to write their
own.
> In slave server there is no indication that the database is corrupt
> (not in logs, it starts normally and show it is applying stream
> changes regularly).
This sounds like what's happening is that you're ending up with PG
thinking that a crash happened because backup_label is missing, which
will happen if you do pg_start/stop_backup on the replica and don't make
sure to take the results from pg_stop_backup and create the backup_label
file before starting PostgreSQL after the restore.
This isn't something that would happen if you used a backup tool that
knew about how to perform a non-exclusive backup or how to properly
backup using a replica instead of trying to write your own without
understanding how all these pieces play together.
> So that is the point: how to detect that a database is corrupt so
> cluster doesn't even start...
I'm not sure that the database is actually corrupt in this specific
case- it sounds like everything is actually fine, but you didn't include
the backup_label file when restoring and therefore PG thinks there is
crash recovery happening when it should be replaying WAL from the start
of the backup, but how is PG going to know that? Well, it'd know that
from the backup_label file, if it was there.. Otherwise, it seems
pretty difficult for us to know that we're not doing crash recovery.
I'm certainly open to ideas on how to detect that, but nothing springs
to mind off-hand.
Again, using a backup tool instead of trying to roll your own would make
this much less likely to happen. This isn't something which should
happen when you're using pg_basebackup or the other PG-specific backup
tools, rather it's only happening because you're trying to do your own
with pg_start/stop_backup and rsync and didn't completely read the
documentation on non-exclusive backups from replicas (that said, those
docs could certainly use improvment...).
Of course, perhaps I'm misunderstanding exactly what you're doing or
what file you're referring to, but this is my best guess based on the
information you've provided so far.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 21:52 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 51+ messages in thread
From: Alvaro Herrera @ 2017-12-27 21:52 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
For context: this was first reported in the Barman forum here:
https://groups.google.com/forum/#!msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ
They are using Barman for the backups.
Stephen Frost wrote:
> > But at some point in time, slave became corrupt (one of the base
> > files are zero size where it should be 16Mb in size), and IMHO a
> > "red alert" should arise - Slave server shall not even startup at
> > all.
>
> How do you know it should be 16Mb in size...? That sounds like you're
> describing a WAL file, but you should be archiving your WAL files during
> a backup, not just using whatever is in pg_xlog/pg_wal..
It's not a WAL file -- it's a file backing a table.
> > Since backups are taken from slave server, all backups are also corrupt.
>
> If you aren't following the appropriate process to perform a backup
> then, yes, you're going to end up with corrupt and useless/bad backups.
A few guys went over the backup-taking protocol upthread already.
But anyway the backup tool is a moot point. The problem doesn't
originate in the backup -- it originates in the standby, from where the
backup is taken. The file can be seen as size 0 in the standby.
Edson's question is: why wasn't the problem detected in the standby?
It seems a valid question to me, to which we currently we don't have any
good answer.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-27 23:03 David Steele <david@pgmasters.net>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
1 sibling, 0 replies; 51+ messages in thread
From: David Steele @ 2017-12-27 23:03 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; Martin Marques <martin.marques@2ndquadrant.com>; pgsql-general
On 12/26/17 4:58 PM, Alvaro Herrera wrote:
>
>> pgBackRest will validate all page checksums (including indexes, etc.) in the
>> cluster during backup. Full backups check everything, incr/differential
>> backups check only the files that have changed.
>
> If a table or index file is of zero length when backed up, as in the
> described case, nothing will be checked, right? I mean, there is
> nothing externally indicating that the file ought to be of a different
> size. Am I wrong?
Yes - that is how it works.
> So Edson's situation here would not raise any red
> flags.
It wasn't clear to me from the OP that the primary and standby were
different - I thought there was just a zero file in general.
In any case, my reply was more directed at Pavel's reply about using
pg_dump to validate checksums. There are better ways...
--
-David
david@pgmasters.net
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 12:16 Stephen Frost <sfrost@snowman.net>
parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 51+ messages in thread
From: Stephen Frost @ 2017-12-28 12:16 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Alvaro,
* Alvaro Herrera (alvherre@alvh.no-ip.org) wrote:
> For context: this was first reported in the Barman forum here:
> https://groups.google.com/forum/#!msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ
> They are using Barman for the backups.
Ahhhh, I see. I wasn't aware of that history.
> Stephen Frost wrote:
>
> > > But at some point in time, slave became corrupt (one of the base
> > > files are zero size where it should be 16Mb in size), and IMHO a
> > > "red alert" should arise - Slave server shall not even startup at
> > > all.
> >
> > How do you know it should be 16Mb in size...? That sounds like you're
> > describing a WAL file, but you should be archiving your WAL files during
> > a backup, not just using whatever is in pg_xlog/pg_wal..
>
> It's not a WAL file -- it's a file backing a table.
Interesting.
> > > Since backups are taken from slave server, all backups are also corrupt.
> >
> > If you aren't following the appropriate process to perform a backup
> > then, yes, you're going to end up with corrupt and useless/bad backups.
>
> A few guys went over the backup-taking protocol upthread already.
>
> But anyway the backup tool is a moot point. The problem doesn't
> originate in the backup -- it originates in the standby, from where the
> backup is taken. The file can be seen as size 0 in the standby.
> Edson's question is: why wasn't the problem detected in the standby?
> It seems a valid question to me, to which we currently we don't have any
> good answer.
The last message on that thread seems pretty clear to me- the comment is
"I think this is a failure in standby build." It's not clear what that
failure was but I agree it doesn't appear related to the backup tool
(the comment there is "I'm using rsync"), or, really, PostgreSQL at all
(a failure during the build of the replica isn't something we're
necessairly going to pick up on..).
As discussed on this thread, zero-byte files are entirely valid to
appear in the PostgreSQL data directory.
To try and dig into what happened, I'd probably look at what forks there
are of that relation, the entry in pg_class, and try to figure out how
it is that replication isn't complaining when the file on the primary
appeared to be modified well after the last modify timestamp on the
replica. If it's possible to replica this into a test environment,
maybe even do a no-op update of a row of that table and see what happens
with replication. One thing I wonder is if this table used to be
unlogged and it was later turned into a logged table but something
didn't quite happen correctly with that. I'd also suggest looking for
other file size mismatches between the primary and the replica.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 17:46 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Stephen Frost <sfrost@snowman.net>
0 siblings, 2 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-28 17:46 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 28/12/2017 10:16, Stephen Frost escreveu:
> Alvaro,
>
> * Alvaro Herrera (alvherre@alvh.no-ip.org) wrote:
>> For context: this was first reported in the Barman forum here:
>> https://groups.google.com/forum/#!msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ
>> They are using Barman for the backups.
> Ahhhh, I see. I wasn't aware of that history.
>
>> Stephen Frost wrote:
>>
>>>> But at some point in time, slave became corrupt (one of the base
>>>> files are zero size where it should be 16Mb in size), and IMHO a
>>>> "red alert" should arise - Slave server shall not even startup at
>>>> all.
>>> How do you know it should be 16Mb in size...? That sounds like you're
>>> describing a WAL file, but you should be archiving your WAL files during
>>> a backup, not just using whatever is in pg_xlog/pg_wal..
>> It's not a WAL file -- it's a file backing a table.
> Interesting.
>
>>>> Since backups are taken from slave server, all backups are also corrupt.
>>> If you aren't following the appropriate process to perform a backup
>>> then, yes, you're going to end up with corrupt and useless/bad backups.
>> A few guys went over the backup-taking protocol upthread already.
>>
>> But anyway the backup tool is a moot point. The problem doesn't
>> originate in the backup -- it originates in the standby, from where the
>> backup is taken. The file can be seen as size 0 in the standby.
>> Edson's question is: why wasn't the problem detected in the standby?
>> It seems a valid question to me, to which we currently we don't have any
>> good answer.
> The last message on that thread seems pretty clear to me- the comment is
> "I think this is a failure in standby build." It's not clear what that
> failure was but I agree it doesn't appear related to the backup tool
> (the comment there is "I'm using rsync"), or, really, PostgreSQL at all
> (a failure during the build of the replica isn't something we're
> necessairly going to pick up on..).
>
> As discussed on this thread, zero-byte files are entirely valid to
> appear in the PostgreSQL data directory.
>
> To try and dig into what happened, I'd probably look at what forks there
> are of that relation, the entry in pg_class, and try to figure out how
> it is that replication isn't complaining when the file on the primary
> appeared to be modified well after the last modify timestamp on the
> replica. If it's possible to replica this into a test environment,
> maybe even do a no-op update of a row of that table and see what happens
> with replication. One thing I wonder is if this table used to be
> unlogged and it was later turned into a logged table but something
> didn't quite happen correctly with that. I'd also suggest looking for
> other file size mismatches between the primary and the replica.
>
> Thanks!
>
> Stephen
The table was never unlogged. From very beginning, it was always logged.
I've dozens of databases with exactly same setup - and right now, I'm
rebuilding the slave server. Instead of investigating something probably
I will not find the cause, I would like to have a alert for the future.
Would be possible to include in future versions:
1) After start standby, standby run all WAL files until it is
synchronized with master (current behavior)
3) Before getting into "accept read only queries", check if all base
files have same size as master server (new behavior). In case something
is different, throw an error and stop database startup?
4) Then start "accept read only queries" (current behavior)
???
Thanks,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 18:06 Brent Wood <pcreso@yahoo.com>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 2 replies; 51+ messages in thread
From: Brent Wood @ 2017-12-28 18:06 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Some thoughts....
A tool to calculate a checksum of sorts based on the table (file) content would provide a better surety of duplication than simply checking file size - like differently vacuumed tables in each copy could have the same content but be different file sizes.
Something like these could be adapted to compare database content by filesystem checks rather than db queries. Following tablespaces, etc as well.
http://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-ha... other similar tools
Yes, there is some overhead, especially for large databases but it would be worth that to robustly ensure genuine and complete duplication.
I do wonder though - given the order of records in a table (file) is not necessarily identical (or is it?) event this may be problematic. Perhaps a checksum based on the result of a query output ordered by primary key could work?
Brent Wood
From: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
To: pgsql-general@lists.postgresql.org
Sent: Friday, December 29, 2017 6:47 AM
Subject: Re: Does PostgreSQL check database integrity at startup?
Em 28/12/2017 10:16, Stephen Frost escreveu:
> Alvaro,
>
> * Alvaro Herrera (alvherre@alvh.no-ip.org) wrote:
>> For context: this was first reported in the Barman forum here:
>> https://groups.google.com/forum/#!msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ
>> They are using Barman for the backups.
> Ahhhh, I see. I wasn't aware of that history.
>
>> Stephen Frost wrote:
>>
>>>> But at some point in time, slave became corrupt (one of the base
>>>> files are zero size where it should be 16Mb in size), and IMHO a
>>>> "red alert" should arise - Slave server shall not even startup at
>>>> all.
>>> How do you know it should be 16Mb in size...? That sounds like you're
>>> describing a WAL file, but you should be archiving your WAL files during
>>> a backup, not just using whatever is in pg_xlog/pg_wal..
>> It's not a WAL file -- it's a file backing a table.
> Interesting.
>
>>>> Since backups are taken from slave server, all backups are also corrupt.
>>> If you aren't following the appropriate process to perform a backup
>>> then, yes, you're going to end up with corrupt and useless/bad backups.
>> A few guys went over the backup-taking protocol upthread already.
>>
>> But anyway the backup tool is a moot point. The problem doesn't
>> originate in the backup -- it originates in the standby, from where the
>> backup is taken. The file can be seen as size 0 in the standby.
>> Edson's question is: why wasn't the problem detected in the standby?
>> It seems a valid question to me, to which we currently we don't have any
>> good answer.
> The last message on that thread seems pretty clear to me- the comment is
> "I think this is a failure in standby build." It's not clear what that
> failure was but I agree it doesn't appear related to the backup tool
> (the comment there is "I'm using rsync"), or, really, PostgreSQL at all
> (a failure during the build of the replica isn't something we're
> necessairly going to pick up on..).
>
> As discussed on this thread, zero-byte files are entirely valid to
> appear in the PostgreSQL data directory.
>
> To try and dig into what happened, I'd probably look at what forks there
> are of that relation, the entry in pg_class, and try to figure out how
> it is that replication isn't complaining when the file on the primary
> appeared to be modified well after the last modify timestamp on the
> replica. If it's possible to replica this into a test environment,
> maybe even do a no-op update of a row of that table and see what happens
> with replication. One thing I wonder is if this table used to be
> unlogged and it was later turned into a logged table but something
> didn't quite happen correctly with that. I'd also suggest looking for
> other file size mismatches between the primary and the replica.
>
> Thanks!
>
> Stephen
The table was never unlogged. From very beginning, it was always logged.
I've dozens of databases with exactly same setup - and right now, I'm
rebuilding the slave server. Instead of investigating something probably
I will not find the cause, I would like to have a alert for the future.
Would be possible to include in future versions:
1) After start standby, standby run all WAL files until it is
synchronized with master (current behavior)
3) Before getting into "accept read only queries", check if all base
files have same size as master server (new behavior). In case something
is different, throw an error and stop database startup?
4) Then start "accept read only queries" (current behavior)
???
Thanks,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 18:16 Stephen Frost <sfrost@snowman.net>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
1 sibling, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-28 18:16 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: pgsql-general@lists.postgresql.org
Greetings,
* Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> Would be possible to include in future versions:
> 1) After start standby, standby run all WAL files until it is
> synchronized with master (current behavior)
> 3) Before getting into "accept read only queries", check if all base
> files have same size as master server (new behavior). In case
> something is different, throw an error and stop database startup?
> 4) Then start "accept read only queries" (current behavior)
I'm afraid it wouldn't be nearly that simple with a running system. If
you're that concerned about it, you could shut down the primary, verify
that the replica has fully caught up to where the primary was, and then
compare the file sizes on disk using a script yourself (excluding the
temporary files and unlogged relations, etc, of course). I'm not
completely sure that there isn't a valid reason for them to be different
even with everything shut down and fully caught up, but that seems like
the best chance way to match things up.
On a running system where lots of processes are potentially writing to
different files across the system, getting a point-in-time snapshot of
the file sizes across the entire system as of a certain WAL point (so
you could replay to there and then compare on the replica) seems
unlikely to be possible, at least with just PG. Perhaps with help from
the OS/filesystem, you might be able to get such a snapshot.
Do you have some way of knowing that such a check would have actually
caught this..? Isn't it possible that the file became zero'd out
sometime after the replica started up and was running fine for a while?
One of the questions I asked earlier drove at exactly this question- why
weren't there any errors thrown during WAL replay on the replica, given
that the relation clearly appeared to be modified after the replica was
built? Another thing which could be done would be to look through the
WAL for references to that file and see what the WAL included for it.
Also, really, if this is happening then there's something pretty wrong
with some part of the process and that simply needs to be fixed- just
throwing an error saying the replica isn't valid isn't really good for
anyone. Where the issue is, I don't think we have any idea, because
there's a lot of details missing here, which is why I was asking
questions about the other data and information since it might help us
figure out what happened. Perhaps it's an issue in the OS or filesystem
or another layer (though there should really be logs if that's the case)
or maybe it really is a PG issue, but if so, we need a lot more info to
debug and address it.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 18:26 Stephen Frost <sfrost@snowman.net>
parent: Brent Wood <pcreso@yahoo.com>
1 sibling, 2 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-28 18:26 UTC (permalink / raw)
To: Brent Wood <pcreso@yahoo.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Greetings Brent,
* Brent Wood (pcreso@yahoo.com) wrote:
> A tool to calculate a checksum of sorts based on the table (file) content would provide a better surety of duplication than simply checking file size - like differently vacuumed tables in each copy could have the same content but be different file sizes.
PG has support for checksums and there are tools out there to validate
that the checksum is correct for all pages which have one, but that
wouldn't help in this case because the file is zero'd out (and a zero'd
out file is actually a valid file in a PG data directory).
Also, the files on the primary and the replica actually can be different
when looked at with a complete-file checksum due to hint bits being set
differently (at least, possibly other ways too). That doesn't make them
invalid or incorrect though.
Rather than trying to compare a running primary to a running replica,
such a check to verify that the files backed up during a backup have the
same checksum as the files being restored from that backup can be done,
and that *is* done in at least some of the PG backup tools already
(pgBackRest has an independent manifest that it stores for each backup
which contains the checksum of each file as-backed-up, and it verifies
that checksum when performing a restore to make sure that the backed up
file wasn't corrupted in place, other tools hopefully have similar).
> I do wonder though - given the order of records in a table (file) is not necessarily identical (or is it?) event this may be problematic. Perhaps a checksum based on the result of a query output ordered by primary key could work?
The order of records in a *file* should be the same in the heap on the
primary as they are on the replica, but that doesn't mean the contents
of those files will be exactly the same (as mentioned above, hint bits
can differ). We used to have cases where the indexes could also be
different, but I believe that was changed so they should match.
I've used the approach of doing a checksum across the results of an
ordered query to compare between systems and that generally does work,
but it's a bit tricky if you're trying to compare a table that's heavily
modified- you need to determine the point in the WAL stream that you're
at on the primary when you run the query and then replay the replica to
that point in the WAL and then run the query on the replica, otherwise
you could end up with differences that are just because of the ongoing
transactions being run to update the table.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 18:33 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Brent Wood <pcreso@yahoo.com>
1 sibling, 0 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-28 18:33 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 28/12/2017 16:06, Brent Wood escreveu:
> Some thoughts....
>
> A tool to calculate a checksum of sorts based on the table (file)
> content would provide a better surety of duplication than simply
> checking file size - like differently vacuumed tables in each copy
> could have the same content but be different file sizes.
>
> Something like these could be adapted to compare database content by
> filesystem checks rather than db queries. Following tablespaces, etc
> as well.
>
> http://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-ha...
> or other similar tools
>
> Yes, there is some overhead, especially for large databases but it
> would be worth that to robustly ensure genuine and complete duplication.
>
> I do wonder though - given the order of records in a table (file) is
> not necessarily identical (or is it?) event this may be problematic.
> Perhaps a checksum based on the result of a query output ordered by
> primary key could work?
>
> Brent Wood
>
> ------------------------------------------------------------------------
> *From:* Edson Carlos Ericksson Richter <richter@simkorp.com.br>
> *To:* pgsql-general@lists.postgresql.org
> *Sent:* Friday, December 29, 2017 6:47 AM
> *Subject:* Re: Does PostgreSQL check database integrity at startup?
>
> Em 28/12/2017 10:16, Stephen Frost escreveu:
> > Alvaro,
> >
> > * Alvaro Herrera (alvherre@alvh.no-ip.org
> <mailto:alvherre@alvh.no-ip.org>) wrote:
> >> For context: this was first reported in the Barman forum here:
> >>
> https://groups.google.com/forum/#!msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ
> <https://groups.google.com/forum/#%21msg/pgbarman/3aXWpaKWRFI/weUIZxspDAAJ;
> >> They are using Barman for the backups.
> > Ahhhh, I see. I wasn't aware of that history.
> >
> >> Stephen Frost wrote:
> >>
> >>>> But at some point in time, slave became corrupt (one of the base
> >>>> files are zero size where it should be 16Mb in size), and IMHO a
> >>>> "red alert" should arise - Slave server shall not even startup at
> >>>> all.
> >>> How do you know it should be 16Mb in size...? That sounds like you're
> >>> describing a WAL file, but you should be archiving your WAL files
> during
> >>> a backup, not just using whatever is in pg_xlog/pg_wal..
> >> It's not a WAL file -- it's a file backing a table.
> > Interesting.
> >
> >>>> Since backups are taken from slave server, all backups are also
> corrupt.
> >>> If you aren't following the appropriate process to perform a backup
> >>> then, yes, you're going to end up with corrupt and useless/bad
> backups.
> >> A few guys went over the backup-taking protocol upthread already.
> >>
> >> But anyway the backup tool is a moot point. The problem doesn't
> >> originate in the backup -- it originates in the standby, from where the
> >> backup is taken. The file can be seen as size 0 in the standby.
> >> Edson's question is: why wasn't the problem detected in the standby?
> >> It seems a valid question to me, to which we currently we don't
> have any
> >> good answer.
> > The last message on that thread seems pretty clear to me- the comment is
> > "I think this is a failure in standby build." It's not clear what that
> > failure was but I agree it doesn't appear related to the backup tool
> > (the comment there is "I'm using rsync"), or, really, PostgreSQL at all
> > (a failure during the build of the replica isn't something we're
> > necessairly going to pick up on..).
> >
> > As discussed on this thread, zero-byte files are entirely valid to
> > appear in the PostgreSQL data directory.
> >
> > To try and dig into what happened, I'd probably look at what forks there
> > are of that relation, the entry in pg_class, and try to figure out how
> > it is that replication isn't complaining when the file on the primary
> > appeared to be modified well after the last modify timestamp on the
> > replica. If it's possible to replica this into a test environment,
> > maybe even do a no-op update of a row of that table and see what happens
> > with replication. One thing I wonder is if this table used to be
> > unlogged and it was later turned into a logged table but something
> > didn't quite happen correctly with that. I'd also suggest looking for
> > other file size mismatches between the primary and the replica.
> >
> > Thanks!
> >
> > Stephen
> The table was never unlogged. From very beginning, it was always logged.
> I've dozens of databases with exactly same setup - and right now, I'm
> rebuilding the slave server. Instead of investigating something probably
> I will not find the cause, I would like to have a alert for the future.
>
> Would be possible to include in future versions:
> 1) After start standby, standby run all WAL files until it is
> synchronized with master (current behavior)
> 3) Before getting into "accept read only queries", check if all base
> files have same size as master server (new behavior). In case something
> is different, throw an error and stop database startup?
> 4) Then start "accept read only queries" (current behavior)
> ???
>
> Thanks,
>
>
> Edson
Thanks, Brent. I'll think about it.
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-28 18:35 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 0 replies; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-28 18:35 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 28/12/2017 16:26, Stephen Frost escreveu:
> Greetings Brent,
>
> * Brent Wood (pcreso@yahoo.com) wrote:
>> A tool to calculate a checksum of sorts based on the table (file) content would provide a better surety of duplication than simply checking file size - like differently vacuumed tables in each copy could have the same content but be different file sizes.
> PG has support for checksums and there are tools out there to validate
> that the checksum is correct for all pages which have one, but that
> wouldn't help in this case because the file is zero'd out (and a zero'd
> out file is actually a valid file in a PG data directory).
>
> Also, the files on the primary and the replica actually can be different
> when looked at with a complete-file checksum due to hint bits being set
> differently (at least, possibly other ways too). That doesn't make them
> invalid or incorrect though.
>
> Rather than trying to compare a running primary to a running replica,
> such a check to verify that the files backed up during a backup have the
> same checksum as the files being restored from that backup can be done,
> and that *is* done in at least some of the PG backup tools already
> (pgBackRest has an independent manifest that it stores for each backup
> which contains the checksum of each file as-backed-up, and it verifies
> that checksum when performing a restore to make sure that the backed up
> file wasn't corrupted in place, other tools hopefully have similar).
>
>> I do wonder though - given the order of records in a table (file) is not necessarily identical (or is it?) event this may be problematic. Perhaps a checksum based on the result of a query output ordered by primary key could work?
> The order of records in a *file* should be the same in the heap on the
> primary as they are on the replica, but that doesn't mean the contents
> of those files will be exactly the same (as mentioned above, hint bits
> can differ). We used to have cases where the indexes could also be
> different, but I believe that was changed so they should match.
>
> I've used the approach of doing a checksum across the results of an
> ordered query to compare between systems and that generally does work,
> but it's a bit tricky if you're trying to compare a table that's heavily
> modified- you need to determine the point in the WAL stream that you're
> at on the primary when you run the query and then replay the replica to
> that point in the WAL and then run the query on the replica, otherwise
> you could end up with differences that are just because of the ongoing
> transactions being run to update the table.
>
> Thanks!
>
> Stephen
Stephen, thanks for you detailed reasoning on why this would not be so
simple.
I'll take all of that in consideration. I hope I find something that
gives a bit more confidence that my replicas are enought reliable. At
this moment, I just don't trust them.
Regards,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 00:14 Jan Wieck <jan@wi3ck.info>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 2 replies; 51+ messages in thread
From: Jan Wieck @ 2017-12-30 00:14 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Brent Wood <pcreso@yahoo.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Thu, Dec 28, 2017 at 1:26 PM, Stephen Frost <sfrost@snowman.net> wrote:
> Greetings Brent,
>
> * Brent Wood (pcreso@yahoo.com) wrote:
> > A tool to calculate a checksum of sorts based on the table (file)
> content would provide a better surety of duplication than simply checking
> file size - like differently vacuumed tables in each copy could have the
> same content but be different file sizes.
>
> PG has support for checksums and there are tools out there to validate
> that the checksum is correct for all pages which have one, but that
> wouldn't help in this case because the file is zero'd out (and a zero'd
> out file is actually a valid file in a PG data directory).
>
> Also, the files on the primary and the replica actually can be different
> when looked at with a complete-file checksum due to hint bits being set
> differently (at least, possibly other ways too). That doesn't make them
> invalid or incorrect though.
>
In addition to what Stephen and everyone else said, it is impossible to get
a valid snapshot of the whole "file" on a running server without locking
the relation and reading it through the PostgreSQL buffer cache. On data
files such as heap and index, PostgreSQL does extensive write caching.
Preventing data loss from write caching is a primary purpose of WAL. Write
caching in the application (PostgreSQL in this case) prevents the OS from
actually knowing the correct "logical" state of the file at any given point
in time. This means that even a LVM snapshot will not give you consistent
data files of a running server, because the not yet written changes (in
shared buffers) waiting for a checkpoint to force them into OS buffers
won't be visible from outside PostgreSQL.
Regards, Jan
such a check to verify that the files backed up during a backup have the
> same checksum as the files being restored from that backup can be done,
> and that *is* done in at least some of the PG backup tools already
> (pgBackRest has an independent manifest that it stores for each backup
> which contains the checksum of each file as-backed-up, and it verifies
> that checksum when performing a restore to make sure that the backed up
> file wasn't corrupted in place, other tools hopefully have similar).
>
> > I do wonder though - given the order of records in a table (file) is not
> necessarily identical (or is it?) event this may be problematic. Perhaps a
> checksum based on the result of a query output ordered by primary key could
> work?
>
> The order of records in a *file* should be the same in the heap on the
> primary as they are on the replica, but that doesn't mean the contents
> of those files will be exactly the same (as mentioned above, hint bits
> can differ). We used to have cases where the indexes could also be
> different, but I believe that was changed so they should match.
>
> I've used the approach of doing a checksum across the results of an
> ordered query to compare between systems and that generally does work,
> but it's a bit tricky if you're trying to compare a table that's heavily
> modified- you need to determine the point in the WAL stream that you're
> at on the primary when you run the query and then replay the replica to
> that point in the WAL and then run the query on the replica, otherwise
> you could end up with differences that are just because of the ongoing
> transactions being run to update the table.
>
> Thanks!
>
> Stephen
>
--
Jan Wieck
Senior Postgres Architect
http://pgblog.wi3ck.info
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 01:03 Edson Carlos Ericksson Richter <richter@simkorp.com.br>
parent: Jan Wieck <jan@wi3ck.info>
1 sibling, 1 reply; 51+ messages in thread
From: Edson Carlos Ericksson Richter @ 2017-12-30 01:03 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Em 29/12/2017 22:14, Jan Wieck escreveu:
>
>
> On Thu, Dec 28, 2017 at 1:26 PM, Stephen Frost <sfrost@snowman.net
> <mailto:sfrost@snowman.net>> wrote:
>
> Greetings Brent,
>
> * Brent Wood (pcreso@yahoo.com <mailto:pcreso@yahoo.com>) wrote:
> > A tool to calculate a checksum of sorts based on the table
> (file) content would provide a better surety of duplication than
> simply checking file size - like differently vacuumed tables in
> each copy could have the same content but be different file sizes.
>
> PG has support for checksums and there are tools out there to validate
> that the checksum is correct for all pages which have one, but that
> wouldn't help in this case because the file is zero'd out (and a
> zero'd
> out file is actually a valid file in a PG data directory).
>
> Also, the files on the primary and the replica actually can be
> different
> when looked at with a complete-file checksum due to hint bits
> being set
> differently (at least, possibly other ways too). That doesn't
> make them
> invalid or incorrect though.
>
>
> In addition to what Stephen and everyone else said, it is impossible
> to get a valid snapshot of the whole "file" on a running server
> without locking the relation and reading it through the PostgreSQL
> buffer cache. On data files such as heap and index, PostgreSQL does
> extensive write caching. Preventing data loss from write caching is a
> primary purpose of WAL. Write caching in the application (PostgreSQL
> in this case) prevents the OS from actually knowing the correct
> "logical" state of the file at any given point in time. This means
> that even a LVM snapshot will not give you consistent data files of a
> running server, because the not yet written changes (in shared
> buffers) waiting for a checkpoint to force them into OS buffers won't
> be visible from outside PostgreSQL.
>
>
> Regards, Jan
>
>
>
> such a check to verify that the files backed up during a backup
> have the
> same checksum as the files being restored from that backup can be
> done,
> and that *is* done in at least some of the PG backup tools already
> (pgBackRest has an independent manifest that it stores for each backup
> which contains the checksum of each file as-backed-up, and it verifies
> that checksum when performing a restore to make sure that the
> backed up
> file wasn't corrupted in place, other tools hopefully have similar).
>
> > I do wonder though - given the order of records in a table
> (file) is not necessarily identical (or is it?) event this may be
> problematic. Perhaps a checksum based on the result of a query
> output ordered by primary key could work?
>
> The order of records in a *file* should be the same in the heap on the
> primary as they are on the replica, but that doesn't mean the contents
> of those files will be exactly the same (as mentioned above, hint bits
> can differ). We used to have cases where the indexes could also be
> different, but I believe that was changed so they should match.
>
> I've used the approach of doing a checksum across the results of an
> ordered query to compare between systems and that generally does work,
> but it's a bit tricky if you're trying to compare a table that's
> heavily
> modified- you need to determine the point in the WAL stream that
> you're
> at on the primary when you run the query and then replay the
> replica to
> that point in the WAL and then run the query on the replica, otherwise
> you could end up with differences that are just because of the ongoing
> transactions being run to update the table.
>
> Thanks!
>
> Stephen
>
>
>
>
> --
> Jan Wieck
> Senior Postgres Architect
> http://pgblog.wi3ck.info
One last question:
There should be a "catalog" that point where tables are stored in
physical files (I think, at least, because at some point PostgreSQL need
to know from where to read the data).
Based on information from this catalog, would I have a tool (perhaps, a
C function) that check that data is really there?
Thanks,
Edson
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 01:09 Stephen Frost <sfrost@snowman.net>
parent: Jan Wieck <jan@wi3ck.info>
1 sibling, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 01:09 UTC (permalink / raw)
To: Jan Wieck <jan@wi3ck.info>; +Cc: Brent Wood <pcreso@yahoo.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Jan, all,
* Jan Wieck (jan@wi3ck.info) wrote:
> On Thu, Dec 28, 2017 at 1:26 PM, Stephen Frost <sfrost@snowman.net> wrote:
> > * Brent Wood (pcreso@yahoo.com) wrote:
> > > A tool to calculate a checksum of sorts based on the table (file)
> > content would provide a better surety of duplication than simply checking
> > file size - like differently vacuumed tables in each copy could have the
> > same content but be different file sizes.
> >
> > PG has support for checksums and there are tools out there to validate
> > that the checksum is correct for all pages which have one, but that
> > wouldn't help in this case because the file is zero'd out (and a zero'd
> > out file is actually a valid file in a PG data directory).
> >
> > Also, the files on the primary and the replica actually can be different
> > when looked at with a complete-file checksum due to hint bits being set
> > differently (at least, possibly other ways too). That doesn't make them
> > invalid or incorrect though.
>
> In addition to what Stephen and everyone else said, it is impossible to get
> a valid snapshot of the whole "file" on a running server without locking
> the relation and reading it through the PostgreSQL buffer cache. On data
> files such as heap and index, PostgreSQL does extensive write caching.
> Preventing data loss from write caching is a primary purpose of WAL. Write
> caching in the application (PostgreSQL in this case) prevents the OS from
> actually knowing the correct "logical" state of the file at any given point
> in time. This means that even a LVM snapshot will not give you consistent
> data files of a running server, because the not yet written changes (in
> shared buffers) waiting for a checkpoint to force them into OS buffers
> won't be visible from outside PostgreSQL.
Indeed, and just to follow that through- that's what WAL exists to
correct in the event of a crash. Anything cache'd in PostgreSQL but
actually committed will have already been written into the WAL and
sync'd to disk, so when PostgreSQL restarts it'll realize that a crash
had happened and go back to the last checkpoint in the WAL stream and
replay the WAL from there to get back to consistency.
This is also how online backups of PostgreSQL happen, but PG can't then
start the replay from the *latest* checkpoint, it has to start from the
checkpoint where the backup started, and it can't just finish at any
point in the WAL stream- it must reach consistency (where the backup
finished). The starting location is provided by PostgreSQL when doing a
non-exclusive backup to the process issuing the 'pg_stop_backup()' call
in its result and must then be put into a file called 'backup_label'
when PG is restored from that backup, so that PG knows that a backup was
done and where to start WAL replay from.
The stopping location is written into the WAL stream when doing a backup
from a primary, but if you're doing a backup from a replica then we use
the latest checkpoint written into pg_control as the stopping point- but
this means that pg_control *must* be copied last when doing a backup
from a standby. Sadly, we don't seem to have gotten around to actually
documenting this fact as yet, which is really a bug that we should fix
and back-patch because it's absolutely critical.
The various backup tools written by folks who have delved into all of
this deeply handle these requirements, thankfully, but it just goes to
show how difficult this all is to get right. :/
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 01:13 Stephen Frost <sfrost@snowman.net>
parent: Edson Carlos Ericksson Richter <richter@simkorp.com.br>
0 siblings, 2 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 01:13 UTC (permalink / raw)
To: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; +Cc: pgsql-general@lists.postgresql.org
Greetings,
* Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> There should be a "catalog" that point where tables are stored in physical
> files (I think, at least, because at some point PostgreSQL need to know from
> where to read the data).
Yes, it's pg_class. Specifically, the relfilenode.
> Based on information from this catalog, would I have a tool (perhaps, a C
> function) that check that data is really there?
You could write such a function, but it wouldn't be able to be general
purpose as a zero-byte file is, in fact, a valid file. You could just
as easily do a 'select 1 from table limit 1;' and make sure that you get
back a successful, single-row, result, if you wish to verify that certain
tables in your database always have at least 1 row.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:03 Melvin Davidson <melvin6925@gmail.com>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Melvin Davidson @ 2017-12-30 02:03 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
>There should be a "catalog" that point where tables are stored in physical
files...
Here is the query that gives you that information.
SELECT c.oid,
n.nspname as schema,
c.relname as table,
(SELECT oid FROM pg_database WHERE datname =
current_database() ) as db_dir,
c.relfilenode as filename
FROM pg_class c
JOIN pg_namespace n ON (n.oid = c.relnamespace)
WHERE relname NOT LIKE 'pg_%'
AND relname NOT LIKE 'information%'
AND relname NOT LIKE 'sql_%'
AND relkind = 'r'
ORDER BY 2, relname;
On Fri, Dec 29, 2017 at 8:13 PM, Stephen Frost <sfrost@snowman.net> wrote:
> Greetings,
>
> * Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> > There should be a "catalog" that point where tables are stored in
> physical
> > files (I think, at least, because at some point PostgreSQL need to know
> from
> > where to read the data).
>
> Yes, it's pg_class. Specifically, the relfilenode.
>
> > Based on information from this catalog, would I have a tool (perhaps, a C
> > function) that check that data is really there?
>
> You could write such a function, but it wouldn't be able to be general
> purpose as a zero-byte file is, in fact, a valid file. You could just
> as easily do a 'select 1 from table limit 1;' and make sure that you get
> back a successful, single-row, result, if you wish to verify that certain
> tables in your database always have at least 1 row.
>
> Thanks!
>
> Stephen
>
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:07 Stephen Frost <sfrost@snowman.net>
parent: Melvin Davidson <melvin6925@gmail.com>
0 siblings, 1 reply; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 02:07 UTC (permalink / raw)
To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Greetings,
* Melvin Davidson (melvin6925@gmail.com) wrote:
> >There should be a "catalog" that point where tables are stored in physical
> files...
>
> Here is the query that gives you that information.
>
> SELECT c.oid,
> n.nspname as schema,
> c.relname as table,
> (SELECT oid FROM pg_database WHERE datname =
> current_database() ) as db_dir,
> c.relfilenode as filename
> FROM pg_class c
> JOIN pg_namespace n ON (n.oid = c.relnamespace)
> WHERE relname NOT LIKE 'pg_%'
> AND relname NOT LIKE 'information%'
> AND relname NOT LIKE 'sql_%'
> AND relkind = 'r'
> ORDER BY 2, relname;
This isn't a terribly good query- it's entirely valid to have 'pg_blah'
and 'informationblah' tables in user schemas. If you'd like to filter
out the catalogs/internal schemas, filter based on schema name instead.
Also, this doesn't actually provide what Edson is asking for. Edson's
asking for a query that uses pg_ls_dir() or some custom function which
will run 'stat' on each file and return the size, according to the OS.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:14 Melvin Davidson <melvin6925@gmail.com>
parent: Stephen Frost <sfrost@snowman.net>
0 siblings, 2 replies; 51+ messages in thread
From: Melvin Davidson @ 2017-12-30 02:14 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
On Fri, Dec 29, 2017 at 9:07 PM, Stephen Frost <sfrost@snowman.net> wrote:
> Greetings,
>
> * Melvin Davidson (melvin6925@gmail.com) wrote:
> > >There should be a "catalog" that point where tables are stored in
> physical
> > files...
> >
> > Here is the query that gives you that information.
> >
> > SELECT c.oid,
> > n.nspname as schema,
> > c.relname as table,
> > (SELECT oid FROM pg_database WHERE datname =
> > current_database() ) as db_dir,
> > c.relfilenode as filename
> > FROM pg_class c
> > JOIN pg_namespace n ON (n.oid = c.relnamespace)
> > WHERE relname NOT LIKE 'pg_%'
> > AND relname NOT LIKE 'information%'
> > AND relname NOT LIKE 'sql_%'
> > AND relkind = 'r'
> > ORDER BY 2, relname;
>
> This isn't a terribly good query- it's entirely valid to have 'pg_blah'
> and 'informationblah' tables in user schemas. If you'd like to filter
> out the catalogs/internal schemas, filter based on schema name instead.
>
> Also, this doesn't actually provide what Edson is asking for. Edson's
> asking for a query that uses pg_ls_dir() or some custom function which
> will run 'stat' on each file and return the size, according to the OS.
>
> Thanks!
>
> Stephen
>
*Edson's original request was for a query that shows the FILENAMEs for the
table.*
*As for "qood" query, that is entirely an opinion. The query WILL show all
files associated*
*with ALL tables. You are free to edit and reconstruct as you choose. *
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:22 Stephen Frost <sfrost@snowman.net>
parent: Melvin Davidson <melvin6925@gmail.com>
1 sibling, 1 reply; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 02:22 UTC (permalink / raw)
To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Melvin,
* Melvin Davidson (melvin6925@gmail.com) wrote:
> On Fri, Dec 29, 2017 at 9:07 PM, Stephen Frost <sfrost@snowman.net> wrote:
> > * Melvin Davidson (melvin6925@gmail.com) wrote:
> > > >There should be a "catalog" that point where tables are stored in
> > physical
> > > files...
> > >
> > > Here is the query that gives you that information.
> > >
> > > SELECT c.oid,
> > > n.nspname as schema,
> > > c.relname as table,
> > > (SELECT oid FROM pg_database WHERE datname =
> > > current_database() ) as db_dir,
> > > c.relfilenode as filename
> > > FROM pg_class c
> > > JOIN pg_namespace n ON (n.oid = c.relnamespace)
> > > WHERE relname NOT LIKE 'pg_%'
> > > AND relname NOT LIKE 'information%'
> > > AND relname NOT LIKE 'sql_%'
> > > AND relkind = 'r'
> > > ORDER BY 2, relname;
> >
> > This isn't a terribly good query- it's entirely valid to have 'pg_blah'
> > and 'informationblah' tables in user schemas. If you'd like to filter
> > out the catalogs/internal schemas, filter based on schema name instead.
> >
> > Also, this doesn't actually provide what Edson is asking for. Edson's
> > asking for a query that uses pg_ls_dir() or some custom function which
> > will run 'stat' on each file and return the size, according to the OS.
>
> *Edson's original request was for a query that shows the FILENAMEs for the
> table.*
As quoted previously, he request included:
---
> Based on information from this catalog, would I have a tool (perhaps, a C
> function) that check that data is really there?
---
Which is asking about having a function to 'stat' the files and check
their length ('data is really there').
> *As for "qood" query, that is entirely an opinion. The query WILL show all
> files associated*
> *with ALL tables. You are free to edit and reconstruct as you choose. *
No, it won't, it'll filter out tables which exist in user schemas that
happen to start with one of the strings that the query includes ('pg_',
'information', and 'sql_').
I encourage you to test it- create a table in the public schema called
'pg_whatever' and see if your query picks it up or not. This isn't a
minor complaint about style, the query is outright wrong.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:31 Melvin Davidson <melvin6925@gmail.com>
parent: Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 51+ messages in thread
From: Melvin Davidson @ 2017-12-30 02:31 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
>the query is outright wrong.
Really? I submit a query to help and all you can do is criticize?
Yes it is legal to create a table that starts with pg_, but any PostgreSQL
developer should
know that is not a good idea.
If you don't like the query, write a better one yourself, but
kindly do not try to degrade the efforts of others.
On Fri, Dec 29, 2017 at 9:22 PM, Stephen Frost <sfrost@snowman.net> wrote:
> Melvin,
>
> * Melvin Davidson (melvin6925@gmail.com) wrote:
> > On Fri, Dec 29, 2017 at 9:07 PM, Stephen Frost <sfrost@snowman.net>
> wrote:
> > > * Melvin Davidson (melvin6925@gmail.com) wrote:
> > > > >There should be a "catalog" that point where tables are stored in
> > > physical
> > > > files...
> > > >
> > > > Here is the query that gives you that information.
> > > >
> > > > SELECT c.oid,
> > > > n.nspname as schema,
> > > > c.relname as table,
> > > > (SELECT oid FROM pg_database WHERE datname =
> > > > current_database() ) as db_dir,
> > > > c.relfilenode as filename
> > > > FROM pg_class c
> > > > JOIN pg_namespace n ON (n.oid = c.relnamespace)
> > > > WHERE relname NOT LIKE 'pg_%'
> > > > AND relname NOT LIKE 'information%'
> > > > AND relname NOT LIKE 'sql_%'
> > > > AND relkind = 'r'
> > > > ORDER BY 2, relname;
> > >
> > > This isn't a terribly good query- it's entirely valid to have 'pg_blah'
> > > and 'informationblah' tables in user schemas. If you'd like to filter
> > > out the catalogs/internal schemas, filter based on schema name instead.
> > >
> > > Also, this doesn't actually provide what Edson is asking for. Edson's
> > > asking for a query that uses pg_ls_dir() or some custom function which
> > > will run 'stat' on each file and return the size, according to the OS.
> >
> > *Edson's original request was for a query that shows the FILENAMEs for
> the
> > table.*
>
> As quoted previously, he request included:
>
> ---
> > Based on information from this catalog, would I have a tool (perhaps, a C
> > function) that check that data is really there?
> ---
>
> Which is asking about having a function to 'stat' the files and check
> their length ('data is really there').
>
> > *As for "qood" query, that is entirely an opinion. The query WILL show
> all
> > files associated*
> > *with ALL tables. You are free to edit and reconstruct as you choose. *
>
> No, it won't, it'll filter out tables which exist in user schemas that
> happen to start with one of the strings that the query includes ('pg_',
> 'information', and 'sql_').
>
> I encourage you to test it- create a table in the public schema called
> 'pg_whatever' and see if your query picks it up or not. This isn't a
> minor complaint about style, the query is outright wrong.
>
> Thanks!
>
> Stephen
>
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:35 Steve Atkins <steve@blighty.com>
parent: Melvin Davidson <melvin6925@gmail.com>
1 sibling, 0 replies; 51+ messages in thread
From: Steve Atkins @ 2017-12-30 02:35 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
> On Dec 29, 2017, at 6:14 PM, Melvin Davidson <melvin6925@gmail.com> wrote:
>
> Edson's original request was for a query that shows the FILENAMEs for the table.
Which the query you provide does not do.
> As for "qood" query, that is entirely an opinion.
But a well informed one. Your query may work well enough for you, but when you're
suggesting others rely on it you should expect more informed users to point out
that it has some critical flaws - especially ones that might not be obvious to new
users - lest others naively rely on it.
> The query WILL show all files associated
> with ALL tables.
No, it won't. You're filtering out a bunch of things via the name of the table. That
doesn't do the right thing. You're heading in the right direction, but the query you
gave gets some things badly wrong.
Listen to the criticism from others and you'll improve your knowledge and skills.
There's absolutely nothing wrong with posting information that's not quite right,
nor with getting feedback from others on what's wrong with it. Copping an attitude
in response to that feedback is where things go downhill.
Cheers,
Steve
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 02:51 Stephen Frost <sfrost@snowman.net>
parent: Melvin Davidson <melvin6925@gmail.com>
0 siblings, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 02:51 UTC (permalink / raw)
To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Melvin,
* Melvin Davidson (melvin6925@gmail.com) wrote:
> >the query is outright wrong.
> Really? I submit a query to help and all you can do is criticize?
I explained exactly what was wrong with it, and how to write a proper
query to answer this question, with the thought that you'd appreciate
the help and would create a proper query. I'm a bit mystified as to why
you seem to be unhappy with this.
> Yes it is legal to create a table that starts with pg_, but any PostgreSQL
> developer should
> know that is not a good idea.
That's really not an excuse for providing an incorrect query when you
could simply adjust the query to properly filter on nspname instead of
relname, further, while perhaps 'pg_' instead a good prefix to use in a
PG database (note that other databases, of course, wouldn't have any
issue using such a prefix), using a table name starting with
'information' or 'sql_' isn't nearly as questionable, yet your query
also filtered those out.
> If you don't like the query, write a better one yourself, but
> kindly do not try to degrade the efforts of others.
No, pointing out that a query is wrong and doesn't acurately answer the
question is something which should be done, just as someone should call
out a bug in code that's been submitted for inclusion in PostgreSQL.
I've tried to be kind and point out exactly what's wrong, along with
encouraging words of how to adjust the query to be correct. Having
misleading and incorrect information in our list archives isn't being
helpful- those archives are preserved for more-or-less forever, end up
being returned in google search results, and have caused confusion and
even data loss in multiple cases that I'm personally aware of (thank you
to pg_resetxlog...). We should all try to work to minimize that, and to
correct it when necessary as best we can through responses.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 05:09 Jan Wieck <jan@wi3ck.info>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Jan Wieck @ 2017-12-30 05:09 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
This whole discussion left out the critical point of
*how on earth did that file end up having zero bytes?*
There is the possibility that this is due to a bug in PostgreSQL. But over
the 20+ years I've been using and hacking it, that has never happened.
OP never told us what type of OS, hardware and specifically storage
subsystem that "slave" was running on. Filesystems zapping files to zero
after a catastrophic IO failure (no longer throwing them into lost+found)
isn't unheard of.
Regards, Jan
On Fri, Dec 29, 2017 at 8:13 PM, Stephen Frost <sfrost@snowman.net> wrote:
> Greetings,
>
> * Edson Carlos Ericksson Richter (richter@simkorp.com.br) wrote:
> > There should be a "catalog" that point where tables are stored in
> physical
> > files (I think, at least, because at some point PostgreSQL need to know
> from
> > where to read the data).
>
> Yes, it's pg_class. Specifically, the relfilenode.
>
> > Based on information from this catalog, would I have a tool (perhaps, a C
> > function) that check that data is really there?
>
> You could write such a function, but it wouldn't be able to be general
> purpose as a zero-byte file is, in fact, a valid file. You could just
> as easily do a 'select 1 from table limit 1;' and make sure that you get
> back a successful, single-row, result, if you wish to verify that certain
> tables in your database always have at least 1 row.
>
> Thanks!
>
> Stephen
>
--
Jan Wieck
Senior Postgres Architect
http://pgblog.wi3ck.info
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 11:25 Alban Hertroys <haramrae@gmail.com>
parent: Jan Wieck <jan@wi3ck.info>
0 siblings, 1 reply; 51+ messages in thread
From: Alban Hertroys @ 2017-12-30 11:25 UTC (permalink / raw)
To: Jan Wieck <jan@wi3ck.info>; +Cc: Stephen Frost <sfrost@snowman.net>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
> On 30 Dec 2017, at 6:09, Jan Wieck <jan@wi3ck.info> wrote:
>
> This whole discussion left out the critical point of
>
> how on earth did that file end up having zero bytes?
>
> There is the possibility that this is due to a bug in PostgreSQL. But over the 20+ years I've been using and hacking it, that has never happened.
>
> OP never told us what type of OS, hardware and specifically storage subsystem that "slave" was running on. Filesystems zapping files to zero after a catastrophic IO failure (no longer throwing them into lost+found) isn't unheard of.
If this is indeed a case of a corrupt database, then it's possible that we're looking at a system that claims to have the disk cache flushed when it hasn't yet done that.
It gets even more fun if there are multiple table-spaces in use with different behaviour in "whatever is causing this" (fsync, file system zappery, etc.); the WAL log can get out of synch with the table files in that case. The WAL would reflect a situation where more has been flushed to the respective files than is actually the case - data got lost.
But of course it's also entirely possible that these empty files are not in fact a problem, as suggested up-thread.
No reason to panic - yet.
In fact, I don't see it mentioned explicitly anywhere, but are we actually looking at a problem?
The standby server started up just fine, from what I'm reading. Is there any evidence of corruption?
So far, the database has been labeled corrupt by Edson because a base file was 0 bytes, but that's apparently not a definitive indication of corruption.
What would be definitive is if querying certain relations causes errors or does give results that were never in that database. I do think that those 0 byte files are a good starting point, by querying the relations that those belong to (if any). Otherwise we may be searching for a needle in a haystack that doesn't necessarily contain one.
I do realise that not finding any evidence of corruption does not necessarily mean there is none.
I'm not convinced by the argument that a CRC check of a 0 byte file on a standby would not detect corruption. At the least, the CRC would be different or we would be left with a CRC on the master that we can't match any CRC's on the slave to if the file is larger on the master.
If CRC's can be relied on to detect corruption (which they were designed to do), then that answers Edson's question.
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 15:27 Stephen Frost <sfrost@snowman.net>
parent: Alban Hertroys <haramrae@gmail.com>
0 siblings, 2 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 15:27 UTC (permalink / raw)
To: Alban Hertroys <haramrae@gmail.com>; +Cc: Jan Wieck <jan@wi3ck.info>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Greetings Alban,
* Alban Hertroys (haramrae@gmail.com) wrote:
> In fact, I don't see it mentioned explicitly anywhere, but are we actually looking at a problem?
From the discussion in the google barman group, it's clear that the file
shouldn't be zero bytes in this specific case.
> I'm not convinced by the argument that a CRC check of a 0 byte file on a standby would not detect corruption. At the least, the CRC would be different or we would be left with a CRC on the master that we can't match any CRC's on the slave to if the file is larger on the master.
As discussed, files on the primary can be different at a byte level from
those on replicas and still be perfectly valid and correct, for a
variety of reasons from hint bit differences to differences due to the
replica not being at exactly the same point as the primary.
> If CRC's can be relied on to detect corruption (which they were designed to do), then that answers Edson's question.
The checksums included in PG are page-level and therefore there simply
isn't one to look at if the file is zero bytes.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 16:19 Melvin Davidson <melvin6925@gmail.com>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Melvin Davidson @ 2017-12-30 16:19 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Alban Hertroys <haramrae@gmail.com>; Jan Wieck <jan@wi3ck.info>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
On Sat, Dec 30, 2017 at 10:27 AM, Stephen Frost <sfrost@snowman.net> wrote:
> Greetings Alban,
>
> * Alban Hertroys (haramrae@gmail.com) wrote:
> > In fact, I don't see it mentioned explicitly anywhere, but are we
> actually looking at a problem?
>
> From the discussion in the google barman group, it's clear that the file
> shouldn't be zero bytes in this specific case.
>
> > I'm not convinced by the argument that a CRC check of a 0 byte file on a
> standby would not detect corruption. At the least, the CRC would be
> different or we would be left with a CRC on the master that we can't match
> any CRC's on the slave to if the file is larger on the master.
>
> As discussed, files on the primary can be different at a byte level from
> those on replicas and still be perfectly valid and correct, for a
> variety of reasons from hint bit differences to differences due to the
> replica not being at exactly the same point as the primary.
>
> > If CRC's can be relied on to detect corruption (which they were designed
> to do), then that answers Edson's question.
>
> The checksums included in PG are page-level and therefore there simply
> isn't one to look at if the file is zero bytes.
>
> Thanks!
>
> Stephen
>
*Steve Atkins and Stephen Frost,You both remind me of gawkers at a
disaster, pointing out "mistakes" thatfirst responders are making, but
doing nothing yourselves to help.My query works as designed and has done so
for two years. It shows the filenames for schemas and tables in the
database. If you don't like it,TOO BAD! Shame on you! Use your brains and
write your own query. Nuff said, I shall reply no more. *
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-30 22:06 Stephen Frost <sfrost@snowman.net>
parent: Melvin Davidson <melvin6925@gmail.com>
0 siblings, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-30 22:06 UTC (permalink / raw)
To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Alban Hertroys <haramrae@gmail.com>; Jan Wieck <jan@wi3ck.info>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Greetings,
* Melvin Davidson (melvin6925@gmail.com) wrote:
> My query works as designed and has done so
> for two years. It shows the filenames for schemas and tables in the
> database.
I'm glad to hear that it works in your specific use-case.
Unfortunately, it doesn't work in the general case and therefore isn't a
good example. A proper query to return the filename for each user table
in the current database is:
SELECT
quote_ident(nsp.nspname) || '.' || quote_ident(c.relname),
s.setting || '/base/' || db.oid || '/' || c.relfilenode
FROM
pg_settings s
JOIN pg_database db on (s.name = 'data_directory')
JOIN pg_class c on (datname = current_database())
JOIN pg_namespace nsp on (c.relnamespace = nsp.oid)
WHERE
relfilenode <> 0
AND nsp.nspname !~ '^pg_'
AND nsp.nspname <> 'information_schema';
Note that, as discussed earlier in this thread, this doesn't actually
answer what Edson was asking for. Here's the query that would answer
his original request:
SELECT
quote_ident(nsp.nspname) || '.' || quote_ident(c.relname),
s.setting || '/base/' || db.oid || '/' || c.relfilenode,
(pg_stat_file(s.setting || '/base/' || db.oid || '/' || c.relfilenode)).size as size
FROM
pg_settings s
JOIN pg_database db on (s.name = 'data_directory')
JOIN pg_class c on (datname = current_database())
JOIN pg_namespace nsp on (c.relnamespace = nsp.oid)
WHERE
relfilenode <> 0
AND nsp.nspname !~ '^pg_'
AND nsp.nspname <> 'information_schema';
Technically speaking, while these queries are correct for PG10, in prior
versions of PostgreSQL it's possible to have user schemas that begin
with 'pg_' and therefore the filtering in the WHERE clause would have to
be more specific.
Note that both of these need to be run as a superuser in older versions
of PG. In PostgreSQL 10, a user could be GRANT'd 'pg_read_all_settings'
and be able to run the first query. We don't currently support being
able to GRANT a non-superuser the ability to run pg_stat_file(), but
that will likely be coming in PG 11.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-31 03:10 Jan Wieck <jan@wi3ck.info>
parent: Stephen Frost <sfrost@snowman.net>
1 sibling, 1 reply; 51+ messages in thread
From: Jan Wieck @ 2017-12-31 03:10 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Alban Hertroys <haramrae@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
On Sat, Dec 30, 2017 at 10:27 AM, Stephen Frost <sfrost@snowman.net> wrote:
>
> The checksums included in PG are page-level and therefore there simply
> isn't one to look at if the file is zero bytes.
>
And even if the file wasn't zero bytes you can't tell from the per page
CRCs if you have all the pages you should have. You could have extra pages
that aren't supposed to be there or missing some (or any mix of the two).
A per page CRC is useless for those cases.
Regards, Jan
>
> Thanks!
>
> Stephen
>
--
Jan Wieck
Senior Postgres Architect
http://pgblog.wi3ck.info
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Does PostgreSQL check database integrity at startup?
@ 2017-12-31 16:33 Stephen Frost <sfrost@snowman.net>
parent: Jan Wieck <jan@wi3ck.info>
0 siblings, 0 replies; 51+ messages in thread
From: Stephen Frost @ 2017-12-31 16:33 UTC (permalink / raw)
To: Jan Wieck <jan@wi3ck.info>; +Cc: Alban Hertroys <haramrae@gmail.com>; Edson Carlos Ericksson Richter <richter@simkorp.com.br>; pgsql-general@lists.postgresql.org
Jan, all,
* Jan Wieck (jan@wi3ck.info) wrote:
> On Sat, Dec 30, 2017 at 10:27 AM, Stephen Frost <sfrost@snowman.net> wrote:
> > The checksums included in PG are page-level and therefore there simply
> > isn't one to look at if the file is zero bytes.
>
> And even if the file wasn't zero bytes you can't tell from the per page
> CRCs if you have all the pages you should have. You could have extra pages
> that aren't supposed to be there or missing some (or any mix of the two).
> A per page CRC is useless for those cases.
Right, which is why it makes sense to have whole-file checksums when
doing things like backups, when you're already reading all of the file
and can grab a checksum in stream, to detect if anything bad happens
after the backup has compeleted to the file that's been backed up.
It's unclear if that would have helped here or not since we don't know
when the file ended up being zero'd out, as I understand it.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 51+ messages in thread
end of thread, other threads:[~2017-12-31 16:33 UTC | newest]
Thread overview: 51+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-26 12:52 Does PostgreSQL check database integrity at startup? Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-26 13:44 ` Martin Marques <martin.marques@2ndquadrant.com>
2017-12-26 14:25 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-12-26 15:37 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-26 15:39 ` Peter Geoghegan <pg@bowt.ie>
2017-12-26 15:40 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-12-26 15:50 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-26 15:57 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-12-26 17:06 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-26 21:42 ` David Steele <david@pgmasters.net>
2017-12-26 21:58 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2017-12-26 22:11 ` rob stone <floriparob@gmail.com>
2017-12-27 12:31 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-27 23:03 ` David Steele <david@pgmasters.net>
2017-12-26 17:13 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2017-12-26 17:46 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-26 22:42 ` Martin Marques <martin.marques@2ndquadrant.com>
2017-12-27 12:25 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-27 14:49 ` Stephen Frost <sfrost@snowman.net>
2017-12-27 16:47 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2017-12-27 17:02 ` Stephen Frost <sfrost@snowman.net>
2017-12-27 17:30 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-27 21:33 ` Stephen Frost <sfrost@snowman.net>
2017-12-27 21:52 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2017-12-28 12:16 ` Stephen Frost <sfrost@snowman.net>
2017-12-28 17:46 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-28 18:06 ` Brent Wood <pcreso@yahoo.com>
2017-12-28 18:26 ` Stephen Frost <sfrost@snowman.net>
2017-12-28 18:35 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-30 00:14 ` Jan Wieck <jan@wi3ck.info>
2017-12-30 01:03 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-30 01:13 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 02:03 ` Melvin Davidson <melvin6925@gmail.com>
2017-12-30 02:07 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 02:14 ` Melvin Davidson <melvin6925@gmail.com>
2017-12-30 02:22 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 02:31 ` Melvin Davidson <melvin6925@gmail.com>
2017-12-30 02:51 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 02:35 ` Steve Atkins <steve@blighty.com>
2017-12-30 05:09 ` Jan Wieck <jan@wi3ck.info>
2017-12-30 11:25 ` Alban Hertroys <haramrae@gmail.com>
2017-12-30 15:27 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 16:19 ` Melvin Davidson <melvin6925@gmail.com>
2017-12-30 22:06 ` Stephen Frost <sfrost@snowman.net>
2017-12-31 03:10 ` Jan Wieck <jan@wi3ck.info>
2017-12-31 16:33 ` Stephen Frost <sfrost@snowman.net>
2017-12-30 01:09 ` Stephen Frost <sfrost@snowman.net>
2017-12-28 18:33 ` Edson Carlos Ericksson Richter <richter@simkorp.com.br>
2017-12-28 18:16 ` Stephen Frost <sfrost@snowman.net>
2017-12-27 20:11 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2017-12-27 20:24 ` Stephen Frost <sfrost@snowman.net>
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