Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

第 2 章 Administration

目录

2.1. User 用户管理
2.1.1. 新建用户
2.1.2. SUPERUSER
2.1.3. 删除用户
2.1.4. 链接数限制
2.1.5. 复制用户
2.1.6. 修改用户密码
2.2. Database
2.2.1. 删除数据库
2.3. Table

2.1. User 用户管理

2.1.1. 新建用户

createuser 命令

$ createuser -P wechat
Enter password for new role: 
Enter it again: 
			

新建用户 SQL

CREATE ROLE woodart LOGIN PASSWORD 'chen'
  NOINHERIT
   VALID UNTIL 'infinity';
			

2.1.2. SUPERUSER

CREATE ROLE dba LOGIN
  PASSWORD 'your password'
  SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION;
			

2.1.3. 删除用户

本地操作

$ dropuser dba			
			

远程操作

dropuser -h192.168.1.1 -p 5432 -i -e testuser
User "testuser" and any owned databases will be permanently deleted.
Are you sure? (y/n) y
			

2.1.4. 链接数限制

CREATE ROLE sender LOGIN ENCRYPTED PASSWORD 'md51fd19061f37b296d27bf52b4c32c12ad'
   VALID UNTIL 'infinity' CONNECTION LIMIT 2048;
			

2.1.5. 复制用户

CREATE ROLE sender LOGIN ENCRYPTED PASSWORD 'md51fd19061f37b296d27bf52b4c32c12ad' REPLICATION
   VALID UNTIL 'infinity' CONNECTION LIMIT 2048;
			

2.1.6. 修改用户密码

alter user wechat with password 'new password'
alter user postgres with password 'new password'
			

使用psql运行上面语句

psql -d template1 -U postgres -c "alter role postgres password ‘123456’;"