The doc fragment you shared is explaining to customers that basic syntax checks are done before postgres gets to logging the transaction. I don't think that is the same as clearly explaining to users statement logging happens before execution. At least for me, as a user and reader of the docs but not someone familiar with the code, the docs didn't make it clear to me how statement logging corresponded to query execution.
Do you think there's room to document something like "Statements are logged before they are executed. It's not guaranteed that logged statements have been successfully executed." I'd be happy to submit and iterate on a pull request if you do. I'd also like to understand what happens if there are errors writing the log - like the disk where the log directory is configured being full. My understanding is the following. ereport ( https://github.com/postgres/postgres/blob/71c0921b649d7a800eb2d6f93539890eaa14d979/src/include/utils/elog.h#L163) will end up calling errfinish and errfinish will call EmitErrorReport ( https://github.com/postgres/postgres/blob/master/src/backend/utils/error/elog.c#L543) which will call send_message_to_server_log ( https://github.com/postgres/postgres/blob/71c0921b649d7a800eb2d6f93539890eaa14d979/src/backend/utils/error/elog.c#L1733) and that will call write_syslogger_file ( https://github.com/postgres/postgres/blob/71c0921b649d7a800eb2d6f93539890eaa14d979/src/backend/utils/error/elog.c#L3443C2-L3443C16 ). write_syslogger_file looks like it handles errors by logging to stderr but not raising an error condition that would cancel the transaction ( https://github.com/postgres/postgres/blob/71c0921b649d7a800eb2d6f93539890eaa14d979/src/backend/postmaster/syslogger.c#L1126 ) Do I understand correctly or am I on the wrong codepath? -Daniel On Mon, Jul 28, 2025 at 4:35 PM Bruce Momjian <br...@momjian.us> wrote: > On Mon, Jul 28, 2025 at 04:24:14PM -0700, Daniel Bauman wrote: > > 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. > > Yes, right, it is not that we do some "best effort", whatever that > means, but rather we just log when we start running the statement. The > docs clearly explain we log after parsing but before execution: > > Statements that contain simple syntax errors are not logged even > by the <varname>log_statement</varname> = <literal>all</literal> > setting, because the log message is emitted only after basic > parsing has been done to determine the statement type. > > -- > 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. >