PostgreSQL添加角色,用户,更新密码,设置权限等配置操作

发布时间 2023-10-09 09:49:01作者: 古兆洋

创建用户:

CREATE USER query WITH PASSWORD '123456';

授予用户权限:

(1)给予权限:grant

grant select on 表名 to 用户名;

(2)撤消权限:revoke

revoke select on 表名 from 用户名;

给用户授予全部表的权限:

grant all on all tables in schema public to public;

查看用户权限:

select * from information_schema.table_privileges where grantee='zjy';
注意:任何用户对public的schema都有all的权限,为了安全可以禁止用户对public schema

##移除所有用户(public),superuser除外,对指定DB下的public schema的create 权限。
zjy=# revoke create on schema public from public;
REVOKE

原文链接:https://blog.csdn.net/chenjin_chenjin/article/details/104168647

 

创建角色

CREATE ROLE角色名 语法与创建用户一致

转自:https://blog.csdn.net/weixin_39185173/article/details/129912119

 

更新密码

ALTER USER postgres WITH PASSWORD 'new_password';

 

关于连接PostgreSQL时提示 FATAL: password authentication failed for user "连接用户名" 的解决办法

这是因为密码忘记了,或密码过期

转自:https://blog.csdn.net/weixin_34049948/article/details/92385478

 

升级用户成为超级用户

alter user myuser with superuser;