Skip to content

Commit a5fe66b

Browse files
committed
isolationtester: append session name to application_name.
When writing / debugging an isolation test it sometimes is useful to see which session holds what lock etc. To make it easier, both as part of spec files and interactively, append the session name to application_name. Since b1907d6 application_name already contains the test name, this appends the session's name to that. insert-conflict-specconflict did something like this manually, which can now be removed. As we have done lately with other test infrastructure improvements, backpatch this change, to make it easier to backpatch tests. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Michael Paquier <michael@paquier.xyz> Reviewed-By: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/20211211012052.2blmzcmxnxqawd2z@alap3.anarazel.de Backpatch: 10-, to make backpatching of tests easier.
1 parent fe490f9 commit a5fe66b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/test/isolation/isolationtester.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,14 @@ main(int argc, char **argv)
155155

156156
for (i = 0; i < nconns; i++)
157157
{
158+
const char *sessionname;
159+
158160
if (i == 0)
159-
conns[i].sessionname = "control connection";
161+
sessionname = "control connection";
160162
else
161-
conns[i].sessionname = testspec->sessions[i - 1]->name;
163+
sessionname = testspec->sessions[i - 1]->name;
164+
165+
conns[i].sessionname = sessionname;
162166

163167
conns[i].conn = PQconnectdb(conninfo);
164168
if (PQstatus(conns[i].conn) != CONNECTION_OK)
@@ -183,6 +187,26 @@ main(int argc, char **argv)
183187
blackholeNoticeProcessor,
184188
NULL);
185189

190+
/*
191+
* Similarly, append the session name to application_name to make it
192+
* easier to map spec file sessions to log output and
193+
* pg_stat_activity. The reason to append instead of just setting the
194+
* name is that we don't know the name of the test currently running.
195+
*/
196+
res = PQexecParams(conns[i].conn,
197+
"SELECT set_config('application_name',\n"
198+
" current_setting('application_name') || '/' || $1,\n"
199+
" false)",
200+
1, NULL,
201+
&sessionname,
202+
NULL, NULL, 0);
203+
if (PQresultStatus(res) != PGRES_TUPLES_OK)
204+
{
205+
fprintf(stderr, "setting of application name failed: %s",
206+
PQerrorMessage(conns[i].conn));
207+
exit(1);
208+
}
209+
186210
/* Save each connection's backend PID for subsequent use. */
187211
conns[i].backend_pid = PQbackendPID(conns[i].conn);
188212
conns[i].backend_pid_str = psprintf("%d", conns[i].backend_pid);

0 commit comments

Comments
 (0)