筆記-psql create role and assign user to the role with read only permission
最後有成功,所以先把過程記錄下來,再來研究該怎麼下指令。
建立一個 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.
neo=# GRANT SELECT ON ALL TABLES IN SCHEMA public to readuser;
GRANT
neo=# GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readuser;
GRANT
neo=# GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO readuser;
GRANT