pg_query_rewrite
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_query_rewrite | 0.0.5 | ADMIN | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5030 | pg_query_rewrite | No | Yes | Yes | Yes | No | No | - |
Requires shared_preload_libraries=pg_query_rewrite.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.5 | 1817161514 | pg_query_rewrite | - |
| RPM | PIGSTY | 0.0.5 | 1817161514 | pg_query_rewrite_$v | - |
| DEB | PIGSTY | 0.0.5 | 1817161514 | postgresql-$v-pg-query-rewrite | - |
Build
You can build the RPM / DEB packages for pg_query_rewrite using pig build:
pig build pkg pg_query_rewrite # build RPM / DEB packages
Install
You can install pg_query_rewrite 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 pg_query_rewrite; # Install for current active PG version
pig ext install -y pg_query_rewrite -v 18 # PG 18
pig ext install -y pg_query_rewrite -v 17 # PG 17
pig ext install -y pg_query_rewrite -v 16 # PG 16
pig ext install -y pg_query_rewrite -v 15 # PG 15
pig ext install -y pg_query_rewrite -v 14 # PG 14
dnf install -y pg_query_rewrite_18 # PG 18
dnf install -y pg_query_rewrite_17 # PG 17
dnf install -y pg_query_rewrite_16 # PG 16
dnf install -y pg_query_rewrite_15 # PG 15
dnf install -y pg_query_rewrite_14 # PG 14
apt install -y postgresql-18-pg-query-rewrite # PG 18
apt install -y postgresql-17-pg-query-rewrite # PG 17
apt install -y postgresql-16-pg-query-rewrite # PG 16
apt install -y postgresql-15-pg-query-rewrite # PG 15
apt install -y postgresql-14-pg-query-rewrite # PG 14
Preload:
shared_preload_libraries = 'pg_query_rewrite';
Create Extension:
CREATE EXTENSION pg_query_rewrite;
Usage
- GitHub Repo:
pierreforstmann/pg_query_rewrite - README: pierreforstmann/pg_query_rewrite/blob/master/README.md
pg_query_rewrite is a PostgreSQL extension that translates an exact source SQL statement into another predefined SQL statement. It must be loaded at server level with shared_preload_libraries, then installed in each database.
The README shows the extension as a simple statement rewrite engine backed by shared-memory rules.
Setup
shared_preload_libraries = 'pg_query_rewrite'
pg_query_rewrite.max_rules = 10
CREATE EXTENSION pg_query_rewrite;
The README says the extension has been successfully tested with PostgreSQL 9.5 through 18.
Managing Rules
Use the helper functions to manage translations:
SELECT pgqr_add_rule('select 10;', 'select 11;');
SELECT pgqr_remove_rule('select 10;');
SELECT pgqr_truncate();
SELECT pgqr_rules();
The example in the README rewrites select 10; to select 11; and then shows the rule list after insertion.
Behavior
- Matching is exact and sensitive to case, spaces, and semicolons.
- Parameterized SQL statements are not supported.
- The maximum SQL statement length is hard-coded at 32K.
- Rules live only in shared memory; the extension does not persist settings on its own.
pg_query_rewrite.max_rulescaps the number of SQL statements that can be translated and defaults to10when unset.
Scope
The upstream README is sufficient here: it covers purpose, server-level loading, rule management, a concrete rewrite example, and the main limitations. No separate docs page or homepage was needed.
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.