Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch databases in psql?

In MySQL, I used use database_name;

What's the psql equivalent?

like image 435
Blankman Avatar asked Oct 16 '10 17:10

Blankman


People also ask

How do I switch databases in PostgreSQL?

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> .

How do you switch databases?

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.

How do I switch databases in Linux?

You can just enter use [dbName] to switch between databases without reentering your password.


2 Answers

In PostgreSQL, you can use the \connect meta-command of the client tool psql:

\connect DBNAME 

or in short:

\c DBNAME 
like image 91
Will Hartung Avatar answered Nov 04 '22 07:11

Will Hartung


You can connect to a database with \c <database> or \connect <database>.

like image 24
meagar Avatar answered Nov 04 '22 09:11

meagar