Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have been using the following to set up the log file:

log_statement='all',

log_collector='on',

log_destination='on',

log_filename='filename'

After that, for testing I just executed a query then I have seen the log file in tools>serverstatus. Unfortunately it has a lot of anonymous queries including the query which I ran.

How can I filter out the queries which were executed along with my query (anonymous queries)? Is there any possibility to log the affected table information like:

  • which table got affected?
  • at what time was the query executed?
  • what fields got affected?

And how can I get these details using queries?

share|improve this question

migrated from stackoverflow.com Mar 20 '13 at 11:13

This question came from our site for professional and enthusiast programmers.

    
possible duplicate of Retrive Log Detail –  dezso Mar 20 '13 at 11:37
1  
Let's keep this copy, since @Daniel wrote a very useful answer here, and close the other one. –  Erwin Brandstetter Mar 20 '13 at 22:22

1 Answer 1

up vote 1 down vote accepted

The log_statement in postgresql.conf applies to all users and all databases, but if it's not what you want, you may provide per-database and per-user values, with:

ALTER USER someuser SET log_statement='all';

and/or

ALTER DATABASE dbname SET log_statement='all';

and leave log_statement to 'none' in the global configuration file postgresql.conf.

Also when you're superuser, you can enable logging anytime just for your session with:

SET log_statement='all';

As to what is logged, it can be configured with log_line_prefix but it doesn't go as far as logging tables and columns names. To log which columns are affected by UPDATEs you'd need to do that in triggers in every table, as in tablelog

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.