PostgreSQL常用命令

一、数据库

1 登录数据库

# psql -U postgres

# psql -U postgres -h localhost

# psql -U postgres -h localhost -d postgres

2 查看数据库

# \l

3 删除数据库

postgres=# drop database test;

4 如果数据库名称中包含符号-,则用双引号包括数据库名称

postgres=# drop database "test-study";

5 查看当前数据库

postgres# select current_database();

6 切换数据库

postgres# \c db

7 退出数据库

postgres# \q

二、数据表

1 显示当前数据库中的所有表

# \d

2 显示指定表结构

postgres# \d tableName

4 xx

三、用户

1 查看所有用户

\du

2 查看当前用户

select user;
select current_user;

3 修改用户密码

alter user lining with password '123456';

4 添加用户

create user asan with password '123456';

5 给用户添加权限

alter user asan with SUPERUSER;

6 删除用户

drop user asan;

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/3a9f2d8bd0.html