常用 psql 命令记忆技巧

d → Display

n → Namespaces ⇔ schema

b → Block → 联想到表空间

\d + [首字母] = 显示某类对象

\dt --- Tables (表)

\di --- Indexes (索引)

\dv --- Views (视图)

\df --- Functions (函数)

\ds --- Sequences (序列)

\dy --- Event Triggers (事件触发器)

\l --- List databases (数据库列表)

\c --- Connect (连接)

\conninfo --- Connection Information

\du --- Display Users (用户)

\dg --- Display Groups (角色组)

\db --- Display Tablespace (Block 存储) (表空间)

\dp --- Display Privileges (权限)

\dn --- Display Namespaces,在 PostgreSQL 内部,schema 实际上就是 namespace

sql 复制代码
mydb=# select * from pg_namespace;
  oid  |      nspname       | nspowner |                            nspacl                             
-------+--------------------+----------+---------------------------------------------------------------
    99 | pg_toast           |       10 | 
    11 | pg_catalog         |       10 | {postgres=UC/postgres,=U/postgres}
  2200 | public             |     6171 | {pg_database_owner=UC/pg_database_owner,=U/pg_database_owner}
 13255 | information_schema |       10 | {postgres=UC/postgres,=U/postgres}
 16394 | schema_fred        |       10 | 
(5 rows)

mydb=# select * from information_schema.schemata;
 catalog_name |    schema_name     |   schema_owner    | default_character_set_catalog | default_character_set_schema | default_character_set_name | sql_path 
--------------+--------------------+-------------------+-------------------------------+------------------------------+----------------------------+----------
 mydb         | schema_fred        | postgres          |                               |                              |                            | 
 mydb         | information_schema | postgres          |                               |                              |                            | 
 mydb         | pg_catalog         | postgres          |                               |                              |                            | 
 mydb         | pg_toast           | postgres          |                               |                              |                            | 
 mydb         | public             | pg_database_owner |                               |                              |                            | 
(5 rows)

mydb=#
相关推荐
赵渝强老师1 天前
【赵渝强老师】PostgreSQL中表的碎片
数据库·postgresql
IvorySQL6 天前
揭开 PostgreSQL 读取效率问题的真相
数据库·postgresql·开源
科技D人生6 天前
PostgreSQL学习总结(17)—— PostgreSQL 插件大全:25款核心扩展解锁数据库全能力
数据库·postgresql·pgsql 插件·postgresql插件大全
知识分享小能手6 天前
PostgreSQL 入门学习教程,从入门到精通,PostgreSQL 16 (Windows) 安装与核心语法实战指南(2)
数据库·学习·postgresql
l1t6 天前
DeepSeek总结的PostgreSQL 中 DISTINCT 的三种用法
数据库·postgresql
知识分享小能手7 天前
PostgreSQL 入门学习教程,从入门到精通,PostgreSQL 16 语法知识点与案例详解(1)
数据库·学习·postgresql
木雷坞7 天前
使用Docker Compose部署PostgreSQL:从入门到实践
docker·postgresql·容器
mi20067 天前
Linux下安装postgresql记录
数据库·postgresql
Pluto_CSND7 天前
Mybatis访问PostgreSql异常:PSQLException: 错误: 无法确定参数 $1 的数据类型
postgresql·mybatis
醉颜凉9 天前
PostgreSQL 模式(SCHEMA)详解:数据库对象的命名空间管理
数据库·postgresql