In MySQL, I used use database_name;
What's the psql
equivalent?
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> .
Type "help" for help. Switching between databases is another way of saying you are closing one connection and opening another. When you need to change between databases, you'll use the “connect” command, which is conveniently shortened to \c, followed by the database name.
You can just enter use [dbName] to switch between databases without reentering your password.
In PostgreSQL, you can use the \connect
meta-command of the client tool psql:
\connect DBNAME
or in short:
\c DBNAME
You can connect to a database with \c <database>
or \connect <database>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With