Search code examples
postgresqlpsqlubuntu-20.04createuser

How do I solve this problem to use psql? | psql: error: FATAL: role "postgres" does not exist


I'm having trouble using PostgreSQL. I have recently installed this version (13+223.pgdg20.04+1) of postgresql package in ubuntu 20.04.

I'm trying to run psql command, but I get the following error:

psql: error: FATAL: role "my_username" does not exist

I have tried to create a new user with createuser me, but I get the following error:

createuser: error: could not connect to database template1: FATAL: role "my_username" does not exist

I have tried also forcing the postgres user with createuser me --username=postgres, but I get the following error:

createuser: error: could not connect to database template1: FATAL: Peer authentication failed for user "postgres"

How do I solve these problems to use PostgreSQL locally on my computer without these problems?

PD: I have reinstalled postgres and now I'm getting a different error while doing psql:

psql: error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


Solution

  • I'm not sure why I had a bad installation, but I have completely uninstalled postgres following this post:

    https://kb.objectrocket.com/postgresql/how-to-completely-uninstall-postgresql-757

    after that I have restarted my computer and installed posgres again following the proper instructions in:

    https://www.postgresql.org/download/linux/ubuntu/

    and now it looks like it works without problems