Postgresql: Log every query

Edit your /etc/postgresql/9.3/main/postgresql.conf, and change the lines as follows: Note: If you didn't find the postgresql.conf file, then just type $> locate postgresql.conf in a terminal 1) change #log_directory = 'pg_log' to log_directory = 'pg_log' 2) change #log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' to log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' 3) change #log_statement = 'none' to log_statement = 'all' 4) change #logging_collector = off to logging_collector = on Optional: SELECT set_config('log_statement', 'all', true); sudo /etc/init.d/postgresql restart or sudo service postgresql restart Fire query in postgresql select 2+2 Find current log in /var/lib/pgsql/9.2/data/pg_log/ The log files tend to grow a lot over a time, and might kill your machine. For your safety, write a bash script that'll delete logs and restart postgresql server.
Use this procedure to activate log in order to log every single query on database.

Version depends on your postgres installation. This examples shows version 9.3. Change as appropiate.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.