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
🌐
TutorialsPoint
tutorialspoint.com › postgresql › postgresql_select_database.htm
PostgreSQL - SELECT Database
postgres=# \c testdb; psql (9.2.4) Type "help" for help. You are now connected to database "testdb" as user "postgres". testdb=# You can select your database from the command prompt itself at the time when you login to your database.
🌐
PostgreSQL
postgresql.org › docs › current › sql-select.html
PostgreSQL: Documentation: 18: SELECT
May 14, 2026 - July 16, 2026: PostgreSQL 19 Beta 2 Released! ... Unsupported versions: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1 · SELECT, TABLE, WITH — retrieve rows from a table or view
🌐
Neon
neon.com › postgresql › administration › show-databases
PostgreSQL Show Databases
Use \l or \l+ in psql to show all databases in a PostgreSQL database server. Use the SELECT statement to query data from the pg_database to retrieve all the database names in a PostgreSQL database server.
🌐
Chat2DB
chat2db.ai › resources › blog › how-to-select-database-in-psql
How to Select a Database in PostgreSQL (psql) – Chat2DB
March 25, 2025 - Becoming proficient with the psql interface is essential for efficient database selection. Here are some key commands to master: Launching psql: Connect to your PostgreSQL server using the command:
🌐
PostgreSQL
postgresql.org › docs › current › tutorial-accessdb.html
PostgreSQL: Documentation: 18: 1.4. Accessing a Database
May 14, 2026 - mydb=> SELECT version(); version -------------------------------------------------------------------​----------------------- PostgreSQL 18.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit (1 row) mydb=> SELECT current_date; date ------------ 2016-01-07 (1 row) mydb=> SELECT 2 + 2; ?column?
Find elsewhere
🌐
W3Schools
w3schools.com › postgresql › postgresql_select.php
PostgreSQL - Select Data
To retrieve data from a database, we use the SELECT statement. By specifying the column names, we can choose which columns to select:
🌐
Atlassian
atlassian.com › data › admin › how to list databases and tables in postgresql using psql
How to List databases and tables in PostgreSQL using psql
1postgres=# \l 2 List of databases 3 Name | Owner | Encoding | Collate | Ctype | Access privileges 4-----------+----------+----------+-------------+-------------+----------------------- 5 postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | 6 sales | ubuntu | UTF8 | en_US.UTF-8 | en_US.UTF-8 | 7 template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + 8 | | | | | postgres=CTc/postgres 9 template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + 10 | | | | | postgres=CTc/postgres 11(4 rows)
🌐
PostgreSQL
postgresql.org › message-id › 13676.9322.689673.963792@gate.wadk-berlin.de
PostgreSQL: SELECT across two databases
May 27, 1998 - when I have two databases say db1 and db2 can there be a select statement which accesses both databases eg. select * from db1.t1,db2.t2 (which is illegal syntax in postgresql but legal in informix)
🌐
PostgreSQL
postgresql.org › docs › current › tutorial-select.html
PostgreSQL: Documentation: 18: 2.5. Querying a Table
May 14, 2026 - ... Unsupported versions: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 · To retrieve data from a table, the table is queried. An SQL SELECT statement is used to do this.
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-select
PostgreSQL - SELECT - GeeksforGeeks
June 11, 2026 - SELECT statement is the primary command used to query data in PostgreSQL. It enables users to retrieve records from one or more tables, apply filtering conditions, sort and group results, limit returned rows, and generate summary information ...
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-show-databases
PostgreSQL - Show Databases - GeeksforGeeks
2 weeks ago - Now use the below command to list all databases using a superuser such as postgres: ... To list all databases by querying the pg_database system catalog using the SELECT statement.
🌐
PostgreSQL
postgresql.org › docs › current › app-psql.html
PostgreSQL: Documentation: 18: psql
May 14, 2026 - When this option is used, psql will connect to the database postgres, unless a different database is named on the command line (option -d or non-option argument, possibly via a service entry, but not via an environment variable).
🌐
Bytebase
bytebase.com › references › postgresql how-to guides › top psql commands with examples
Top psql commands with examples | PostgreSQL How-to Guide
You can also filter the results ... to the database mydb, use the following query: postgres-# SELECT * FROM pg_stat_activity WHERE datname = 'mydb' AND state = 'active';...
🌐
CommandPrompt Inc.
commandprompt.com › education › postgresql-listing-and-switching-databases-in-psql
PostgreSQL: Listing and Switching Databases in psql — CommandPrompt Inc.
February 1, 2023 - The “\l” command retrieves seven databases, three of which(i.e., postgres, template0, and template1) are default databases, while the other four are user-defined databases. Alternatively, you can use the “\list” command to get the same ...
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
Vinchin
vinchin.com › home › database backup › how to select a database in postgresql using psql and gui tools?
How to Select a Database in PostgreSQL Using psql and GUI Tools? | Vinchin Backup
October 10, 2025 - To see which databases are available on your server instance, connect using psql (often as the default postgres user) then type the \l command at the prompt. This will list all accessible databases along with their owners and privileges.
🌐
CommandPrompt Inc.
commandprompt.com › education › how-to-selectaccess-a-database-in-postgresql
How to select/access a database in PostgreSQL — CommandPrompt Inc.
July 22, 2022 - Now, you are successfully entered into the PostgreSQL bin’s directory. ... - Here, in the above snippet, we utilized the “-h” option/argument to specify the host, “-p” argument to specify the port number, and “-U” to specify the user name. While “exampledb” is the database to be accessed. - Type the command, press the enter button, and provide the superuser password. - Consequently, the above-mentioned command will select the database named “exampledb”, owned by the user “Postgres”,available on the “localhost”, and has a default port number “5432”:
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
Drizzle ORM
orm.drizzle.team › docs › get-started-postgresql
Drizzle ORM - PostgreSQL
PlanetScale Postgres Neon Vercel Postgres Prisma Postgres Supabase Xata PGLite Nile Bun SQL Effect Postgres Netlify Database AWS Data API Postgres ... Manage schema Data types Indexes & Constraints Sequences Views Schemas Drizzle Relations Row-Level Security (RLS) Extensions · Migrations Overview generate migrate push pull export check up studio Custom migrations Migrations for teams Web and mobile drizzle.config.ts ... Access your data Query Select Insert Update Delete Filters Utils Joins Aliases Magic sql operator SQL comments
🌐
StrongDM
strongdm.com › blog › security
How to List All Databases in PostgreSQL (psql and More)
June 25, 2025 - After successful authentication, you’ll receive the “postgres=#” prompt. Use the "\l" command. If you want additional information on the description, tablespace, or size, you can use the "\l+" command.