Setting up PostgreSQL for the first time
I’m using WSL2 with Ubuntu 26.04 at $DAYJOB and I need to test something that will be using a PostgreSQL database.
Since it has been a while, and for future reference, I dump here what I’m doing.
I tried to do it with Docker using the WSL integration, but it seems to be fiddly and not very reliable: despite setting up Docker Desktop to use
the WSL2 integration, I get a constant docker: command not found or equivalent version. I could not be bothered to fix it after trying for 5 min.
I went to the good old package manager.
I followed the official instructions to set up any version of PostgreSQL in Ubuntu, as I needed an older version that the one included in Ubuntu 26.04.
Next step is to create a database, but for that you first need a user! Unless you want to want to get the following error when running psql:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "USER" does not exist
Let’s go then to create a user. But this assumes you are already inside psql…
Let’s switch users:
sudo su - postgres
psql
Now we can do whatever we want, we are superusers! Inside psql, do:
CREATE USER name LOGIN CREATEDB;
ALTER USER name PASSWORD 'pass';
To go out, do EXIT; or Ctrl+D.
We can now go back to our normal user (do logout). Within the postgres user, do Ctrl+D. Let’s follow the quickstart now:
createdb mydb
psql mydb
Let’s test what we have:
select version();
Now, we should be set to be able to break things.