Skip to content

Commit 6603573

Browse files
Give most recovery conflict errors a retryable error code. From recent
requests and discussions with Yeb Havinga and Kevin Grittner.
1 parent 44e5569 commit 6603573

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/backend/tcop/postgres.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.593 2010/04/20 01:38:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.594 2010/05/12 19:45:02 sriggs Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -174,6 +174,7 @@ static int UseNewLine = 0; /* Use EOF as query delimiters */
174174

175175
/* whether or not, and why, we were cancelled by conflict with recovery */
176176
static bool RecoveryConflictPending = false;
177+
static bool RecoveryConflictRetryable = true;
177178
static ProcSignalReason RecoveryConflictReason;
178179

179180
/* ----------------------------------------------------------------
@@ -2836,6 +2837,15 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
28362837

28372838
Assert(RecoveryConflictPending && (QueryCancelPending || ProcDiePending));
28382839

2840+
/*
2841+
* All conflicts apart from database cause dynamic errors where the
2842+
* command or transaction can be retried at a later point with some
2843+
* potential for success. No need to reset this, since
2844+
* non-retryable conflict errors are currently FATAL.
2845+
*/
2846+
if (reason == PROCSIG_RECOVERY_CONFLICT_DATABASE)
2847+
RecoveryConflictRetryable = false;
2848+
28392849
/*
28402850
* If it's safe to interrupt, and we're waiting for input or a lock,
28412851
* service the interrupt immediately
@@ -2885,6 +2895,11 @@ ProcessInterrupts(void)
28852895
ereport(FATAL,
28862896
(errcode(ERRCODE_ADMIN_SHUTDOWN),
28872897
errmsg("terminating autovacuum process due to administrator command")));
2898+
else if (RecoveryConflictPending && RecoveryConflictRetryable)
2899+
ereport(FATAL,
2900+
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
2901+
errmsg("terminating connection due to conflict with recovery"),
2902+
errdetail_recovery_conflict()));
28882903
else if (RecoveryConflictPending)
28892904
ereport(FATAL,
28902905
(errcode(ERRCODE_ADMIN_SHUTDOWN),
@@ -2936,14 +2951,14 @@ ProcessInterrupts(void)
29362951
DisableCatchupInterrupt();
29372952
if (DoingCommandRead)
29382953
ereport(FATAL,
2939-
(errcode(ERRCODE_ADMIN_SHUTDOWN),
2954+
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
29402955
errmsg("terminating connection due to conflict with recovery"),
29412956
errdetail_recovery_conflict(),
29422957
errhint("In a moment you should be able to reconnect to the"
29432958
" database and repeat your command.")));
29442959
else
29452960
ereport(ERROR,
2946-
(errcode(ERRCODE_QUERY_CANCELED),
2961+
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
29472962
errmsg("canceling statement due to conflict with recovery"),
29482963
errdetail_recovery_conflict()));
29492964
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy