forked from postgrespro/ptrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptrack--2.1--2.2.sql
35 lines (31 loc) · 927 Bytes
/
ptrack--2.1--2.2.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ptrack/ptrack--2.1--2.2.sql */
-- Complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ptrack UPDATE;" to load this file.\ quit
DROP FUNCTION ptrack_get_pagemapset(start_lsn pg_lsn);
CREATE FUNCTION ptrack_get_pagemapset(start_lsn pg_lsn)
RETURNS TABLE (path text,
pagecount bigint,
pagemap bytea)
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT VOLATILE;
CREATE FUNCTION ptrack_get_change_stat(start_lsn pg_lsn)
RETURNS TABLE (
files bigint,
pages numeric,
"size, MB" numeric
) AS
$func$
DECLARE
block_size bigint;
BEGIN
block_size := (SELECT setting FROM pg_settings WHERE name = 'block_size');
RETURN QUERY
SELECT changed_files,
changed_pages,
block_size * changed_pages / (1024.0 * 1024)
FROM
(SELECT count(path) AS changed_files,
sum(pagecount) AS changed_pages
FROM ptrack_get_pagemapset(start_lsn)) s;
END
$func$ LANGUAGE plpgsql;