Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQead-0005Q6-Fn for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Apr 2013 14:04:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UQeac-00057C-ON for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Apr 2013 14:04:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQeab-000576-U8 for pgsql-bugs@postgresql.org; Fri, 12 Apr 2013 14:04:29 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQeaP-0000zP-UK for pgsql-bugs@postgresql.org; Fri, 12 Apr 2013 14:04:29 +0000 Received: from intern.anarazel.de (p5DDC5889.dip.t-dialin.net [93.220.88.137]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 517004F0001; Fri, 12 Apr 2013 16:04:17 +0200 (CEST) Date: Fri, 12 Apr 2013 16:04:16 +0200 From: Andres Freund To: tarvip@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8059: sequence crash recovery is not working properly Message-ID: <20130412140416.GF5766@alap2.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2013-04-12 12:27:01 +0000, tarvip@gmail.com wrote: > The following bug has been logged on the website: > > Bug reference: 8059 > Logged by: Tarvi Pillessaar > Email address: tarvip@gmail.com > PostgreSQL version: 9.2.4 > Operating system: linux > Description: > > Very simple example: > > postgres@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@sbox /usr/local/pgsql $ pgrep -lf writer > 13638 postgres: writer process > 13639 postgres: wal writer process > postgres@sbox /usr/local/pgsql $ kill -9 13638 > postgres@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@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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs