Show information about local file cache in EXPLAIN ANALYZE

This commit is contained in:
Konstantin Knizhnik
2023-10-10 10:11:30 +03:00
parent 7aeec2bc9d
commit 665eff5e08
8 changed files with 31 additions and 35 deletions

View File

@@ -20,7 +20,7 @@ SHLIB_LINK_INTERNAL = $(libpq)
SHLIB_LINK = -lcurl
EXTENSION = neon
DATA = neon--1.0.sql
DATA = neon--1.0.sql neon--1.0--1.1.sql
PGFILEDESC = "neon - cloud storage for PostgreSQL"

View File

@@ -32,11 +32,13 @@
#include "storage/latch.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "utils/builtins.h"
#include "utils/dynahash.h"
#include "utils/guc.h"
#include "storage/fd.h"
#include "storage/pg_shmem.h"
#include "storage/buf_internals.h"
#include "pgstat.h"
/*
* Local file cache is used to temporary store relations pages in local file system.
@@ -496,6 +498,7 @@ lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno,
{
/* Page is not cached */
lfc_ctl->misses += 1; /* race condition here, but precise value is not needed */
pgBufferUsage.file_cache.misses += 1;
LWLockRelease(lfc_lock);
return false;
}
@@ -521,6 +524,7 @@ lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno,
{
Assert(LFC_ENABLED());
lfc_ctl->hits += 1;
pgBufferUsage.file_cache.hits += 1;
Assert(entry->access_count > 0);
if (--entry->access_count == 0)
dlist_push_tail(&lfc_ctl->lru, &entry->lru_node);
@@ -650,25 +654,27 @@ typedef struct
} LocalCachePagesContext;
PG_FUNCTION_INFO_V1(local_cache_hits);
PG_FUNCTION_INFO_V1(neon_get_stat);
Datum
local_cache_hits(PG_FUNCTION_ARGS)
neon_get_stat(PG_FUNCTION_ARGS)
{
if (lfc_ctl)
PG_RETURN_INT64(lfc_ctl->hits);
else
PG_RETURN_NULL();
}
PG_FUNCTION_INFO_V1(local_cache_misses);
Datum
local_cache_misses(PG_FUNCTION_ARGS)
{
if (lfc_ctl)
PG_RETURN_INT64(lfc_ctl->misses);
else
PG_RETURN_NULL();
char *key = text_to_cstring(PG_GETARG_TEXT_PP(0));
if (strcmp(key, "file_cache_misses") == 0)
{
if (lfc_ctl)
PG_RETURN_INT64(lfc_ctl->misses);
}
else if (strcmp(key, "file_cache_hits") == 0)
{
if (lfc_ctl)
PG_RETURN_INT64(lfc_ctl->hits);
}
else if (strcmp(key, "file_cache_used") == 0)
{
if (lfc_ctl)
PG_RETURN_INT64(lfc_ctl->used);
}
PG_RETURN_NULL();
}

View File

@@ -22,16 +22,6 @@ AS 'MODULE_PATHNAME', 'backpressure_throttling_time'
LANGUAGE C STRICT
PARALLEL UNSAFE;
CREATE FUNCTION local_cache_hits() RETURNS bigint
AS 'MODULE_PATHNAME', 'local_cache_hits'
LANGUAGE C PARALLEL SAFE;
CREATE FUNCTION local_cache_misses() RETURNS bigint
AS 'MODULE_PATHNAME', 'local_cache_misses'
LANGUAGE C PARALLEL SAFE;
CREATE FUNCTION local_cache_pages()
RETURNS SETOF RECORD
AS 'MODULE_PATHNAME', 'local_cache_pages'

View File

@@ -1,4 +1,4 @@
# neon extension
comment = 'cloud storage for PostgreSQL'
default_version = '1.0'
default_version = '1.1'
module_pathname = '$libdir/neon'

View File

@@ -1,5 +1,5 @@
{
"postgres-v16": "389ce36b4b3da7aa654a25e1b3f10b641319a87f",
"postgres-v15": "74cfe3e681836747a31fdbd47bdd14b3d81b0772",
"postgres-v14": "5d5cfee12783f0989a9c9fe13bb40b5585812568"
"postgres-v16": "e6c1ece2efbf52277565936925ae43599ce51730",
"postgres-v15": "327f4e5e7db1050ce1b79e19f3d27ef1cff7acca",
"postgres-v14": "80932ee1ae0b8e645390546ed104c357cddc7d0c"
}