pre_prepare
preprepare · Pre Prepare your Statement server side
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5170 | pre_prepare | preprepare | 0.10 | 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_hint_plan plan_filter pg_query_rewrite hypopg pg_qualstats index_advisor online_advisor pg_stat_plans pg_kpart pg_fsql |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
| el8.aarch64 | N/A | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 | PIGSTY 0.9 |
| el9.x86_64 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 |
| el9.aarch64 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 |
| el10.x86_64 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 |
| el10.aarch64 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 | PIGSTY 0.10 |
| d12.x86_64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| d12.aarch64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| d13.x86_64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| d13.aarch64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u22.x86_64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u22.aarch64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u24.x86_64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u24.aarch64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u26.x86_64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
| u26.aarch64 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 | PGDG 0.10 |
Source
github.com/dimitri/preprepare
preprepare-0.10.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pre_prepare prepares server-side SQL statements so clients can reuse them with EXECUTE. Upstream release 0.10 retains SQL extension version 0.4 and removes support for PostgreSQL older than 9.2. Prepared statements belong to each backend session.
Setup
Create the extension as a superuser. Ordinary explicit calls need no preload or restart. Create the statement table and grant each intended caller permission to read it; its rows contain complete PREPARE statements.
Functions
prepare_all() – Prepare all statements from the configured relation:
prepare_all('schema.table') – Prepare statements from a specific table:
discard() – Like DISCARD ALL but without DEALLOCATE ALL (preserves prepared statements):
With PgBouncer
Set connect_query to auto-prepare on each server connection:
Avoid using DISCARD ALL as your reset_query (it would deallocate the prepared statements).
Optional Connection Initialization
To prepare statements when a backend connects, configure local_preload_libraries with pre_prepare, set preprepare.relation, and enable preprepare.at_init. Preserve existing library entries. Reload configuration; the behavior applies to new sessions. This is optional and is not a requirement for explicit prepare_all calls.
An invalid stored statement during initialization can cause a FATAL connection error. Disable preprepare.at_init and reload before retrying. Limit writes to the statement table to trusted maintainers: preparation runs with the connecting role, and SQL is taken directly from that table. discard preserves prepared statements but still resets other session state; verify pooler behavior before using it as a reset command.