Skip to content

Create a PostgreSQL database

Fill in the variables above and set the user’s password in the script:

init.sql
CREATE USER ${{ USERNAME }} WITH PASSWORD 'put_your_password';
CREATE DATABASE ${{ DBNAME }} OWNER ${{ USERNAME }};
GRANT ALL PRIVILEGES ON DATABASE ${{ DBNAME }} TO ${{ USERNAME }};
\c ${{ DBNAME }}
GRANT ALL ON SCHEMA public TO ${{ USERNAME }};

Run as superuser (e.g. postgres):

Terminal window
psql -h ${{ HOSTNAME }} -p 5432 -U postgres -f init.sql

Or inline:

Terminal window
psql -h ${{ HOSTNAME }} -p 5432 -U postgres -c "CREATE USER ${{ USERNAME }} WITH PASSWORD 'put_your_password'; CREATE DATABASE ${{ DBNAME }} OWNER ${{ USERNAME }};"