Fix interaction of log_line_prefix's query_id and log_statement

log_statement is issued before query_id can be computed, so properly
clear the value, and document the interaction.

Reported-by: Fujii Masao, Michael Paquier

Discussion: https://postgr.es/m/YHPkU8hFi4no4NSw@paquier.xyz

Author: Julien Rouhaud
This commit is contained in:
Bruce Momjian 2021-04-20 12:57:59 -04:00
parent 9660834dd8
commit db01f797dd
2 changed files with 11 additions and 0 deletions

View File

@ -7139,6 +7139,16 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
</programlisting>
</para>
</tip>
<note>
<para>
The <literal>%Q</literal> escape always reports a zero identifier
for lines output by <xref linkend="guc-log-statement"/> because
<varname>log_statement</varname> generates output before an
identifier can be calculated, including invalid statements for
which an identifier cannot be calculated.
</para>
</note>
</listitem>
</varlistentry>

View File

@ -398,6 +398,7 @@ pgstat_bestart(void)
lbeentry.st_state = STATE_UNDEFINED;
lbeentry.st_progress_command = PROGRESS_COMMAND_INVALID;
lbeentry.st_progress_command_target = InvalidOid;
lbeentry.st_query_id = UINT64CONST(0);
/*
* we don't zero st_progress_param here to save cycles; nobody should