Quick tip: setting up PostgreSQL on Linux

January 14, 2020

Here is a quick bash script to remind me how to set-up a Postgres DB locally without knowing the postgres password.


cat << EOF > /tmp/createdb
create database ${db_name};
create user ${db_user};
alter user ${db_user} with password 'pwd';
grant all privileges on database ${db_name} to ${db_user};
show hba_file;

sudo -u postgres psql postgres -f /tmp/createdb

I usually use a Docker image for this, but on some occasions this might come in handy.