session_variable
session_variable : Registration and manipulation of session variables and constants
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 9120 | session_variable | session_variable | 3.6 |
SIM | GPL-3.0 | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | session_variable |
| See Also | orafce db2fce pgtt ivorysql_ora pg_statement_rollback pg_variables omni_var |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 3.6 |
18 17 16 15 14 | session_variable |
- |
| RPM | PIGSTY | 3.6 |
18 17 16 15 14 | session_variable_$v |
- |
| DEB | PIGSTY | 3.6 |
18 17 16 15 14 | postgresql-$v-session-variable |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| el8.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| el9.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| el9.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| el10.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| el10.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| d12.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| d12.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| d13.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| d13.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u22.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u22.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u24.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u24.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u26.x86_64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
| u26.aarch64 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 | PIGSTY 3.6 |
Source
github.com/splendiddata/session_variable
session_variable-3.6.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
session_variable defines database-level variables and constants with a separate value in each session. Changes to session-local values do not affect other connections.
Creating Variables and Constants
Getting and Setting Values
Using in PL/pgSQL
Administration Functions
Key Behaviors
- Variables are defined at the database level; each session gets a local copy
set()only changes the session-local copy; other sessions are unaffectedalter_value()changes the stored value; new sessions see it, existing sessions needinit()to refresh- Constants cannot be changed via
set(), only viaalter_value() - Variable and constant names must be unique across both types
Privileges, Reads and Version Boundaries
A superuser installs this non-relocatable extension in schema session_variable; no shared preload or restart is required for the SQL workflow. Grant session_variable_administrator_role to manage definitions and session_variable_user_role for ordinary access. The administrator role includes the user role.
session_variable.set and session_variable.alter_value return boolean true on success, not the previous value. A successful stored-definition change becomes visible in the caller immediately and in future sessions after commit; existing sessions keep their local state until session_variable.init() resets all values. Definitions are stored in session_variable.variables and included in logical backups.
session_variable.get_stable may cache a value during a statement; use the regular getter when a trigger changes that value within the same statement. session_variable.get_constant is IMMUTABLE and can return cached results after administrative constant changes; use the regular getter during such changes.
Release 3.6 removes obsolete version-1 initialization support. The preceding 3.5 rejects non-null initial values for collection and icollection because text initialization can crash a backend. For those types, create a null-initialized variable and follow the source’s initialization hook session_variable.variable_initialisation(); the README’s alternate hook name is inconsistent with the implementation. Upstream lists PostgreSQL 14-18 and provisional PostgreSQL 19 support.