Search code examples
postgresqlpsqlpostgresql-12

How do I connect to database with postgresql version 12 using psql?


I want to connect to my newly created database called "test" in psql, I have seen a command like this:

Connection
  \c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
                         connect to new database (currently "postgres")

What does that mean?

I tried to write:

  \c {test|- postgres|- localhost|- 5432|- | conninfo}

but got error:

invalid integer value "5432|-" for connection option "port"

What should I do?


Solution

  • Did you try

    \c postgresql://user@localhost/test

    Or

    \c "host=localhost port=5432 dbname=test connect_timeout=10"

    Source