Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Last active May 29, 2019 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huacnlee/4bb04f046e809596ea82e659cdc2023a to your computer and use it in GitHub Desktop.
Save huacnlee/4bb04f046e809596ea82e659cdc2023a to your computer and use it in GitHub Desktop.
PostgreSQL create readonly user for all database(创建一个 readonly 的用户,并给予对所有表的只读权限)
-- 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