Auditing SQL

There are two main ways to log SQL

  • Using the PostgreSQL log_statement parameter
  • Using the pgaudit extension’s pgaudit.log parameter

The log_statement parameter can be set to one of the following options:

  • ALL: logs all SQL statements executed at top-level
  • MOD: logs all SQL statements for INSERT, UPDATE, DELETE, and TRUNCATE
  • ddl: logs all SQL statements for DDL commands
  • NONE: no statements logged

For example,to log all DDL commands, edit your postgresql.conf file to set the following

log_statement  =  'ddl'

The log_statement SQL statements explicitly given in top-level commands. It is still possible to perform SQL without it being logged by this setting if you use any of the PL languages, either through DO statements or by calling ...

Get PostgreSQL 10 Administration Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.