mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Add context type field to pg_backend_memory_contexts
Since we now (as of v17) have 4 MemoryContext types, the type of context seems like useful information to include in the pg_backend_memory_contexts view. Here we add that. Reviewed-by: David Christensen, Michael Paquier Discussion: https://postgr.es/m/CAApHDvrXX1OR09Zjb5TnB0AwCKze9exZN%3D9Nxxg1ZCVV8W-3BA%40mail.gmail.com
This commit is contained in:
@ -490,6 +490,15 @@
|
|||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry role="catalog_table_entry"><para role="column_definition">
|
||||||
|
<structfield>type</structfield> <type>text</type>
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
Type of the memory context
|
||||||
|
</para></entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry role="catalog_table_entry"><para role="column_definition">
|
<entry role="catalog_table_entry"><para role="column_definition">
|
||||||
<structfield>level</structfield> <type>int4</type>
|
<structfield>level</structfield> <type>int4</type>
|
||||||
|
@ -36,7 +36,7 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
|
|||||||
TupleDesc tupdesc, MemoryContext context,
|
TupleDesc tupdesc, MemoryContext context,
|
||||||
const char *parent, int level)
|
const char *parent, int level)
|
||||||
{
|
{
|
||||||
#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 9
|
#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 10
|
||||||
|
|
||||||
Datum values[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
|
Datum values[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
|
||||||
bool nulls[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
|
bool nulls[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
|
||||||
@ -44,6 +44,7 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
|
|||||||
MemoryContext child;
|
MemoryContext child;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *ident;
|
const char *ident;
|
||||||
|
const char *type;
|
||||||
|
|
||||||
Assert(MemoryContextIsValid(context));
|
Assert(MemoryContextIsValid(context));
|
||||||
|
|
||||||
@ -96,12 +97,32 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
|
|||||||
else
|
else
|
||||||
nulls[2] = true;
|
nulls[2] = true;
|
||||||
|
|
||||||
values[3] = Int32GetDatum(level);
|
switch (context->type)
|
||||||
values[4] = Int64GetDatum(stat.totalspace);
|
{
|
||||||
values[5] = Int64GetDatum(stat.nblocks);
|
case T_AllocSetContext:
|
||||||
values[6] = Int64GetDatum(stat.freespace);
|
type = "AllocSet";
|
||||||
values[7] = Int64GetDatum(stat.freechunks);
|
break;
|
||||||
values[8] = Int64GetDatum(stat.totalspace - stat.freespace);
|
case T_GenerationContext:
|
||||||
|
type = "Generation";
|
||||||
|
break;
|
||||||
|
case T_SlabContext:
|
||||||
|
type = "Slab";
|
||||||
|
break;
|
||||||
|
case T_BumpContext:
|
||||||
|
type = "Bump";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = "???";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
values[3] = CStringGetTextDatum(type);
|
||||||
|
values[4] = Int32GetDatum(level);
|
||||||
|
values[5] = Int64GetDatum(stat.totalspace);
|
||||||
|
values[6] = Int64GetDatum(stat.nblocks);
|
||||||
|
values[7] = Int64GetDatum(stat.freespace);
|
||||||
|
values[8] = Int64GetDatum(stat.freechunks);
|
||||||
|
values[9] = Int64GetDatum(stat.totalspace - stat.freespace);
|
||||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||||
|
|
||||||
for (child = context->firstchild; child != NULL; child = child->nextchild)
|
for (child = context->firstchild; child != NULL; child = child->nextchild)
|
||||||
|
@ -57,6 +57,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 202406281
|
#define CATALOG_VERSION_NO 202407011
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8279,9 +8279,9 @@
|
|||||||
proname => 'pg_get_backend_memory_contexts', prorows => '100',
|
proname => 'pg_get_backend_memory_contexts', prorows => '100',
|
||||||
proretset => 't', provolatile => 'v', proparallel => 'r',
|
proretset => 't', provolatile => 'v', proparallel => 'r',
|
||||||
prorettype => 'record', proargtypes => '',
|
prorettype => 'record', proargtypes => '',
|
||||||
proallargtypes => '{text,text,text,int4,int8,int8,int8,int8,int8}',
|
proallargtypes => '{text,text,text,text,int4,int8,int8,int8,int8,int8}',
|
||||||
proargmodes => '{o,o,o,o,o,o,o,o,o}',
|
proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
|
||||||
proargnames => '{name, ident, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
|
proargnames => '{name, ident, parent, type, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
|
||||||
prosrc => 'pg_get_backend_memory_contexts' },
|
prosrc => 'pg_get_backend_memory_contexts' },
|
||||||
|
|
||||||
# logging memory contexts of the specified backend
|
# logging memory contexts of the specified backend
|
||||||
|
@ -1306,13 +1306,14 @@ pg_available_extensions| SELECT e.name,
|
|||||||
pg_backend_memory_contexts| SELECT name,
|
pg_backend_memory_contexts| SELECT name,
|
||||||
ident,
|
ident,
|
||||||
parent,
|
parent,
|
||||||
|
type,
|
||||||
level,
|
level,
|
||||||
total_bytes,
|
total_bytes,
|
||||||
total_nblocks,
|
total_nblocks,
|
||||||
free_bytes,
|
free_bytes,
|
||||||
free_chunks,
|
free_chunks,
|
||||||
used_bytes
|
used_bytes
|
||||||
FROM pg_get_backend_memory_contexts() pg_get_backend_memory_contexts(name, ident, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes);
|
FROM pg_get_backend_memory_contexts() pg_get_backend_memory_contexts(name, ident, parent, type, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes);
|
||||||
pg_config| SELECT name,
|
pg_config| SELECT name,
|
||||||
setting
|
setting
|
||||||
FROM pg_config() pg_config(name, setting);
|
FROM pg_config() pg_config(name, setting);
|
||||||
|
@ -21,11 +21,11 @@ select count(*) >= 0 as ok from pg_available_extensions;
|
|||||||
|
|
||||||
-- The entire output of pg_backend_memory_contexts is not stable,
|
-- The entire output of pg_backend_memory_contexts is not stable,
|
||||||
-- we test only the existence and basic condition of TopMemoryContext.
|
-- we test only the existence and basic condition of TopMemoryContext.
|
||||||
select name, ident, parent, level, total_bytes >= free_bytes
|
select type, name, ident, parent, level, total_bytes >= free_bytes
|
||||||
from pg_backend_memory_contexts where level = 0;
|
from pg_backend_memory_contexts where level = 0;
|
||||||
name | ident | parent | level | ?column?
|
type | name | ident | parent | level | ?column?
|
||||||
------------------+-------+--------+-------+----------
|
----------+------------------+-------+--------+-------+----------
|
||||||
TopMemoryContext | | | 0 | t
|
AllocSet | TopMemoryContext | | | 0 | t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- We can exercise some MemoryContext type stats functions. Most of the
|
-- We can exercise some MemoryContext type stats functions. Most of the
|
||||||
@ -43,11 +43,11 @@ fetch 1 from cur;
|
|||||||
bbbbbbbbbb | 2
|
bbbbbbbbbb | 2
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
|
select type, name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
|
||||||
from pg_backend_memory_contexts where name = 'Caller tuples';
|
from pg_backend_memory_contexts where name = 'Caller tuples';
|
||||||
name | parent | ?column? | total_nblocks | ?column? | free_chunks
|
type | name | parent | ?column? | total_nblocks | ?column? | free_chunks
|
||||||
---------------+----------------+----------+---------------+----------+-------------
|
------+---------------+----------------+----------+---------------+----------+-------------
|
||||||
Caller tuples | TupleSort sort | t | 2 | t | 0
|
Bump | Caller tuples | TupleSort sort | t | 2 | t | 0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
rollback;
|
rollback;
|
||||||
|
@ -14,7 +14,7 @@ select count(*) >= 0 as ok from pg_available_extensions;
|
|||||||
|
|
||||||
-- The entire output of pg_backend_memory_contexts is not stable,
|
-- The entire output of pg_backend_memory_contexts is not stable,
|
||||||
-- we test only the existence and basic condition of TopMemoryContext.
|
-- we test only the existence and basic condition of TopMemoryContext.
|
||||||
select name, ident, parent, level, total_bytes >= free_bytes
|
select type, name, ident, parent, level, total_bytes >= free_bytes
|
||||||
from pg_backend_memory_contexts where level = 0;
|
from pg_backend_memory_contexts where level = 0;
|
||||||
|
|
||||||
-- We can exercise some MemoryContext type stats functions. Most of the
|
-- We can exercise some MemoryContext type stats functions. Most of the
|
||||||
@ -28,7 +28,7 @@ declare cur cursor for select left(a,10), b
|
|||||||
from (values(repeat('a', 512 * 1024),1),(repeat('b', 512),2)) v(a,b)
|
from (values(repeat('a', 512 * 1024),1),(repeat('b', 512),2)) v(a,b)
|
||||||
order by v.a desc;
|
order by v.a desc;
|
||||||
fetch 1 from cur;
|
fetch 1 from cur;
|
||||||
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
|
select type, name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
|
||||||
from pg_backend_memory_contexts where name = 'Caller tuples';
|
from pg_backend_memory_contexts where name = 'Caller tuples';
|
||||||
rollback;
|
rollback;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user