常用 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=#
相关推荐
IvorySQL5 小时前
PostgreSQL 日报|Anonymizer 3.3 修复高危漏洞(10 月 29 日)
数据库·postgresql
geovindu5 小时前
SQL Data Sampling and Approximation Techniques using postgreSQL 18
大数据·数据库·数据仓库·sql·postgresql·数据库开发·数据库架构
小手cool6 小时前
PostgreSQL 基础入门:从安装到核心概念
数据库·postgresql
代码派6 小时前
PostgreSQL 同构迁移上云方案|NineData 数据复制、实时增量与一致性校验
数据库·postgresql·上云·ninedata·迁移·数据库迁移·版本升级
Jack N7 小时前
【Strapi 系列之八】二次开发 + 生产部署,Docker + PostgreSQL + Nginx 一把梭
nginx·docker·postgresql·strapi
瀚高PG实验室7 小时前
瀚高数据库提交数据后,是否需要COMMIT
数据库·postgresql·瀚高数据库
AI开源软件1 天前
SpringBoot信创项目怎么验收?从数据库迁移到交付证据
postgresql·springboot·达梦·opengauss·信创·企业管理系统
l1t1 天前
DeepSeek总结的ALTER FUNCTION SET work_mem:无需全局更改即可修复 PostgreSQL 磁盘溢出
sql·缓存·postgresql
l1t1 天前
DeepSeek总结的PostgreSQL 中的 SQL 与 PL/pgSQL:计划缓存
sql·缓存·postgresql
boy快快长大1 天前
MySQL 转 PostgreSQL 使用指南
数据库·mysql·postgresql