psql create role and assign priviledges
最後有成功,所以先把過程記錄下來,再來研究該怎麼下指令。
建立一個 role 叫 dbreader
postgres=# CREATE ROLE dbreader; CREATE ROLE讓dbreader這個 role 可以讀取 public 這個 schema 的{usage | select}
postgres=# GRANT USAGE ON SCHEMA public TO dbreader;
GRANT
postgres=# GRANT SELECT ON ALL TABLES IN SCHEMA public TO dbreader;
GRANT
設定public schema 的default 權限 給 dbreader 這個 role
postgres=# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO dbreader; ALTER DEFAULT PRIVILEGES建立資料庫使用者 readuser
postgres=# CREATE USER readuser WITH PASSWORD 'readuserpassword'; CREATE ROLE將dbreader這個role 指定給 readuser
postgres=# GRANT dbreader TO readuser; GRANT ROLE切到 neo DB
postgres=# \q
postgres@hqs022:~$ psql --u postgres neo
psql (9.6.8)
Type "help" for help.
neonexus=# GRANT SELECT ON ALL TABLES IN SCHEMA public to readuser;
GRANT
neonexus=# GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readuser;
GRANT
neonexus=# GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO readuser;
GRANT