[pgpool-hackers: 47] Re: Implementing SERIAL rewriting

Guillaume Lelarge guillaume at lelarge.info
Thu Mar 22 02:21:39 JST 2012


On Wed, 2012-03-21 at 18:11 +0900, Tatsuo Ishii wrote:
> >> One problem I could forsee is:
> >>
> >> Suppose we have two different session A and B to pgpool.  It is
> >> possible that following order of SQL execution could happen:
> >>
> >> A: SELECT nextval('t1_i_seq');          -- suppose this returns 100
> >> B: SELECT nextval('t1_i_seq');          -- suppose this returns 101
> >> A: INSERT INTO t1 VALUES(100, 1);       -- on the master and slaves
> >> B: INSERT INTO t1 VALUES(101, 1);       -- on the master and slaves
> >> B: SELECT setval('t1_i_seq', 101);  -- on the slaves
> >> A: SELECT setval('t1_i_seq', 100);      -- on the slaves
> >>
> >> In this scenario, the sequence' value results in 101 on the master, on
> >> the other hand 100 on the slaves. Any idea how to prevent this?
> > 
> > 
> > My idea is, at slave, before set the value, check if current value is
> > bigger than the given one.
> 
> How do you get the current sequence value without
> incrementing(i.e. nextval()) the sequence value?

SELECT last_value FROM the_sequence;

Not saying this is a good idea, though :)


-- 
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com



More information about the pgpool-hackers mailing list