Re: printf ordering issues?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: James Coleman <jtc331(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: printf ordering issues?
Date: 2018-12-12 00:26:12
Message-ID: 26492.1544574372@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

James Coleman <jtc331(at)gmail(dot)com> writes:
> While using printf to do some good old fashioned print debugging, I
> noticed that it seemed like my printf statements in the executor were
> sometimes not getting printed to the log at all, and sometimes getting
> printed out *before* the ones I have in the planner.

> Upon further investigation I realized instead that the output from the
> executor is getting flushed on the *subsequent* query.

> Is there some kind of weird behavior that most hackers already know
> about and I'm missing?

stdout is usually fully buffered, stderr usually is only line-buffered,
so if you print to stdout you need a lot of fflush'es to keep it in
sync with error/log messages (which go through stderr). Personally
I've developed the habit of just making quick-log logging patches
print to stderr instead ...

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2018-12-12 00:33:23 Re: automatically assigning catalog toast oids
Previous Message Alexander Korotkov 2018-12-12 00:22:09 Re: Connections hang indefinitely while taking a gin index's LWLock buffer_content lock