GithubHelp home page GithubHelp logo

m-martinez / pg-audit-json Goto Github PK

View Code? Open in Web Editor NEW
44.0 1.0 9.0 57 KB

Simple, easily customised trigger-based auditing for PostgreSQL (Postgres). See also pgaudit.

License: Other

PLpgSQL 89.87% Makefile 3.77% Dockerfile 1.61% TSQL 4.75%
postgresql postgresql-extension postgres audit auditing audit-table

pg-audit-json's Issues

[Feature] Add the row primary key value as separate column in Log table

It's common to get the change history for a specific row/record so it helps if a new column can be added to the log table which stores the primary key value. I know we can get that from JSON but comes with some performance cost.

Primary key column can be fetched using a SQL like below:

SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) WHERE i.indrelid = 'table_name'::regclass AND i.indisprimary;

Then we just need to fetch the column value from the table variable NEW.[PK_col_name].

`application_name` is not being saved in the audit.log table

I noticed that application_name is not being saved. Turns out the call to current_setting has a wrong setting_name parameter: instead of

current_setting('audit.application_name', true)

it should be simply

current_setting('application_name', true)

https://github.com/m-martinez/pg-audit-json/blob/master/sql/pg-audit-json--1.0.2.sql#L223-L224

More details about application_name: https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-APPLICATION-NAME

By the way, the other setting the is supposed to be saved (application_user_name) doesn't seem to be valid.

Thanks for this nice tool!

Update statement fails on table that has logging enabled

Update statement fails on table that has logging enabled.
The same values as insert statement succeeds.

2019-05-13 03:59:30.029 UTC [63903] ERROR:  operator does not exist: jsonb - jsonb at character 25
2019-05-13 03:59:30.029 UTC [63903] HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
2019-05-13 03:59:30.029 UTC [63903] QUERY:  SELECT (to_jsonb(NEW.*) - audit_row.row_data) - excluded_cols
2019-05-13 03:59:30.029 UTC [63903] CONTEXT:  PL/pgSQL function audit.if_modified_func() line 48 at assignment

Version:
PostgreSQL 11.2 on x86_64-apple-darwin18.5.0, compiled by Apple LLVM version 10.0.1 (clang-1001.0.46.4), 64-bit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.