Difference between revisions of "Ucmd Postgres"
Jump to navigation
Jump to search
(Created page with "https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html") |
|||
Line 1: | Line 1: | ||
https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html | https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html | ||
+ | |||
+ | Readonly | ||
+ | ``` | ||
+ | To create a new user in PostgreSQL: | ||
+ | |||
+ | CREATE USER username WITH PASSWORD 'your_password'; | ||
+ | To learn more about creating PostgreSQL user, visit this post. | ||
+ | |||
+ | 2. GRANT the CONNECT access: | ||
+ | |||
+ | GRANT CONNECT ON DATABASE database_name TO username; | ||
+ | 3. Then GRANT USAGE on schema: | ||
+ | |||
+ | GRANT USAGE ON SCHEMA schema_name TO username; | ||
+ | 4. GRANT SELECT | ||
+ | |||
+ | Grant SELECT for a specific table: | ||
+ | GRANT SELECT ON table_name TO username; | ||
+ | Grant SELECT for multiple tables: | ||
+ | GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO username; | ||
+ | If you want to grant access to the new table in the future automatically, you have to alter default: | ||
+ | ALTER DEFAULT PRIVILEGES IN SCHEMA schema_name | ||
+ | GRANT SELECT ON TABLES TO username; | ||
+ | ``` |
Revision as of 19:28, 12 February 2022
https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html
Readonly
To create a new user in PostgreSQL: CREATE USER username WITH PASSWORD 'your_password'; To learn more about creating PostgreSQL user, visit this post. 2. GRANT the CONNECT access: GRANT CONNECT ON DATABASE database_name TO username; 3. Then GRANT USAGE on schema: GRANT USAGE ON SCHEMA schema_name TO username; 4. GRANT SELECT Grant SELECT for a specific table: GRANT SELECT ON table_name TO username; Grant SELECT for multiple tables: GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO username; If you want to grant access to the new table in the future automatically, you have to alter default: ALTER DEFAULT PRIVILEGES IN SCHEMA schema_name GRANT SELECT ON TABLES TO username;