To connect to Postgres, you first need to give the default Postgres admin user postgres a password using sudo passwd postgres. Then run the psql command with the postgres identity using sudo -u postgres.

sudo passwd postgres
sudo -u postgres psql

Create a user

If you don’t want to use the default postgres admin user. You can create your own admin user by following the steps below.

sudo -u postgres createuser --interactive
# Enter name of role to add: windsuzu
# Shall the new role be a superuser? (y/n) y

Then edit pg_hba.conf, which is located in /etc/postgresql/<version>/main.

sudo vim /etc/postgresql/16/main/pg_hba.conf

Scroll to the bottom of the file and change all the peer to trust.

local   all             postgres                                trust
local   all             all                                     trust

References