pg_statsinfo library
pg_statsinfo library has the following functionalities.
- Registers custom GUC parameters and adjust required parameters when it is loaded.
- Spawns a pg_statsinfo daemon when it is loaded.
- Provides functions to gather internal activity information used by pg_statsinfo daemon.
Such information is hardly acquirable only with statistics views.
pg_statsinfo daemon
pg_statsinfo daemon consists of Logger, Collector, and Writer.
Logger
Logger parses CSV logs written by PostgreSQL server and receives messages from Collector and Writer, and does the following items:
- Redirects CSV logs and internal error messages into textlog and syslog according to error levels of log records.
- Extracts log records about checkpoints, autovacuum, shutdown, reload and snapshot requests from CSV logs and handles them.
- Monitors postmaster process and shutdown self if the postmaster is missing.
Collector
Collector connects to the monitored instance, and does the following items:
- Installs "statsinfo" schema if not installed.
- Samples activity information for snapshots periodically.
It gathers numbers of processes running or idle, and long transactions.
The sampling is polling-based statistics collection because such kinds of information is not in statistics views.
- Takes snapshots and send them to Writer.
Writer
Writer receives checkpoints and autovacuum activities from Logger and snapshots from Collector, and does the following items:
- Connects to the repository, and installs "statsrepot" schema if not installed.
- Store snapshots, checkpoints, and autovacuum records to the repository.
- Run an alert function just after the storing, and send ALERT messages to Logger if the function returns them.