Global sequence management interfaces v5
PGD provides an interface for converting between a standard PostgreSQL sequence and the PGD global sequence.
The following functions are considered to be DDL
, so DDL replication
and global locking applies to them.
Sequence functions
bdr.alter_sequence_set_kind
Allows the owner of a sequence to set the kind of a sequence.
Once set, seqkind
is visible only by way of the bdr.sequences
view.
In all other ways, the sequence appears as a normal sequence.
PGD treats this function as DDL
, so DDL replication and global locking applies,
if it's currently active. See DDL replication.
Synopsis
bdr.alter_sequence_set_kind(seqoid regclass, seqkind text)
Parameters
seqoid
— Name or Oid of the sequence to alter.seqkind
—local
for a standard PostgreSQL sequence,snowflakeid
orgalloc
for globally unique PGD sequences, ortimeshard
for legacy globally unique sequence.
Notes
When changing the sequence kind to galloc
, the first allocated range for that
sequence uses the sequence start value as the starting point. When there are
existing values that were used by the sequence before it was changed to galloc
,
we recommend moving the starting point so that the newly generated
values don't conflict with the existing ones using the following command:
ALTER SEQUENCE seq_name START starting_value RESTART
This function uses the same replication mechanism as DDL
statements. This means
that the replication is affected by the DDL filters
configuration.
The function takes a global DDL
lock. It also locks the sequence locally.
This function is transactional. You can roll back the effects with the
ROLLBACK
of the transaction. The changes are visible to the current
transaction.
Only the owner of the sequence can execute the bdr.alter_sequence_set_kind
function,
unless bdr.backwards_compatibility
is
set to 30618 or lower.
bdr.extract_timestamp_from_snowflakeid
This function extracts the timestamp component of the snowflakeid
sequence.
The return value is of type timestamptz
.
Synopsis
bdr.extract_timestamp_from_snowflakeid(snowflakeid bigint)
Parameters
snowflakeid