PostgreSQL psql 常用命令总结

2023-12-07 0 333
目录
  • 角色查看
  • 模式查看
  • 表结构查看
  • 表空间查看

今天总结下PostgreSQL 中常用 psql 常用命令以便后续查阅。

角色查看

hrdb=> \\du
List of roles
Role name | Attributes | Member of
———–+————————————————————+———–
admin | Create role, Create DB, Cannot login | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
wdh | Create DB +| {}
| Password valid until 2060-12-31 00:00:00+08 |

对应sql

select * from pg_roles

数据库查看

hrdb=> \\l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
———–+———-+———-+————-+————-+————+—————–+———————–
hrdb | wdh | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres

对应sql

select * from pg_database;

模式查看

hrdb=> \\dn
List of schemas
Name | Owner
——–+——————-
hr | wdh
public | pg_database_owner
(2 rows)

对应sql

select * from pg_namespace;

表结构查看

hrdb=> \\d jobs;
Table \”public.jobs\”
Column | Type | Collation | Nullable | Default
————+———————–+———–+———-+———
job_id | character varying(10) | | not null |
job_title | character varying(35) | | not null |
min_salary | integer | | |
max_salary | integer | | |
Indexes:
\”job_id_pk\” PRIMARY KEY, btree (job_id)
Referenced by:
TABLE \”employees\” CONSTRAINT \”emp_job_fk\” FOREIGN KEY (job_id) REFERENCES jobs(job_id)

表空间查看

hrdb=> \\db
List of tablespaces
Name | Owner | Location
————+———-+———-
pg_default | postgres |
pg_global | postgres |

到此这篇关于PostgreSQL psql 常用命令总结的文章就介绍到这了,更多相关PostgreSQL psql命令内容请搜索悠久资源以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 PostgreSQL PostgreSQL psql 常用命令总结 https://www.u-9.cn/database/postgresql/122515.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务