Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f41f3d7

Browse files
committed
Initial
0 parents  commit f41f3d7

File tree

7 files changed

+562
-0
lines changed

7 files changed

+562
-0
lines changed

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
EXTENSION = memstat
2+
MODULES = memstat
3+
DATA = memstat--1.0.sql
4+
OBJS = memstat.o
5+
REGRESS = memstat
6+
7+
ifdef USE_PGXS
8+
PGXS := $(shell pg_config --pgxs)
9+
include $(PGXS)
10+
else
11+
subdir = contrib/memstat
12+
top_builddir = ../..
13+
include $(top_builddir)/src/Makefile.global
14+
include $(top_srcdir)/contrib/contrib-global.mk
15+
endif
16+
17+

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Module adds statistic report about memory contexts in local and all backends.
2+
3+
Functions:
4+
5+
setof (name text, level integer, nblocks bigint, freechunks bigint,
6+
totalspace bigint, freespace bigint)
7+
local_memory_stats()
8+
prints memory context's statistic for current backend
9+
10+
setof (pid integer, name text, level integer, nblocks bigint, freechunks bigint,
11+
totalspace bigint, freespace bigint)
12+
instance_memory_stats()
13+
prints memory context's statistic for all alive backend, works if library
14+
was preloaded via shared_preload_libraries.
15+
16+
view memory_stats
17+
prints per backend summary memory statistics
18+
19+
To use instance_memory_stats() it's needed to add memstat library to
20+
shared_preload_libraries. And it should be last in that list!
21+
22+
GUC variable:
23+
memstat.period = 10 # seconds
24+
25+
Module collects memory statistics at a begining of each query and
26+
it could be expensive on highloaded instances, so, this variable
27+
set minimal time between statistic obtaining.
28+
29+
Copyright (c) 2016, Teodor Sigaev <teodor@sigaev.ru>

expected/memstat.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE EXTENSION memstat;

memstat--1.0.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION memstat" to load this file. \quit
3+
4+
CREATE FUNCTION local_memory_stats(
5+
OUT name text, OUT level int4,
6+
OUT nblocks int8, OUT freechunks int8, OUT totalspace int8, OUT freespace int8)
7+
RETURNS SETOF record
8+
AS 'MODULE_PATHNAME', 'get_local_memory_stats'
9+
LANGUAGE C IMMUTABLE;
10+
11+
COMMENT ON FUNCTION local_memory_stats() IS
12+
'statistic of local memory of backend';
13+
14+
CREATE FUNCTION instance_memory_stats(
15+
OUT pid int4, OUT name text, OUT level int4,
16+
OUT nblocks int8, OUT freechunks int8, OUT totalspace int8, OUT freespace int8)
17+
RETURNS SETOF record
18+
AS 'MODULE_PATHNAME', 'get_instance_memory_stats'
19+
LANGUAGE C IMMUTABLE;
20+
21+
COMMENT ON FUNCTION instance_memory_stats() IS
22+
'statistic of local memory of all backends';
23+
24+
CREATE OR REPLACE VIEW memory_stats AS
25+
SELECT
26+
pid,
27+
pg_size_pretty(sum(totalspace)) AS totalspace,
28+
pg_size_pretty(sum(freespace)) AS freespace
29+
FROM
30+
instance_memory_stats()
31+
GROUP BY
32+
pid;
33+
34+

0 commit comments

Comments
 (0)