PG_ACTIVITY(1)
π pg_activity(1) π
okay bestie, welcome to pg_activity β the command line tool for PostgreSQL server activity monitoring, and yes she's that girl. this is a real manpage, pg_activity(1), and we're gonna get through all of it together. grab a strawberry π, hydrate, and let's go.
β¨ NAME β¨
pg_activity β Realtime PostgreSQL database server monitoring tool
πΈ SYNOPSIS πΈ
pg_activity [option..] [connection string]
π¦ DESCRIPTION π¦
Command line tool for PostgreSQL server activity monitoring. periodt.
pg_activity has ONE big requirement and she's not flexible about it: she must run on the same server as the instance, and as the user running the instance (or root), otherwise the CPU, MEM, READ and WRITE columns and the other system info just... won't show up. no cap. it's giving "run me right or don't run me at all" π
π THE HEADER π
The first line of the header shows PostgreSQL's version, the host name, the connection string, the refresh rate and the duration mode. iconic.
After that, the header splits into three groups: instance, worker processes, system. The info gets filtered according to the filter parameters when that's appropriate β that's what the (filtered) mentions below mean, so watch for them. Depending on the version you're on, some info might not be available at all, and in that case it gets replaced by a dash. sad but honest π
The instance group displays information about the PostgreSQL instance (or cluster). You can show or hide this whole group with the I key.
Global:
uptime: since when is the instance running;dbs size: total size of the databases (filtered);growth: growth in B/s of the databases (filtered);cache hit ratio: the percentage of page read from the PostgreSQL's cache since last snapshot (filtered).
Sessions:
total: session count (filtered) /max_connections;active: number of active sessions (filtered);idle: number of idle sessions (filtered);idle in txn: number of sessions who are in the idle in transaction state (filtered);idle in txn abrt: number of sessions who are in the idle in transaction aborted state (filtered);waiting: number of sessions that are waiting for a lock (filtered).
Activity:
tps: transaction per second (sum of commit & rollback for all databases / time elapsed since last snapshot) (filtered);insert/s: number of inserts per second (filtered);updates/s: number of updates per second (filtered);delete/s: number of deletes per second (filtered);temp files: number of temporary files created on the instance;temp size: total temporary file size on the instance.
The worker processes group displays information about background workers, autovacuum processes, wal senders and wal receivers. It also gives you the tea on replication slots π«. Heads up tho: except for the autovacuum workers count, most of this info is not related to a specific database, so their values will be zero when the data is filtered. not a bug, just how she is.
Worker processes:
total: total worker count / maximum number of worker slots, parallel workers and logical replication workers are taken from this amount (filtered);logical workers: logical replication worker count / maximum number of logical replication workers (filtered);parallel workers: parallel worker count for maintenance & queries / maximum number of parallel workers (filtered).
Other processes & information:
autovacuum workers: number of autovacuum worker in action / maximum number of autovacuum workers (filtered);wal senders: number of wal senders / maximum number of wal senders processes (filtered);wal receivers: number of wal receivers / maximum number of wal receiver processes (filtered);repl. slots: number of replication slots / maximum number of replication slots (filtered).
And the last group is all about the system:
Mem.: total / free / used and buff+cached memory with the related percentages;Swap: total / free / used swap;IO: the number of IO per second, current Read and Write throughput (aggregated data gathered with thepsutillibrary);Load: CPU load for the last 1, 5, 15 minutes;
π THE RUNNING QUERIES PANEL π
This panel shows all running queries, transactions or backends (depending on the DURATION_MODE setting) which have lasted for more than min duration seconds. she's picky about duration, we respect it. It displays:
PID: process id of the backend which executes the query;XMIN: xmin horizon of the backend;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 socket connection;CPU%: percentage of CPU used by the backend as reported by thepsutillibrary;MEM%: percentage of memory used by the backend as reported by thepsutillibrary;READ/s: read thruput as reported by thepsutillibrary;WRITE/s: write thruput as reported by thepsutillibrary;TIME: time since the beginning of the query / transaction / backend start depending on theDURATION_MODEcurrently 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 thepsutillibrary;state: state of the backend;Query: the query.
π THE WAITING QUERIES PANEL π
The waiting queries view displays queries that are waiting for a lock. (the drama. the tension.) It shows:
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 socket 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 theDURATION_MODEsetting;state: the state of the transaction;Query: the query.
π THE BLOCKING QUERIES PANEL π
The blocking queries view displays the queries that lock an object which is required by another session. yes, she's the problem π. 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 socket 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 theDURATION_MODEsetting;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 β
π§ CONFIGURATION π§
-P PROFILE,--profile=PROFILEβ Configuration profile matching aPROFILE.conffile in${XDG_CONFIG_HOME:~/.config}/pg_activity/or/etc/pg_activity/, or a built-in profile.
π₯ OPTIONS π₯
--blocksize=BLOCKSIZEβ Filesystem blocksize (default:4096).--rdsβ Enable support for AWS RDS (implies--no-tempfilesand filters out therdsadmindatabase from space calculation).--output=FILEPATHβ Store running queries as CSV.--db-size,--no-db-sizeβ Enable/disable total size of DB.--tempfiles,--no-tempfilesβ Enable/disable tempfile count and size.--walreceiver,--no-walreceiverβ Enable/disable walreceiver checks.-w,--wrap-queryβ Wrap query column instead of truncating.--min-duration=SECONDSβ Don't display queries with smaller than specified duration (in seconds).--filter=FIELD:REGEXβ Filter activities with a (case insensitive) regular expression applied on selected fields. Known fields are:dbname.
Note: It's possible to filter out a database with negative lookahead, eg: '^(?!database_name)'
--helpβ Show this help message and exit.--versionβ Show program's version number and exit.
π«Ά CONNECTION 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.
πΈ PROCESS DISPLAY OPTIONS πΈ
--pid,--no-pidβ Enable/disablePID.--xmin,--no-xminβ Enable/disableXMIN.--database,--no-databaseβ Enable/disableDATABASE.--user,--no-userβ Enable/disableUSER.--client,--no-clientβ Enable/disableCLIENT.--cpu,--no-cpuβ Enable/disableCPU%.--mem,--no-memβ Enable/disableMEM%.--read,--no-readβ Enable/disableREAD/s.--write,--no-writeβ Enable/disableWRITE/s.--time,--no-timeβ Enable/disableTIME+.--wait,--no-waitβ Enable/disableW.--app-name,--no-app-nameβ Enable/disableAPP.
π HEADER DISPLAY OPTIONS π
--no-inst-infoβ Hide instance information.--no-sys-infoβ Hide system information.--no-proc-infoβ Hide workers process information.
π OTHER DISPLAY OPTIONS π
--refreshβ Change the refresh rate, allowed values are:0.5,1,2,3,4,5(in seconds) (default:2).
π ENVIRONMENT VARIABLES π
All the environment variables supported by libpq (PostgreSQL's query protocol) are supported by pg_activity. all of them. she's generous like that π
See: https://www.postgresql.org/docs/current/libpq-envars.html
β¨ INTERACTIVE COMMANDS β¨
rβ Sort byREAD/s, descending.wβ Sort byWRITE/s, descending.cβ Sort byCPU%, descending.mβ Sort byMEM%, descending.tβ Sort byTIME+, descending.yβ Copy focused query to clipboard.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.PAGE UPβ Move the cursor to the first line.PAGE DOWNβ Move the cursor to the last line.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.
π MISSING DATA IN THE UI? π
okay bestie, real talk β if your UI is looking a lil sparse, it's probably not a bug, it's a permissions thing. here's the tea β
pg_activity is best used with a user owning the SUPERUSER privilege. Ordinary users can only see all the information about their own sessions (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null or not picked by pg_activity. It will impact both the information gathered in the HEADER section and the ACTIVITY PANEL. no cap, that's just how it is π
If a user doesn't have the CONNECT privilege on a database the pg_database_size() function will fail and pg_activity will crash. The --no-db-size option can be used in this case. This situation is frequent for cloud database where the service provider has created a service database with a restricted access. (cloud providers stay doing the most, fr fr π)
Some settings are visible only to superusers or members of pg_read_all_settings such as the data_directory guc. If the user cannot read this parameter or access the pid file in the PGDATA directory, the system information HEADER group will not be displayed. The %CPU, %MEM, Read/s and Write/s columns will also be missing from the ACTIVITY PANEL. gone. vanished. not invited to the party π
On some OS like MacOS, psutil's io_counters() is not implemented. The effects are the same as those described when data_directory is not readable. π
pg_activity needs to access the pgsql_tmp directory stored in all tablespaces in order to compute the number and size of the temporary files. This requires the usage of the pg_ls_tmpdir() function (or pg_ls_dir() and pg_stats_file() for versions older than PostgreSQL 12). The user needs to own the SUPERUSER privilege, be a member of pg_read_server_files or have EXECUTE rights on the function to fetch the information. When the number of tempfiles grows a lot, the query might also timeout. The first failure to access this data will disable tempfile statistics. The feature can be disabled with --no-tempfiles. π
Aurora doesn't provide thepg_stat_get_wal_receiver()function. Therefore there is no wal receiver data in the process & informationHEADERgroup. The first failure to access this data might be logged by the PostgreSQL, the following checks will be skipped. Wal receiver checks can be completely disabled with--no-walreceiver.
Finally, some information is not available in older version of PostgreSQL, the fields will therefore be empty. it's giving "old software, old problems" π¦
β¨ EXAMPLES β¨
okay here's how the girlies actually run it π«Ά
Password via env var, connect as pgadmin on localhost, and skip the client info:
PGPASSWORD='mypassword' pg_activity -U pgadmin -h 127.0.0.1 --no-client
Connect over the local unix socket:
pg_activity -h /var/run/postgresql
Hit a remote-ish host on a custom port with a specific db and user:
pg_activity -h myserver -p 5433 -d nagios -U nagios
and that's the whole page, bestie!! you ate that π β¨ go watch your server, she's serving main character energy and you've got the receipts π
this was pg_activity version 3.6.2, dated 2026-05-12 β the PG...Y(1) manual page, if you're keeping track π. now go forth and monitor, mwah ππ
π¦ where this page comes from
- fedora 43: pg_activity 3.6.2-1.fc43 Β· PostgreSQL
- fedora 44: pg_activity 3.6.2-1.fc44 Β· PostgreSQL
- ubuntu stonking: pg-activity 3.6.2-1 Β· PostgreSQL_Dalibo
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms