Last active
May 29, 2019 07:34
-
-
Save huacnlee/4bb04f046e809596ea82e659cdc2023a to your computer and use it in GitHub Desktop.
PostgreSQL create readonly user for all database(创建一个 readonly 的用户,并给予对所有表的只读权限)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create a final user with password | |
CREATE USER "readonly-user" WITH PASSWORD '123456'; | |
-- 选择一个数据库,后面的权限制定是对单个库有效的 | |
-- Grant access to existing tables | |
GRANT USAGE ON SCHEMA public TO "readonly-user"; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "readonly-user"; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "readonly-user"; | |
-- Grant access to future tables | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO "readonly-user"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment