PG_ACTIVITY(1)

NAME
pg_activity - Realtime PostgreSQL database server monitoring tool

SYNOPSIS
pg_activity [option..] [connection string]

DESCRIPTION
Command line tool for PostgreSQL server activity monitoring.

pg_activity must run on the same server as the instance and as the user running the instance (or root) to show CPU, MEM, READ or WRITE columns and other system information.

  THE HEADER
The first line of the header displays PostgreSQL's version, the host name, the connection string and the refresh rate.

The rest of the header displays the following information:

- Size: size of the database you are connected to - Growth in B/s;
- Mem.: percentage of memory used - memory used / memory available;
- Swap: percentage of  swap used - swap used / swap available;
- Load: CPU load;
- TPS: transaction per second (sum of commit & rollback for all databases / time elapsed since last snap);
- IO Max: the number of IO per second (aggregated data gathered with the psutil library);
- Read: current Read throughput (aggregated data gathered with the psutil library);
- Write: current Write throughput (aggregated data gathered with the psutil library);
- Active connections: number of active connections;
- Duration mode: query, transaction or backend.

  THE RUNNING QUERIES PANEL
The running queries panel shows all running queries, transactions or backends (depending on the DURATION_MODE setting) which have lasted for more than min duration seconds. It displays the following information:

- PID: process id of the backend which executes the query;
- DATABASE: database specified in the connection string;
- APP: application name specified in the connection string;
- USER: user name specified in the connection string;
- CLIENT: client address or "local" in case of linux socker connection;
- CPU%: percentage of CPU used by the backend as reported by the psutil library;
- MEM%: percentage of memory used by the backend as reported by the psutil library;
- READ/s:  read thruput as reported by the psutil library;
- WRITE/s: write thruput as reported by the psutil library;
- TIME: time since the beginning of the query / transaction / backend start depending on the DURATION_MODE currently in use;
- Waiting: for PostgreSQL 9.6+: a specific wait event or nothing. Otherwise, a boolean indicating if we are waiting for a Lock;
- IOW: boolean indicating that the process is waiting for IO as reported by the psutil library;
- state: state of the backend;
- Query: the query.

  THE WAITING QUERIES PANNEL
The waiting queries view displays queries that are wainting for a lock. It shows the following information:

- PID: process id of the backend which executes the query;
- DATABASE: database specified in the connection string;
- APP: application name specified in the connection string;
- USER: user name specified in the connection string;
- CLIENT: client address or "local" in case of linux socker connection;
- RELATION: the name of the relation being locked if applicable;
- TYPE: the type of lock;
- MODE: the mode of the lock;
- TIME+: the duration of the query, transaction or session depending on the DURATION_MODE setting;
- state: the state of the transaction;
- Query: the query.

  THE BLOCKING QUERIES PANNEL
The blocking queries view displays the queries that lock an object which is requiered by another session. It shows following information:

- PID: process id of the backend which executes the query;
- DATABASE: database specified in the connection string;
- APP: application name specified in the connection string;
- USER: user name specified in the connection string;
- CLIENT: client address or "local" in case of linux socker connection;
- RELATION: the name of the relation being locked if applicable;
- TYPE: the type of lock;
- MODE: the mode of the lock;
- TIME+: the duration of the query, transaction or session depending on the DURATION_MODE setting;
- Waiting: for PostgreSQL 9.6+: a specific wait event or nothing. Otherwise, a boolean indicating if we are waiting for a Lock;
- state: the state of the transaction;
- Query: the query.

COMMAND-LINE OPTIONS

-U USERNAME, --username=USERNAME
            Database user name.

-p PORT, --port=PORT
            Database server port.

-h HOSTNAME, --host=HOSTNAME
            Database server host or socket directory.

-d DBNAME, --dbname=DBNAME
        Database name to connect to.

--blocksize=BLOCKSIZE
            Filesystem blocksize (default: 4096).

--rds
            Enable support for AWS RDS.

--output=FILEPATH
            Store running queries as CSV.

--no-db-size
            Skip total size of DB.

-w DISPLAY_MODE, --query-display-mode=DISPLAY_MODE
            Queries display mode. Values: 1-TRUNCATED, 2-FULL(default), 3-INDENTED

--duration-mode=DURATION_MODE
            Duration mode. Values: 1-QUERY(default), 2-TRANSACTION, 3-BACKEND

--min-duration=SECONDS
            Don't display queries with smaller than specified duration (in seconds).

--help
            Show this help message and exit.

--version
            Show program's version number and exit.

ENVIRONMENT VARIABLES
    All the environnement variables supported by libpq (PostgreSQL's query protocol) are supported by pg_activity.

    See: https://www.postgresql.org/docs/current/libpq-envars.html

DISPLAY OPTIONS

--no-pid
            Disable PID.

--no-database
            Disable DATABASE.

--no-user
            Disable USER.

--no-client
            Disable CLIENT.

--no-cpu
            Disable CPU%.

--no-mem
            Disable MEM%.

--no-read
            Disable READ/s.

--no-write
            Disable WRITE/s.

--no-time
            Disable TIME+.

--no-wait
            Disable W.

--no-app-name
            Disable App.

INTERACTIVE COMMANDS

r     Sort by READ/s, descending.
w     Sort by WRITE/s, descending.
c     Sort by CPU%, descending.
m     Sort by MEM%, descending.
t     Sort by TIME+, descending.
T     Change duration mode: query, transaction, backend
Space Pause on/off.
v     Change queries display mode: full, truncated, indented
UP / DOWN Scroll process list.
k / j Scroll process list.
q     Quit
+     Increase refresh time. Maximum value: 3s
-     Decrease refresh time. Minimum Value: 1s
F1/1  Running queries monitoring.
F2/2  Waiting queries monitoring.
F3/3  Blocking queries monitoring.
h     Help page.
R     Refresh.
D     Refresh database size.

NAVIGATION MODE

UP / k    Move up the cursor.
DOWN / j  Move down the cursor.
K     Terminate the current backend/tagged backends.
C     Cancel the current backend/tagged backends.
Space Tag or untag the process.
q     Quit.
Other Back to activity.

EXAMPLES
PGPASSWORD='mypassword' pg_activity -U pgadmin -h 127.0.0.1 --no-client

pg_activity -h /var/run/postgresql

pg_activity -h myserver -p 5433 -d nagios -U nagios