Skip to content

Commit cddcf78

Browse files
committed
Clarify some errors in pg_receivewal when closing WAL segments
A WAL segment closed during a WAL stream for pg_receivewal would generate incorrect error messages depending on the context, as the file name used when referring to a WAL segment ignored partial files or the compression method used. In such cases, the error message generated (failure on close, seek or rename) would not match a physical file name. The same code paths are used by pg_basebackup, but it uses no partial suffix so it is not impacted. 7fbe0c8 has introduced in walmethods.c a callback to get the exact physical file name used for a given context, this commit makes use of it to improve those error messages. This could be extended to more code paths of pg_basebackup/ in the future, if necessary. Extracted from a larger patch by the same author. Author: Georgios Kokolatos Discussion: https://postgr.es/m/ZCm1J5vfyQ2E6dYvXz8si39HQ2gwxSZ3IpYaVgYa3lUwY88SLapx9EEnOf5uEwrddhx2twG7zYKjVeuP5MwZXCNPybtsGouDsAD1o2L_I5E=@pm.me
1 parent 5adb067 commit cddcf78

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/bin/pg_basebackup/receivelog.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,27 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
185185
static bool
186186
close_walfile(StreamCtl *stream, XLogRecPtr pos)
187187
{
188+
char *fn;
188189
off_t currpos;
189190
int r;
190191

191192
if (walfile == NULL)
192193
return true;
193194

195+
/* Note that this considers the compression used if necessary */
196+
fn = stream->walmethod->get_file_name(current_walfile_name,
197+
stream->partial_suffix);
198+
194199
currpos = stream->walmethod->get_current_pos(walfile);
200+
195201
if (currpos == -1)
196202
{
197203
pg_log_error("could not determine seek position in file \"%s\": %s",
198-
current_walfile_name, stream->walmethod->getlasterror());
204+
fn, stream->walmethod->getlasterror());
199205
stream->walmethod->close(walfile, CLOSE_UNLINK);
200206
walfile = NULL;
201207

208+
pg_free(fn);
202209
return false;
203210
}
204211

@@ -208,8 +215,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
208215
r = stream->walmethod->close(walfile, CLOSE_NORMAL);
209216
else
210217
{
211-
pg_log_info("not renaming \"%s%s\", segment is not complete",
212-
current_walfile_name, stream->partial_suffix);
218+
pg_log_info("not renaming \"%s\", segment is not complete", fn);
213219
r = stream->walmethod->close(walfile, CLOSE_NO_RENAME);
214220
}
215221
}
@@ -221,10 +227,14 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
221227
if (r != 0)
222228
{
223229
pg_log_error("could not close file \"%s\": %s",
224-
current_walfile_name, stream->walmethod->getlasterror());
230+
fn, stream->walmethod->getlasterror());
231+
232+
pg_free(fn);
225233
return false;
226234
}
227235

236+
pg_free(fn);
237+
228238
/*
229239
* Mark file as archived if requested by the caller - pg_basebackup needs
230240
* to do so as files can otherwise get archived again after promotion of a

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy