
postgresql创建只读用户并授权CREATE USER yk WITH ENCRYPTED PASSWORD your_password; GRANT USAGE ON SCHEMA public to yk; GRANT SELECT ON ALL TABLES IN SCHEMA public TO yk;根据以上创建的用户出现一个问题对新建的表没有查询权限需要重新授权一次才可以。通过下面的方法可以解决。GRANT SELECT ON ALL TABLES IN SCHEMA public TO yk; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO yk;postgresql 管理员登录创建账号授权新用户访问业务库的连接权限管理员身份登录业务库授权新用户访问业务库的USAGE权限授权新用户访问表的权限。$ psql psql (12.10) Type help for help. postgres# CREATE USER testuser1 WITH PASSWORD Sjztdb#2026; CREATE ROLE postgres# \c testdb You are now connected to database testdb as user postgres. testdb# GRANT USAGE ON SCHEMA public TO testuser1; GRANT testdb# GRANT SELECT ON ALL TABLES IN SCHEMA public TO testuser1; GRANT testdb# grant connect on database testdb to testuser1; GRANT testdb# \c testdb testuser1 You are now connected to database testdb as user testuser1. testdb testdb select count(*) from tab1; count ------- 0 (1 row) testdb