From a188cb0f8ccc51a2d0e75d03146fd8b97bbffe7c Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Thu, 21 Nov 2024 00:58:31 +0100 Subject: [PATCH] chore(postgres): add permissions command examples --- snippets/postgres/primer.sql | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/snippets/postgres/primer.sql b/snippets/postgres/primer.sql index c157785..cf6f305 100644 --- a/snippets/postgres/primer.sql +++ b/snippets/postgres/primer.sql @@ -105,7 +105,7 @@ ALTER DEFAULT PRIVILEGES FOR ROLE juan IN SCHEMA cache REVOKE all ON TABLES FROM -- List users with respective roles \du -\du+ +\du+ mark -- List users only SELECT usename FROM pg_catalog.pg_user; -- List roles only @@ -144,12 +144,16 @@ ALTER ROLE fred VALID UNTIL 'infinity'; -- Rename roles ALTER ROLE manager RENAME TO boss; --- Assign roles to users +-- Assign roles to users or other roles GRANT rds_superuser TO mike; +-- Assume roles for the current session +SET ROLE admin; + -- Remove role memberships from users REVOKE engineers FROM mike; + -- List permissions -- on tables SELECT * @@ -173,7 +177,14 @@ JOIN LATERAL ( ) a ON true JOIN pg_user e ON a.grantee = e.usesysid JOIN pg_user r ON a.grantor = r.usesysid -WHERE e.usename = 'darwin'; +WHERE e.usename IN ('darwin', 'salesmen'); +-- detailed +SELECT grantor, grantee, table_schema, table_name, privilege_type +FROM information_schema.table_privileges +WHERE grantee = 'engineers'; + +-- Assign permissions +GRANT USAGE ON SCHEMA bar_schema TO donald; -- Close the connection to the current DB