Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to switch database using PostgreSQL

By Flavio Copes

Learn how to switch the active database inside the psql tool in PostgreSQL using the connect command (or its c shortcut) to reconnect to another database.

~~~

Inside psql, you always have one active database, where you are “into”. By default it’s the one you connect to in the first place. When you run:

psql postgres

you’ll connect to the postgres database.

To switch database, use the \connect command, or \c:

Switch database in PostgreSQL

PostgreSQL will close the connection to the previous database you were connected to, and will connect to the new one you specified.

~~~

Related posts about database: