Here's where I think the logging is happening. https://github.com/postgres/postgres/blob/master/src/backend/tcop/postgres.c#L1070 It seems like the log is happening before application of the transaction, not after.
So consistency is best effort. ie - a crash after the log but before the transaction is committed could result in a logged statement that wasn't actually committed. Logging is not handled in the WAL and is not guaranteed to be consistent in the way that different statements in a transaction are, which is the nuance that I'm interested in documenting. Maybe the doc update should be to say that statements in the log may not have been applied rather than saying that applied statements might not appear in the log. I'm not very familiar with the codebase yet. If you know this section well, I'd be very happy to learn what inconsistencies you think are possible in postgres and whether you think there's scope to make the docs clearer about them. If you're saying that there is some mechanism to keep the log consistent with which transactions are actually committed could you please share a link to that part of the code so I can learn more? -Daniel On Mon, Jul 28, 2025 at 11:38 AM Bruce Momjian <br...@momjian.us> wrote: > On Fri, Jul 25, 2025 at 03:24:48PM -0700, Daniel Bauman wrote: > > Hey pgsql hackers > > This is my first email to this list. I'm reaching out about a possible > doc > > update for the log_statement parameter. > > Here's the current doc - https://www.postgresql.org/docs/current/ > > runtime-config-logging.html > > The doc already has a Note bubble for the log_statement parameter with > some > > important callouts. > > > > I am proposing adding something there to call out that there is no > guarantee > > provided that all committed statements in the DB will be logged. The > logging to > > the log file is not part of PGs ACID compliant DB engine but instead a > separate > > best-effort system. This might be obvious to some people but I don't > think it > > is for everyone. > > > > In many cases people will use these logs for security, legal or > compliance > > reasons and I think it's relevant to users to make the consistency > guarantees > > explicit and clear. > > > > Please let me know what you think and also if you think there's a > different > > place where this notification would be better placed. Maybe it already > exists > > somewhere else. > > > > This would be very similar to the documentation that MySQL have over > here - > > > https://dev.mysql.com/doc/refman/8.4/en/audit-log-logging-configuration.html > > "Regardless of strategy, logging occurs on a best-effort basis, with no > > guarantee of consistency." > > > > I believe the same applies to the PGAudit extension but I'm starting out > here. > > Why do you think log_statement is best effort? > > -- > Bruce Momjian <br...@momjian.us> https://momjian.us > EDB https://enterprisedb.com > > Do not let urgent matters crowd out time for investment in the future. >