emaj
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
emaj | 5.0.0 | TIME | GPL-3.0 | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1050 | emaj | No | Yes | No | Yes | No | No | emaj |
| Related | btree_gist dblink table_version pgmemento data_historization table_log ddl_historization periods temporal_tables |
|---|
Requires max_prepared_transactions
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 5.0.0 | 1817161514 | emaj | btree_gist, dblink |
| RPM | PIGSTY | 5.0.0 | 1817161514 | e-maj_$v | - |
| DEB | PIGSTY | 5.0.0 | 1817161514 | postgresql-$v-emaj | - |
Build
You can build the RPM / DEB packages for emaj using pig build:
pig build pkg emaj # build RPM / DEB packages
Install
You can install emaj 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 emaj; # Install for current active PG version
pig ext install -y emaj -v 18 # PG 18
pig ext install -y emaj -v 17 # PG 17
pig ext install -y emaj -v 16 # PG 16
pig ext install -y emaj -v 15 # PG 15
pig ext install -y emaj -v 14 # PG 14
dnf install -y e-maj_18 # PG 18
dnf install -y e-maj_17 # PG 17
dnf install -y e-maj_16 # PG 16
dnf install -y e-maj_15 # PG 15
dnf install -y e-maj_14 # PG 14
apt install -y postgresql-18-emaj # PG 18
apt install -y postgresql-17-emaj # PG 17
apt install -y postgresql-16-emaj # PG 16
apt install -y postgresql-15-emaj # PG 15
apt install -y postgresql-14-emaj # PG 14
Create Extension:
CREATE EXTENSION emaj CASCADE; -- requires: btree_gist, dblink
Usage
Sources:
The canonical extension name is emaj; E-Maj records table and sequence changes for a coordinated table group and can roll that group back to a named mark. It is useful for repeatable test runs, batch savepoints, change inspection, and targeted recovery, but an E-Maj rollback is not a replacement for PostgreSQL transaction rollback or backup.
Core Workflow
CREATE EXTENSION emaj CASCADE;
GRANT emaj_adm TO app_admin;
SELECT emaj.emaj_create_group('my_group', true);
SELECT emaj.emaj_assign_table('app', 'orders', 'my_group');
SELECT emaj.emaj_assign_sequences('app', '.*', '', 'my_group');
SELECT emaj.emaj_start_group('my_group', 'mark_1');
-- Run application changes.
SELECT emaj.emaj_set_mark_group('my_group', 'mark_2');
-- Run more application changes.
SELECT emaj.emaj_rollback_group('my_group', 'mark_1');
SELECT emaj.emaj_stop_group('my_group');
SELECT emaj.emaj_drop_group('my_group');
A rollbackable table group can contain tables and sequences from several schemas, but each table must have a primary key. Audit-only groups can record changes for objects that are not rollbackable. Starting and stopping a group takes locks on its application tables, so plan these operations around concurrent traffic.
Important Objects
emaj_create_groupand assignment functions define table groups.emaj_start_group,emaj_set_mark_group, andemaj_stop_groupmanage logging sessions and marks.emaj_rollback_groupperforms an unlogged rollback;emaj_logged_rollback_grouprecords the compensating changes.- Multi-group variants operate on arrays of group names at one common point in time.
- Statistics and change-dump functions inspect changes between marks or generate SQL for replay.
emaj_set_paramchanges or resets an E-Maj parameter without direct writes to the internal parameter table.emaj_drop_extension()is the supported full-removal helper.
Version 5.0 Upgrade
For an E-Maj extension installed at version 2.3.1 or later, install the new package files and run:
ALTER EXTENSION emaj UPDATE;
The documented extension upgrade preserves logs and can run while groups remain in the LOGGING state. Review these 5.0 compatibility changes before cutover:
- PostgreSQL 14 through 19 are supported; PostgreSQL 12 and 13 are no longer supported.
- Direct
INSERT,UPDATE, orDELETEagainstemaj_parammust be replaced byemaj_set_param. - Idempotent start and stop calls have new allow-already-active or allow-already-idle parameters; named-argument callers must review renamed parameters.
- The PHP command-line clients and
emaj_uninstall.sqlwere removed.
Installations made with the standalone SQL script do not have the same in-place extension upgrade path; follow the official delete-and-reinstall procedure.
Requirements and Caveats
The standard CREATE EXTENSION path requires superuser privileges and installs dblink plus btree_gist through CASCADE. E-Maj also supports a limited non-superuser script installation, with capability restrictions tied to the installer role.
max_prepared_transactions is required only for the parallel rollback client and must be at least the intended session count; changing it requires a restart. Large groups can also require a higher max_locks_per_transaction. Treat E-Maj log tables as operational data: size retention deliberately, monitor their growth, and keep ordinary backups for disaster recovery.
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.