pg_stat_tcpinfo
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_stat_tcpinfo | 1.1 | STAT | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 6480 | pg_stat_tcpinfo | No | Yes | No | Yes | No | Yes | - |
Linux >=4.18; procfs and NETLINK_INET_DIAG required. Monitoring roles can see all server-OS-user sockets. No preload or upstream 1.0-to-1.1 upgrade script. PG14-18; PGDG remains principal supplier; PGSTY 1.1 batch supplements published.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.1 | 1817161514 | pg_stat_tcpinfo | - |
| RPM | PGDG | 1.1 | 1817161514 | pg_stat_tcpinfo_$v | - |
| DEB | PGDG | 1.1 | 1817161514 | postgresql-$v-pg-stat-tcpinfo | - |
Build
You can build the RPM / DEB packages for pg_stat_tcpinfo using pig build:
Install
You can install pg_stat_tcpinfo directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
pg_stat_tcpinfo 1.1 exposes Linux TCP socket statistics through SQL. It helps investigate slow client connections, replication links and foreign-server traffic using round-trip time, retransmissions, congestion control and queue sizes, without shell access to the host.
It requires Linux 4.18 or later, access to /proc, and the NETLINK_INET_DIAG interface. Install as a superuser; no preload or server restart is required.
Core Workflow
Objects and Metrics
The pg_stat_tcpinfo view calls pg_stat_get_tcpinfo(). Each row contains a process and OS user ID, local and remote addresses and ports, connection state, receive and send queues, and a tcpinfo JSONB object. IPv4 and IPv6 sockets are supported. The rtt field is expressed in milliseconds; total_retrans is the cumulative retransmission counter.
The view includes every TCP socket owned by the server’s OS user, including sockets from other database clusters or programs running under that account. Joining on the backend PID narrows the result to connections visible in the current cluster. Unix-domain connections are not TCP sockets and do not appear; TIME-WAIT sockets have no owner and are omitted. Metrics unavailable on an older kernel may be null.
Permissions
The installation revokes public execution of the function and grants function and view access to pg_read_all_stats; pg_monitor inherits that access. Ordinary application roles cannot read the metrics by default. Additional grants expose all sockets owned by the server OS user, not only the caller’s database connections.
Operational Boundaries
Each call scans process descriptors and queries the kernel; it is an on-demand observation, not a historical sampler. Container PID and network namespaces and procfs restrictions determine which sockets and PIDs are visible. Choose a sampling interval appropriate to the number of processes and connections.
Use a package built for the server’s PostgreSQL major version. The 1.1 release includes fresh-install SQL for versions 1.0 and 1.1 but no upgrade script between them, so an existing 1.0 installation has no upstream-provided ALTER EXTENSION pg_stat_tcpinfo UPDATE path.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)