0%
PostgreSQL分析#005#客户端常用操作命令

本文介绍PostgreSQL客户端常用的操作命令。

数据库命令

0x00:查询所有数据库

1
\l

0x01:查看当前数据库

1
select current_database();

0x02:选择数据库
使用 \c + 数据库名 来选择其他数据库:

1
\c db_mancode

用户管理命令

0x00:查询用户列表

列出数据库中所有的用户,以及相应角色属性和所属角色组。

1
2
3
4
5
\du

SELECT * FROM pg_user;

SELECT usename, usesysid, usecreatedb, usesuper, passwd, valuntil, useconfig FROM pg_shadow;

注意:pg_user是系统目录表,该表存储所有数据库用户的信息,包括用户名、密码和角色等。查询pg_user返回当前数据库实例的所有用户,查询pg_shadow表是返回整个PostgreSQL服务器的所有用户。

0x01:查看当前连接的用户名

1
2
3
4
5
\c

SELECT user;

SELECT * FROM current_user;

参考资料

https://blog.csdn.net/rainbow702/article/details/50985672
https://blog.csdn.net/huangbaokang/article/details/88862791
https://www.runoob.com/postgresql/postgresql-create-database.html
https://www.runoob.com/postgresql/postgresql-select-database.html
http://www.postgres.cn/docs/9.3/manage-ag-createdb.html