forked from mtusi2026/mtusi2026lab2
Исправление по замечанию: отзыв сессии выдерживает гонку с наполнением кэша
This commit is contained in:
+60
-60
@@ -8,7 +8,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
=== 1. Засев истории: цель 120000 сообщений, чаты неравномерные ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.616654 | 67113 | 120000 | 120000
|
||||
00:00:00.637022 | 66707 | 120000 | 120000
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -26,15 +26,15 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..47.47 rows=50 width=90) (actual time=0.009..0.020 rows=50 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.42..6827.62 rows=7255 width=90) (actual time=0.008..0.018 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
Buffers: shared hit=54
|
||||
Limit (cost=0.42..52.46 rows=50 width=89) (actual time=0.015..0.024 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.42..7478.52 rows=7184 width=89) (actual time=0.014..0.021 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
Planning:
|
||||
Buffers: shared hit=19
|
||||
Planning Time: 0.086 ms
|
||||
Execution Time: 0.042 ms
|
||||
Planning Time: 0.097 ms
|
||||
Execution Time: 0.047 ms
|
||||
(9 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -44,46 +44,46 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.00105
|
||||
00:00:00.001077
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.083522
|
||||
00:00:00.085221
|
||||
(1 row)
|
||||
|
||||
############ Вариант B: только (chat_id) ############
|
||||
index_size
|
||||
------------
|
||||
848 kB
|
||||
856 kB
|
||||
(1 row)
|
||||
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3231.76..3231.89 rows=50 width=90) (actual time=1.856..1.860 rows=50 loops=1)
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Sort (cost=3231.76..3249.63 rows=7146 width=90) (actual time=1.855..1.857 rows=50 loops=1)
|
||||
Limit (cost=3274.42..3274.55 rows=50 width=90) (actual time=2.027..2.031 rows=50 loops=1)
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Sort (cost=3274.42..3292.14 rows=7088 width=90) (actual time=2.026..2.028 rows=50 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 33kB
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Bitmap Heap Scan on messages (cost=408.67..2994.38 rows=7146 width=90) (actual time=1.514..1.710 rows=3630 loops=1)
|
||||
Recheck Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid))
|
||||
Rows Removed by Filter: 32675
|
||||
Heap Blocks: exact=451
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Bitmap Index Scan on messages_chat_only_idx (cost=0.00..406.88 rows=36612 width=0) (actual time=0.362..0.362 rows=36305 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared read=33
|
||||
I/O Timings: shared read=0.074
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Bitmap Heap Scan on messages (cost=428.23..3038.96 rows=7088 width=90) (actual time=1.631..1.839 rows=3829 loops=1)
|
||||
Recheck Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid))
|
||||
Rows Removed by Filter: 34464
|
||||
Heap Blocks: exact=475
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Bitmap Index Scan on messages_chat_only_idx (cost=0.00..426.46 rows=38156 width=0) (actual time=0.397..0.397 rows=38293 loops=1)
|
||||
Index Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Buffers: shared read=35
|
||||
I/O Timings: shared read=0.088
|
||||
Planning:
|
||||
Buffers: shared hit=28 read=1
|
||||
Buffers: shared hit=27 read=1
|
||||
I/O Timings: shared read=0.009
|
||||
Planning Time: 0.126 ms
|
||||
Execution Time: 1.879 ms
|
||||
Planning Time: 0.123 ms
|
||||
Execution Time: 2.056 ms
|
||||
(24 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -93,12 +93,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:02.460907
|
||||
00:00:02.52905
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.077769
|
||||
00:00:00.080589
|
||||
(1 row)
|
||||
|
||||
############ Вариант C: (chat_id, created_at, id) INCLUDE (sender_id, text) ############
|
||||
@@ -109,19 +109,19 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..43.36 rows=50 width=90) (actual time=0.039..0.045 rows=50 loops=1)
|
||||
Limit (cost=0.42..45.99 rows=50 width=89) (actual time=0.014..0.018 rows=50 loops=1)
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.012
|
||||
-> Index Only Scan using messages_history_covering_idx on messages (cost=0.42..6095.87 rows=7098 width=90) (actual time=0.038..0.041 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
I/O Timings: shared read=0.005
|
||||
-> Index Only Scan using messages_history_covering_idx on messages (cost=0.42..6560.61 rows=7197 width=89) (actual time=0.013..0.015 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid)))
|
||||
Heap Fetches: 0
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.012
|
||||
I/O Timings: shared read=0.005
|
||||
Planning:
|
||||
Buffers: shared hit=29 read=1
|
||||
I/O Timings: shared read=0.007
|
||||
Planning Time: 0.144 ms
|
||||
Execution Time: 0.056 ms
|
||||
Buffers: shared hit=28 read=1
|
||||
I/O Timings: shared read=0.003
|
||||
Planning Time: 0.118 ms
|
||||
Execution Time: 0.027 ms
|
||||
(13 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -131,12 +131,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.000723
|
||||
00:00:00.000734
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.085783
|
||||
00:00:00.08596
|
||||
(1 row)
|
||||
|
||||
############ Схема после эксперимента (ROLLBACK вернул индексы) ############
|
||||
@@ -147,7 +147,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
(2 rows)
|
||||
|
||||
|
||||
Самый большой чат: 174a0477-1fd5-47a9-ab90-ee8b7ef903af
|
||||
Самый большой чат: 69ee7d45-68b4-4606-befe-efaeecdedd32
|
||||
|
||||
=== 3. Состояние источника до бэкапа ===
|
||||
relation | rows
|
||||
@@ -156,19 +156,19 @@ Docker version 29.7.2, build a7dcaa6
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 45
|
||||
users | 76
|
||||
users | 78
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
38293 | f18725746ed1acbdda044e804cdc4c7c
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
1d15f9ed-952e-45e7-9553-dcd3bc3dd76e | 2026-10-23 14:36:54.449674+00 | load-2-0
|
||||
4bc8c702-07e1-42d2-be14-8cdd6dad31a7 | 2026-10-23 14:36:54.450312+00 | load-0-0
|
||||
3993ceca-7c29-400d-a1e9-287137672829 | 2026-10-23 14:36:54.450773+00 | load-1-0
|
||||
39cb2935-f53c-4e54-a75d-8b197126a6b4 | 2026-10-23 20:11:07.699544+00 | load-3-0
|
||||
62d3d8a1-fdaa-4a6c-812f-79ef268ada42 | 2026-10-23 20:11:07.700168+00 | load-1-0
|
||||
4fa775f1-6033-4d84-9e6c-0f39844e6201 | 2026-10-23 20:11:07.700828+00 | load-0-0
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -178,7 +178,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
|
||||
=== 4. Бэкап pg_dump -Fc ===
|
||||
backup_seconds=0.741
|
||||
backup_seconds=0.743
|
||||
dump_size=5.7M
|
||||
|
||||
=== 5. Запись после бэкапа: граница потери данных ===
|
||||
@@ -188,7 +188,7 @@ dump_size=5.7M
|
||||
/var/run/postgresql:5432 - accepting connections
|
||||
|
||||
=== 7. Восстановление в новое хранилище ===
|
||||
restore_seconds=0.357
|
||||
restore_seconds=0.354
|
||||
|
||||
=== 8. Сверка восстановленной копии ===
|
||||
relation | rows
|
||||
@@ -197,19 +197,19 @@ restore_seconds=0.357
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 45
|
||||
users | 76
|
||||
users | 78
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
38293 | f18725746ed1acbdda044e804cdc4c7c
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
1d15f9ed-952e-45e7-9553-dcd3bc3dd76e | 2026-10-23 14:36:54.449674+00 | load-2-0
|
||||
4bc8c702-07e1-42d2-be14-8cdd6dad31a7 | 2026-10-23 14:36:54.450312+00 | load-0-0
|
||||
3993ceca-7c29-400d-a1e9-287137672829 | 2026-10-23 14:36:54.450773+00 | load-1-0
|
||||
39cb2935-f53c-4e54-a75d-8b197126a6b4 | 2026-10-23 20:11:07.699544+00 | load-3-0
|
||||
62d3d8a1-fdaa-4a6c-812f-79ef268ada42 | 2026-10-23 20:11:07.700168+00 | load-1-0
|
||||
4fa775f1-6033-4d84-9e6c-0f39844e6201 | 2026-10-23 20:11:07.700828+00 | load-0-0
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -219,9 +219,9 @@ restore_seconds=0.357
|
||||
|
||||
|
||||
=== 9. Итог ===
|
||||
backup_seconds=0.741 restore_seconds=0.357
|
||||
backup_seconds=0.743 restore_seconds=0.354
|
||||
messages_source_without_marker=120000 messages_restored=120000
|
||||
big_chat_md5_source=1841fdf890f6207bc78cb973bedeec27
|
||||
big_chat_md5_restored=1841fdf890f6207bc78cb973bedeec27
|
||||
big_chat_md5_source=f18725746ed1acbdda044e804cdc4c7c
|
||||
big_chat_md5_restored=f18725746ed1acbdda044e804cdc4c7c
|
||||
RESULT: восстановленная копия совпадает с источником на момент бэкапа
|
||||
маркеров после бэкапа в восстановленной копии: 0 (ожидается 0: всё, что подтверждено после снимка, в дампе отсутствует)
|
||||
|
||||
Reference in New Issue
Block a user