Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6H2Y-0001m1-EF for pgsql-admin@arkaria.postgresql.org; Wed, 21 Jul 2021 18:33:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6H2X-0005AT-DX for pgsql-admin@arkaria.postgresql.org; Wed, 21 Jul 2021 18:33:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6H2W-0005AK-Ql for pgsql-admin@lists.postgresql.org; Wed, 21 Jul 2021 18:33:53 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m6H2S-0001QD-JM for pgsql-admin@lists.postgresql.org; Wed, 21 Jul 2021 18:33:51 +0000 Received: by mail-oi1-x235.google.com with SMTP id y66so3851170oie.7 for ; Wed, 21 Jul 2021 11:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=lJVHFubpsQ2bs2y6dFjhzgSX0Id8rTwO4YfQSj/kUtY=; b=o5UeTQ6alQyBdzoS7IcKVoWGgOrqccij35ZARuBGpN0BCX2tdJQOJu2/F7IQbL5H/m WsWN0jxPkzM7DX7noeMQWIwMqet1u4WOq5wTg10V5Njm9QUip6YhZK0jG9sX+/yuyxvf CEweuIXYSzsJAds+TqUlVYip70ih+jpngKszztb4cJ9wwEAP+H8ywSRWs413DxGBlth2 PSvFFMpAE2tZ9V3ybP7gY7lM+SJNxVG2NQV2YFdrXvj4tMpG7GkgueH5Cnu2Qg/BR6FH wN41onfT6KiBq5ImHrwRoS4PnQD1q2tvYN4fFHjtC6wuMqxI+riymRXAvzrrteRuTbmb 92Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=lJVHFubpsQ2bs2y6dFjhzgSX0Id8rTwO4YfQSj/kUtY=; b=fYs80Vb8v3QWy6GKWydKbjs+dfDdOWPdtkVUvwihciG3AmW0zbz9RuZs2SChoz6zw6 8UW7ksPl+JJXRzZ+PRl1dJkJJgaqvdPvQ2MmiCIOMCPXz9iknquIOCYG4S8y1wo2G6zD benXZgKxBIrkZd5IbO/3ztGAyAXgLhQdTuj55X6tgLtFaGNNfsAkGxQtZeOjJlFs4Ggh GjewZnTVHDfnc9oRpb/1MWc6rt0Xd0fJtC6XjKUVd1qGdX+sw87J8GBvNcT3VYqoRbuy UhuM73SecHPZiC0AugglxQ5JczibLaydlzltgiKQ8yYxywwAfyQw7oPxFL+zvG0nrqMw 22rg== X-Gm-Message-State: AOAM530nN7wkGlJr/DWnPrKxzPT6s0dpjbwKvaIdHRBTqLqUlRMWG7lS ywmiuHx2Y2CnbgiXZPHfSFlKB8g72GI= X-Google-Smtp-Source: ABdhPJy6HQITnNUZFTWk7QMRNwLUwzz0iSnAYiDHdzBmwR5W+ZK4nhGULeQY7iUU+1hoOuy7aO+dtA== X-Received: by 2002:aca:5f8a:: with SMTP id t132mr3521601oib.72.1626892427556; Wed, 21 Jul 2021 11:33:47 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id f2sm4983230oij.45.2021.07.21.11.33.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Jul 2021 11:33:47 -0700 (PDT) Subject: Re: Data corruption To: pgsql-admin@lists.postgresql.org References: From: Ron Message-ID: <608090c5-0972-9fee-fb6f-9462ee3fc941@gmail.com> Date: Wed, 21 Jul 2021 13:33:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E763DE98E7620E029883FE65" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------E763DE98E7620E029883FE65 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I've zeroes out Pg 8.4 pc_clog files using dd (instructions are out there on the web) without any visible negative effect. Naturally, YMMV. On 7/21/21 11:14 AM, Konrad Garus wrote: > Hello, > > we have a database that apparently got corrupted in a crash a few months > ago, long enough that there is no "good" backup. > > There are at least two tables occasionally emitting errors like this: > > ERROR: invalid page header in block 39684 of relation base/12926/32397 > while performing SQL query: SQL DML: insert into foo (a, b, c) values (?, > ?, ?) | PARAMETERS: foo, bar, baz: org.postgresql.util.PSQLException: > ERROR: invalid page header in block 39684 of relation base/12926/32397 > > The files in question (e.g. 32397) correspond to the table itself, not an > index. The larger of these tables has two files (32397 & 32397.1), almost > 2G total. > > To make things worse, vacuum ends with: > > ERROR:  could not access status of transaction 2828785257 > DETAIL:  Could not open file "pg_clog/0A89": No such file or directory. > > That file is nowhere to be found. > > When I do this: > > set zero_damaged_pages = on; > select count(*) from foo > > It shows 3 errors like this: > > WARNING:  invalid page header in block 78550 of relation base/12926/31642; > zeroing out page > WARNING:  invalid page header in block 78551 of relation base/12926/31642; > zeroing out page > WARNING:  invalid page header in block 78552 of relation base/12926/31642; > zeroing out page > > One idea I found is to generate a zero file for the missing clog, set > zero_damaged_pages=on, then vacuum or recreate the table. Looks like it > might work, but I'm trying to understand the implications. > > 1. When I generate a zero clog file like this, what impact will it have on > everything? Can it break anything else in the database, introduce some > kind of inconsistency with other (correctly committed) table data? > > 2. How can I gauge how much actual data (e.g. how many rows) will be lost > by doing this (zero clog file + vacuum/recreate table)? > > 3. Is there some place I can look to reliably tell how many rows the table > should have, so I can compare to how many I can read after setting > zero_damaged_pages? > > 4. Is there any way at all to recover/repair the corrupted data at this point? > > -- > Konrad Garus -- Angular momentum makes the world go 'round. --------------E763DE98E7620E029883FE65 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit I've zeroes out Pg 8.4 pc_clog files using dd (instructions are out there on the web) without any visible negative effect.

Naturally, YMMV.

On 7/21/21 11:14 AM, Konrad Garus wrote:
Hello,

we have a database that apparently got corrupted in a crash a few months ago, long enough that there is no "good" backup.

There are at least two tables occasionally emitting errors like this:

ERROR: invalid page header in block 39684 of relation base/12926/32397 while performing SQL query: SQL DML: insert into foo (a, b, c) values (?, ?, ?) | PARAMETERS: foo, bar, baz: org.postgresql.util.PSQLException: ERROR: invalid page header in block 39684 of relation base/12926/32397

The files in question (e.g. 32397) correspond to the table itself, not an index. The larger of these tables has two files (32397 & 32397.1), almost 2G total.

To make things worse, vacuum ends with:

ERROR:  could not access status of transaction 2828785257
DETAIL:  Could not open file "pg_clog/0A89": No such file or directory.

That file is nowhere to be found.

When I do this:

set zero_damaged_pages = on;
select count(*) from foo

It shows 3 errors like this:

WARNING:  invalid page header in block 78550 of relation base/12926/31642; zeroing out page
WARNING:  invalid page header in block 78551 of relation base/12926/31642; zeroing out page
WARNING:  invalid page header in block 78552 of relation base/12926/31642; zeroing out page

One idea I found is to generate a zero file for the missing clog, set zero_damaged_pages=on, then vacuum or recreate the table. Looks like it might work, but I'm trying to understand the implications.

1. When I generate a zero clog file like this, what impact will it have on everything? Can it break anything else in the database, introduce some kind of inconsistency with other (correctly committed) table data?

2. How can I gauge how much actual data (e.g. how many rows) will be lost by doing this (zero clog file + vacuum/recreate table)?

3. Is there some place I can look to reliably tell how many rows the table should have, so I can compare to how many I can read after setting zero_damaged_pages?

4. Is there any way at all to recover/repair the corrupted data at this point?

--
Konrad Garus

--
Angular momentum makes the world go 'round.
--------------E763DE98E7620E029883FE65--