pre_prepare
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
preprepare | 0.9 | ADMIN | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5170 | pre_prepare | No | Yes | No | Yes | No | Yes | - |
| Related | pg_store_plans auto_explain pg_stat_statements plpgsql_check pg_show_plans pg_qualstats pg_hint_plan pgaudit |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 0.9 | 1817161514 | preprepare | - |
| RPM | PIGSTY | 0.9 | 1817161514 | preprepare_$v | - |
| DEB | PGDG | 0.9 | 1817161514 | postgresql-$v-preprepare | - |
Build
You can build the RPM packages for preprepare using pig build:
pig build pkg preprepare # build RPM packages
Install
You can install preprepare 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 preprepare; # Install for current active PG version
pig ext install -y preprepare -v 18 # PG 18
pig ext install -y preprepare -v 17 # PG 17
pig ext install -y preprepare -v 16 # PG 16
pig ext install -y preprepare -v 15 # PG 15
pig ext install -y preprepare -v 14 # PG 14
dnf install -y preprepare_18 # PG 18
dnf install -y preprepare_17 # PG 17
dnf install -y preprepare_16 # PG 16
dnf install -y preprepare_15 # PG 15
dnf install -y preprepare_14 # PG 14
apt install -y postgresql-18-preprepare # PG 18
apt install -y postgresql-17-preprepare # PG 17
apt install -y postgresql-16-preprepare # PG 16
apt install -y postgresql-15-preprepare # PG 15
apt install -y postgresql-14-preprepare # PG 14
Create Extension:
CREATE EXTENSION pre_prepare;
Usage
pre_prepare automatically prepares SQL statements at connection time so clients can directly use EXECUTE without calling PREPARE first.
Setup
Configure in postgresql.conf:
preprepare.relation = 'preprepare.statements'
preprepare.at_init = on -- auto-prepare on connection (requires local_preload_libraries)
Create a table to store statements:
CREATE TABLE preprepare.statements (name text PRIMARY KEY, statement text);
Insert statements (include the full PREPARE syntax):
INSERT INTO preprepare.statements VALUES ('test', 'prepare test as select 1');
Functions
prepare_all() – Prepare all statements from the configured relation:
SELECT prepare_all();
prepare_all('schema.table') – Prepare statements from a specific table:
SELECT prepare_all('public.expensive_planning');
discard() – Like DISCARD ALL but without DEALLOCATE ALL (preserves prepared statements):
SELECT discard();
With PgBouncer
Set connect_query to auto-prepare on each server connection:
[databases]
foo = port=5432 connect_query='SELECT prepare_all();'
Avoid using DISCARD ALL as your reset_query (it would deallocate the prepared statements).
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.