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

Commite102b2f

Browse files
committed
[PGPRO-5691] move mmapped ptrack map into shared postgres memory
1 parentb5d2c58 commite102b2f

File tree

5 files changed

+260
-204
lines changed

5 files changed

+260
-204
lines changed

‎README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ postgres=# CREATE EXTENSION ptrack;
5757

5858
##Configuration
5959

60-
The only one configurable option is`ptrack.map_size` (in MB). Default is`-1`, which means`ptrack` is turned off. In order to reduce number of false positives it is recommended to set`ptrack.map_size` to`1 / 1000` of expected`PGDATA` size (i.e.`1000` for a 1 TB database).
60+
The only one configurable option is`ptrack.map_size` (in MB). Default is`0`, which means`ptrack` is turned off. In order to reduce number of false positives it is recommended to set`ptrack.map_size` to`1 / 1000` of expected`PGDATA` size (i.e.`1000` for a 1 TB database).
6161

6262
To disable`ptrack` and clean up all remaining service files set`ptrack.map_size` to`0`.
6363

@@ -74,7 +74,7 @@ Usage example:
7474
postgres=# SELECT ptrack_version();
7575
ptrack_version
7676
----------------
77-
2.2
77+
2.3
7878
(1 row)
7979

8080
postgres=# SELECT ptrack_init_lsn();
@@ -115,27 +115,29 @@ Usually, you have to only install new version of `ptrack` and do `ALTER EXTENSIO
115115

116116
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.
117117

118+
####Upgrading from 2.2.* to 2.3.*:
119+
TODO
120+
118121
##Limitations
119122

120123
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.
121124

122125
2. The only one production-ready backup utility, that fully supports`ptrack` is[pg_probackup](https://github.com/postgrespro/pg_probackup).
123126

124-
3.Currently, youcannot resize`ptrack` map in runtime, only on postmaster start. Also, you will loose all tracked changes, so it is recommended to do so in the maintainance window and accompany this operation with full backup. See[TODO](#TODO) for details.
127+
3.Youcannot resize`ptrack` map in runtime, only on postmaster start. Also, you will loose all tracked changes, so it is recommended to do so in the maintainance window and accompany this operation with full backup.
125128

126-
4. You will need up to`ptrack.map_size *3` of additional disk space, since`ptrack` usestwoadditional temporaryfiles for durability purpose. See[Architecture section](#Architecture) for details.
129+
4. You will need up to`ptrack.map_size *2` of additional disk space, since`ptrack` uses additional temporaryfile for durability purpose. See[Architecture section](#Architecture) for details.
127130

128131
##Benchmarks
129132

130133
Briefly, an overhead of using`ptrack` on TPS usually does not exceed a couple of percent (~1-3%) for a database of dozens to hundreds of gigabytes in size, while the backup time scales down linearly with backup size with a coefficient~1. It means that an incremental`ptrack` backup of a database with only 20% of changed pages will be 5 times faster than a full backup. More details[here](benchmarks).
131134

132135
##Architecture
133136

134-
We use a single shared hash table in`ptrack`, which is mapped in memory from the file on disk using`mmap`. Due to the fixed size of the map there may be false positives (when some block is marked as changed without being actually modified), but not false negative results. However, these false postives may be completely eliminated by setting a high enough`ptrack.map_size`.
137+
We use a single shared hash table in`ptrack`. Due to the fixed size of the map there may be false positives (when some block is marked as changed without being actually modified), but not false negative results. However, these false postives may be completely eliminated by setting a high enough`ptrack.map_size`.
135138

136-
All reads/writes are made using atomic operations on`uint64` entries, so the map is completely lockless during the normal PostgreSQL operation. Because we do not use locks for read/write access and cannot control`mmap` eviction back to disk,`ptrack` keeps a map (`ptrack.map`) since the last checkpoint intact and uses up to2 additional temporaryfiles:
139+
All reads/writes are made using atomic operations on`uint64` entries, so the map is completely lockless during the normal PostgreSQL operation. Because we do not use locks for read/write access,`ptrack` keeps a map (`ptrack.map`) since the last checkpoint intact and uses up to1 additional temporaryfile:
137140

138-
* working copy`ptrack.map.mmap` for doing`mmap` on it (there is a[TODO](#TODO) item);
139141
* temporary file`ptrack.map.tmp` to durably replace`ptrack.map` during checkpoint.
140142

141143
Map is written on disk at the end of checkpoint atomically block by block involving the CRC32 checksum calculation that is checked on the next whole map re-read after crash-recovery or restart.
@@ -165,8 +167,6 @@ Available test modes (`MODE`) are `basic` (default) and `paranoia` (per-block ch
165167

166168
###TODO
167169

168-
* Use POSIX`shm_open()` instead of`open()` to do not create an additional working copy of`ptrack` map file.
169170
* Should we introduce`ptrack.map_path` to allow`ptrack` service files storage outside of`PGDATA`? Doing that we will avoid patching PostgreSQL binary utilities to ignore`ptrack.map.*` files.
170171
* Can we resize`ptrack` map on restart but keep the previously tracked changes?
171-
* Can we resize`ptrack` map dynamicaly?
172172
* Can we write a formal proof, that we never loose any modified page with`ptrack`? With TLA+?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp