From: Heikki Linnakangas Date: Mon, 20 Apr 2015 13:40:57 +0000 (+0300) Subject: sequence.c should be in charge of ensuring that the tuple is WAL-logged, X-Git-Url: http://git.postgresql.org/gitweb/review?a=commitdiff_plain;h=d6681759e375c370e1c7f75deeaef6df8b9ab65b;p=users%2Fheikki%2Fpostgres.git sequence.c should be in charge of ensuring that the tuple is WAL-logged, after a checkpoint. Otherwise you might get a torn page. sequence_save_tuple() should force the tuple to be WAL-logged after a checkpoint, even if !do_wal. --- diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 755df07af1..f68dd9034f 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -1029,6 +1029,13 @@ sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal) page = BufferGetPage(seqh->buf); + /* + * Force the change to be WAL-logged, if we the tuple hasn't been logged + * since the last checkpoint. + */ + if (RelationNeedsWAL(seqh->rel) && sequence_needs_wal(seqh)) + do_wal = true; + /* * If something needs to be WAL logged, acquire an xid, so this * transaction's commit will trigger a WAL flush and wait for