Re: Sequence's value can be rollback after a crashed recovery. - Mailing list pgsql-hackers

From Andy Fan
Subject Re: Sequence's value can be rollback after a crashed recovery.
Date
Msg-id CAKU4AWp39gxGw0=PErOpHNebPE+VWtgu4Uu18Jfz_KeJbfiH+A@mail.gmail.com
Whole thread Raw
In response to Re: Sequence's value can be rollback after a crashed recovery.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

You could say that that's the same rookie error as relying on the
persistence of any other uncommitted DML ... 

IIUC, This is not the same as uncommitted DML exactly.   For any uncommitted 
DML, it is a rollback for sure.  But as for sequence, The xmax is not changed
during sequence's value update by design and we didn't maintain the multi versions
for sequence,  so sequence can't be rolled back clearly.  The fact is a dirty data page flush 
can persist the change no matter the txn is committed or aborted.  The below example
can show the difference: 

SELECT nextval('s'); -- 1
begin;
SELECT nextval('s');  \watch 0.1 for a while, many checkpointer or data flush happened. 
-- crashed. 

If we run nextval('s') from the recovered system, we probably will _not_ get
the 2 (assume cachesize=1) like uncommitted DML.


--
Best Regards
Andy Fan 

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Failed transaction statistics to measure the logical replication progress
Next
From: "Bossart, Nathan"
Date:
Subject: Re: XMAX_LOCK_ONLY and XMAX_COMMITTED (fk/multixact code)