pre_prepare
preprepare : Pre Prepare your Statement server side
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5170 | pre_prepare | preprepare | 0.9 | ADMIN | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_store_plans auto_explain pg_stat_statements plpgsql_check pg_show_plans pg_qualstats pg_hint_plan pgaudit |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.9 | 18 17 16 15 14 | preprepare | - |
| RPM | PIGSTY | 0.9 | 18 17 16 15 14 | preprepare_$v | - |
| DEB | PGDG | 0.9 | 18 17 16 15 14 | postgresql-$v-preprepare | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
el8.aarch64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
el9.x86_64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
el9.aarch64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
el10.x86_64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
el10.aarch64 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
d12.x86_64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
d12.aarch64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
d13.x86_64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
d13.aarch64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
u22.x86_64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
u22.aarch64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
u24.x86_64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
u24.aarch64 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 | PGDG 0.9 |
Source
pig build pkg preprepare; # 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 preprepare; # install via package name, for the active PG version
pig install pre_prepare; # install by extension name, for the current active PG version
pig install pre_prepare -v 18; # install for PG 18
pig install pre_prepare -v 17; # install for PG 17
pig install pre_prepare -v 16; # install for PG 16
pig install pre_prepare -v 15; # install for PG 15
pig install pre_prepare -v 14; # install for PG 14Create this extension with:
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).