pre_prepare

Pre Prepare your Statement server side

Overview

PackageVersionCategoryLicenseLanguage
preprepare0.9ADMINPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
5170pre_prepareNoYesNoYesNoYes-
Relatedpg_store_plans auto_explain pg_stat_statements plpgsql_check pg_show_plans pg_qualstats pg_hint_plan pgaudit

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED0.91817161514preprepare-
RPMPIGSTY0.91817161514preprepare_$v-
DEBPGDG0.91817161514postgresql-$v-preprepare-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
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

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: Pre Prepare your Statement server side

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).


Last Modified 2026-03-12: add pg extension catalog (95749bf)