How to get the name of the current database from within PostgreSQL?
The function current_database() returns the name of the current database:

 SELECT current_database();


It's an SQL function, so you must call it as part of an SQL statement. PostgreSQL doesn't support running functions as standalone queries, and has no CALL statement like some other SQL engines, so you just use SELECT to call a function.