pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Question on corruption (PostgreSQL 9.6.1)
4+ messages / 3 participants
[nested] [flat]

* Question on corruption (PostgreSQL 9.6.1)
@ 2018-03-13 08:48 Andy Halsall <andyh@live.co.uk>
  2018-03-13 13:58 ` Re: Question on corruption (PostgreSQL 9.6.1) Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Andy Halsall @ 2018-03-13 08:48 UTC (permalink / raw)
  To: pgsql-general

Following a number of kernel crashes due to memory corruption, we experienced "ERROR: invalid memory alloc request size 8589934587" from pg_dump. We assume because of corruption to a PostgreSQL page due to the same memory problems causing the crashes. Fortunately this was low impact - we could remove the single problematic row through the application. pg_dump now ok.


But recently we hit a different problem when restoring a pg_dump, seemingly caused by empty data in a not-null column. From pg_dump:

...

CREATE TABLE xxxxx (
    col_a bigint NOT NULL,
    col_b bytea,
    col_c integer NOT NULL,
    col_d bytea,
    col_e integer NOT NULL,
    last_modified timestamp without time zone NOT NULL
);

COPY xxxxx (col_a, col_b, col_c, col_d, col_e, last_modified) FROM stdin;
....
4675632 \\x     0       \\x     0       2017-09-27 10:34:38.109677
4675633 \\x     0       \\x     0       2017-09-27 10:34:38.113812
4675634 \\x     0       \\x     0       2017-09-27 10:34:38.118072
\N      \N      \N      \N      \N      \N
4675636 \\x     0       \\x     0       2017-09-27 10:34:38.128796
4675637 \\x     0       \\x     0       2017-09-27 10:34:38.132003
4675638 \\x     0       \\x     0       2017-09-27 10:34:38.134197
....


And then investigating rows 4675634 and 4675635:


db=# select * from xxxxx where col_a = 4675634;
 col_a   | col_b       | col_c           | col_d     | col_e         |       last_modified
---------+-------------+-----------------+-----------+---------------+----------------------------
 4675634 | \x          |               0 | \x        |             0 | 2017-09-27 10:34:38.118072
 (1 row)

 db=# select * from xxxxx where col_a = 4675635;
 col_a   | col_b       | col_c           | col_d     | col_e         |  last_modified
--------+-------------+-----------------+-----------+---------------+---------------
        |             |                 |           |               |
(1 row)


Row 4675635 is very odd - NULL columns and at the same time retrievable by a value in col_a.


Can this be explained in any other way than by corruption or could it be some other behaviour that we should worry about?


(We've never seen anything like it in test, just on the system that's had the problems. Previous problem row was col_a=4675656 - same table and perhaps page and so perhaps same corruption).


Fortunately again low impact - we were able to delete the row through the application.


Thanks.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Question on corruption (PostgreSQL 9.6.1)
  2018-03-13 08:48 Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
@ 2018-03-13 13:58 ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-03-15 15:16   ` Re: Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2018-03-13 13:58 UTC (permalink / raw)
  To: Andy Halsall <andyh@live.co.uk>; +Cc: pgsql-general

Andy Halsall <andyh@live.co.uk> writes:
>  db=# select * from xxxxx where col_a = 4675635;
>  col_a   | col_b       | col_c           | col_d     | col_e         |  last_modified
> --------+-------------+-----------------+-----------+---------------+---------------
>         |             |                 |           |               |
> (1 row)

> Row 4675635 is very odd - NULL columns and at the same time retrievable by a value in col_a.

Doesn't seem particularly surprising if col_a is indexed.  That query
would choose an indexscan plan, which would normally not bother to
re-verify the index condition against heap tuples found via the index.

If you're continuing to use this damaged database, it might be a good
idea to try to REINDEX all your indexes.  That'd be particularly
useful for primary/unique indexes, since if corruption has led to
any apparent duplicate rows, the reindex would fail and complain.
But in any case it'd clean up heap-vs-index inconsistencies like the
above, as well as repairing any cases where the corruption was in an
index rather than heap.

Another test I'd strongly recommend is to see if you can pg_dumpall
and reload into a spare server.  That might catch forms of data
corruption that reindexing would not, such as violated CHECK constraints.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Question on corruption (PostgreSQL 9.6.1)
  2018-03-13 08:48 Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
  2018-03-13 13:58 ` Re: Question on corruption (PostgreSQL 9.6.1) Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-15 15:16   ` Andy Halsall <andyh@live.co.uk>
  2018-03-16 18:24     ` Re: Question on corruption (PostgreSQL 9.6.1) Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 4+ messages in thread

From: Andy Halsall @ 2018-03-15 15:16 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

Thanks for the advice. I re-indexed and reloaded a pg_dumpall into a spare server - no errors. Will run pg_catcheck asap.

regards,
Andy

Andy Halsall <andyh@live.co.uk> writes:
>  db=# select * from xxxxx where col_a = 4675635;
>  col_a   | col_b       | col_c           | col_d     | col_e         |  last_modified
> --------+-------------+-----------------+-----------+---------------+---------------
>         |             |                 |           |               |
> (1 row)

> Row 4675635 is very odd - NULL columns and at the same time retrievable by a value in col_a.

Doesn't seem particularly surprising if col_a is indexed.  That query
would choose an indexscan plan, which would normally not bother to
re-verify the index condition against heap tuples found via the index.

If you're continuing to use this damaged database, it might be a good
idea to try to REINDEX all your indexes.  That'd be particularly
useful for primary/unique indexes, since if corruption has led to
any apparent duplicate rows, the reindex would fail and complain.
But in any case it'd clean up heap-vs-index inconsistencies like the
above, as well as repairing any cases where the corruption was in an
index rather than heap.

Another test I'd strongly recommend is to see if you can pg_dumpall
and reload into a spare server.  That might catch forms of data
corruption that reindexing would not, such as violated CHECK constraints.

                        regards, tom lane
    



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Question on corruption (PostgreSQL 9.6.1)
  2018-03-13 08:48 Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
  2018-03-13 13:58 ` Re: Question on corruption (PostgreSQL 9.6.1) Tom Lane <tgl@sss.pgh.pa.us>
  2018-03-15 15:16   ` Re: Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
@ 2018-03-16 18:24     ` Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Geoghegan @ 2018-03-16 18:24 UTC (permalink / raw)
  To: Andy Halsall <andyh@live.co.uk>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

On Thu, Mar 15, 2018 at 8:16 AM, Andy Halsall <andyh@live.co.uk> wrote:
> Thanks for the advice. I re-indexed and reloaded a pg_dumpall into a spare server - no errors. Will run pg_catcheck asap.

You can also run amcheck. Get the version targeting earlier Postgres
releases off Github (there are packages for most Linux systems). This
can verify that the heap is consistent with indexes.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-03-16 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-13 08:48 Question on corruption (PostgreSQL 9.6.1) Andy Halsall <andyh@live.co.uk>
2018-03-13 13:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-15 15:16   ` Andy Halsall <andyh@live.co.uk>
2018-03-16 18:24     ` Peter Geoghegan <pg@bowt.ie>

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