Files
neon/test_runner/regress/test_vm_truncate.py
Konstantin Knizhnik f70611c8df Correctly truncate VM (#9342)
## Problem

https://github.com/neondatabase/neon/issues/9240

## Summary of changes

Correctly truncate VM page instead just replacing it with zero page.

## Checklist before requesting a review

- [ ] I have performed a self-review of my code.
- [ ] If it is a core feature, I have added thorough tests.
- [ ] Do we need to implement analytics? if so did you add the relevant
metrics to the dashboard?
- [ ] If this PR requires public announcement, mark it with
/release-notes label and add several sentences in this section.

## Checklist before merging

- [ ] Do not forget to reformat commit message to not include the above
checklist

---------

Co-authored-by: Konstantin Knizhnik <knizhnik@neon.tech>
Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
2024-11-14 17:19:13 +02:00

34 lines
1.4 KiB
Python

from fixtures.neon_fixtures import NeonEnv
#
# Test that VM is properly truncated
#
def test_vm_truncate(neon_simple_env: NeonEnv):
env = neon_simple_env
endpoint = env.endpoints.create_start("main")
con = endpoint.connect()
cur = con.cursor()
cur.execute("CREATE EXTENSION neon_test_utils")
cur.execute("CREATE EXTENSION pageinspect")
cur.execute(
"create table t(pk integer primary key, counter integer default 0, filler text default repeat('?', 200))"
)
cur.execute("insert into t (pk) values (generate_series(1,1000))")
cur.execute("delete from t where pk>10")
cur.execute("vacuum t") # truncates the relation, including its VM and FSM
# get image of the first block of the VM excluding the page header. It's expected
# to still be in the buffer cache.
# ignore page header (24 bytes, 48 - it's hex representation)
cur.execute("select substr(encode(get_raw_page('t', 'vm', 0), 'hex'), 48)")
pg_bitmap = cur.fetchall()[0][0]
# flush shared buffers
cur.execute("SELECT clear_buffer_cache()")
# now download the first block of the VM from the pageserver ...
cur.execute("select substr(encode(get_raw_page('t', 'vm', 0), 'hex'), 48)")
ps_bitmap = cur.fetchall()[0][0]
# and check that content of bitmaps are equal, i.e. PS is producing the same VM page as Postgres
assert pg_bitmap == ps_bitmap