序列相关操作

最近更新时间: 2024-10-17 17:10:00

  • 建立序列。
postgres=# create sequence tbase_seq;
CREATE SEQUENCE
postgres=# create sequence pgxc.tbase_seq;
CREATE SEQUENCE
  • \d查看序列定义和使用情况。
postgres=# \d tbase_seq                
         Sequence "public.tbase_seq"
  Column   |  Type  | Value 
------------+---------+-------
 last_value | bigint  | 1
 log_cnt   | bigint  | 0
 is_called | boolean | f 
  • \ds查看序列列表。
postgres=# \ds
          List of relations
 Schema |  Name    |   Type  | Owner 
--------+-----------+----------+-------
 pgxc   |tbase_seq  | sequence | tbase
 public | tbase_seq | sequence | tbase
(2 rows)
  • \ds+查看序列列表详细信息(包含注释),占用空间大小。
postgres=# \ds+
          List of relations
 Schema |  Name    |   Type  | Owner |    Size    | Description 
--------+-----------+----------+-------+------------+-------------
 pgxc   |tbase_seq | sequence | tbase  | 8192bytes | 
 public | tbase_seq | sequence | tbase  | 8192 bytes | tbase序列
(2 rows)
  • \ds+显示某个模式下的所有序列。
postgres=# \ds+ pgxc.*
          List of relations
 Schema |  Name    |   Type  | Owner |    Size    | Description 
--------+----------+----------+-------+------------+-------------
 pgxc   |tbase_seq | sequence | tbase  | 8192bytes | 
(1 row)
  • \ds+序列名显示某个序列的详细信息。
postgres=# \ds+ tbase_seq
          List of relations
 Schema |  Name    |   Type  | Owner |    Size    | Description 
--------+-----------+----------+-------+------------+-------------
 public | tbase_seq | sequence | tbase  | 8192 bytes | tbase序列
(1 row)
  • \ds+通配符列出适配的序列。
postgres=# \ds *_seq
          List of relations
 Schema |  Name    |   Type  | Owner 
--------+-----------+----------+-------
 pgxc   |tbase_seq  | sequence | tbase
 public | tbase_seq | sequence | tbase
(2 rows)

postgres=# \ds t*_seq
          List of relations
 Schema |  Name    |   Type  | Owner 
--------+-----------+----------+-------
 public | tbase_seq | sequence | tbase
(1 row)