Skip to content

Commit 863471e

Browse files
committed
Set application_name to make shardman deadlock detector happy.
Also port postgres_fdw.use_repeatable_read guc.
1 parent 50caa58 commit 863471e

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

contrib/postgres_fdw/connection.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,23 +451,24 @@ static void
451451
begin_remote_xact(ConnCacheEntry *entry)
452452
{
453453
int curlevel = GetCurrentTransactionNestLevel();
454+
char sql[128];
455+
454456

455457
/* Start main transaction if we haven't yet */
456458
if (entry->xact_depth <= 0)
457459
{
458-
const char *sql;
459-
460460
elog(DEBUG3, "starting remote transaction on connection %p",
461461
entry->conn);
462462

463463
if (UseGlobalSnapshots && (!IsolationUsesXactSnapshot() ||
464464
IsolationIsSerializable()))
465465
elog(ERROR, "Global snapshots support only REPEATABLE READ");
466466

467-
if (IsolationIsSerializable())
468-
sql = "START TRANSACTION ISOLATION LEVEL SERIALIZABLE";
469-
else
470-
sql = "START TRANSACTION ISOLATION LEVEL REPEATABLE READ";
467+
468+
sprintf(sql, "START TRANSACTION %s; set application_name='pgfdw:%lld:%d';",
469+
IsolationIsSerializable() ? "ISOLATION LEVEL SERIALIZABLE" :
470+
UseRepeatableRead ? "ISOLATION LEVEL REPEATABLE READ" : "",
471+
(long long) GetSystemIdentifier(), MyProcPid);
471472

472473
entry->changing_xact_state = true;
473474
do_sql_command(entry->conn, sql);

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ typedef struct
273273
} ec_member_foreign_arg;
274274

275275
bool UseGlobalSnapshots;
276+
bool UseRepeatableRead;
276277
void _PG_init(void);
277278

278279
/*
@@ -5911,4 +5912,8 @@ _PG_init(void)
59115912
"Use global snapshots for FDW transactions", NULL,
59125913
&UseGlobalSnapshots, false, PGC_USERSET, 0, NULL,
59135914
NULL, NULL);
5915+
DefineCustomBoolVariable("postgres_fdw.use_repeatable_read",
5916+
"Use repeatable read isilation error for remote transactions", NULL,
5917+
&UseRepeatableRead, true, PGC_USERSET, 0, NULL,
5918+
NULL, NULL);
59145919
}

contrib/postgres_fdw/postgres_fdw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ extern const char *get_jointype_name(JoinType jointype);
187187
extern bool is_builtin(Oid objectId);
188188
extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
189189

190+
extern bool UseRepeatableRead;
190191
extern bool UseGlobalSnapshots;
191192

192193
#endif /* POSTGRES_FDW_H */

0 commit comments

Comments
 (0)