Skip to content

Instantly share code, notes, and snippets.

@kstromeiraos
Last active March 16, 2021 15:55
Show Gist options
  • Save kstromeiraos/b04ff80d0b01c4739258651dbfd4101f to your computer and use it in GitHub Desktop.
Save kstromeiraos/b04ff80d0b01c4739258651dbfd4101f to your computer and use it in GitHub Desktop.
Create a standard user for a RDS DB instance running PostgreSQL

Create standard role

CREATE ROLE api;   

Grant access to all existing tables/sequences/functions

GRANT ALL PRIVILEGES ON SCHEMA public to api;
GRANT ALL ON ALL TABLES IN SCHEMA public to api;
GRANT ALL ON ALL SEQUENCES IN SCHEMA public to api;
GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to api;

Create user and grant role to this user

CREATE ROLE user_api WITH PASSWORD 'password' LOGIN;   
GRANT api TO user_api;

Login as user_api and grant all privileges on future tables/sequences/functions

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO api;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO api;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment