pgtt
pgtt
pgtt : Extension to add Global Temporary Tables feature to PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 9110 | pgtt | pgtt | 4.4 | SIM | ISC | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd-- | No | Yes | Yes | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | pgtt_schema |
| See Also | oracle_fdw orafce session_variable pg_statement_rollback pg_dbms_metadata pg_dbms_lock pg_dbms_job periods |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 4.4 | 18 17 16 15 14 | pgtt | - |
| RPM | PGDG | 4.4 | 18 17 16 15 14 | pgtt_$v | - |
| DEB | PGDG | 4.4 | 18 17 16 15 14 | postgresql-$v-pgtt | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
el8.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
el9.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
el9.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
el10.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
el10.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
d12.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
d12.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
d13.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
d13.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
u22.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
u22.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
u24.x86_64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
u24.aarch64 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 | PGDG 4.4 |
Source
pig build pkg pgtt; # build debInstall
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pgtt; # install via package name, for the active PG version
pig install pgtt -v 18; # install for PG 18
pig install pgtt -v 17; # install for PG 17
pig install pgtt -v 16; # install for PG 16
pig install pgtt -v 15; # install for PG 15
pig install pgtt -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pgtt';Create this extension with:
CREATE EXTENSION pgtt;Usage
pgtt: Extension to add Global Temporary Tables feature to PostgreSQL
Creating a Global Temporary Table
CREATE EXTENSION pgtt;
-- ON COMMIT PRESERVE ROWS: data persists across transactions within a session
CREATE GLOBAL TEMPORARY TABLE test_gtt (
id integer,
lbl text
) ON COMMIT PRESERVE ROWS;
-- ON COMMIT DELETE ROWS: data is deleted at transaction commit
CREATE GLOBAL TEMPORARY TABLE session_data (
id integer,
value text
) ON COMMIT DELETE ROWS;The GLOBAL keyword can also be used as a comment to avoid warnings:
CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt (
LIKE other_table INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES
) ON COMMIT PRESERVE ROWS;CREATE AS Form
CREATE /*GLOBAL*/ TEMPORARY TABLE gtt_copy
AS SELECT * FROM source_table WITH DATA;Using Global Temporary Tables
INSERT INTO test_gtt VALUES (1, 'one'), (2, 'two');
SELECT * FROM test_gtt; -- visible only in current sessionCreating Indexes
CREATE INDEX ON test_gtt (id);Constraints
All constraints except FOREIGN KEYS are supported:
CREATE GLOBAL TEMPORARY TABLE t2 (
c1 serial PRIMARY KEY,
c2 VARCHAR(50) UNIQUE NOT NULL,
c3 boolean DEFAULT false
);Dropping
DROP TABLE test_gtt; -- can be dropped even while used by other sessionsConfiguration
SET pgtt.enabled TO off; -- disable GTT rerouting
SET pgtt.enabled TO on; -- re-enable GTT reroutingKey Behaviors
- GTT content is session-local; other sessions cannot see your data
- The table structure is persistent (visible to all users), but data is per-session
- Requires loading via
session_preload_libraries = 'pgtt' - Partitioning is not supported on GTTs
Last updated on