Global sequence management interfaces v5.6
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
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:
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
Parameters
snowflakeid
— Value of asnowflakeid
sequence.
Notes
This function executes only on the local node.
bdr.extract_nodeid_from_snowflakeid
This function extracts the nodeid component of the snowflakeid
sequence.
Synopsis
Parameters
snowflakeid
— Value of asnowflakeid
sequence.
Notes
This function executes only on the local node.
bdr.extract_localseqid_from_snowflakeid
This function extracts the local sequence value component of the snowflakeid
sequence.
Synopsis
Parameters
snowflakeid
— Value of asnowflakeid
sequence.
Notes
This function executes only on the local node.
bdr.timestamp_to_snowflakeid
This function converts a timestamp value to a dummy snowflakeid
sequence value.
This is useful for doing indexed searches or comparisons of values in the
snowflakeid
column and for a specific timestamp.
For example, given a table foo
with a column id
that's using a snowflakeid
sequence, you can get the number of changes since yesterday midnight like this:
A query formulated this way uses an index scan on the column id
.
Synopsis
Parameters
ts
— Timestamp to use for thesnowflakeid
sequence generation.
Notes
This function executes only on the local node.
bdr.extract_timestamp_from_timeshard
This function extracts the timestamp component of the timeshard
sequence.
The return value is of type timestamptz
.
Synopsis
Parameters
timeshard_seq
— Value of atimeshard
sequence.
Notes
This function executes only on the local node.
bdr.extract_nodeid_from_timeshard
This function extracts the nodeid component of the timeshard
sequence.
Synopsis
Parameters
timeshard_seq
— Value of atimeshard
sequence.
Notes
This function executes only on the local node.
bdr.extract_localseqid_from_timeshard
This function extracts the local sequence value component of the timeshard
sequence.