Registry / database / pg-triggers

pg-triggers

JSON →
library0.4.6jsnpmunverified

pg-triggers is a PostgreSQL trigger-based auditing library (v0.4.6, maintained intermittently) that automatically records changes to tables (INSERT, UPDATE, DELETE) into changelog tables. It uses PSQL scripts and requires manual enabling per table via the `enance_table` function. Differentiates from other auditing extensions by being lightweight and SQL-only (no PG extensions).

npm install pg-triggers
INSTALL
IMPORT
SIG · PG-TRIGGERS
P
pg-triggers
databasejavascriptv0.4.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pg-triggers
psql < node_modules/pg-triggers/lib/recreate-his.sql
npm install pg-triggers
This is a PostgreSQL extension installed via SQL scripts, not a JavaScript package. Use psql to execute the provided SQL files.

Shows how to install the SQL triggers and enable auditing on a table using psql commands.

-- Install required SQL objects psql -d your_database < node_modules/pg-triggers/lib/recreate-his.sql psql -d your_database < node_modules/pg-triggers/lib/table-changes.sql psql -d your_database < node_modules/pg-triggers/lib/function-changes-trg.sql -- Enable auditing for table 'users' with primary key 'id' psql -d your_database -c "SELECT enance_table('users', 'id');" -- Now any changes to 'users' will be recorded in 'changes' table
Debug
Known issues
gotchaThis package is not a JavaScript module; it is a collection of SQL scripts. Running `npm install pg-triggers` only downloads the files; you must execute the SQL scripts manually with psql.
fix
Execute the SQL files using psql as described in the README.
affects: >=0.0.0
gotchaYou must call enance_table for each table you want to audit. Failure to do so means no triggers are created and no changes will be logged.
fix
Run: psql -c "SELECT enance_table('table_name','primary_key_columns')"
affects: >=0.0.0
deprecatedThe package uses `lib/enance.sql` which may not be included in newer versions; the README references files that might have been removed or renamed.
fix
Check the actual file names in the `lib/` directory; use `ls node_modules/pg-triggers/lib/` to see available scripts.
affects: >=0.4.0
gotchaThe generated changelog tables may have performance implications on write-heavy tables; triggers add overhead to every DML operation.
fix
Monitor query performance and consider asynchronous logging alternatives for high-throughput systems.
affects: >=0.0.0
Errors
Common errors & fixes
ERROR: relation "history" does not exist
The required SQL scripts (recreate-his.sql, table-changes.sql, function-changes-trg.sql) have not been executed.
fix
Run: psql < node_modules/pg-triggers/lib/recreate-his.sql
ERROR: function enance_table(unknown, unknown) does not exist
The enance.sql script has not been executed, or the function was not created in the correct schema.
fix
Run: psql -d your_database < node_modules/pg-triggers/lib/enance.sql
Upgrade
Version history
0.4.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
pg-triggers — npm install pg-triggers · libregistry