pg_stat_tcpinfo
pg_stat_tcpinfo : Linux TCP connection statistics, latency and retransmissions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6480 | pg_stat_tcpinfo | pg_stat_tcpinfo | 1.1 |
STAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgnodemx system_stats pg_stat_kcache pg_statvfs |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 1.1 |
18 17 16 15 14 | pg_stat_tcpinfo |
- |
| RPM | PGDG | 1.1 |
18 17 16 15 14 | pg_stat_tcpinfo_$v |
- |
| DEB | PGDG | 1.1 |
18 17 16 15 14 | postgresql-$v-pg-stat-tcpinfo |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| el8.aarch64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| el9.x86_64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| el9.aarch64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| el10.x86_64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| el10.aarch64 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 | PIGSTY 1.1 |
| d12.x86_64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| d12.aarch64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| d13.x86_64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| d13.aarch64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u22.x86_64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u22.aarch64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u24.x86_64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u24.aarch64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u26.x86_64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
| u26.aarch64 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 | PGDG 1.1 |
Source
github.com/jakubwartakEDB/pg_stat_tcpinfo
pg_stat_tcpinfo-1.1.tar.gz
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
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.