xact_redo_abort.py
text/x-python
Filename: xact_redo_abort.py
Type: text/x-python
Part: 0
# Repro for https://www.postgresql.org/message-id/b029fce3-4fac-4265-968e-16f36ff4d075.mengjuan.cmj%40alibaba-inc.com
import psycopg2
import subprocess
import time
subprocess.run(["initdb", "-D", "data-master"])
f = open('data-master/postgresql.conf', 'a')
f.write("full_page_writes='off'\n")
f.close();
subprocess.run(["pg_ctl", "-D", "data-master", "start"])
conn = psycopg2.connect("dbname=postgres host=localhost")
cur = conn.cursor()
cur.execute("create table foo (t text)")
cur.execute("insert into foo values ('foo')");
subprocess.run(["pg_basebackup", "-D", "data-standby", "-R"])
f = open('data-standby/postgresql.conf', 'a')
f.write("port='5433'\n")
f.close();
subprocess.run(["pg_ctl", "-D", "data-standby", "start"])
cur.execute("delete from foo");
conn.rollback();
time.sleep(2) # wait for the ROLLBACK record to reach the standby
subprocess.run(["pg_ctl", "-D", "data-standby", "stop", "-m", "immediate"])
subprocess.run(["pg_ctl", "-D", "data-standby", "start"])