การตั้งค่าให้ PostgreSQL เก็บค่า logs นี้เหมาะสำหรับ นักพัฒนาไว้สำหรับตามดูคำสั่ง SQL ที่เราเขียนไปหรือ ถ้ามีการใช้งาน ORM เราก็สามารถดูได้จาก logs นี้ว่า แท้ที่จริงแล้ว ORM ที่เราเรียกใช้ Query คำสั่งอะไรใส่ฐานข้อมูลเรา
วิธีตั้งค่าให้ PGSQL เก็บ logs query ทำดังนี้ 1. เปิดไฟล์ data/postgresql.conf
2.เปลี่ยนบันทัด #log_statement = 'none' เป็น log_statement = 'all'
3.เอาเครื่องหมาย # หน้า log_directory = 'pg_log' ออก
4. Restart PostgreSQL
วิธีดู logs SQL ให้เข้าไปที่ PostgreSQL\data\pg_log
ตัวอย่างชื่อไฟล์ postgresql-2014-06-03_010835.log
ตัวอย่าง log SQL ของ OpenERP
2014-06-03 01:27:04 ICT LOG: statement: RESET ALL
2014-06-03 01:27:04 ICT LOG: statement: SET SESSION AUTHORIZATION DEFAULT
2014-06-03 01:27:04 ICT LOG: statement: SHOW default_transaction_isolation
2014-06-03 01:27:04 ICT LOG: statement: SET default_transaction_isolation TO 'repeatable read'
2014-06-03 01:27:04 ICT LOG: statement: BEGIN
2014-06-03 01:27:04 ICT LOG: statement: SELECT 1 FROM ir_module_module WHERE name='base' AND latest_version='7.0.1.3'
2014-06-03 01:27:04 ICT LOG: statement: SELECT * FROM ir_cron
WHERE numbercall != 0
AND active AND nextcall <= (now() at time zone 'UTC')
ORDER BY priority
2014-06-03 01:27:04 ICT LOG: statement: ROLLBACK