List Databases in SQL: MySQL, MariaDB, PostgreSQL & More
Compare how MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, and Oracle list databases, schemas, or attached files, including visibility limits.
There is no universal command for listing databases. MySQL and MariaDB treat “database” and “schema” as synonyms, PostgreSQL lists databases within a cluster, SQLite reports databases attached to the current connection, and Oracle distinguishes schemas from pluggable databases.
Quick reference
| Engine | Command or view | What it lists |
|---|---|---|
| MySQL / MariaDB | SHOW DATABASES; |
Databases visible to the current account; SHOW SCHEMAS is a synonym. |
| PostgreSQL | \l in psql, or pg_database |
Databases in the PostgreSQL cluster. |
| SQL Server | sys.databases |
Databases visible to the current login, with Azure SQL Database scope depending on the current database context. |
| SQLite | PRAGMA database_list; |
main, temp, and databases attached to the current connection. |
| Oracle | ALL_USERS, DBA_PDBS |
Visible schemas/users, or pluggable databases when queried from a CDB root with suitable privileges. |
MySQL and MariaDB
Use SHOW DATABASES to list database names visible to the account:
SHOW DATABASES;
SHOW SCHEMAS is a synonym. Add a pattern when you need to find a matching name:
SHOW DATABASES LIKE 'app%';
An account normally sees databases on which it has privileges; the global SHOW DATABASES privilege exposes all names, subject to MySQL partial revokes. MariaDB has a similar privilege rule, and --skip-show-database can require the global privilege to run the statement at all. An empty result therefore does not always mean the database is absent. See MySQL’s SHOW DATABASES reference and MariaDB’s SHOW DATABASES reference. For MySQL command-line examples, see List Databases in MySQL.
PostgreSQL
In the psql client, use its \l meta-command to list databases in the cluster:
\l
To query the catalog from SQL, read pg_database:
SELECT datname
FROM pg_catalog.pg_database
ORDER BY datname;
\l is a psql command, not SQL. PostgreSQL databases are separate; connect to the intended database before querying its schemas and tables. See PostgreSQL’s psql manual and pg_database catalog reference. For more examples, see List Databases in PostgreSQL.
From a shell, psql --list (or psql -l) prints the database list and exits:
psql -U app_user --list
By default, psql connects to the postgres database to perform this operation. If it is unavailable, pass another existing database with --dbname. See the PostgreSQL psql manual.
SQL Server
On SQL Server, query sys.databases:
SELECT name
FROM sys.databases
ORDER BY name;
Results depend on permissions and metadata visibility; for example, an offline database may be hidden from a low-privilege login. In Azure SQL Database, run the query in master to list databases on the logical server. From a user database, sys.databases shows only that database and master. See Microsoft’s sys.databases reference and metadata visibility guidance.
SQLite
SQLite does not have a server-wide database catalog. PRAGMA database_list shows the database files attached to the current connection:
PRAGMA database_list;
The result includes main and temp when present, plus databases opened with ATTACH DATABASE. It does not search the filesystem for other database files. See SQLite’s database_list pragma.
Oracle
An Oracle schema belongs to a user inside a database; it is not a separate database. Use ALL_USERS to list users visible to the current account:
SELECT username
FROM all_users
ORDER BY username;
To display the name of the database to which the session is connected:
SELECT SYS_CONTEXT('USERENV', 'DB_NAME') AS database_name
FROM dual;
In a multitenant container database, query DBA_PDBS from the CDB root to list its pluggable databases; the view’s scope depends on the current container and the account’s privileges. See Oracle’s ALL_USERS, SYS_CONTEXT, and DBA_PDBS references.
After selecting a database, see how to list its tables across SQL databases. For other syntax and behavior differences, browse the cross-database SQL comparison guides.