List sessions / active connections in PostgreSQL database

PostgreSQL table contains a lot of useful information about database sessions.

Query

select pid as process_id, 
       usename as username, 
       datname as database_name, 
       client_addr as client_address, 
       application_name,
       backend_start,
       state,
       state_change
from pg_stat_activity;

Columns

  • process_id - process ID of this backend
  • username - name of the user logged into this backend
  • database_name - name of the database this backend is connected to
  • client_address - IP address of the client connected to this backend
  • application_name - name of the application that is connected to this backend
  • backend_start - time when this process was started. For client backends, this is the time the client connected to the server.
  • state - current overall state of this backend. Possible values are:
    • active
    • idle
    • idle in transaction
    • idle in transaction (aborted)
    • fastpath function call
    • disabled
  • state_change - time when the state was last changed

Rows

  • One row: represents one active connection
  • Scope of rows: all active connections

Sample results

You can see session list on our test server.

sample results

Using pgAdmin

In the Browser pane, select our database (1) and then click on the Dashboard tab (2). In the bottom of page there is Server Activity panel which contain all connected sessions (3).

sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.