Skip to content

Instantly share code, notes, and snippets.

@kerma
Created March 30, 2017 12:06
Show Gist options
  • Save kerma/91d5584ad8871f8e4c7753bdb95573d2 to your computer and use it in GitHub Desktop.
Save kerma/91d5584ad8871f8e4c7753bdb95573d2 to your computer and use it in GitHub Desktop.
PostgreSQL user management
-- Add a user with readonly privileges to db
CREATE USER username WITH PASSWORD '<password>';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO username;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO username;
-- Delete a user
revoke all privileges on all tables in schema public from username;
drop user username;
-- Add a "root" user to database
GRANT ALL PRIVILEGES ON DATABASE database_name TO root;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO root;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO root;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment