We are running a PostgreSQL 9.1.20 with a database of about 50GB.
- All things works fine.
- After some days strange unexpected values appear in numeric columns, like negative or bigger values in unexpected places.
- The strange part: if we run a
pg_dump
of the same "corrupted" database, and then restore it (in the same server), the data becomes all ok. Now the same queries return different values!
Why does the database dump have different values when we are taking the dump exactly from the "corrupted" database? (The dump has corrected values from our perception!)
Can this be related to some kind of broken transaction or hard drive trouble? Note that restarting the database does not solve the problem.
What can be the cause behind this problem?
As requested in the comments some examples of data:
#psql
\c base
select * from salXXXX where sal_id=2323;
sal_id | sal_XXXX | XXXXXX | XXXXXX | XXXXX | XXXXX | XXXXX
--------+-----------+---------------+--------------------+------------+-----------------------+------------
2323 | -30.43 | 42586501 | 6 | 13 | f |
\quit
pg_dump -h 127.0.0.1 -p 5432 --user=postgres >backup.sql
psql
drop database base;
create database base;
\c base
\i backup.sql
(no errors found here)
select * from salXXXX where sal_id=2323;
sal_id | sal_XXXX | XXXXXX | XXXXXX | XXXXX | XXXXX | XXXXX
--------+-----------+---------------+--------------------+------------+-----------------------+------------
2323 | 245.43 | 42586501 | 6 | 13 | f |
It is hard to emulate it, rarely occurs, but when it occurs we just do a dump, it is a ridiculous solution, but it works.
This is just an example, many more wrong values start to appear, even if we reprocess the data. But if the database is dumped and restored, values are in the expected range again.