Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUca8-00080E-DD for pgsql-general@arkaria.postgresql.org; Thu, 28 Dec 2017 18:07:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUca7-0000pg-PF for pgsql-general@arkaria.postgresql.org; Thu, 28 Dec 2017 18:07:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eUca7-0000oW-B9 for pgsql-general@lists.postgresql.org; Thu, 28 Dec 2017 18:07:03 +0000 Received: from sonic317-40.consmr.mail.ne1.yahoo.com ([66.163.184.51]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eUca2-0003xu-MB for pgsql-general@lists.postgresql.org; Thu, 28 Dec 2017 18:07:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1514484414; bh=9zfPkebWgGMnDsQDz4rQr0Io3tAAp6Z33GF+0quoyBY=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=ryz/81ljZ4ogf+9Vk+tfAeiRS5OhkCL9KeBF/wrdIQbCTjRiFP5foVmr+eOLCFFbtqMv/dC5DRCFeLsM4ZIUbm2ksD6ZVv4ar69tCmEmt9g+ZvijHg3R3VqP/cIsM+00pIkNSg/H2MYDyjKb86AnOwAzonXgEhcO3NOZlgOnUIGkGT0ETHhUzYv2TvlMSL97uV2d5wIUfXo3DUoM0YxgbwP7eXJ89Nztoi3Uxqvu7x5O6qEGKLQHhdPFxVekjNTC898nOc0Xzj0nWBserCceJ7w1D7raw5DgEvFGwb7lbvNTrKGF5QwsIL+hN/xQFY7w/RP+OmCiyv1VKY3gy+BtXA== X-YMail-OSG: qBgeNa4VM1kXt244qcHZblkNYG6NRnv4_yiITjFixhJG9.w01N1rPb26wgi_Nm9 Mxa6lZzGOVDV0oIW8Wt215hxU3sFX3YlE0qN84XksHjg80UXysgrRnSbxcSn7a0.uTzWZy6zonGb RoZIiflMEXlyAIMhMs8BPyQ35T6p.kQMeU8URMMcjJLz4HciEkf5pOKP0UPmUJs7IxV135lCr1AR xKvyxO.DW1gx7jfkKLBx1pczUjJDNnS5Lm.qon0BG5p0e8sGjhJMtKwIu_SMhowN8Bv88MzNC2JR f9bS9SZgGi6k57wnsQmwxib2SxID60opcTPwWJRKPuYc7QR9.xryzkJsYNs99.noKwzw_ayvENdB 6FEGke2b6pi.2o5G27kaqlJECs6tyndy.ekfS1UIedttStU9CDMk4gs9k_y4ltcpdBgYnWT8szli BqJ46eI3HohMlK6RAAzhlskZUMA4WOxFWfGgMtsc0qnDx07W64MudYfTuuSvHaSelMAjotZzrzUu j6CXIpt.uQ5HKexcMoe5jygj0 Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Thu, 28 Dec 2017 18:06:54 +0000 Date: Thu, 28 Dec 2017 18:06:48 +0000 (UTC) From: Brent Wood Reply-To: Brent Wood To: Edson Carlos Ericksson Richter , "pgsql-general@lists.postgresql.org" Message-ID: <743808611.5608368.1514484408822@mail.yahoo.com> In-Reply-To: <42cda197-fead-a7e5-a7e2-750d98bc4eb2@simkorp.com.br> References: <20171227213314.GY4628@tamriel.snowman.net> <20171227215204.nucxo7b2ssmyznip@alvherre.pgsql> <20171228121651.GZ4628@tamriel.snowman.net> <42cda197-fead-a7e5-a7e2-750d98bc4eb2@simkorp.com.br> Subject: Re: Does PostgreSQL check database integrity at startup? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5608367_501143289.1514484408816" X-Mailer: WebService/1.1.11051 YahooMailNeo Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0 Content-Length: 14645 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_5608367_501143289.1514484408816 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Some thoughts.... A tool to calculate a checksum of sorts based on the table (file) content w= ould 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.=20 Something like these could be adapted to compare database content by filesy= stem 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-hashor 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 ne= cessarily identical (or is it?) event this may be problematic. Perhaps a ch= ecksum based on the result of a query output ordered by primary key could w= ork? Brent Wood From: Edson Carlos Ericksson Richter To: pgsql-general@lists.postgresql.org=20 Sent: Friday, December 29, 2017 6:47 AM Subject: Re: Does PostgreSQL check database integrity at startup? =20 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.=C2=A0 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...?=C2=A0 That sounds like yo= u're >>> describing a WAL file, but you should be archiving your WAL files durin= g >>> 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 corrup= t. >>> 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.=C2=A0 The problem doesn't >> originate in the backup -- it originates in the standby, from where the >> backup is taken.=C2=A0 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."=C2=A0 It's not clear what t= hat > 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.=C2=A0 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.=C2=A0 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.=C2=A0 I'd also suggest looking f= or > other file size mismatches between the primary and the replica. > > Thanks! > > Stephen The table was never unlogged. From very beginning, it was always logged.=20 I've dozens of databases with exactly same setup - and right now, I'm=20 rebuilding the slave server. Instead of investigating something probably=20 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=20 synchronized with master (current behavior) 3) Before getting into "accept read only queries", check if all base=20 files have same size as master server (new behavior). In case something=20 is different, throw an error and stop database startup? 4) Then start "accept read only queries" (current behavior) ??? Thanks, Edson =20 ------=_Part_5608367_501143289.1514484408816 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Some thoughts....

A tool to calculate a c= hecksum of sorts based on the table (file) content would provide a better s= urety of duplication than simply checking file size - like differently vacu= umed 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 th= an db queries. Following tablespaces, etc as well.

http://www.commandlinefu.com/commands/view= /3555/find-duplicate-files-based-on-size-first-then-md5-hash
or other similar tools=

Yes, there is some overhead, es= pecially 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 n= ot 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 co= uld work?

<= /div>
Brent Wood

=
From: Edson Carlos= Ericksson Richter <richter@simkorp.com.br>
To: pgsql-general@lists.postgr= esql.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 F= rost escreveu:
> Alvaro,
>
> * Alvaro Herrera (alvherre@alvh.= no-ip.org) wrote:
>> For context: this was firs= t reported in the Barman forum here:
>> https://groups.google.com/forum/#!msg/pgbarm= an/3aXWpaKWRFI/weUIZxspDAAJ
>> They are using B= arman for the backups.
> Ahhhh, I see.  I wasn't = aware of that history.
>
>> St= ephen 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
>>&g= t;> all.
>>> How do you know it should be 16M= b 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_xlo= g/pg_wal..
>> It's not a WAL file -- it's a file ba= cking 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
&= gt;>> 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.
>> E= dson'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."&nb= sp; It's not clear what that
> failure was but I agree= it doesn't appear related to the backup tool
> (the c= omment there is "I'm using rsync"), or, really, PostgreSQL at all
> (a failure during the build of the replica isn't something w= e're
> necessairly going to pick up on..).
>
> As discussed on this thread, zero-byte f= iles are entirely valid to
> appear in the PostgreSQL = data directory.
>
> To try and di= g 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 th= e file on the primary
> appeared to be modified well a= fter 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 hap= pens
> with replication.  One thing I wonder is i= f this table used to be
> unlogged and it was later tu= rned 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.<= br clear=3D"none">>
> Thanks!
>= ;
> Stephen
The table was never unlo= gged. From very beginning, it was always logged.
I've do= zens of databases with exactly same setup - and right now, I'm
rebuilding the slave server. Instead of investigating something prob= ably
I will not find the cause, I would like to have a a= lert for the future.

Would be possible= to include in future versions:
1) After start standby, s= tandby run all WAL files until it is
synchronized with m= aster (current behavior)
3) Before getting into "accept r= ead only queries", check if all base
files have same siz= e as master server (new behavior). In case something
is = different, throw an error and stop database startup?
4) T= hen start "accept read only queries" (current behavior)
?= ??

Thanks,


Edson



------=_Part_5608367_501143289.1514484408816--