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

\connect DBNAME

or in short:

\c DBNAME

Note that it is not possible to switch the current database via an SQL command, like you asked.

MySQL's USE DatabaseName is named somewhat confusingly, because what MySQL calls a "database" is more similar to what other systems (like Oracle or PostgreSQL) call a "schema" (and PostgreSQL also lets you access multiple schemas from a single SQL session). To quote the official documentation:

Users coming from an Oracle Database background may find that the MySQL meaning of a database is closer to what Oracle Database calls a schema.

Answer from Will Hartung on Stack Overflow
🌐
Liquid Web
liquidweb.com › home › listing and switching databases in postgresql
List of Databases in PostgreSQL: How to Switch and Navigate | Liquid Web
January 15, 2026 - Step 4: Switching Between Databases in PostgreSQL Switching between databases is another way of saying you are closing one connection and opening another.
Discussions

PSQL - change default database from postgres to another database
You can set those parameters as environment variables in your shell. In bash on MacOS and Linux, for example: $ export PGDATABASE=mydata $ export PGUSER=myuser $ psql Here's the list: https://www.postgresql.org/docs/13/libpq-envars.html More on reddit.com
🌐 r/PostgreSQL
4
7
January 8, 2022
plpgsql - PostgreSQL: How to switch database inside cursor script - Database Administrators Stack Exchange
I want to write function for postgresql 10 to grant read-only access to on all databases for the specified user (considerably should be run from superuser) But I have difficulties in database swit... More on dba.stackexchange.com
🌐 dba.stackexchange.com
December 26, 2021
[PostgreSQL] Programmatically switch database but not \c
Just make another client variable More on reddit.com
🌐 r/SQL
2
0
February 16, 2025
postgresql - How to switch databases in postgres? - Stack Overflow
You got errors because every command in psql CLI have to be terminated with ";" So, just do \connect database_name; And then, select * from table_name; ... Technically PostgreSQL can't switch databases. More on stackoverflow.com
🌐 stackoverflow.com
🌐
CommandPrompt Inc.
commandprompt.com › education › postgresql-listing-and-switching-databases-in-psql
PostgreSQL: Listing and Switching Databases in psql — CommandPrompt Inc.
February 1, 2023 - Alternatively, you can use the “\connect” command followed by the database name to switch the databases in psql:
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
SQLines
sqlines.com › postgresql › pgadmin › change_database
PostgreSQL pgAdmin - How to Change Database in Query Tool - SQLines Tools
In PostgreSQL you can work with a single database only, and there is no a USE dbname statement to change the database, you have to close the current connection and then connect to another database.
🌐
EDUCBA
educba.com › home › data science › data science tutorials › postgresql tutorial › postgres switch database
Postgres Switch Database | Example of Postgres Switch Database
May 25, 2023 - ... Saying that database doesn’t exist. ... We can switch between the databases in PostgreSQL using \c or \connect metacommand, which creates a new connection and closes the current one.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
AlexHost
alexhost.com › home › faq › administration › listing and switching databases in postgresql: the complete technical guide
Listing and Switching Databases in PostgreSQL: The Complete Technical Guide
October 24, 2024 - Method 1: Exit and Reconnect from the Shell Inside psql, exit the current session: q Then connect to the target database: psql -U postgres -d target_database Method 2: Use c (Connect) Inside psql This is the most practical method for interactive ...
Find elsewhere
🌐
RunxBuild
runxbuild.com › home › blog › switching databases in psql: the three commands that actually move you
Switching Databases in psql: The Three Commands That Actually Move You
June 10, 2026 - A psql session is bound to one database at a time — there is no USE <db> SQL command in Postgres the way there is in MySQL — so the only way to move the connection to a different database is to reconnect.
🌐
Koenwoortman
koenwoortman.com › postgresql-switch-database-with-connect
Switch databases in PostgreSQL with `\connect`
April 12, 2021 - With good ol' MySQL I was used ... the Postgres terminal, you enter using the psql command, you can switch databases with \connect &LTdb_name> command or with the shorter \c &LTdb_name>....
🌐
Reddit
reddit.com › r/postgresql › psql - change default database from postgres to another database
r/PostgreSQL on Reddit: PSQL - change default database from postgres to another database
January 8, 2022 -

I know that it is possible since I changed the default database in the past but I forgot how I did. There is a file where one can change that, I think.

When you open the psql shell you have to type your own server, database, port etc or accept the default values by entering. And there is a way how to change these default values.

Can anybody help me please? :)

Thank you!

🌐
PostgreSQL
postgresql.org › message-id › v02140b77b1efa8a7d563@[207.152.64.133]
PostgreSQL: Switch database inside psql?
August 6, 1998 - I get an error message when I try createdb from the command line, but once I've done psql -u, I can do it, so I guess if I had to do this from some sort of Perl/sed/awk/??? script (none of which I could write anyway), I'd need to know how to convince createdb that I *am* a valid database-creator, by golly.
🌐
Codemia
codemia.io › knowledge-hub › path › how_to_switch_databases_in_psql
How to switch databases in psql?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Reddit
reddit.com › r/sql › [postgresql] programmatically switch database but not \c
r/SQL on Reddit: [PostgreSQL] Programmatically switch database but not \c
February 16, 2025 -
const client = new Client({database: 'postgres'});
await client.connect();
await client.query('CREATE DATABASE tester;');
await client.query("CREATE ROLE test_role WITH PASSWORD 'password' IN ROLE other_role LOGIN;");
await client.query('CREATE SCHEMA schemes AUTHORIZATION test_role;');

 

I'm trying to programmatically spin up a new testing database. Im working towards building experience with docker, and incorporating migrations, and as the code is currently written, I start up a client. create a db, user, and schema, then insert a bunch of tables. My issue is that I login to "postgres" DB, and the schema is created in "postgres" but I want it created in the new DB "tester". Besides logging out and back in, is there a way to programmatically switch databases, or create the schema in a database that user isn't currently logged into?

 

This is javascript, node, porsager/pg

🌐
Its Linux FOSS
itslinuxfoss.com › home › postgresql › how to switch a database in postgres
How to Switch a Database in Postgres – Its Linux FOSS
September 28, 2023 - To switch a database in Postgres, execute the “\c db_name” or “\connect db_name” command in psql. Or you can switch a database manually using pgAdmin.
🌐
w3resource
w3resource.com › PostgreSQL › snippets › use-database-command-postgresql.php
How to Use the equivalent of "USE database_name" in PostgreSQL
December 23, 2024 - To "switch" databases in PostgreSQL, you must either: Exit the current session and connect to a new database, or · Use \c database_name within the psql command-line interface.
🌐
tutorialpedia
tutorialpedia.org › blog › how-to-switch-databases-in-psql
How to Switch Databases in psql: MySQL 'use database_name' Equivalent Explained — tutorialpedia.org
This is intentional: PostgreSQL enforces stricter separation between databases for security and isolation. As a result, there’s no SQL command like use to switch databases mid-session. Instead, switching databases in psql (PostgreSQL’s interactive client) is handled via client-side meta-commands or by reconnecting to the server with the target database.
🌐
Kompulsa
kompulsa.com › home › postgresql tutorial: how to connect or switch to a database in postgresql
PostgreSQL Tutorial: How To Connect Or Switch To A Database In PostgreSQL
January 4, 2024 - How to switch to or enter a different database in PostgreSQL using the PostgreSQL command line interface.
🌐
Devgex
devgex.com › en › article › 00001614
Complete Guide to Database Switching and Management in PostgreSQL psql - DevGex
As mentioned in Reference Article ... native command-line tool, provides the most direct and efficient way to switch databases with its \c and \connect commands, especially suitable for automated scripts and advanced management tasks....