@@ -104,6 +104,9 @@ typedef struct XLogPageReadPrivate
104
104
#ifdef HAVE_LIBZ
105
105
gzFile gz_xlogfile ;
106
106
char gz_xlogpath [MAXPGPATH ];
107
+
108
+ char gz_buf [XLOG_BLCKSZ ];
109
+ uint32 gz_prev_off ;
107
110
#endif
108
111
} XLogPageReadPrivate ;
109
112
@@ -1057,22 +1060,30 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
1057
1060
#ifdef HAVE_LIBZ
1058
1061
else
1059
1062
{
1060
- if (gzseek (private_data -> gz_xlogfile , (z_off_t ) targetPageOff , SEEK_SET ) == -1 )
1063
+ if (private_data -> gz_prev_off != 0 &&
1064
+ private_data -> gz_prev_off == targetPageOff )
1065
+ memcpy (readBuf , private_data -> gz_buf , XLOG_BLCKSZ );
1066
+ else
1061
1067
{
1062
- elog (WARNING , "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s" ,
1063
- private_data -> thread_num ,
1064
- private_data -> gz_xlogpath ,
1065
- get_gz_error (private_data -> gz_xlogfile ));
1066
- return -1 ;
1067
- }
1068
+ if (gzseek (private_data -> gz_xlogfile , (z_off_t ) targetPageOff , SEEK_SET ) == -1 )
1069
+ {
1070
+ elog (WARNING , "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s" ,
1071
+ private_data -> thread_num ,
1072
+ private_data -> gz_xlogpath ,
1073
+ get_gz_error (private_data -> gz_xlogfile ));
1074
+ return -1 ;
1075
+ }
1068
1076
1069
- if (gzread (private_data -> gz_xlogfile , readBuf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
1070
- {
1071
- elog (WARNING , "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s" ,
1072
- private_data -> thread_num ,
1073
- private_data -> gz_xlogpath ,
1074
- get_gz_error (private_data -> gz_xlogfile ));
1075
- return -1 ;
1077
+ if (gzread (private_data -> gz_xlogfile , readBuf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
1078
+ {
1079
+ elog (WARNING , "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s" ,
1080
+ private_data -> thread_num ,
1081
+ private_data -> gz_xlogpath ,
1082
+ get_gz_error (private_data -> gz_xlogfile ));
1083
+ return -1 ;
1084
+ }
1085
+ private_data -> gz_prev_off = targetPageOff ;
1086
+ memcpy (private_data -> gz_buf , readBuf , XLOG_BLCKSZ );
1076
1087
}
1077
1088
}
1078
1089
#endif
@@ -1131,6 +1142,7 @@ CleanupXLogPageRead(XLogReaderState *xlogreader)
1131
1142
{
1132
1143
gzclose (private_data -> gz_xlogfile );
1133
1144
private_data -> gz_xlogfile = NULL ;
1145
+ private_data -> gz_prev_off = 0 ;
1134
1146
}
1135
1147
#endif
1136
1148
private_data -> xlogexists = false;
0 commit comments