List databases on PostgreSQL instance

Query below lists databases on PostgresSQL instance.


select oid as database_id,
       datname as database_name,
       datallowconn as allow_connect,
       datconnlimit as connection_limit
from pg_database
order by oid;


  • database_id - databalase id, unique within an instance of PostgreSQL
  • database_name - database name
  • allow_connect - indicate if anybody can connect to database
  • connection_limit - shows maximum number of concurrent connections to database (-1 means no limit)


  • One row represents one database
  • Scope of rows: all databases on PostgreSQL instance, including system databases
  • Ordered by database id

Sample results

View of databases in pgAdmin. Blue rectangle shows databases.

There are no comments. Click here to write the first comment.