Re: Silent data corruption in PostgreSQL 17 - how to detect it proactively?

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pawel Kudzia <kudzia(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Silent data corruption in PostgreSQL 17 - how to detect it proactively?
Date: 2025-09-14 13:40:08
Message-ID: 696bc97940384f72eca0d410bc069061902e43c9.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 2025-09-14 at 14:47 +0200, Pawel Kudzia wrote:
> On Sun, Sep 14, 2025 at 12:35 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
> > On Sun, 2025-09-14 at 10:30 +0200, Pawel Kudzia wrote:
> > > I've hit a silent data corruption for TOAST data - leading to some
> > > infinite loop when accessing bytea column for very particular row. I
> > > did not suffer data loss - data from streaming replica was fine, I've
> > > used it to rebuild the main server.
> > >
> > > I'm wondering if there's any proactive way of detecting that type of
> > > an issue rather than discovering pile-up of SELECT queries leading to
> > > CPU starvation or finding hanged backup jobs.
> > >
> > > PostgreSQL's log does not have any error messages indicating data corruption.
> > >
> > > This server does not have checksums enabled, but - as I understand -
> > > such checksums cannot be checked online anyway. So - how can I detect
> > > similar corruption?
> >
> > A proactive way of detecting TOAST corruption... how about
> >
> > pg_dump -f /dev/null yourdatabase
> >
> > If there is TOAST corruption, that should give you an error.
>
> Thanks for your answer! pg_dump mydatabase ends with ~the same as the
> SELECT statement.
> It hangs leaving 'postgres: 17/main: postgres application_cache
> [local] COPY' using 100% of single CPU core and no messages in PG's
> logs.
>
> I was curious if there's any other tool that can spot that type of
> corruption and state it explicitly rather than guess it by monitoring
> execution time.

Data checksums would certainly be a step in the right direction.
They are checked whenever the data are read from storage.

There is no tool that will reliably detect all kinds of data corruption.

Another tool ar your disposal are the functions from the amcheck
contrib module (or the pg_amcheck executable that calls them).

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message ma lz 2025-09-15 07:16:35 How to use \restrict or \unrestirct in python
Previous Message Pawel Kudzia 2025-09-14 12:47:19 Re: Silent data corruption in PostgreSQL 17 - how to detect it proactively?