Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc90204c

Browse files
committed
Kill pg_basebackup background process when exiting
If an error occurs in the foreground (backup) process of pg_basebackup,and we exit in a controlled way, the background process (streamingxlog process) would stay around and keep streaming.
1 parent8247236 commitc90204c

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static PQExpBuffer recoveryconfcontents = NULL;
7373

7474
/* Function headers */
7575
staticvoidusage(void);
76+
staticvoiddisconnect_and_exit(intcode);
7677
staticvoidverify_dir_is_empty_or_create(char*dirname);
7778
staticvoidprogress_report(inttablespacenum,constchar*filename);
7879

@@ -85,6 +86,26 @@ static void BaseBackup(void);
8586
staticboolreached_end_position(XLogRecPtrsegendpos,uint32timeline,
8687
boolsegment_finished);
8788

89+
90+
staticvoiddisconnect_and_exit(intcode)
91+
{
92+
if (conn!=NULL)
93+
PQfinish(conn);
94+
95+
#ifndefWIN32
96+
/*
97+
* On windows, our background thread dies along with the process.
98+
* But on Unix, if we have started a subprocess, we want to kill
99+
* it off so it doesn't remain running trying to stream data.
100+
*/
101+
if (bgchild>0)
102+
kill(bgchild,SIGTERM);
103+
#endif
104+
105+
exit(code);
106+
}
107+
108+
88109
#ifdefHAVE_LIBZ
89110
staticconstchar*
90111
get_gz_error(gzFilegzf)

‎src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ static void StreamLog();
4545
staticboolstop_streaming(XLogRecPtrsegendpos,uint32timeline,
4646
boolsegment_finished);
4747

48+
#definedisconnect_and_exit(code)\
49+
{\
50+
if (conn != NULL) PQfinish(conn);\
51+
exit(code);\
52+
}
53+
54+
4855
staticvoid
4956
usage(void)
5057
{

‎src/bin/pg_basebackup/streamutil.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,4 @@ extern intdbgetpassword;
1010
/* Connection kept global so we can disconnect easily */
1111
externPGconn*conn;
1212

13-
#definedisconnect_and_exit(code)\
14-
{\
15-
if (conn != NULL) PQfinish(conn);\
16-
exit(code);\
17-
}
18-
1913
externPGconn*GetConnection(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp