@@ -53,11 +53,6 @@ def test_minrecpoint_on_replica(self):
53
53
replica ,
54
54
{'port' :replica .port ,'restart_after_crash' :'off' })
55
55
56
- # we need those later
57
- node .safe_psql (
58
- "postgres" ,
59
- "CREATE EXTENSION plpython3u" )
60
-
61
56
node .safe_psql (
62
57
"postgres" ,
63
58
"CREATE EXTENSION pageinspect" )
@@ -131,48 +126,37 @@ def test_minrecpoint_on_replica(self):
131
126
recovery_config ,"recovery_target_action = 'pause'" )
132
127
replica .slow_start (replica = True )
133
128
129
+ current_xlog_lsn_query = 'SELECT pg_last_wal_replay_lsn() INTO current_xlog_lsn'
134
130
if self .get_version (node )< 100000 :
135
- script = '''
136
- DO
137
- $$
138
- relations = plpy.execute("select class.oid from pg_class class WHERE class.relkind IN ('r', 'i', 't', 'm') and class.relpersistence = 'p'")
139
- current_xlog_lsn = plpy.execute("SELECT min_recovery_end_location as lsn FROM pg_control_recovery()")[0]['lsn']
140
- plpy.notice('CURRENT LSN: {0}'.format(current_xlog_lsn))
141
- found_corruption = False
142
- for relation in relations:
143
- pages_from_future = plpy.execute("with number_of_blocks as (select blknum from generate_series(0, pg_relation_size({0}) / 8192 -1) as blknum) select blknum, lsn, checksum, flags, lower, upper, special, pagesize, version, prune_xid from number_of_blocks, page_header(get_raw_page('{0}'::oid::regclass::text, number_of_blocks.blknum::int)) where lsn > '{1}'::pg_lsn".format(relation['oid'], current_xlog_lsn))
144
-
145
- if pages_from_future.nrows() == 0:
146
- continue
147
-
148
- for page in pages_from_future:
149
- plpy.notice('Found page from future. OID: {0}, BLKNUM: {1}, LSN: {2}'.format(relation['oid'], page['blknum'], page['lsn']))
150
- found_corruption = True
151
- if found_corruption:
152
- plpy.error('Found Corruption')
153
- $$ LANGUAGE plpython3u;
154
- '''
155
- else :
156
- script = '''
131
+ current_xlog_lsn_query = 'SELECT min_recovery_end_location INTO current_xlog_lsn FROM pg_control_recovery()'
132
+
133
+ script = f'''
157
134
DO
158
135
$$
159
- relations = plpy.execute("select class.oid from pg_class class WHERE class.relkind IN ('r', 'i', 't', 'm') and class.relpersistence = 'p'")
160
- current_xlog_lsn = plpy.execute("select pg_last_wal_replay_lsn() as lsn")[0]['lsn']
161
- plpy.notice('CURRENT LSN: {0}'.format(current_xlog_lsn))
162
- found_corruption = False
163
- for relation in relations:
164
- pages_from_future = plpy.execute("with number_of_blocks as (select blknum from generate_series(0, pg_relation_size({0}) / 8192 -1) as blknum) select blknum, lsn, checksum, flags, lower, upper, special, pagesize, version, prune_xid from number_of_blocks, page_header(get_raw_page('{0}'::oid::regclass::text, number_of_blocks.blknum::int)) where lsn > '{1}'::pg_lsn".format(relation['oid'], current_xlog_lsn))
165
-
166
- if pages_from_future.nrows() == 0:
167
- continue
168
-
169
- for page in pages_from_future:
170
- plpy.notice('Found page from future. OID: {0}, BLKNUM: {1}, LSN: {2}'.format(relation['oid'], page['blknum'], page['lsn']))
171
- found_corruption = True
172
- if found_corruption:
173
- plpy.error('Found Corruption')
174
- $$ LANGUAGE plpython3u;
175
- '''
136
+ DECLARE
137
+ roid oid;
138
+ current_xlog_lsn pg_lsn;
139
+ pages_from_future RECORD;
140
+ found_corruption bool := false;
141
+ BEGIN
142
+ { current_xlog_lsn_query } ;
143
+ RAISE NOTICE 'CURRENT LSN: %', current_xlog_lsn;
144
+ FOR roid IN select oid from pg_class class where relkind IN ('r', 'i', 't', 'm') and relpersistence = 'p' LOOP
145
+ FOR pages_from_future IN
146
+ with number_of_blocks as (select blknum from generate_series(0, pg_relation_size(roid) / 8192 -1) as blknum )
147
+ select blknum, lsn, checksum, flags, lower, upper, special, pagesize, version, prune_xid
148
+ from number_of_blocks, page_header(get_raw_page(roid::regclass::text, number_of_blocks.blknum::int))
149
+ where lsn > current_xlog_lsn LOOP
150
+ RAISE NOTICE 'Found page from future. OID: %, BLKNUM: %, LSN: %', roid, pages_from_future.blknum, pages_from_future.lsn;
151
+ found_corruption := true;
152
+ END LOOP;
153
+ END LOOP;
154
+ IF found_corruption THEN
155
+ RAISE 'Found Corruption';
156
+ END IF;
157
+ END;
158
+ $$ LANGUAGE plpgsql;
159
+ ''' .format (current_xlog_lsn_query = current_xlog_lsn_query )
176
160
177
161
# Find blocks from future
178
162
replica .safe_psql (