How to See 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          |
+------------------+

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.