plpgsql_check
plpgsql_check : extended check for plpgsql functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3060 | plpgsql_check
|
plpgsql_check
|
2.9.1 |
LANG
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd--
|
No
|
Yes
|
Yes
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Requires | plpgsql
|
| See Also | pldbgapi
plprofiler
pg_hint_plan
pgtap
auto_explain
plv8
plperl
plpython3u
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED
|
2.9.1 |
18
17
16
15
14
|
plpgsql_check |
plpgsql |
| RPM | PIGSTY
|
2.9.1 |
18
17
16
15
14
|
plpgsql_check_$v |
- |
| DEB | PGDG
|
2.9.1 |
18
17
16
15
14
|
postgresql-$v-plpgsql-check |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
el8.aarch64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
el9.x86_64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
el9.aarch64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
el10.x86_64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
el10.aarch64
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
PIGSTY 2.9.1
|
d12.x86_64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
d12.aarch64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
d13.x86_64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
d13.aarch64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u22.x86_64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u22.aarch64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u24.x86_64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u24.aarch64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u26.x86_64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
u26.aarch64
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
PGDG 2.9.1
|
Source
pig build pkg plpgsql_check; # build rpmInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install plpgsql_check; # install via package name, for the active PG version
pig install plpgsql_check -v 18; # install for PG 18
pig install plpgsql_check -v 17; # install for PG 17
pig install plpgsql_check -v 16; # install for PG 16
pig install plpgsql_check -v 15; # install for PG 15
pig install plpgsql_check -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'plpgsql_check';Create this extension with:
CREATE EXTENSION plpgsql_check CASCADE; -- requires plpgsqlUsage
Sources: official README, v2.9.1 release notes, local package metadata.
plpgsql_check is a PL/pgSQL checker, linter, profiler, tracer, and coverage tool. It detects many errors during development instead of waiting for runtime failures.
CREATE EXTENSION plpgsql_check;Check A Function
SELECT * FROM plpgsql_check_function('my_function()');
SELECT * FROM plpgsql_check_function('my_function(int, text)');
SELECT * FROM plpgsql_check_function('my_function()', fatal_errors := false);The table-returning variant is useful for structured reports:
SELECT *
FROM plpgsql_check_function_tb('my_function()');Output Formats
SELECT * FROM plpgsql_check_function('fx()', format := 'text');
SELECT * FROM plpgsql_check_function('fx()', format := 'json');
SELECT * FROM plpgsql_check_function('fx()', format := 'xml');Check Trigger Functions
SELECT * FROM plpgsql_check_function('my_trigger_func()', 'my_table');
SELECT * FROM plpgsql_check_function(
'my_trigger_func()',
'my_table',
newtable := 'newtab',
oldtable := 'oldtab'
);Warning Categories
SELECT * FROM plpgsql_check_function(
'fx()',
extra_warnings := true,
performance_warnings := true,
security_warnings := true,
compatibility_warnings := true
);extra_warningscovers issues such as missing returns, dead code, and unused arguments.performance_warningscovers performance-related checks.security_warningsincludes checks such as SQL injection risk.compatibility_warningsreports obsolete or version-sensitive PL/pgSQL patterns.
Batch Check All Functions
SELECT p.oid, p.proname, plpgsql_check_function(p.oid)
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_proc p ON p.pronamespace = n.oid
JOIN pg_catalog.pg_language l ON p.prolang = l.oid
WHERE l.lanname = 'plpgsql'
AND p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype;Passive Mode
Passive mode checks functions when they start. It is intended for development or preproduction because it adds overhead.
LOAD 'plpgsql_check';
SET plpgsql_check.mode = 'every_start';Common settings:
plpgsql_check.mode = [ disabled | by_function | fresh_start | every_start ]
plpgsql_check.fatal_errors = [ yes | no ]
plpgsql_check.show_nonperformance_warnings = false
plpgsql_check.show_performance_warnings = falseProfiler
SELECT plpgsql_check_profiler(true);
SELECT my_function();
SELECT lineno, avg_time, source
FROM plpgsql_profiler_function_tb('my_function()');
SELECT stmtid, parent_stmtid, lineno, exec_stmts, stmtname
FROM plpgsql_profiler_function_statements_tb('my_function()');
SELECT * FROM plpgsql_profiler_functions_all();
SELECT plpgsql_profiler_reset_all();For shared profiler statistics, preload plpgsql before plpgsql_check:
shared_preload_libraries = 'plpgsql,plpgsql_check'Without shared preload, profiler data is limited to the active session.
Tracer
Tracing emits notices for function and statement entry/exit and can expose variable values. It is disabled by default and should be enabled only with superuser-controlled settings.
SET plpgsql_check.enable_tracer = on;
SELECT plpgsql_check_tracer(true);
SET plpgsql_check.tracer_verbosity = terse;Dependency Tracking
SELECT *
FROM plpgsql_show_dependency_tb('my_function(int)');Coverage Metrics
SELECT * FROM plpgsql_coverage_statements('my_function()');
SELECT * FROM plpgsql_coverage_branches('my_function()');Pragma Directives
Use pragma calls inside functions to tell plpgsql_check about dynamic SQL, temporary tables, inferred record types, or local check settings:
CREATE OR REPLACE FUNCTION fx(anyelement) RETURNS text AS $$
BEGIN
PERFORM plpgsql_check_pragma('type: r (id int, processed bool)');
RETURN $1::text;
END;
$$ LANGUAGE plpgsql;Caveats
- Pigsty packages
plpgsql_check2.9.1 for PostgreSQL 14-18 as RPMs; DEB packages come from PGDG. - The extension requires
plpgsql. Preloading is optional for active checking, but needed for shared profiler storage and reliable early tracer/profiler initialization. - v2.9.1 fixes a possible crash when a traced inline block fails; no new user-facing SQL API was documented for this patch release.
- The tracer can expose function arguments or variable values. Use it carefully around security-definer functions or sensitive data.