Skip to content

Instantly share code, notes, and snippets.

@stephenlacy
Created January 16, 2025 22:25
Show Gist options
  • Save stephenlacy/cd3248506b8ce6cd88c4b352555f608a to your computer and use it in GitHub Desktop.
Save stephenlacy/cd3248506b8ce6cd88c4b352555f608a to your computer and use it in GitHub Desktop.
because I need to google this each time...
-- Create the database
CREATE DATABASE your_database_name;
-- Create the user with a password
CREATE USER your_username WITH PASSWORD 'your_password';
-- Grant all current and future permissions on the database to the user
GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_username;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_username;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO your_username;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO your_username;
-- Grant permissions on future tables/sequences/functions
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO your_username;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO your_username;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO your_username;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment