How to find the name of the current database from within PostgreSQL?

In this article, we will see how to find the name of the current database from within PostgreSQL.

We can get the current database in PostgreSQL by using below commands

select current_database(); \c \conninfo SELECT * FROM current_catalog;

Examples:

1. Get the current database by using current_database():

select current_database();

2. Get the current database by using \c

\c

3. Get the current database by using \conninfo

\conninfo

4. Get the current database by using SELECT * FROM current_catalog;:

SELECT * FROM current_catalog;

How to find the name of the current database from within PostgreSQL?