Search code examples
postgresqlarchlinuxcreateuser

createuser: could not connect to database postgres: could not connect to server: No such file or directory


I installed on using this command:

sudo pacman -S postgresql

And it installed OK. But when I want to create a new user, like this:

sudo -iu postgres
[postgres@amirashabani ~]$ createuser amirashabani

I receive this error:

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

How can I fix this?


Solution

  • The problem was that I forgot to start and enable the service, which was mentioned in the ArchWiki:

    Finally, start and enable the postgresql.service.

    After doing this:

    systemctl start postgresql.service
    systemctl enable postgresql.service 
    

    Everything worked fine.