m-martinez / pg-audit-json Goto Github PK
View Code? Open in Web Editor NEWSimple, easily customised trigger-based auditing for PostgreSQL (Postgres). See also pgaudit.
License: Other
Simple, easily customised trigger-based auditing for PostgreSQL (Postgres). See also pgaudit.
License: Other
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.
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
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]
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.