Search code examples
postgresqlmacospsqlapple-m1

Postgres CLI error: database "dev" does not exist on trying to run any psql command


I install postgres version 14 using homebrew.

brew install postgresql 

Whenever, I try to run psql command, I get the following error:

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: 
FATAL: database "dev" does not exist

Following are my system paths

/Users/dev/.nvm/versions/node/v15.14.0/bin:
/opt/homebrew/bin:
/opt/homebrew/sbin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/MacGPG2/bin:
/Library/Apple/usr/bin:

Solution

  • You must be using the 'dev' name in your connection string? Can you show us that? The default db in postgres is called postgres there is no dev database.

    When connecting to a fresh install of Postgres entering psql into the command line actually executes something like

    psql -d postgres -U postgres -p 5432 -h localhost
    

    Those are the default values so psql is fine.

    You/your application is entering something like:

    psql -d dev -U [user] -p [port] -h [host]