Audit entries are written to the standard logging facility and contain
the following columns in comma-separated format:
<note>
<para>
Output is compliant CSV format only if the log line prefix portion
of each log entry is removed.
</para>
</note>
<itemizedlist>
<listitem>
<para>
<literal>AUDIT_TYPE</> - <literal>SESSION</> or
<literal>OBJECT</>.
</para>
</listitem>
<listitem>
<para>
<literal>STATEMENT_ID</> - Unique statement ID for this session.
Each statement ID represents a backend call. Statement IDs are
sequential even if some statements are not logged. There may be
multiple entries for a statement ID when more than one relation
is logged.
</para>
</listitem>
<listitem>
<para>
<literal>SUBSTATEMENT_ID</> - Sequential ID for each
substatement within the main statement. For example, calling
a function from a query. Substatement IDs are continuous
even if some substatements are not logged. There may be multiple
entries for a substatement ID when more than one relation is logged.
</para>
</listitem>
<listitem>
<para>
<literal>CLASS</> - e.g. (<literal>READ</>,
<literal>ROLE</>) (see <xref linkend="guc-pgaudit-log">).
</para>
</listitem>
<listitem>
<para>
<literal>COMMAND</> - e.g. <literal>ALTER TABLE</>,
<literal>SELECT</>.
</para>
</listitem>
<listitem>
<para>
<literal>OBJECT_TYPE</> - <literal>TABLE</>,
<literal>INDEX</>, <literal>VIEW</>, etc.
Available for <literal>SELECT</>, <literal>DML</> and most
<literal>DDL</> statements.
</para>
</listitem>
<listitem>
<para>
<literal>OBJECT_NAME</> - The fully-qualified object name
(e.g. public.account). Available for <literal>SELECT</>,
<literal>DML</> and most <literal>DDL</> statements.
</para>
</listitem>
<listitem>
<para>
<literal>STATEMENT</> - Statement executed on the backend.
</para>
</listitem>
</itemizedlist>
</para>
<para>
Use <xref linkend="guc-log-line-prefix"> to add any other fields that
are needed to satisfy your audit log requirements. A typical log line
prefix might be <literal>'%m %u %d: '</> which would provide the date/time,
user name, and database name for each audit log.
</para>
</sect2>
<sect2>
<title>Caveats</title>
<itemizedlist>
<listitem>
<para>
Object renames are logged under the name they were renamed to.
For example, renaming a table will produce the following result:
</para>
<programlisting>
ALTER TABLE test RENAME TO test2;
AUDIT: SESSION,36,1,DDL,ALTER TABLE,TABLE,public.test2,ALTER TABLE test RENAME TO test2
</programlisting>
</listitem>
<listitem>
<para>
It is possible to have a command logged more than once. For example,
when a table is created with a primary key specified at creation time
the index for the primary key will be logged independently and another
audit log will be made for the index under the create entry. The
multiple entries will however be contained within one statement ID.
</para>
</listitem>
<listitem>
<para>
Autovacuum and Autoanalyze are not logged.
</para>
</listitem>
<listitem>
<para>
Statements that are executed after a transaction enters an aborted state
will not be audit logged. However, the statement that caused the error
and any subsequent statements executed in the aborted transaction will
be logged as ERRORs by the standard logging facility.
</para>
</listitem>
</itemizedlist>
</sect2>
<sect2>
<title>Authors</title>
<para>
Abhijit Menon-Sen <email>ams@2ndQuadrant.com</email>, Ian Barwick <email>ian@2ndQuadrant.com</email>, and David Steele <email>david@pgmasters.net</email>.