Hands-on Lab·PostgreSQL
PostgreSQL pg_stat_activity and Session Control
The first view anyone opens on a busy server - and the one that quietly lies to you. As a non-superuser it showed ten of eleven sessions as nothing but a pid.
Monitoring and Operations Guide 38 of 47 Intermediate
- OSUbuntu 26.04 LTS (resolute)
- PostgreSQL18.6-0ubuntu0.26.04.1
- Host2 core / 4 GB, 400,000-row test table
- TimeAbout 17 min
- Reviewed27 August 2026
Written against the versions above. `io worker` appears in `backend_type` from PostgreSQL 18, which introduced asynchronous I/O. On 17 and earlier you will see three fewer background processes here.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
Before you start
- A running cluster with the
appdbdatabase. - Shell access as a user who can
sudo -u postgres.
-
Look at every session on the server
-
Find out why most of it was blank
-
Watch a query while it runs
-
Cancel it
-
Spot a transaction holding on
-
Terminate it, and see the difference