This page in other versions: 0.9 / 1.0 / 1.0.3

10.3. Using global sequences

Basic usage of global sequences is trivial: In a BDR node, when creating a sequence, append USING bdr; to your sequence creation statement:

   CREATE SEQUENCE test_seq USING bdr;

Once you've created a global sequence you may use it with nextval like any other sequence.

Most PostgreSQL applications don't use CREATE SEQUENCE directly; instead, they use the SERIAL pseudo-type. To accomodate this, BDR provides the default_sequenceam parameter. When set to bdr, all sequences will be automatically created as global sequences unless explicitly overridden by a USING option. So every SERIAL or BIGSERIAL will automatically be a global sequence. e.g.:


    SET LOCAL default_sequenceam = 'bdr';

    CREATE TABLE gstest (
      id serial primary key,
      parrot text


will create a global sequence named gstest_id_seq and set the DEFAULT of to nextval('gstest_id_seq').