{
  "id": 18771437,
  "title": "PGHist | History and audit of table changes in PostgreSQL",
  "url": "https://urgent.news/2026/11/07/pghist-history-and-audit-of-table-changes-in-postgresql",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-07T19:04:47.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/pgsuite/pghist-history-and-audit-of-table-changes-in-postgresql-356"
  },
  "original_language": "en",
  "account": "PGHist is an open-source tool for tracking and viewing change history in PostgreSQL tables. It is designed for medium-sized projects and low-load tables, focusing on displaying modifications rather than logging them. The tool sets up statement-level triggers for INSERT, UPDATE, DELETE, and TRUNCATE operations, as well as stored procedures and views for data retrieval.\n\nWhen a table is modified, triggers efficiently copy only the changed fields to the history schema. Special event triggers handle DDL operations like ALTER TABLE, automatically rebuilding the history tables and stored procedures. The storage structure is Transaction-Expression-Row, which minimizes redundancy and matches the database management system's operation.\n\nTo enable history tracking, users call pghist.hist_enable() on the target table. They can then view change logs by row, changes by field, or tables at a specific timestamp. The tool also allows defining SQL expressions for each table and column to describe changed rows and field values. By default, descriptions are created for foreign key fields and table rows.\n\nPGHist supports inheritance, with stored procedures having a 'cascade' parameter to retrieve data with or without inheritance. It tracks modifications in a hierarchical manner (Change → Query → Transaction), allowing retrieval of all edits within a specific transaction or by a particular SQL statement. Optional conditions can be applied to the primary or foreign key when listing changes.\n\nThe tool has some limitations, such as not supporting updates to primary key values and potential issues when the table undergoes significant changes, requiring the history to be rebuilt. There is also a write overhead, as the tool captures changes using triggers and splits them dynamically across structured tables, resulting in roughly twice the write latency compared to standard operations.",
  "summary": "Hello community! I have developed PGHist — an open-source utility designed for saving, auditing, and viewing table change history in PostgreSQL. 🎯 Target audience: PGHist is specifically tailored for medium-sized projects and low-load tables within larger systems . Fully handles change auditing (log + temporal tables) but focuses primarily on displaying modifications to users. Setting up a…",
  "key_points": [
    "PGHist tracks and displays change history in PostgreSQL tables for medium-sized projects.",
    "Users enable tracking with pghist.histenable() and view logs by row, field, or specific timestamps."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}