Re: BUG #8059: sequence crash recovery is not working properly

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: tarvip(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8059: sequence crash recovery is not working properly
Date: 2013-04-12 14:04:16
Message-ID: 20130412140416.GF5766@alap2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2013-04-12 12:27:01 +0000, tarvip(at)gmail(dot)com wrote:
> The following bug has been logged on the website:
>
> Bug reference: 8059
> Logged by: Tarvi Pillessaar
> Email address: tarvip(at)gmail(dot)com
> PostgreSQL version: 9.2.4
> Operating system: linux
> Description:
>
> Very simple example:
>
> postgres(at)sbox /usr/local/pgsql $ /usr/local/pgsql/bin/psql test
> psql (9.2.4)
> Type "help" for help.
>
> test=# create sequence s;
> CREATE SEQUENCE
> test=# begin;
> BEGIN
> test=# select nextval('s');
> nextval
> ---------
> 1
> (1 row)
>
>
> Now let's crash the cluster:
>
> postgres(at)sbox /usr/local/pgsql $ pgrep -lf writer
> 13638 postgres: writer process
> 13639 postgres: wal writer process
> postgres(at)sbox /usr/local/pgsql $ kill -9 13638
> postgres(at)sbox /usr/local/pgsql $ tail logfile
> HINT: In a moment you should be able to reconnect to the database and
> repeat your command.
> LOG: all server processes terminated; reinitializing
> LOG: database system was interrupted; last known up at 2013-04-12 14:28:26
> EEST
> LOG: database system was not properly shut down; automatic recovery in
> progress
> LOG: redo starts at 0/177C9E0
> LOG: record with zero length at 0/1791888
> LOG: redo done at 0/1791858
> LOG: last completed transaction was at log time 2013-04-12
> 14:29:48.562356+03
> LOG: database system is ready to accept connections
> LOG: autovacuum launcher started
> postgres(at)sbox /usr/local/pgsql $

Thats caused by the fact that you didn't do anything that forces a WAL
flush since you didn't do any inserts or such. If you would do any
DML in the nextval() calling transaction this shouldn't happen (unless
you use synchronous_commit=off).
Now, there's a legitimate argument to be made that returning the
sequence value to the user kinda persists it. On the other hand, at
least in the first example you haven't even committed the transaction so
there's nothing that could flush the transaction unless we we would
*always* flush nextval() immediately if needs to get new values which
doesn't seem reasonable.

I think a reasonable compromise would be that nextval_internal()
acquires a real xid (by calling GetTopTransactionId()). In that case the
commit would force a WAL flush but there are no forced wal flushes ones
inside the transaction. And it would support async commits.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2013-04-12 14:07:27 Re: BUG #8058: CLUSTER and VACUUM FULL fail to free space
Previous Message shaun.c.mccrery 2013-04-12 13:04:50 BUG #8060: postgresql service not in Microsoft services