Thursday, February 1. 2007Log Table Changes in PostgreSQL with tablelogTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
For PostgreSQL >=8.2 you need this simple patch: http://pgfoundry.org/tracker/index.php?func=detail&aid=1000870&group_id=1000074&atid=360 Comments ()
If you want to use this as an audit trail you must stop your users from inserting arbitraty data into _log files. You can achieve this by making another role (let's say - 'auditor') to become these functions owner, creating all the audit tables as a user with such role and issuing: ALTER FUNCTION table_log() security definer; This way only 'auditor' role has access to _log tables and you're preventing your users from faking it. Comments ()
How could you get the last date a value in a field of a logged table changed? E.g. when did a user changed his password the last time Comments ()
Sorry, I think I have it: select trigger_changed from ( select DISTINCT ON (subj_upass) * from log.subject_log where subj_id=6) drvdtbl ORDER BY trigger_id DESC LIMIT 1 Comments ()
Yes, just select the latest matching value from the log table. Comments ()
How does the table_log_restore_table function work when a table is audited in a separate schema? I have a table called "show" in a test schema called "junk_schema" with primary key called "show_index01", and it is audited as "show" in an audit schema called "audit" with primay key "show_pkey". The following just gives me the error "ERROR: could not check relation: show" select table_log_restore_table('show','show_index01','show','show_pkey','restored_show',NOW()); Does the restore function work across schemas? Comments ()
You can no only use the table name but also prepend the table name with the schema name: audit.show Comments ()
Thanks Andreas, however I get the following; JUNK=# select table_log_restore_table('junk_schema.show','show_index01','audit.show','show_pkey','restored_show',NOW()); ERROR: could not check relation: junk_schema.show If I look at the code (I may be looking in the wrong place) on line 631: / check original table / snprintf(query, 249, "SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname = %s AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY a.attnum", do_quote_literal(table_orig)); Checking against pg_class, so would passing the schema name as above not work? Comments ()
Looks like i never thought about this issue. Hmm, don't know a way around this problem, sorry. As a workaround you can use another table name and habe both schemes in your search_path. I'm sorry for this circumstances :-( By the way: would you prefer a C or a pl/pgSQL version of tablelog? I'm thinking about a rewrite, the current code is approx. 8 years old and way behind the current possibilities. Comments ()
On the whole I prefer C, I think it's neater in the long run. However if plpgsql is the better tool these days so be it. Would I be oversimplifying things by thinking we just need to add in the schema names to the log_table_restore_table function and then add in a check for pg_class.nspname in each of the queries against pg_class? Comments ()
That would be possible. May i bug you to send me a patch? ;-) Comments ()
Is it possible to have only the changes displayed in some way - what values of a record have changed during each step? I guess this would be based on similar technique to restore (or not). Thx. SWK Comments ()
You could compare each field from the old and new value - and only display different fields. Comments ()
Yes, but I don't know any generic way to do that. Maybe it is possible to write such a function in plpgSQL but its certainly beyond my abilities. eg. Select * from change_log("tableName") Comments ()
I install postgres 8.3 anda i have this msg when i try to execute CREATE FUNCTION table_log () RETURNS TRIGGER AS '/usr/lib/pgsql/table_log' LANGUAGE 'C'; ERROR: incompatible library "/usr/lib/pgsql/table_log.so": version mismatch DETAIL: Server is version 8.3, library is version 8.2. ********** Error ********** ERROR: incompatible library "/usr/lib/pgsql/table_log.so": version mismatch SQL state: XX000 Detail: Server is version 8.3, library is version 8.2. Comments ()
DETAIL: Server is version 8.3, library is version 8.2. That's obvious, your module is compiled for 8.2, you have to recompile the module. Oh, and you should check that no libraries, binaries or development stuff from 8.2 is still on your system. Comments ()
"I'm thinking about a rewrite, the current code is approx. 8 years old and way behind the current possibilities." Have you had a chance to look into this yet? I'm interested in looking into this project, hoping it's still maintained... Thanks, Josh Comments ()
Not yet. I found out that plpgsql is even after 8 years not able to provide all the functionality needed for table_log. Especially it's not possible to do something like: NEW.$column Comments ()
Hi andreas, this is fantastic contrib, but i need save in audit tables other user than current user. Example: current_user = 'System' but i need to save:'Claudio@atn'. How i can do this? Thnx Comments ()
Hello Claudio, that's not possible, because the data is written by a trigger and not by the insert itself. You can probably modify the trigger function and extract the data from a setting or environment variable ... Comments ()
Would it be possible to get a patch of table_log with properly escaped quotes? Comments ()
I get warnings like: WARNING: nonstandard use of \' in a string literal HINT: Use '' to write quotes in strings, or use the escape string syntax (E'...'). Comments ()
I attempted to build the most recent cvs version hoping it might fix the problem, but that fails to build ( on ubuntu 9.10 w/ postgresql 8.4) Comments ()
|
QuicksearchBlog AdministrationUBERWACH!BookmarksCalendarUpcoming EventsCategoriesLetzte Google SucheStatisticsLast entry: 2010-03-03 23:05
661 entries written
446 comments have been made
3995 visitor(s) this month
14 visitor(s) online
Top Referrerswww.google.com (3255)
www.google.de (2260) google.com (1582) planet.postgresql.org (1447) ads.wars-nicht.de (1167) www.postgresql.org (1035) www.planetpostgresql.org (956) image.youdao.com (377) www.netvibes.com (221) lars-schenk.com (182) ArchivesRecent Entries
Tagged entriesApple Autobahn Auto fahren Bürokratie Baby Bahnhof Brussels Bugs Chemnitzer Linuxtage Code snippets Community Platforms Deutsche PostgreSQL Usergruppe Deutsche Sprache Deutschland Die Bahn Einkaufen Elefant Elephant Event Familie Finanzamt Flug FOSDEM Fotografie Hasselbachplatz Hochzeitsreise Hochzeitsvorbereitungen Innenminister iPod Linux Magdeburg Magdeburg bei Nacht Magdeburger Open-Source-Tag Magdeburger Verkehrsbetriebe MVB MySQL Nachwuchs Namensfindung Navigationssystem Performance Perl PGDay Italien PGDay Italy PHP Politik PostgreSQL PostgreSQL User Group Europe PostgreSQL User Group Germany PostgreSQL weekly news Prato Restaurants und Bars in Magdeburg Schönebeck/Elbe Servicewüste Software SQL Steuern stupid Talk Ubuntu Ultraschall Umsatzsteuer-Identifikationsnummer Universität Magdeburg Unterwegs Urlaub Vortrag Wöchentlicher PostgreSQL Newsletter Werbung
Once upon a timeOne year ago ...
Mon, 09.03.2009 11:33"Wöchentlicher PostgreSQL Ne [...]" " |