@@ -1701,29 +1701,26 @@ def version_to_num(self, version):
17011701 num = num * 100 + int (re .sub (r"[^\d]" , "" , part ))
17021702 return num
17031703
1704- def switch_wal_segment (self , node ):
1704+ def switch_wal_segment (self , node , sleep_seconds = 1 , and_tx = False ):
17051705 """
1706- Execute pg_switch_wal/xlog () in given node
1706+ Execute pg_switch_wal() in given node
17071707
17081708 Args:
17091709 node: an instance of PostgresNode or NodeConnection class
17101710 """
17111711 if isinstance (node , testgres .PostgresNode ):
1712- if self .version_to_num (
1713- node .safe_psql ('postgres' , 'show server_version' ).decode ('utf-8' )
1714- ) >= self .version_to_num ('10.0' ):
1715- node .safe_psql ('postgres' , 'select pg_switch_wal()' )
1716- else :
1717- node .safe_psql ('postgres' , 'select pg_switch_xlog()' )
1712+ with node .connect ('postgres' ) as con :
1713+ if and_tx :
1714+ con .execute ('select txid_current()' )
1715+ con .execute ('select pg_switch_wal()' )
1716+ lsn = con .execute ('select pg_switch_wal()' )[0 ][0 ]
17181717 else :
1719- if self .version_to_num (
1720- node .execute ('show server_version' )[0 ][0 ]
1721- ) >= self .version_to_num ('10.0' ):
1722- node .execute ('select pg_switch_wal()' )
1723- else :
1724- node .execute ('select pg_switch_xlog()' )
1718+ node .execute ('select pg_switch_wal()' )
1719+ lsn = node .execute ('select pg_switch_wal()' )[0 ][0 ]
17251720
1726- sleep (1 )
1721+ if sleep_seconds > 0 :
1722+ sleep (sleep_seconds )
1723+ return lsn
17271724
17281725 def wait_until_replica_catch_with_master (self , master , replica ):
17291726
0 commit comments