Skip to content

Commit f2dcff4

Browse files
Andrey Kazarinovdanolivo
Andrey Kazarinov
authored andcommitted
[PGPRO-7366] add function which shows memory usage
function memctx_htab_sizes outputs allocated sizes and used sizes of aqo's memory contexts and hash tables
1 parent 93a2291 commit f2dcff4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

aqo--1.5--1.6.sql

+16
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,19 @@ AS 'MODULE_PATHNAME', 'aqo_queries'
9898
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
9999

100100
CREATE VIEW aqo_queries AS SELECT * FROM aqo_queries();
101+
102+
CREATE FUNCTION aqo_memory_usage(
103+
OUT name text,
104+
OUT allocated_size int,
105+
OUT used_size int
106+
)
107+
RETURNS SETOF record
108+
AS $$
109+
SELECT name, total_bytes, used_bytes FROM pg_backend_memory_contexts
110+
WHERE name LIKE 'AQO%'
111+
UNION
112+
SELECT name, allocated_size, size FROM pg_shmem_allocations
113+
WHERE name LIKE 'AQO%';
114+
$$ LANGUAGE SQL;
115+
COMMENT ON FUNCTION aqo_memory_usage() IS
116+
'Show allocated sizes and used sizes of aqo`s memory contexts and hash tables';

t/001_pgbench.pl

+9
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
WHERE v.exec_time > 0.");
161161
is($res, 3);
162162

163+
$res = $node->safe_psql('postgres', "SELECT * FROM aqo_memory_usage() AS t1");
164+
note("MEMORY:\n$res\n");
165+
163166
# ##############################################################################
164167
#
165168
# pgbench on a database with AQO in 'learn' mode.
@@ -184,6 +187,9 @@
184187
"$TRANSACTIONS", '-c', "$CLIENTS", '-j', "$THREADS" ],
185188
'pgbench in frozen mode');
186189

190+
$res = $node->safe_psql('postgres', "SELECT * FROM aqo_memory_usage() AS t1");
191+
note("MEMORY:\n$res\n");
192+
187193
# ##############################################################################
188194
#
189195
# Check procedure of ML-knowledge data cleaning.
@@ -299,6 +305,9 @@
299305
is($new_stat_count == $stat_count - $pgb_stat_count, 1,
300306
'Total number of samples in aqo_query_stat');
301307

308+
$res = $node->safe_psql('postgres', "SELECT * FROM aqo_memory_usage() AS t1");
309+
note("MEMORY:\n$res\n");
310+
302311
# ##############################################################################
303312
#
304313
# AQO works after moving to another schema

0 commit comments

Comments
 (0)