Hi, While re-testing Jeff's patch [1], I found a similar issue with pg_commit_ts. After a crash, the row I had inserted was gone and pg_xact_status() said aborted, which is fine for an async commit, but pg_xact_commit_timestamp() still returned its commit timestamp instead of NULL.
I used track_commit_timestamp = on, commit_timestamp_buffers = 16 and wal_writer_delay = 10s on the primary. I set synchronous_commit = off for the transaction that did the INSERT and left it off for the next 20,000 commits to evict its timestamp page. Then I did an immediate shutdown. Happy to share the script if it's useful. AFAICS the commit_ts page just got written out before the commit record. I think setting the timestamp in memory early is fine, since redo would set it again from the commit record, but the page shouldn't reach disk before the commit record does. For async commits, pg_xact passes the commit LSN to SLRU so SlruPhysicalWritePage() can flush WAL first. pg_commit_ts doesn't pass an LSN. On a standby, writing the timestamp page doesn't advance minRecoveryPoint, much like the pg_xact case Jeff fixed. If the standby then crashes and I recover the same data directory to just before the commit, the timestamp from the earlier replay can still be there. A fresh restore that never replayed the commit wouldn't have it. IIUC, pg_commit_ts doesn't need to flush WAL at every commit. The attached patch keeps the highest commit LSN for each dirty page. Before writing the page, SLRU makes sure WAL is flushed at least through the end of that commit record. I don't know the pg_commit_ts code that well, so I may be missing something. Is there a reason not to use the same SLRU flush as pg_xact here? [1] https://postgr.es/m/[email protected] Regards, Ayush
v1-0001-Flush-WAL-before-writing-commit-timestamp-pages.patch
Description: Binary data
