Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUY6f-00062s-R2 for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:24:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUY6e-0007Sw-FL for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:24:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUXsX-0006gr-75 for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:10:17 +0000 Received: from mx1.islonline.com ([91.217.255.130]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUXsU-0005k6-8j for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:10:15 +0000 Received: from spamtitan.islonline.com (unknown [10.9.1.102]) by mx1.islonline.com (Postfix) with ESMTP id B48731FC3B for ; Wed, 5 Dec 2018 15:10:12 +0100 (CET) X-Virus-Scanned: by SpamTitan at islonline.com Received: from [172.16.118.118] (5-255-217-91.xlab.si [91.217.255.5]) by zimbra.islonline.com (Postfix) with ESMTPSA id A90AE22DC7B0 for ; Wed, 5 Dec 2018 14:10:11 +0000 (UTC) To: pgsql-general@lists.postgresql.org From: Dejan Petrovic Subject: Database corruption in cascaded replica, "pg_xact/003A" doesn't exist, reading as zeroes" Message-ID: Date: Wed, 5 Dec 2018 15:10:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I believe this is a result of my "broken" procedure for setting up a=20 cascaded replica. I would love to know where the issue is. This is a report of a database corruption which was detected after=20 promoting a replica server to a master server. We suspect the actual=20 corruption occurred during replication of a two-level cascaded replica,=20 however it was not detected until after it was promoted to master server=20 when pg_dump and pg_restore failed. After re-checking postgresql logs on=20 the corrupted node, we found this log line, which was the only indicator=20 of a possible issue, but was overlooked: "2018-07-25 13:14:42 UTCLOG:=20 file "pg_xact/003A" doesn't exist, reading as zeroes". After extensive investigation, we detected three different cases of data=20 corruption: 1.)Issue with pg_toast - happens during pg_dump or when row with=20 corrupted data is selected "pg_dump: Dumping the contents of table failed: PQgetResult() failed. pg_dump: Error message from server: ERROR: missing chunk number 2 for=20 toast value 86123528 in pg_toast_41291242" 2.) Issue with uncommitted transactions, occurs when running VACUUM or=20 pg_dump/pg_restore: "ERROR: uncommitted xmin 60817551 from before xid cutoff 61487222 needs=20 to be frozen SQL state: XX001" 3.) 2 duplicated rows in different tables, violated PK unique=20 constraint, occurs during pg_restore This is how we fixed the three issues: 1.) Using bisection and SELECT, we found the row/column with corrupted=20 data. We nulled the corrupt column and deleted the row (it was not=20 critical, had no FKs) 2.) We ran VACUUM on all tables to check where this issue occured and=20 updated all rows between reported xmin and xid cutoff with same data -=20 this generated a new xmin on the broken rows, which fixed the issue. 3.) We removed the duplicated rows in a transaction, disabled all=20 triggers before and enabled them right after 4.) Our final step is to do a full dump and restore on master DB so that=20 the DB is rebuilt This is the procedure we used to replicate the cascaded replica (master=20 -> replica -> replica) Notes: Machines are running on Centos 7, Postgresql 10.2 DB-1 =3D master DB-2 =3D replica of DB-1 DB-3 =3D replica of DB-2 --------------> DB-3 (new cascaded replica) systemctl disable postgresql-10 systemctl stop postgresql-10 --------------> DB-1 (master) psql -U postgres select pg_start_backup('clone',true); <------------- DB-3 (cascaded replica) rsync -azv -e --delete DB-2:/isl/pgsql10/data /isl/pgsql10/ --exclude=20 pg_wal --exclude postgresql.pid assert rsync finished vi recovery.conf =C2=A0=C2=A0=C2=A0 standby_mode =3D 'on' =C2=A0=C2=A0=C2=A0 primary_conninfo =3D 'host=3DDB-2' =C2=A0=C2=A0=C2=A0 recovery_target_timeline =3D 'latest' -------------> DB-1 select pg_stop_backup(); <------------- DB-3 rsync -azv -e --delete DB-2:/isl/pgsql10/data/pg_wal /isl/pgsql10/data/ systemctl start postgresql-10 systemctl enable postgresql-10 tail log file Any comments regarding the cascaded replication procedure or database=20 corruption detection or resolution are welcome. Best regards, Dejan Petrovic ISL Online