pg_profile
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_profile | 4.11 | STAT | BSD 2-Clause | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 6000 | pg_profile | No | Yes | No | Yes | No | No | - |
| Related | dblink plpgsql plprofiler pg_stat_kcache powa pg_stat_statements pg_show_plans pg_stat_monitor pg_qualstats pg_store_plans |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 4.11 | 1817161514 | pg_profile | dblink, plpgsql |
| RPM | PGDG | 4.11 | 1817161514 | pg_profile_$v | - |
| DEB | PIGSTY | 4.11 | 1817161514 | postgresql-$v-pg-profile | - |
Build
You can build the DEB packages for pg_profile using pig build:
pig build pkg pg_profile # build DEB packages
Install
You can install pg_profile directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_profile; # Install for current active PG version
pig ext install -y pg_profile -v 18 # PG 18
pig ext install -y pg_profile -v 17 # PG 17
pig ext install -y pg_profile -v 16 # PG 16
pig ext install -y pg_profile -v 15 # PG 15
pig ext install -y pg_profile -v 14 # PG 14
dnf install -y pg_profile_18 # PG 18
dnf install -y pg_profile_17 # PG 17
dnf install -y pg_profile_16 # PG 16
dnf install -y pg_profile_15 # PG 15
dnf install -y pg_profile_14 # PG 14
apt install -y postgresql-18-pg-profile # PG 18
apt install -y postgresql-17-pg-profile # PG 17
apt install -y postgresql-16-pg-profile # PG 16
apt install -y postgresql-15-pg-profile # PG 15
apt install -y postgresql-14-pg-profile # PG 14
Create Extension:
CREATE EXTENSION pg_profile CASCADE; -- requires: dblink, plpgsql
Usage
pg_profile: historical performance profiling tool for PostgreSQL
pg_profile collects periodic samples of PostgreSQL statistics and generates detailed historical performance reports. It depends on pg_stat_statements and optionally uses pg_stat_kcache and pg_wait_sampling for additional metrics.
Taking Samples
Samples must be taken periodically (e.g., via cron). Each sample captures the current state of statistics:
SELECT profile.take_sample();
Generating Reports
Build a report between two sample IDs to analyze performance during that interval:
-- Regular report between samples 1 and 2
SELECT profile.get_report(1, 2);
-- Differential report comparing two intervals
SELECT profile.get_diffreport(1, 2, 3, 4);
Managing Servers
pg_profile can collect statistics from remote clusters:
-- Define a remote server
SELECT profile.create_server('remote', 'host=remote_host dbname=postgres');
-- List defined servers
SELECT * FROM profile.show_servers();
-- Enable/disable a server
SELECT profile.enable_server('remote');
SELECT profile.disable_server('remote');
Baselines
Baselines protect sample ranges from automatic cleanup:
-- Create a baseline preserving samples 10 through 20
SELECT profile.create_baseline('incident_2024', 10, 20);
-- List baselines
SELECT * FROM profile.show_baselines();
-- Drop a baseline
SELECT profile.drop_baseline('incident_2024');
Retention
Control how long samples are kept:
-- Set retention to 7 days for the local server
SELECT profile.set_server_max_sample_age('local', 7);
Sample Information
-- Show available samples
SELECT * FROM profile.show_samples();
-- Show time spent taking samples (requires pg_profile.track_sample_timings = on)
SELECT * FROM v_sample_timings;
Recommended Settings
track_activities = on
track_counts = on
track_io_timing = on
track_wal_io_timing = on # PG 14+
track_functions = all
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.