pg_profile

PostgreSQL load profile repository and report builder

Overview

PackageVersionCategoryLicenseLanguage
pg_profile4.11STATBSD 2-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
6000pg_profileNoYesNoYesNoNo-
Relateddblink plpgsql plprofiler pg_stat_kcache powa pg_stat_statements pg_show_plans pg_stat_monitor pg_qualstats pg_store_plans

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED4.111817161514pg_profiledblink, plpgsql
RPMPGDG4.111817161514pg_profile_$v-
DEBPIGSTY4.111817161514postgresql-$v-pg-profile-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
d13.aarch64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
u22.x86_64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
u22.aarch64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
u24.x86_64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
u24.aarch64
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
PIGSTY 4.11
u26.x86_64
u26.aarch64

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;
track_activities = on
track_counts = on
track_io_timing = on
track_wal_io_timing = on      # PG 14+
track_functions = all

Last Modified 2026-05-01: update extension data (aaef844)