2001-06-22 21:18:36 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2001-06-25 22:20:02 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
#include "miscadmin.h"
|
2001-06-22 21:18:36 +02:00
|
|
|
#include "utils/hsearch.h"
|
|
|
|
#include "access/xact.h"
|
|
|
|
#include "catalog/pg_shadow.h"
|
|
|
|
#include "nodes/execnodes.h"
|
|
|
|
|
|
|
|
#include "pgstat.h"
|
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS);
|
2002-08-04 21:51:30 +02:00
|
|
|
extern Datum pg_backend_pid(PG_FUNCTION_ARGS);
|
2002-08-20 06:47:52 +02:00
|
|
|
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
|
2001-10-25 07:50:21 +02:00
|
|
|
extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS);
|
2003-03-20 04:34:57 +01:00
|
|
|
extern Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS);
|
2001-10-25 07:50:21 +02:00
|
|
|
|
|
|
|
extern Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_numscans(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->numscans);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_tuples_returned(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->tuples_returned);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->tuples_fetched);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->tuples_inserted);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_tuples_updated(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->tuples_updated);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->tuples_deleted);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->blocks_fetched);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_blocks_hit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatTabEntry *tabentry;
|
|
|
|
Oid relid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
relid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (tabentry->blocks_hit);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
FmgrInfo *fmgr_info = fcinfo->flinfo;
|
|
|
|
int32 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-09-30 23:01:39 +02:00
|
|
|
if (fcinfo->resultinfo == NULL ||
|
|
|
|
!IsA(fcinfo->resultinfo, ReturnSetInfo))
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("set-valued function called in context that "
|
|
|
|
"cannot accept a set")));
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if (fmgr_info->fn_extra == NULL)
|
|
|
|
{
|
|
|
|
if (fmgr_info->fn_mcxt == NULL)
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(ERROR, "no function memory context in set-function");
|
|
|
|
|
2001-09-30 23:01:39 +02:00
|
|
|
fmgr_info->fn_extra = MemoryContextAlloc(fmgr_info->fn_mcxt,
|
|
|
|
2 * sizeof(int));
|
2001-10-25 07:50:21 +02:00
|
|
|
((int *) (fmgr_info->fn_extra))[0] = 0;
|
|
|
|
((int *) (fmgr_info->fn_extra))[1] = pgstat_fetch_stat_numbackends();
|
2001-06-22 21:18:36 +02:00
|
|
|
}
|
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
((int *) (fmgr_info->fn_extra))[0] += 1;
|
|
|
|
result = ((int *) (fmgr_info->fn_extra))[0];
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
if (result > ((int *) (fmgr_info->fn_extra))[1])
|
2001-06-22 21:18:36 +02:00
|
|
|
{
|
2001-09-30 23:01:39 +02:00
|
|
|
pfree(fmgr_info->fn_extra);
|
|
|
|
fmgr_info->fn_extra = NULL;
|
2001-10-25 07:50:21 +02:00
|
|
|
((ReturnSetInfo *) (fcinfo->resultinfo))->isDone = ExprEndResult;
|
2001-06-22 21:18:36 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
}
|
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
((ReturnSetInfo *) (fcinfo->resultinfo))->isDone = ExprMultipleResult;
|
2001-06-22 21:18:36 +02:00
|
|
|
PG_RETURN_INT32(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 02:40:40 +02:00
|
|
|
Datum
|
2002-08-04 21:51:30 +02:00
|
|
|
pg_backend_pid(PG_FUNCTION_ARGS)
|
2002-07-31 02:40:40 +02:00
|
|
|
{
|
|
|
|
PG_RETURN_INT32(MyProcPid);
|
|
|
|
}
|
|
|
|
|
2002-08-20 06:47:52 +02:00
|
|
|
/*
|
|
|
|
* Built-in function for resetting the counters
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
pg_stat_reset(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
pgstat_reset_counters();
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(true);
|
|
|
|
}
|
2002-07-31 02:40:40 +02:00
|
|
|
|
2001-06-22 21:18:36 +02:00
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatBeEntry *beentry;
|
|
|
|
int32 beid;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
beid = PG_GETARG_INT32(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
PG_RETURN_INT32(beentry->procpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatBeEntry *beentry;
|
|
|
|
int32 beid;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
beid = PG_GETARG_INT32(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
PG_RETURN_OID(beentry->databaseid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatBeEntry *beentry;
|
|
|
|
int32 beid;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
beid = PG_GETARG_INT32(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2002-12-04 06:18:38 +01:00
|
|
|
PG_RETURN_INT32(beentry->userid);
|
2001-06-22 21:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatBeEntry *beentry;
|
|
|
|
int32 beid;
|
|
|
|
int len;
|
|
|
|
text *result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
beid = PG_GETARG_INT32(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2003-03-20 19:51:16 +01:00
|
|
|
if (!superuser() && beentry->userid != GetUserId())
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2001-06-22 21:18:36 +02:00
|
|
|
len = strlen(beentry->activity);
|
|
|
|
result = palloc(VARHDRSZ + len);
|
|
|
|
VARATT_SIZEP(result) = VARHDRSZ + len;
|
|
|
|
memcpy(VARDATA(result), beentry->activity, len);
|
|
|
|
|
|
|
|
PG_RETURN_TEXT_P(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-20 04:34:57 +01:00
|
|
|
Datum
|
|
|
|
pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
PgStat_StatBeEntry *beentry;
|
|
|
|
int32 beid;
|
|
|
|
AbsoluteTime sec;
|
|
|
|
int usec;
|
2003-04-04 05:03:54 +02:00
|
|
|
TimestampTz result;
|
2003-03-20 04:34:57 +01:00
|
|
|
|
|
|
|
beid = PG_GETARG_INT32(0);
|
|
|
|
|
2003-04-04 05:03:54 +02:00
|
|
|
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
2003-03-20 04:34:57 +01:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2003-04-04 05:03:54 +02:00
|
|
|
if (!superuser() && beentry->userid != GetUserId())
|
2003-03-20 04:34:57 +01:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
sec = beentry->activity_start_sec;
|
|
|
|
usec = beentry->activity_start_usec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No time recorded for start of current query -- this is the case
|
|
|
|
* if the user hasn't enabled query-level stats collection.
|
|
|
|
*/
|
|
|
|
if (sec == 0 && usec == 0)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2003-04-04 06:50:44 +02:00
|
|
|
result = AbsoluteTimeUsecToTimestampTz(sec, usec);
|
2003-03-20 04:34:57 +01:00
|
|
|
|
2003-04-04 05:03:54 +02:00
|
|
|
PG_RETURN_TIMESTAMPTZ(result);
|
2003-03-20 04:34:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-22 21:18:36 +02:00
|
|
|
Datum
|
|
|
|
pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatDBEntry *dbentry;
|
|
|
|
Oid dbid;
|
|
|
|
int32 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
dbid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int32) (dbentry->n_backends);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT32(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatDBEntry *dbentry;
|
|
|
|
Oid dbid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
dbid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (dbentry->n_xact_commit);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatDBEntry *dbentry;
|
|
|
|
Oid dbid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
dbid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (dbentry->n_xact_rollback);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatDBEntry *dbentry;
|
|
|
|
Oid dbid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
dbid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (dbentry->n_blocks_fetched);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_StatDBEntry *dbentry;
|
|
|
|
Oid dbid;
|
|
|
|
int64 result;
|
2001-06-22 21:18:36 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
dbid = PG_GETARG_OID(0);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
|
|
|
|
result = 0;
|
|
|
|
else
|
2001-10-25 07:50:21 +02:00
|
|
|
result = (int64) (dbentry->n_blocks_hit);
|
2001-06-22 21:18:36 +02:00
|
|
|
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|