Skip to content

Instantly share code, notes, and snippets.

@supix
Last active August 1, 2019 05:26
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 supix/a48f0865ec2c37c598ebf8033608482b to your computer and use it in GitHub Desktop.
Save supix/a48f0865ec2c37c598ebf8033608482b to your computer and use it in GitHub Desktop.
Create new postgres database with owner and app user
psql -U postgres
create database myNewDB;
create user myNewDB_web;
create user myNewDB_owner;
ALTER USER myNewDB_web WITH PASSWORD 'pwd';
ALTER USER myNewDB_owner WITH PASSWORD 'pwd';
psql -U postgres -d myNewDB
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
grant usage on schema public to myNewDB_owner;
GRANT ALL PRIVILEGES ON SCHEMA public to myNewDB_owner;
GRANT all privileges on all tables IN SCHEMA public TO myNewDB_owner;
# if you want to enable the owner to create new schema within the database
grant create on database myNewDB to myNewDB_owner;
grant usage on schema public to myNewDB_web;
GRANT SELECT, update, delete, insert ON ALL TABLES IN SCHEMA public TO myNewDB_web;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public to myNewDB_web;
psql -U myNewDB_owner -d myNewDB
ALTER DEFAULT PRIVILEGES in schema public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO myNewDB_web;
ALTER DEFAULT PRIVILEGES in schema public GRANT USAGE, SELECT ON SEQUENCES to myNewDB_web;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment