Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3026be9

Browse files
committed
Add new function ptrack_get_change_file_stat(start_lsn pg_lsn)
1 parent829f96c commit3026be9

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

‎README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ To disable `ptrack` and clean up all remaining service files set `ptrack.map_siz
6565

6666
* ptrack_version() — returns ptrack version string.
6767
* ptrack_init_lsn() — returns LSN of the last ptrack map initialization.
68-
* ptrack_get_pagemapset('LSN') — returns a set of changed data files with bitmaps of changed blocks since specified LSN.
68+
* ptrack_get_pagemapset(start_lsn pg_lsn) — returns a set of changed data files with bitmaps of changed blocks since specified`start_lsn`.
69+
* ptrack_get_change_stat(start_lsn pg_lsn) — returns statistic of changes (number of files, pages and size in MB) since specified`start_lsn`.
70+
* ptrack_get_change_file_stat(start_lsn pg_lsn) — returns per file statistic of changes (number of pages and size in MB) since specified`start_lsn`.
6971

7072
Usage example:
7173

@@ -102,6 +104,10 @@ Usually, you have to only install new version of `ptrack` and do `ALTER EXTENSIO
102104
* Do`ALTER EXTENSION 'ptrack' UPDATE;`.
103105
* Restart your server.
104106

107+
####Upgrading from 2.1.* to 2.2.*:
108+
109+
Since version 2.2 we use a different algorithm for tracking changed pages. Thus, data recorded in the`ptrack.map` using pre 2.2 versions of`ptrack` is incompatible with newer versions. After extension upgrade and server restart old`ptrack.map` will be discarded with`WARNING` and initialized from the scratch.
110+
105111
##Limitations
106112

107113
1. You can only use`ptrack` safely with`wal_level >= 'replica'`. Otherwise, you can lose tracking of some changes if crash-recovery occurs, since[certain commands are designed not to write WAL at all if wal_level is minimal](https://www.postgresql.org/docs/12/populate.html#POPULATE-PITR), but we only durably flush`ptrack` map at checkpoint time.

‎ptrack--2.1--2.2.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,28 @@ BEGIN
2727
FROM ptrack_get_pagemapset(start_lsn)) s;
2828
END
2929
$func$ LANGUAGE plpgsql;
30+
31+
CREATEFUNCTIONptrack_get_change_file_stat(start_lsn pg_lsn)
32+
RETURNS TABLE (
33+
file_pathtext,
34+
pagesint,
35+
"size, MB"numeric
36+
)AS
37+
$func$
38+
DECLARE
39+
block_sizebigint;
40+
BEGIN
41+
block_size := (SELECT settingFROM pg_settingsWHERE name='block_size');
42+
43+
RETURN QUERY
44+
SELECTs.path,
45+
changed_pages,
46+
block_size*changed_pages/(1024.0*1024)
47+
FROM
48+
(SELECTpath,
49+
length(replace(right((pagemap)::text,-1)::varbit::text,'0',''))
50+
AS changed_pages
51+
FROM ptrack_get_pagemapset(start_lsn)) s
52+
ORDER BY (changed_pages,s.path)DESC;
53+
END
54+
$func$ LANGUAGE plpgsql;

‎t/001_basic.pl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use TestLib;
1111
use Test::More;
1212

13-
plantests=>24;
13+
plantests=>25;
1414

1515
my$node;
1616
my$res;
@@ -119,6 +119,9 @@
119119
$res_stdout =$node->safe_psql("postgres","SELECT pages FROM ptrack_get_change_stat('$flush_lsn')");
120120
is($res_stdout > 0, 1,'should be able to get aggregated stats of changes');
121121

122+
$res_stdout =$node->safe_psql("postgres","SELECT count(*) FROM ptrack_get_change_file_stat('$flush_lsn')");
123+
is($res_stdout > 0, 1,'should be able to get per file stats of changes');
124+
122125
# We should be able to change ptrack map size (but loose all changes)
123126
$node->append_conf(
124127
'postgresql.conf',q{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp