How to See Which PostgreSQL Database Is Currently Selected?

Check which PostgreSQL database is currently selected

You can find out which PostgreSQL database is currently selected by using either of the following:

SELECT current_catalog;
-- or
SELECT * FROM current_catalog;
SELECT current_database();
-- or
SELECT * FROM current_database();

Both of them are synonymous to each other and do the same thing. current_catalog() is considered the standard though, because databases are called "catalogs" in the SQL standard.

It will produce an output like the following:

+------------------+
| current_database |
+------------------+
| db_name          |
+------------------+

Hope you found this post useful. It was published . Please show your love and support by sharing this post.