mirror of
https://github.com/postgres/postgres.git
synced 2025-10-15 05:46:52 +03:00
Add client_hostname field to pg_stat_activity.
Peter Eisentraut, reviewed by Steve Singer, Alvaro Herrera, and me.
This commit is contained in:
@@ -506,7 +506,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
|
||||
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
||||
|
||||
tupdesc = CreateTemplateTupleDesc(11, false);
|
||||
tupdesc = CreateTemplateTupleDesc(12, false);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "datid", OIDOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "procpid", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "usesysid", OIDOID, -1, 0);
|
||||
@@ -517,7 +517,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "query_start", TIMESTAMPTZOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "backend_start", TIMESTAMPTZOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "client_addr", INETOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "client_port", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "client_hostname", TEXTOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 12, "client_port", INT4OID, -1, 0);
|
||||
|
||||
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
|
||||
|
||||
@@ -569,8 +570,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
if (funcctx->call_cntr < funcctx->max_calls)
|
||||
{
|
||||
/* for each row */
|
||||
Datum values[11];
|
||||
bool nulls[11];
|
||||
Datum values[12];
|
||||
bool nulls[12];
|
||||
HeapTuple tuple;
|
||||
PgBackendStatus *beentry;
|
||||
SockAddr zero_clientaddr;
|
||||
@@ -647,6 +648,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
{
|
||||
nulls[9] = true;
|
||||
nulls[10] = true;
|
||||
nulls[11] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -671,13 +673,18 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
{
|
||||
nulls[9] = true;
|
||||
nulls[10] = true;
|
||||
nulls[11] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
||||
values[9] = DirectFunctionCall1(inet_in,
|
||||
CStringGetDatum(remote_host));
|
||||
values[10] = Int32GetDatum(atoi(remote_port));
|
||||
if (beentry->st_clienthostname)
|
||||
values[10] = CStringGetTextDatum(beentry->st_clienthostname);
|
||||
else
|
||||
nulls[10] = true;
|
||||
values[11] = Int32GetDatum(atoi(remote_port));
|
||||
}
|
||||
}
|
||||
else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
|
||||
@@ -689,13 +696,15 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
* errors.
|
||||
*/
|
||||
nulls[9] = true;
|
||||
values[10] = DatumGetInt32(-1);
|
||||
nulls[10] = true;
|
||||
values[11] = DatumGetInt32(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown address type, should never happen */
|
||||
nulls[9] = true;
|
||||
nulls[10] = true;
|
||||
nulls[11] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,6 +718,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
nulls[8] = true;
|
||||
nulls[9] = true;
|
||||
nulls[10] = true;
|
||||
nulls[11] = true;
|
||||
}
|
||||
|
||||
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
|
||||
|
Reference in New Issue
Block a user