Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a6c926a

Browse files
committed
Set application name in postgres_fdw to allow distributed deadlock detection
1 parent a92b783 commit a6c926a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

contrib/postgres_fdw/connection.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,18 @@ begin_remote_xact(ConnCacheEntry *entry)
501501
{
502502
int curlevel = GetCurrentTransactionNestLevel();
503503
PGresult *res;
504+
char sql[128];
504505

505506

506507
/* Start main transaction if we haven't yet */
507508
if (entry->xact_depth <= 0)
508509
{
509-
const char *sql;
510-
511510
elog(DEBUG3, "starting remote transaction on connection %p",
512511
entry->conn);
513512

514-
if (IsolationIsSerializable())
515-
sql = "START TRANSACTION ISOLATION LEVEL SERIALIZABLE";
516-
else if (UseRepeatableRead)
517-
sql = "START TRANSACTION ISOLATION LEVEL REPEATABLE READ";
518-
else
519-
sql = "START TRANSACTION";
513+
sprintf(sql, "START TRANSACTION %s; set application_name='pgfdw:%lld:%d';",
514+
IsolationIsSerializable() ? "ISOLATION LEVEL SERIALIZABLE" : UseRepeatableRead ? "ISOLATION LEVEL REPEATABLE READ" : "",
515+
(long long)GetSystemIdentifier(), MyProcPid);
520516
entry->changing_xact_state = true;
521517
do_sql_command(entry->conn, sql);
522518
entry->xact_depth = 1;
@@ -568,8 +564,6 @@ begin_remote_xact(ConnCacheEntry *entry)
568564
*/
569565
while (entry->xact_depth < curlevel)
570566
{
571-
char sql[64];
572-
573567
snprintf(sql, sizeof(sql), "SAVEPOINT s%d", entry->xact_depth + 1);
574568
entry->changing_xact_state = true;
575569
do_sql_command(entry->conn, sql);

0 commit comments

Comments
 (0)