pre_prepare

pre_prepare

preprepare : Pre Prepare your Statement server side

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
5170
pre_prepare
preprepare
0.9
ADMIN
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--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

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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 / PGPG18PG17PG16PG15PG14
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 rpm

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install 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 14

Create this extension with:

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 updated on