1、首先切换到postgres
# su - postgres -- 首先切换到postgres
-bash-4.1$ psql -- 输入psql
psql (10.5)
Type "help" for help.
postgres=#
2、创建用户
postgres=# create user test_user with password '123456'; --创建用户test_user,密码为123456
CREATE ROLE
postgres=#
3、创建数据库
postgres=# create database test_db owner test_user; -- 创建数据库test_db,并指定给用户test_user
CREATE DATABASE
postgres=#
4、将数据库得权限,全部赋给某个用户
postgres=# grant all on database test_db to test_user; -- 将test_db所有权限赋值给test_user
GRANT
postgres=#
5、创建和删除schema
postgres=# create schema s01 authorization test_db;
CREATE SCHEMA
postgres=# create schema authorization test_db;
指定了owner,不指定schema,则schema名字与owner一致
删除schema
drop schema pfm_test cascade;
加了cascade可以把关联的表、视图等等也一起删掉
6、修改数据库密码
ALTER USER
test_user
WITH PASSWORD 'new_password'
;
7、导入整个数据库
退出数据库编辑模式
postgres=# \q
psql -U test_user test_db < /data/backup.sql -- 用户名和数据库名