At postgresql.conf, you can turn on logging for query. It is helpful if you are catching some query error.

Lines to look for

log_destination = 'stderr'
logging_collector = on 
log_directory = '/var/log/postgresql'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_file_mode = 0506

Be sure to turn it off because it dramatically reduce the performance of Postgresql.