Setting up Postgres locally with peer-authentication
It's a common task to want a local database available for development purposes. This article tells you how to do this with PostgreSQL on Debian, with peer-authentication so you can login locally without a password.
Install it from apt:
sudo apt install postgresql
Note which version of Postgres you have installed. For me it is 13.
Now try to connect with:
If that doesn't work it's because by default the only user account is "postgres". It's a good idea to make a separate user for our purposes. By matching the Postgres username to your system username we can do "peer authentication" which means no password is required. Let's do that now.
sudo -u postgres psql
Now you are in the postgres shell:
CREATE USER yoursystemname WITH CREATEDB; CREATE DATABASE yoursystemname; \du
Now quit out of that and test you can login as your username by simply typing:
Now you may create databases for your apps at your leisure just by
psql and running
psql CREATE DATABASE my_app;