How to enable logging of all SQL executed by PostgreSQL 8.3?
Edited (more info) I changed these lines :
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_statement = 'all'
And restart PostgreSQL service... but no log was created... I'm using Windows Server 2003.
Any ideas?
With a corresponding user right may use the query above after connect. This will affect logging until session ends.
You should also set this parameter to log every statement:
In your
data/postgresql.conf
file, change thelog_statement
setting to'all'
.Edit
Looking at your new information, I'd say there may be a few other settings to verify:
log_destination
variablelogging_collector
log_directory
directory already exists inside of thedata
directory, and that the postgres user can write to it.FYI: The other solutions will only log statements from the default database—usually
postgres
—to log others; start with their solution; then:Ref: https://serverfault.com/a/376888 /
log_statement
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#log_directory = 'pg_log'
tolog_directory = 'pg_log'
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
tolog_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
#log_statement = 'none'
tolog_statement = 'all'
#logging_collector = off
tologging_collector = on
Optional:
SELECT set_config('log_statement', 'all', true);
sudo /etc/init.d/postgresql restart
orsudo 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.
Thanks @paul , @Jarret Hardie , @Zoltán , @Rix Beck , @Latif Premani
Just to have more details for CentOS 6.4 (Red Hat 4.4.7-3) running PostgreSQL 9.2, based on the instructions found on this web page:
log_statement = 'all'
andlog_min_error_statement = error
in/var/lib/pgsql/9.2/data/postgresql.conf
./usr/pgsql-9.2/bin/pg_ctl reload -D /var/lib/pgsql/9.2/data/
./var/lib/pgsql/9.2/data/pg_log/