{"id":19891421,"url":"https://github.com/mohamed-kaizen/pg-audit","last_synced_at":"2025-06-13T08:06:04.755Z","repository":{"id":199206811,"uuid":"702335010","full_name":"Mohamed-Kaizen/pg-audit","owner":"Mohamed-Kaizen","description":"Easy-to-use, customizable auditing for PostgreSQL using triggers","archived":false,"fork":false,"pushed_at":"2023-10-09T07:08:05.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T05:17:25.230Z","etag":null,"topics":["audit","audit-table","auditing","postgres","postgresql","postgresql-extension"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mohamed-Kaizen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":"audit.sql","citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-09T05:56:45.000Z","updated_at":"2023-10-09T06:00:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c3bae8d-e32c-4225-9ea7-75f1aa8a0576","html_url":"https://github.com/Mohamed-Kaizen/pg-audit","commit_stats":null,"previous_names":["mohamed-kaizen/pg-audit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Mohamed-Kaizen/pg-audit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohamed-Kaizen%2Fpg-audit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohamed-Kaizen%2Fpg-audit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohamed-Kaizen%2Fpg-audit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohamed-Kaizen%2Fpg-audit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mohamed-Kaizen","download_url":"https://codeload.github.com/Mohamed-Kaizen/pg-audit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohamed-Kaizen%2Fpg-audit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259606867,"owners_count":22883556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audit","audit-table","auditing","postgres","postgresql","postgresql-extension"],"created_at":"2024-11-12T18:18:13.377Z","updated_at":"2025-06-13T08:06:04.730Z","avatar_url":"https://github.com/Mohamed-Kaizen.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"Easy-to-use, customizable auditing for PostgreSQL using triggers\n\n## Installation\n\nLoad `audit.sql` into the database where you want to set up auditing. You can do this via psql or any other tool that lets you execute sql on the database.\n\n```bash\npsql -h \u003cdb-host\u003e -p \u003cdb-port\u003e -U \u003cdb-user\u003e -d \u003cdb\u003e -f audit.sql --single-transaction\n```\n\n## Usage\n\n### Enable\n\nRun the following sql to setup audit on a table\n\n```sql\n\nselect audit.enable('account');\n\n```\n\nFor a table in a different schema name\n\n```sql\nselect audit.enable('public.account');\n```\n\n#### Options\n\nThe function `audit.enable` takes the following arguments.\n\nThe first optional argument, `audit_rows`, specifies whether to log row-level changes or only statement-level changes. The default value is `true`, which means that row-level changes will be logged.\n\n```sql\n\nselect audit.enable('account', false);\n\n```\n\nThe second optional argument, `audit_query_text`, specifies whether to log statement-level changes. The default value is `true`, which means that statement-level changes will be logged.\n\n```sql\n\nselect audit.enable('account', true, false);\n\n```\n\nThe third optional argument, `audit_inserts`, specifies whether to audit insert statements or only updates/deletes/truncates. The default value is `true`, which means that insert statement will be logged.\n\n\n```sql\n\nselect audit.enable('account', true, true, false);\n\n```\n\nThe last optional argument, `ignored_cols`, specifies which columns to exclude from audit logs when rows are updated. If only the ignored columns are updated, the update will not be logged.\n\n```sql\n\nselect audit.enable('account', true, true, true, '{updated_at,phone_number}');\n\n```\n\n### Disable\n\nRun the following sql to setup audit on a table\n\n```sql\n\nselect audit.disable('account');\n\n```\n\nFor a table in a different schema name\n\n```sql\nselect audit.disable('public.account');\n```\n\n### Getting data\n\nThe `audit.sql` create table called `logs` and view called `tables`:\n\n1. **tables**: This view shows all tables whose auditing is enabled.\n  ```sql\n    select * from audit.tables\n  ```\n\n2. **logs**: Will store all audit records.\n  ```sql\n    select * from audit.logs\n  ```\n\n## Logs Table Reference\n\nColumn | Type | Not\u0026nbsp;Null | Description\n--- | --- | :---: | ---\n`id` | `uuid` | \u0026#x2611;  | Unique identifier for each auditable event\n`schema_name` | `TEXT` | \u0026#x2611;  | Database schema audited table for this event is in\n`table_name` | `TEXT` | \u0026#x2611;  | Non-schema-qualified table name of table event occured in\n`table_oid` | `OID` | \u0026#x2611;  | Table OID. Changes with drop/create.\n`transaction_id` | `BIGINT` || Identifier of transaction that made the change. \u003cbr /\u003eUnique when paired with `transaction_start_at.`\n`row_id` | `TEXT` || Primary key ID of the row. Only for `updates/deletes/truncates`\n`action` | `TEXT` | \u0026#x2611;  | Action type: \u003cbr /\u003e `insert` \u003cbr /\u003e `delete` \u003cbr /\u003e `update` \u003cbr/\u003e `truncate`\n`row_data` | `JSONB` | | Record value. Null for statement-level trigger.\u003cbr /\u003eFor INSERT this is the new tuple.\u003cbr /\u003e For DELETE and UPDATE it is the old tuple.\n`changed_fields` | `JSONB` | | New values of fields changed by UPDATE. Null except for row-level UPDATE events. \u003cbr /\u003e Null for INSERT or DELETE.\n`session_user_name` | `TEXT` || Login / session user whose statement caused the event\n`application_name` | `TEXT` | | The name of the application when this event occurred.\n`client_addr` | `INET` | | IP address of client that issued query. Null for unix domain socket.\n`client_port` | `INTEGER` | | Port address of client that issued query. \u003cbr /\u003eUndefined for unix socket.\n`client_query` | `TEXT` | | Top-level query that caused this auditable event. \u003cbr /\u003eMay be more than one.\n`statement_only` | `BOOLEAN` | \u0026#x2611;  | `t` if audit event is from an FOR EACH STATEMENT trigger \u003cbr /\u003e `f` for FOR EACH ROW\n`transaction_start_at` | `TIMESTAMP` | \u0026#x2611; | Transaction start timestamp for tx in which audited event occurred\n`statement_start_at` | `TIMESTAMP` | \u0026#x2611; | Statement start timestamp for tx in which audited event occurred\n`wall_clock_time` | `TIMESTAMP` | \u0026#x2611; | Wall clock time at which audited event's trigger call occurred\n\n\n## Credits\n\n* [hasura/audit-trigger](https://github.com/hasura/audit-trigger)\n* [iloveitaly/audit-trigger](https://github.com/iloveitaly/audit-trigger)\n* [2ndQuadrant/audit-trigger](https://github.com/2ndQuadrant/audit-trigger)\n* [Wiki Audit Trigger 91plus](https://wiki.postgresql.org/wiki/Audit_trigger_91plus)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamed-kaizen%2Fpg-audit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohamed-kaizen%2Fpg-audit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamed-kaizen%2Fpg-audit/lists"}