Switch databases in PostgreSQL with `\connect`
April 12, 2021 ‐ 1 min read
With good ol' MySQL I was used to switch database with use <db_name>;
. Postgres has a different way to switch databases, you do so using one of its meta-commands. Once you are in the Postgres terminal, you enter using the psql
command, you can switch databases with \connect <db_name>
command or with the shorter \c <db_name>
.
postgres=# \c myproject
You are now connected to database "myproject" as user "postgres".
myproject=#
postgres=# \connect myproject
You are now connected to database "myproject" as user "postgres".
myproject=#
In order to list the available databases you use the \l
or \list
meta-command.