Re: WAIT FOR NO_THROW option could use some documentation
Re: WAIT FOR NO_THROW option could use some documentation
Hi Peter,
On Thu, Sep 3, 2026 at 4:05 AM Peter Eisentraut wrote:
>
> On 01.09.26 08:28, Xuneng Zhou wrote:
> > 'NO_THROW' was added to make those statuses available for ordinary
> > application control flow. Without it, 'timeout' and 'not in recovery'
> > are raised as SQL errors. With it, they are returned as status values,
> > allowing the application to retry, report replication lag, refresh its
> > routing information, or direct a subsequent read to the primary. In
> > that sense, 'NO_THROW' selects how these expected wait outcomes are
> > reported: through the error channel or through the result row.
>
> This just explains the technical distinction, not why it's needed.
> Applications or client frameworks could just as well inspect an error
> return with for example an appropriate error code. That's what they'd d
> for any other command.
That's interesting. I was unaware of the use of error codes as the
states of application logical control flow. But that use seems not
elegant to me or maybe I misunderstood its usage.
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
ERRCODE_QUERY_CANCELED
These error codes are overloaded in terms of meaning and the
conditions lead to each. They are not tailed for the return states of
WAIT FOR. If I was a user, I would be less happy to figure out what
they mean and what they are represented for.
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("recovery is not in progress"),
errcode + errmsg together seems to be a more sensible state, but it
would require extra parsing effort.
But this alone seems not warrant a standalone option. The direction
that Rithvika put earlier now makes more sense to me. But I would
suggest adjusting its expression and adding examples. I'll reply later
while I get more time.
--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
Re: WAIT FOR NO_THROW option could use some documentation
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
Hi,
On Thu, Sep 3, 2026 at 1:10 AM Xuneng Zhou <xunengzhou@gmail.com> wrote:
Hi Peter,
On Thu, Sep 3, 2026 at 4:05 AM Peter Eisentraut <peter@eisentraut.org> wrote:
>
> On 01.09.26 08:28, Xuneng Zhou wrote:
> > 'NO_THROW' was added to make those statuses available for ordinary
> > application control flow. Without it, 'timeout' and 'not in recovery'
> > are raised as SQL errors. With it, they are returned as status values,
> > allowing the application to retry, report replication lag, refresh its
> > routing information, or direct a subsequent read to the primary. In
> > that sense, 'NO_THROW' selects how these expected wait outcomes are
> > reported: through the error channel or through the result row.
>
> This just explains the technical distinction, not why it's needed.
> Applications or client frameworks could just as well inspect an error
> return with for example an appropriate error code. That's what they'd d
> for any other command.
That's interesting. I was unaware of the use of error codes as the
states of application logical control flow. But that use seems not
elegant to me or maybe I misunderstood its usage.
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
ERRCODE_QUERY_CANCELED
These error codes are overloaded in terms of meaning and the
conditions lead to each. They are not tailed for the return states of
WAIT FOR. If I was a user, I would be less happy to figure out what
they mean and what they are represented for.
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("recovery is not in progress"),
errcode + errmsg together seems to be a more sensible state, but it
would require extra parsing effort.
But this alone seems not warrant a standalone option. The direction
that Rithvika put earlier now makes more sense to me. But I would
suggest adjusting its expression and adding examples. I'll reply later
while I get more time.
Maybe something along these lines - "NO_THROW option safely prevents the database
from aborting an active transaction, allowing subsequent queries within the transaction
to proceed without losing prior work"?
Thanks,
Satya
Re: WAIT FOR NO_THROW option could use some documentation
On Thu, Sep 3, 2026 at 4:39 PM Peter Eisentraut wrote: > On 03.09.26 17:21, SATYANARAYANA NARLAPURAM wrote: > > Maybe something along these lines - "NO_THROW option safely prevents the > > database > > from aborting an active transaction, allowing subsequent queries within > > the transaction > > to proceed without losing prior work"? > > Maybe that's what it is meant for, but that seems separate from the > status reporting mechanism. It could also send an error message to the > client but not abort the transaction on the server. I think sending an error without aborting the transaction on the server would invite too much confusion. But I also wonder if the documentation's claim that this option will just cause the server to categorically not throw errors can really be correct. In most places where we have an error-suppression facility of some kind, it's much more narrowly scoped. -- Robert Haas EDB: http://www.enterprisedb.com
Re: WAIT FOR NO_THROW option could use some documentation
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
On Thu, Sep 3, 2026 at 4:20 PM Robert Haas <robertmhaas@gmail.com> wrote:
On Thu, Sep 3, 2026 at 4:39 PM Peter Eisentraut <peter@eisentraut.org> wrote:
> On 03.09.26 17:21, SATYANARAYANA NARLAPURAM wrote:
> > Maybe something along these lines - "NO_THROW option safely prevents the
> > database
> > from aborting an active transaction, allowing subsequent queries within
> > the transaction
> > to proceed without losing prior work"?
>
> Maybe that's what it is meant for, but that seems separate from the
> status reporting mechanism. It could also send an error message to the
> client but not abort the transaction on the server.
I think sending an error without aborting the transaction on the
server would invite too much confusion. But I also wonder if the
documentation's claim that this option will just cause the server to
categorically not throw errors can really be correct. In most places
where we have an error-suppression facility of some kind, it's much
more narrowly scoped.
Agree with Robert on this. I would say the error suppression is narrow here as well.
When an incorrect mode or LSN is provided, it throws an error even with the NO_THROW option.
postgres=# WAIT FOR LSN '0/306EEk0' WITH (TIMEOUT '100ms', NO_THROW, MODE primary_flush);
ERROR: invalid input syntax for type pg_lsn: "0/306EEk0"
postgres=# WAIT FOR LSN '0/306EE0' WITH (TIMEOUT '100ms', NO_THROW, MODE primary_flush2);
ERROR: unrecognized value for WAIT option "mode": "primary_flush2"
ERROR: invalid input syntax for type pg_lsn: "0/306EEk0"
postgres=# WAIT FOR LSN '0/306EE0' WITH (TIMEOUT '100ms', NO_THROW, MODE primary_flush2);
ERROR: unrecognized value for WAIT option "mode": "primary_flush2"
Re: WAIT FOR NO_THROW option could use some documentation
От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
Hi Satya, On Fri, Sep 4, 2026 at 7:00 AM SATYANARAYANA NARLAPURAM wrote: > > Hi, > > On Thu, Sep 3, 2026 at 1:39 PM Peter Eisentraut wrote: >> >> On 03.09.26 17:21, SATYANARAYANA NARLAPURAM wrote: >> > Maybe something along these lines - "NO_THROW option safely prevents the >> > database >> > from aborting an active transaction, allowing subsequent queries within >> > the transaction >> > to proceed without losing prior work"? >> >> Maybe that's what it is meant for, but that seems separate from the >> status reporting mechanism. It could also send an error message to the >> client but not abort the transaction on the server. > > > Curious, Is there an existing precedent for this in the core where we send an error > but not abort a transaction on the server? Parsing error messages is painful compared > to reading the result set it seems. I asked Sol to investigate this, and it said it did not find one. > Additionally, I see the information passed to the client when an error is thrown much richer > than a row returned like timeout. Perhaps if we decide to support NO_THROW should > we consider adding a current replay LSN as well? I think this depends on how applications are expected to use the result. If the primary use of it is states for application control flow, then the brevity seems good to me. For extended diagnostic or monitoring purposes, adding a companioning LSN might make sense. Humans might prefer richer messages if they would look at it, but it might not necessarily be the interface an application should have to parse.I don't know how users would actually use it. > postgres=# WAIT FOR LSN '0/306EE20' WITH (TIMEOUT '0.1s'); > ERROR: timed out while waiting for target LSN 0/306EE20 to be replayed; current replay LSN 0/306EA60 > > postgres=# WAIT FOR LSN '0/306EE20' WITH (TIMEOUT '100ms', NO_THROW); > status > --------- > timeout > (1 row) > > Thanks, > Satya -- Regards, Xuneng Zhou HighGo Software Co., Ltd.
Re: WAIT FOR NO_THROW option could use some documentation
От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
On Thu, Sep 3, 2026 at 11:21 PM SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> wrote:
>
> Hi,
>
> On Thu, Sep 3, 2026 at 1:10 AM Xuneng Zhou <xunengzhou@gmail.com> wrote:
>>
>> Hi Peter,
>>
>> On Thu, Sep 3, 2026 at 4:05 AM Peter Eisentraut <peter@eisentraut.org> wrote:
>> >
>> > On 01.09.26 08:28, Xuneng Zhou wrote:
>> > > 'NO_THROW' was added to make those statuses available for ordinary
>> > > application control flow. Without it, 'timeout' and 'not in recovery'
>> > > are raised as SQL errors. With it, they are returned as status values,
>> > > allowing the application to retry, report replication lag, refresh its
>> > > routing information, or direct a subsequent read to the primary. In
>> > > that sense, 'NO_THROW' selects how these expected wait outcomes are
>> > > reported: through the error channel or through the result row.
>> >
>> > This just explains the technical distinction, not why it's needed.
>> > Applications or client frameworks could just as well inspect an error
>> > return with for example an appropriate error code. That's what they'd d
>> > for any other command.
>>
>> That's interesting. I was unaware of the use of error codes as the
>> states of application logical control flow. But that use seems not
>> elegant to me or maybe I misunderstood its usage.
>>
>> ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
>> ERRCODE_QUERY_CANCELED
>>
>> These error codes are overloaded in terms of meaning and the
>> conditions lead to each. They are not tailed for the return states of
>> WAIT FOR. If I was a user, I would be less happy to figure out what
>> they mean and what they are represented for.
>>
>> errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
>> errmsg("recovery is not in progress"),
>>
>> errcode + errmsg together seems to be a more sensible state, but it
>> would require extra parsing effort.
>>
>>
>> But this alone seems not warrant a standalone option. The direction
>> that Rithvika put earlier now makes more sense to me. But I would
>> suggest adjusting its expression and adding examples. I'll reply later
>> while I get more time.
>
>
> Maybe something along these lines - "NO_THROW option safely prevents the database
> from aborting an active transaction, allowing subsequent queries within the transaction
> to proceed without losing prior work"?
Thanks for the suggestion. I guess that this is the main differentiater from other alternatives.
As Robert and you pointed out earlier -- no_throw cannot suppress all errors. I think it's true. Then the first part of the para may be too broad -- it cannot protect everything -- some errors still abort txn. I am also wondering whether we need to emphasize "why no_throw is genuinely needed" over "when/how to use it". Yeah, there are alternatives to achieve almost the same thing(maybe less graceful) like riding a horse or car can both go to a place (may not be a good analogy). Do users really care that much why a car is better than a horse in what aspects and why do they want a car even they have a horse? If we offer them an option, we might want to tell them when/how to use it just like a car manual won't have much material about why it is unreplaceble from and superior to its peers.
As Robert and you pointed out earlier -- no_throw cannot suppress all errors. I think it's true. Then the first part of the para may be too broad -- it cannot protect everything -- some errors still abort txn. I am also wondering whether we need to emphasize "why no_throw is genuinely needed" over "when/how to use it". Yeah, there are alternatives to achieve almost the same thing(maybe less graceful) like riding a horse or car can both go to a place (may not be a good analogy). Do users really care that much why a car is better than a horse in what aspects and why do they want a car even they have a horse? If we offer them an option, we might want to tell them when/how to use it just like a car manual won't have much material about why it is unreplaceble from and superior to its peers.
If that make sense, I found the version that Kiran suggested to be useful. Here's a edited version on that:
Use
NO_THROW when timeout or not in recovery is an expected result that the application intends to handle, for example by retrying the wait, reporting replication delay, or choosing another server for a subsequent operation. The command then returns the result as a status, which the application must check before assuming that the target LSN was reached. Omit NO_THROW when the application must not proceed unless the target LSN is reached, so that an unsuccessful wait stops normal execution with an error. Returning a status also leaves an explicit transaction usable; without NO_THROW, the corresponding error requires rollback of the transaction or to a savepoint before further commands can be issued. NO_THROW changes only how timeout and not in recovery are reported; other errors are still raised. It does not limit the duration of the wait; specify TIMEOUT for that purpose.WDT?
---
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
Xuneng Zhou
HighGo Software Co., Ltd.
Re: WAIT FOR NO_THROW option could use some documentation
От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
On Fri, Sep 4, 2026 at 8:26 AM SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> wrote:
>
>
>
> On Thu, Sep 3, 2026 at 4:20 PM Robert Haas <robertmhaas@gmail.com> wrote:
>>
>> On Thu, Sep 3, 2026 at 4:39 PM Peter Eisentraut <peter@eisentraut.org> wrote:
>> > On 03.09.26 17:21, SATYANARAYANA NARLAPURAM wrote:
>> > > Maybe something along these lines - "NO_THROW option safely prevents the
>> > > database
>> > > from aborting an active transaction, allowing subsequent queries within
>> > > the transaction
>> > > to proceed without losing prior work"?
>> >
>> > Maybe that's what it is meant for, but that seems separate from the
>> > status reporting mechanism. It could also send an error message to the
>> > client but not abort the transaction on the server.
>>
>> I think sending an error without aborting the transaction on the
>> server would invite too much confusion. But I also wonder if the
>> documentation's claim that this option will just cause the server to
>> categorically not throw errors can really be correct. In most places
>> where we have an error-suppression facility of some kind, it's much
>> more narrowly scoped.
>
>
> Agree with Robert on this. I would say the error suppression is narrow here as well.
Yeah, I also think Robert is right for not claiming it absolutely.
"If NO_THROW is specified, the command returns a status string instead of throwing errors."
We may need to soften this line.
> When an incorrect mode or LSN is provided, it throws an error even with the NO_THROW option.
>
>
> postgres=# WAIT FOR LSN '0/306EEk0' WITH (TIMEOUT '100ms', NO_THROW, MODE primary_flush);
> ERROR: invalid input syntax for type pg_lsn: "0/306EEk0"
> postgres=# WAIT FOR LSN '0/306EE0' WITH (TIMEOUT '100ms', NO_THROW, MODE primary_flush2);
> ERROR: unrecognized value for WAIT option "mode": "primary_flush2"
Thanks for testing this. I agree that the behavior is not aligned with the description of doc. The behavior itself seems fine to me, what we need to change is the doc. These errors are not supposed to be suppressed because they are not valid inputs in the first place. Another one error needs consideration is primary_flush waiting in standby. Currently, we prevent this use by erroring out before entering the wait, hence no_throw option cannot suppress it. I think this behavior is fine. To suppressithat error implies that we want a new return status like 'in recovery' after valid waiting. However, that needs seems not true because we don't expect a primary being demoted to a standby. We might still need extra description for it.
--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
Re: WAIT FOR NO_THROW option could use some documentation
On Thu, Sep 10, 2026 at 9:10 AM Xuneng Zhou wrote: > > Hi Rithvika, > > On Tue, Sep 8, 2026 at 11:49 AM Rithvika Devisetti > wrote: > > > > Thank you everyone for the suggestions. > > v3 attached, folding in the remaining points. > > > > The description now says the command "reports these outcomes as a > > status string instead of raising an error", tying it to the timeout and > > promotion cases named just above rather than claiming suppression > > generally. > > > > The option entry uses the consolidated wording from earlier in the > > thread, and its last paragraph now names what still errors: invalid > > inputs (Satya's malformed-LSN and unrecognized-mode examples), and > > requesting primary_flush during recovery, which is rejected before the > > wait begins, per Xuneng's note. > > Personally, v3 LGTM. I've rebased the patch. Also, I've slightly adjusted the 3rd paragraph. In v3 it assumes to enumerate the full list of possible errors. I think it's fragile as this list becomes invalid with every new possible error. I've reworded it in the way it specifies some of possible errors. > That said, I am not familiar with and very sure about the exact use of > the option in the application side. It would be helpful to hear other > hackers' opinions on it. I think nobody can be very sure on the exact usage pattern. The usage pattern that motivate this feature is "read-your writes" consistency: after committing something on the primary, read the database at least containing these changes on replica. What application should do in the case of timeout or not-in-recovery state we can't exactly know. It depends on the business logic and the replication cluster configuration. The point of NO_THROW is that these states may appear even when application doesn't misuse WAIT commit (like issuing WAIT while already holding the snapshot). So, it makes sense to let app distinguish these states without having to parse the error message. >T he patch seems to deserve a mention in the > open items page[1]. Can you add it, if you have the access? I emailed > the administrator [pgsql-www@lists.postgresql.org] some time ago, but > got no response back. > > And again, please place your response *after* the snippet of the email > you want to reply to like this comment from me did. It protects the > logic flow of reading email. > > [1] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items I'm going to push this if no objection (in this case I think we can skip open items as it's going to be resolved anyway). ------ Regards, Alexander Korotkov Supabase
Re: WAIT FOR NO_THROW option could use some documentation
От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
On Thu, Sep 17, 2026 at 6:00 AM Alexander Korotkov wrote: > I've rebased the patch. Also, I've slightly adjusted the 3rd > paragraph. In v3 it assumes to enumerate the full list of possible > errors. I think it's fragile as this list becomes invalid with every > new possible error. I've reworded it in the way it specifies some of > possible errors. Make sense. > > That said, I am not familiar with and very sure about the exact use of > > the option in the application side. It would be helpful to hear other > > hackers' opinions on it. > > I think nobody can be very sure on the exact usage pattern. The usage > pattern that motivate this feature is "read-your writes" consistency: > after committing something on the primary, read the database at least > containing these changes on replica. What application should do in > the case of timeout or not-in-recovery state we can't exactly know. > It depends on the business logic and the replication cluster > configuration. The point of NO_THROW is that these states may appear > even when application doesn't misuse WAIT commit (like issuing WAIT > while already holding the snapshot). So, it makes sense to let app > distinguish these states without having to parse the error message. Thanks for the explanation. > I'm going to push this if no objection (in this case I think we can > skip open items as it's going to be resolved anyway). LGTM. -- Regards, Xuneng Zhou HighGo Software Co., Ltd.
Re: WAIT FOR NO_THROW option could use some documentation
От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Thu, Sep 17, 2026 at 6:41 AM Xuneng Zhou wrote: > On Thu, Sep 17, 2026 at 6:00 AM Alexander Korotkov wrote: > > > I've rebased the patch. Also, I've slightly adjusted the 3rd > > paragraph. In v3 it assumes to enumerate the full list of possible > > errors. I think it's fragile as this list becomes invalid with every > > new possible error. I've reworded it in the way it specifies some of > > possible errors. > > Make sense. > > > > That said, I am not familiar with and very sure about the exact use of > > > the option in the application side. It would be helpful to hear other > > > hackers' opinions on it. > > > > I think nobody can be very sure on the exact usage pattern. The usage > > pattern that motivate this feature is "read-your writes" consistency: > > after committing something on the primary, read the database at least > > containing these changes on replica. What application should do in > > the case of timeout or not-in-recovery state we can't exactly know. > > It depends on the business logic and the replication cluster > > configuration. The point of NO_THROW is that these states may appear > > even when application doesn't misuse WAIT commit (like issuing WAIT > > while already holding the snapshot). So, it makes sense to let app > > distinguish these states without having to parse the error message. > > Thanks for the explanation. > > > I'm going to push this if no objection (in this case I think we can > > skip open items as it's going to be resolved anyway). > > LGTM. Thank you, pushed. ------ Regards, Alexander Korotkov Supabase