pg_variables

Session-scoped variables with scalar, array, and record types

Overview

PackageVersionCategoryLicenseLanguage
pg_variables1.2.5FEATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
2820pg_variablesNoYesNoYesNoYes-
Relatedsession_variable orafce plisql

Release tag 1.2.5 still ships extension SQL version 1.2.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.2.51817161514pg_variables-
RPMPIGSTY1.2.51817161514pg_variables_$v-
DEBPIGSTY1.2.51817161514postgresql-$v-pg-variables-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
d13.x86_64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
d13.aarch64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
u22.x86_64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
u22.aarch64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
u24.x86_64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
u24.aarch64
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5
PIGSTY 1.2.5

Build

You can build the RPM / DEB packages for pg_variables using pig build:

pig build pkg pg_variables         # build RPM / DEB packages

Install

You can install pg_variables 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_variables;          # Install for current active PG version
pig ext install -y pg_variables -v 18  # PG 18
pig ext install -y pg_variables -v 17  # PG 17
pig ext install -y pg_variables -v 16  # PG 16
pig ext install -y pg_variables -v 15  # PG 15
pig ext install -y pg_variables -v 14  # PG 14
dnf install -y pg_variables_18       # PG 18
dnf install -y pg_variables_17       # PG 17
dnf install -y pg_variables_16       # PG 16
dnf install -y pg_variables_15       # PG 15
dnf install -y pg_variables_14       # PG 14
apt install -y postgresql-18-pg-variables   # PG 18
apt install -y postgresql-17-pg-variables   # PG 17
apt install -y postgresql-16-pg-variables   # PG 16
apt install -y postgresql-15-pg-variables   # PG 15
apt install -y postgresql-14-pg-variables   # PG 14

Create Extension:

CREATE EXTENSION pg_variables;

Usage

pg_variables provides session-scoped variables grouped into named packages. Variables live only in the current session and are non-transactional by default unless created with is_transactional := true.

Basic Set And Get

CREATE EXTENSION pg_variables;

SELECT pgv_set('vars', 'int1', 101);
SELECT pgv_get('vars', 'int1', NULL::int);

Transactional variables participate in savepoints and rollbacks:

BEGIN;
SELECT pgv_set('vars', 'trans_int', 101, true);
SAVEPOINT sp1;
SELECT pgv_set('vars', 'trans_int', 102, true);
ROLLBACK TO sp1;
COMMIT;

Core APIs

The README documents generic scalar and array APIs:

  • pgv_set(package, name, value, is_transactional default false)
  • pgv_get(package, name, NULL::type, strict default true)

It also documents record-oriented APIs:

  • pgv_insert()
  • pgv_update()
  • pgv_delete()
  • pgv_select()

Useful administration helpers include pgv_exists(), pgv_remove(), pgv_free(), pgv_list(), and pgv_stats().

Error And Strictness Behavior

pgv_get() checks both existence and type. The README shows that missing packages, missing variables, or mismatched types raise errors unless strict := false, in which case NULL is returned for missing values.

Deprecated Helpers And Version Note

Upstream still ships deprecated type-specific helpers such as pgv_set_int() / pgv_get_int() and pgv_set_jsonb() / pgv_get_jsonb(), but recommends the generic pgv_set() / pgv_get() API.

The repository tag is v1.2.5, while the current pg_variables.control file still declares default_version = '1.2'. That matches the packaging note that the release tag advanced without changing the SQL extension version string.


Last Modified 2026-04-19: update extension stub docs (9f178c3)