mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Set debug_query_string in worker_spi.
This makes elog.c emit the string, which is good practice for a background worker that executes SQL strings. Reviewed by Tom Lane. Discussion: https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
This commit is contained in:
parent
f90e80b913
commit
d2246cde82
@ -119,6 +119,7 @@ initialize_worker_spi(worktable *table)
|
|||||||
appendStringInfo(&buf, "select count(*) from pg_namespace where nspname = '%s'",
|
appendStringInfo(&buf, "select count(*) from pg_namespace where nspname = '%s'",
|
||||||
table->schema);
|
table->schema);
|
||||||
|
|
||||||
|
debug_query_string = buf.data;
|
||||||
ret = SPI_execute(buf.data, true, 0);
|
ret = SPI_execute(buf.data, true, 0);
|
||||||
if (ret != SPI_OK_SELECT)
|
if (ret != SPI_OK_SELECT)
|
||||||
elog(FATAL, "SPI_execute failed: error code %d", ret);
|
elog(FATAL, "SPI_execute failed: error code %d", ret);
|
||||||
@ -134,6 +135,7 @@ initialize_worker_spi(worktable *table)
|
|||||||
|
|
||||||
if (ntup == 0)
|
if (ntup == 0)
|
||||||
{
|
{
|
||||||
|
debug_query_string = NULL;
|
||||||
resetStringInfo(&buf);
|
resetStringInfo(&buf);
|
||||||
appendStringInfo(&buf,
|
appendStringInfo(&buf,
|
||||||
"CREATE SCHEMA \"%s\" "
|
"CREATE SCHEMA \"%s\" "
|
||||||
@ -147,15 +149,19 @@ initialize_worker_spi(worktable *table)
|
|||||||
/* set statement start time */
|
/* set statement start time */
|
||||||
SetCurrentStatementStartTimestamp();
|
SetCurrentStatementStartTimestamp();
|
||||||
|
|
||||||
|
debug_query_string = buf.data;
|
||||||
ret = SPI_execute(buf.data, false, 0);
|
ret = SPI_execute(buf.data, false, 0);
|
||||||
|
|
||||||
if (ret != SPI_OK_UTILITY)
|
if (ret != SPI_OK_UTILITY)
|
||||||
elog(FATAL, "failed to create my schema");
|
elog(FATAL, "failed to create my schema");
|
||||||
|
|
||||||
|
debug_query_string = NULL; /* rest is not statement-specific */
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_finish();
|
SPI_finish();
|
||||||
PopActiveSnapshot();
|
PopActiveSnapshot();
|
||||||
CommitTransactionCommand();
|
CommitTransactionCommand();
|
||||||
|
debug_query_string = NULL;
|
||||||
pgstat_report_activity(STATE_IDLE, NULL);
|
pgstat_report_activity(STATE_IDLE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +268,7 @@ worker_spi_main(Datum main_arg)
|
|||||||
StartTransactionCommand();
|
StartTransactionCommand();
|
||||||
SPI_connect();
|
SPI_connect();
|
||||||
PushActiveSnapshot(GetTransactionSnapshot());
|
PushActiveSnapshot(GetTransactionSnapshot());
|
||||||
|
debug_query_string = buf.data;
|
||||||
pgstat_report_activity(STATE_RUNNING, buf.data);
|
pgstat_report_activity(STATE_RUNNING, buf.data);
|
||||||
|
|
||||||
/* We can now execute queries via SPI */
|
/* We can now execute queries via SPI */
|
||||||
@ -291,6 +298,7 @@ worker_spi_main(Datum main_arg)
|
|||||||
SPI_finish();
|
SPI_finish();
|
||||||
PopActiveSnapshot();
|
PopActiveSnapshot();
|
||||||
CommitTransactionCommand();
|
CommitTransactionCommand();
|
||||||
|
debug_query_string = NULL;
|
||||||
pgstat_report_stat(false);
|
pgstat_report_stat(false);
|
||||||
pgstat_report_activity(STATE_IDLE, NULL);
|
pgstat_report_activity(STATE_IDLE, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user