research=# DROP TABLE messages_seed; DROP TABLE Time: 4.369 ms research=# CREATE INDEX idx_messages_chat_history ON messages (chat_id, created_at, id); CREATE INDEX Time: 75.459 ms research=# ANALYZE messages; ANALYZE Time: 92.896 ms research=# SELECT count(*) FROM messages; count -------- 100000 (1 row) Time: 7.997 ms research=# SELECT md5(string_agg(id::text || chat_id::text || created_at::text || text, '' ORDER BY id)) AS full_hash FROM messages; full_hash ---------------------------------- 3b0b6c7f0769218c3d3d1a7b660f521c (1 row) Time: 74.820 ms research=# SELECT md5(string_agg(id::text || text, '' ORDER BY created_at, id)) AS page_hash FROM (SELECT * FROM messages WHERE chat_id = (SELECT id FROM chats WHERE title = 'big') AND (created_at, id) > ('2026-01-15 00:00+00', '00000000-0000-0000-0000-000000000000') ORDER BY created_at, id LIMIT 50) p; page_hash ---------------------------------- 1b111bf87f61b52ef916f31037c4acb5 (1 row) Time: 0.736 ms research=# \q > Measure-Command { docker compose exec postgres pg_dump -U messenger -d research -Fc -f /tmp/research.dump } | Select-Object TotalSeconds TotalSeconds ------------ 0,6917214 > docker compose exec postgres psql -U messenger -d postgres -c "CREATE DATABASE research_restore;" CREATE DATABASE > Measure-Command { docker compose exec postgres pg_restore -U messenger -d research_restore /tmp/research.dump } | Select-Object TotalSeconds TotalSeconds ------------ 0,5392463 > docker compose exec postgres ls -lh /tmp/research.dump -rw-r--r-- 1 root root 4.1M Oct 7 19:48 /tmp/research.dump > docker compose exec postgres psql -U messenger -d research_restore psql (18.6 (Debian 18.6-1.pgdg13+2)) Type "help" for help. research_restore=# SELECT count(*) FROM messages; count -------- 100000 (1 row) research_restore=# SELECT md5(string_agg(id::text || chat_id::text || created_at::text || text, '' ORDER BY id)) AS full_hash FROM messages; full_hash ---------------------------------- 3b0b6c7f0769218c3d3d1a7b660f521c (1 row) research_restore=# SELECT md5(string_agg(id::text || text, '' ORDER BY created_at, id)) AS page_hash FROM (SELECT * FROM messages WHERE chat_id = (SELECT id FROM chats WHERE title = 'big') AND (created_at, id) > ('2026-01-15 00:00+00', '00000000-0000-0000-0000-000000000000') ORDER BY created_at, id LIMIT 50) p; page_hash ---------------------------------- 1b111bf87f61b52ef916f31037c4acb5 (1 row) research_restore=# \q > docker compose exec postgres rm /tmp/research.dump