Skip to content

pgtt

pgtt : Extension to add Global Temporary Tables feature to PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
9110
pgtt
pgtt
4.4
SIM
ISC
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
Schemaspgtt_schema
See Also
oracle_fdw
orafce
session_variable
pg_statement_rollback
pg_dbms_metadata
pg_dbms_lock
pg_dbms_job
periods

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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 / PGPG18PG17PG16PG15PG14
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
u26.x86_64
PGDG 4.4
PGDG 4.4
PGDG 4.4
PGDG 4.4
PGDG 4.4
u26.aarch64
PGDG 4.4
PGDG 4.4
PGDG 4.4
PGDG 4.4
PGDG 4.4
PackageVersionOSORGSIZEFile URL
pgtt_184.4el8.x86_64pgdg38.7 KiBpgtt_18-4.4-1PGDG.rhel8.x86_64.rpm
pgtt_184.4el8.aarch64pgdg37.2 KiBpgtt_18-4.4-1PGDG.rhel8.aarch64.rpm
pgtt_184.4el9.x86_64pgdg37.7 KiBpgtt_18-4.4-1PGDG.rhel9.x86_64.rpm
pgtt_184.4el9.aarch64pgdg36.3 KiBpgtt_18-4.4-1PGDG.rhel9.aarch64.rpm
pgtt_184.4el10.x86_64pgdg38.0 KiBpgtt_18-4.4-1PGDG.rhel10.x86_64.rpm
pgtt_184.4el10.aarch64pgdg37.0 KiBpgtt_18-4.4-1PGDG.rhel10.aarch64.rpm
postgresql-18-pgtt4.4d12.x86_64pgdg58.3 KiBpostgresql-18-pgtt_4.4-2.pgdg12+1_amd64.deb
postgresql-18-pgtt4.4d12.aarch64pgdg56.7 KiBpostgresql-18-pgtt_4.4-2.pgdg12+1_arm64.deb
postgresql-18-pgtt4.4d13.x86_64pgdg57.8 KiBpostgresql-18-pgtt_4.4-2.pgdg13+1_amd64.deb
postgresql-18-pgtt4.4d13.aarch64pgdg56.8 KiBpostgresql-18-pgtt_4.4-2.pgdg13+1_arm64.deb
postgresql-18-pgtt4.4u22.x86_64pgdg54.7 KiBpostgresql-18-pgtt_4.4-2.pgdg22.04+1_amd64.deb
postgresql-18-pgtt4.4u22.aarch64pgdg52.9 KiBpostgresql-18-pgtt_4.4-2.pgdg22.04+1_arm64.deb
postgresql-18-pgtt4.4u24.x86_64pgdg53.6 KiBpostgresql-18-pgtt_4.4-2.pgdg24.04+1_amd64.deb
postgresql-18-pgtt4.4u24.aarch64pgdg51.9 KiBpostgresql-18-pgtt_4.4-2.pgdg24.04+1_arm64.deb
postgresql-18-pgtt4.4u26.x86_64pgdg52.7 KiBpostgresql-18-pgtt_4.4-2.pgdg26.04+1_amd64.deb
postgresql-18-pgtt4.4u26.x86_64pigsty48.0 KiBpostgresql-18-pgtt_4.4-1PIGSTY~resolute_amd64.deb
postgresql-18-pgtt4.4u26.aarch64pgdg51.5 KiBpostgresql-18-pgtt_4.4-2.pgdg26.04+1_arm64.deb
postgresql-18-pgtt4.4u26.aarch64pigsty47.5 KiBpostgresql-18-pgtt_4.4-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pgtt;		# build deb

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

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

Config 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 session

Creating 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 sessions

Configuration

SET pgtt.enabled TO off;   -- disable GTT rerouting
SET pgtt.enabled TO on;    -- re-enable GTT rerouting

Key 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