This topic describes how to use the sequential-uuids extension. ApsaraDB RDS for PostgreSQL provides this extension to generate UUIDs in a more sequential pattern.

Prerequisites

  • Your RDS instance runs one of the following database engine versions:
  • A privileged account is used to connect to your RDS instance. You can check the type of the account that you use on the Accounts page in the ApsaraDB RDS console. If the account is a standard account, you must create a privileged account and use the privileged account to connect to your RDS instance. For more information, see Create an account on an ApsaraDB RDS for PostgreSQL instance.

Enable or disable the extension

  • Execute the following statement to enable the sequential-uuids extension:
    CREATE EXTENSION sequential_uuids;
  • Execute the following statement to disable the sequential-uuids extension:
    DROP EXTENSION sequential_uuids;

Examples

This extension provides two functions to generate sequential UUIDs by using sequences or timestamps.
Note For more information about how to use the extension and related parameters, see Sequential UUID generators.
  • The uuid_sequence_nextval function
    Syntax:
    uuid_sequence_nextval(sequence regclass, block_size int default 65536, block_count int default 65536)
    Sample statement:
    CREATE SEQUENCE s;
    SELECT uuid_sequence_nextval('s'::regclass, 256, 256);
    Sample result:
            uuid_sequence_nextval
    --------------------------------------
     00cf26f7-ef7a-4746-8871-08b9c475713e
    (1 row)
  • The uuid_time_nextval function
    Syntax:
    uuid_time_nextval(interval_length int default 60, interval_count int default 65536) RETURNS uuid
    Sample statement:
    SELECT uuid_time_nextval(1, 256);
    Sample result:
              uuid_time_nextval
    --------------------------------------
     179f542c-978c-454c-9dee-5f4ba75288e1
    (1 row)