plprofiler
server-side support for profiling PL/pgSQL functions
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
plprofiler | 4.2.5 | LANG | Artistic | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3070 | plprofiler | No | Yes | No | Yes | No | Yes | - |
| Related | pldbgapi plpgsql_check plpgsql pgtap pg_profile pg_stat_statements pg_store_plans auto_explain |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 4.2.5 | 1817161514 | plprofiler | - |
| RPM | PGDG | 4.2.5 | 1817161514 | plprofiler_$v | - |
| DEB | PGDG | 4.2.5 | 1817161514 | postgresql-$v-plprofiler | - |
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
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.