One point - a serial datatype will not increment to infinity, as it is effectively a 4 byte integer with a sequence imposed, it can only store values upto MAXINT (2147483647) .
Above this it may well wrap around where MAXINT + 1 = 1
-- You can delay the problem (significantly) by using bigserial (8 byte integer) instead of serial - this has MAXINT=9223372036854775807 http://www.postgresql.org/docs/9.2/static/datatype-numeric.html Otherwise you might run a cron job or trigger to reset the serial values & the sequence when you think it timely. I can't see how this would cause the missing records though. Cheers Brent Wood
Programme leader: Environmental Information Delivery NIWA DDI: +64 (4) 3860529 From: pgsql-general-owner@xxxxxxxxxxxxxx [pgsql-general-owner@xxxxxxxxxxxxxx] on behalf of Thom Brown [thom@xxxxxxxxx]
Sent: Thursday, March 06, 2014 8:01 AM To: Israel Brewster Cc: PGSQL Mailing List Subject: Re: Mysterious DB reset On 5 March 2014 18:22, Israel Brewster <israel@xxxxxxxxxxxxx> wrote:
That is odd. Even if it were an unlogged table, and there was a crash, the sequence wouldn't reset, and even if it was running in a very long-running transaction held open by a buggy connection pooler, the sequence would still progress as it's immune
to the effects of transactions.
So if all the data went missing, and the sequence reset, the only thing I can think of is:
Someone ran:
TRUNCATE data RESTART IDENTITY;
or someone restored the table structure from a backup that deleted the original table.
Do you log DDL?
Was the table partitioned?
You should also really be on 9.2.7, although I can't think of any bug that's been fixed which could be responsible for this issue.
Thom Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd. |