ERROR: cannot execute nextval() in a read-only transaction

Started by Dae-man Yangalmost 15 years ago2 messagesgeneral
Jump to latest
#1Dae-man Yang
yangsclub@gmail.com

I upgrade postgresql from 8.4.2 to 9.0.4.
But I have one problem.
The Error message 'cannot execute nextval() in a read-only transaction'

Please help me.

[Version 8.4.2]
DEVDB=# select version();
version

-------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.2 on x86_64-unknown-linux-gnu, compiled by GCC gcc
(GCC) 3.4.6 20060404 (Red Hat 3.4.6-10), 64-bit
(1 row)

DEVDB=# select version();
version
-------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.2 on x86_64-unknown-linux-gnu, compiled by GCC gcc
(GCC) 3.4.6 20060404 (Red Hat 3.4.6-10), 64-bit
(1 row)

DEVDB=# SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
SET
DEVDB=# select nextval('ws_blog_sns_inf_sns_inf_master_seq_seq');
nextval
---------
5
(1 row)

DEVDB=# SHOW transaction_read_only;
transaction_read_only
-----------------------
on
(1 row)

[Version 9.0.4]

web_dev=# select version();
version
-------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.0.4 on x86_64-unknown-linux-gnu, compiled by GCC gcc
(GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

web_dev=# SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
SET
web_dev=# SHOW transaction_read_only;
transaction_read_only
-----------------------
on
(1 row)

web_dev=# select nextval('ws_blog_sns_inf_sns_inf_master_seq_seq');
ERROR: cannot execute nextval() in a read-only transaction

#2Craig Ringer
craig@2ndquadrant.com
In reply to: Dae-man Yang (#1)
Re: ERROR: cannot execute nextval() in a read-only transaction

On 05/11/2011 02:29 PM, Dae-man Yang wrote:

I upgrade postgresql from 8.4.2 to 9.0.4.
But I have one problem.
The Error message 'cannot execute nextval() in a read-only transaction'

Please help me.

nextval() modifies a sequence, so you shouldn't be doing it in a
read-only transaction. Pg 9.0.4 enforces this, but it was still a bug in
whatever was trying to use nextval() in a read-only transaction before
9.0, Pg just didn't notice and warn you.

--
Craig Ringer