plprofiler

server-side support for profiling PL/pgSQL functions

Overview

PackageVersionCategoryLicenseLanguage
plprofiler4.2.5LANGArtisticC
IDExtensionBinLibLoadCreateTrustRelocSchema
3070plprofilerNoYesNoYesNoYes-
Relatedpldbgapi plpgsql_check plpgsql pgtap pg_profile pg_stat_statements pg_store_plans auto_explain

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG4.2.51817161514plprofiler-
RPMPGDG4.2.51817161514plprofiler_$v-
DEBPGDG4.2.51817161514postgresql-$v-plprofiler-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
d12.aarch64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
d13.x86_64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
d13.aarch64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
u22.x86_64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
u22.aarch64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
u24.x86_64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
u24.aarch64
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5
PGDG 4.2.5

Install

You can install plprofiler directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install plprofiler;          # Install for current active PG version
pig ext install -y plprofiler -v 18  # PG 18
pig ext install -y plprofiler -v 17  # PG 17
pig ext install -y plprofiler -v 16  # PG 16
pig ext install -y plprofiler -v 15  # PG 15
pig ext install -y plprofiler -v 14  # PG 14
dnf install -y plprofiler_18       # PG 18
dnf install -y plprofiler_17       # PG 17
dnf install -y plprofiler_16       # PG 16
dnf install -y plprofiler_15       # PG 15
dnf install -y plprofiler_14       # PG 14
apt install -y postgresql-18-plprofiler   # PG 18
apt install -y postgresql-17-plprofiler   # PG 17
apt install -y postgresql-16-plprofiler   # PG 16
apt install -y postgresql-15-plprofiler   # PG 15
apt install -y postgresql-14-plprofiler   # PG 14

Create Extension:

CREATE EXTENSION plprofiler;

Usage

plprofiler: server-side support for profiling PL/pgSQL functions

plprofiler is a profiling tool for PL/pgSQL functions that identifies performance bottlenecks and generates interactive flame graph reports.

CREATE EXTENSION plprofiler;

Configuration

Add to postgresql.conf:

shared_preload_libraries = 'plprofiler'

Command-Line Tool

The plprofiler command-line utility controls profiling and generates reports:

# Profile a specific SQL command
plprofiler run -d mydb --command "SELECT my_function()" --output report.html

# Monitor profiling in real-time
plprofiler monitor -d mydb

# Save profiling data for later analysis
plprofiler save -d mydb --name "my_profile"

# Generate HTML report with flame graphs
plprofiler report -d mydb --from-data "my_profile" --output report.html

# List saved profiling datasets
plprofiler list -d mydb

# Reset profiling data
plprofiler reset-data -d mydb

# Export/import profiling data
plprofiler export -d mydb --from-data "my_profile" > profile.json
plprofiler import -d mydb --into-data "imported" < profile.json

SQL Interface

-- Enable profiling for the current session
SELECT pl_profiler_set_enabled_local(true);

-- Execute functions to be profiled
SELECT my_function();

-- Collect profiling data into shared hash tables
SELECT pl_profiler_collect_data();

-- Disable profiling
SELECT pl_profiler_set_enabled_local(false);

-- Enable profiling globally (for all sessions)
SELECT pl_profiler_set_enabled_global(true);

-- Reset local/shared profiling data
SELECT pl_profiler_reset_local();
SELECT pl_profiler_reset_shared();

Report Output

Generated HTML reports include:

  • Interactive flame graphs showing wall-clock time spent in PL/pgSQL code
  • Per-function statistics with self-time (total minus children)
  • Top functions ranked by time consumption (default: top 10)
  • Self-contained HTML requiring no external dependencies

Profiling Methods

  • Direct profiling: Run specific SQL while collecting data
  • Timed collection: Interval-based statistics gathering
  • Per-user profiling: Enable profiling for specific database users via ALTER USER
  • Production monitoring: Low-overhead profiling on live systems

Last Modified 2026-03-12: add pg extension catalog (95749bf)