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

Commit63ab2be

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 parent1c9acd5 commit63ab2be

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
@@ -76,6 +76,7 @@ static PQExpBuffer recoveryconfcontents = NULL;
7676

7777
/* Function headers */
7878
staticvoidusage(void);
79+
staticvoiddisconnect_and_exit(intcode);
7980
staticvoidverify_dir_is_empty_or_create(char*dirname);
8081
staticvoidprogress_report(inttablespacenum,constchar*filename,boolforce);
8182

@@ -88,6 +89,26 @@ static void BaseBackup(void);
8889
staticboolreached_end_position(XLogRecPtrsegendpos,uint32timeline,
8990
boolsegment_finished);
9091

92+
93+
staticvoiddisconnect_and_exit(intcode)
94+
{
95+
if (conn!=NULL)
96+
PQfinish(conn);
97+
98+
#ifndefWIN32
99+
/*
100+
* On windows, our background thread dies along with the process.
101+
* But on Unix, if we have started a subprocess, we want to kill
102+
* it off so it doesn't remain running trying to stream data.
103+
*/
104+
if (bgchild>0)
105+
kill(bgchild,SIGTERM);
106+
#endif
107+
108+
exit(code);
109+
}
110+
111+
91112
#ifdefHAVE_LIBZ
92113
staticconstchar*
93114
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
@@ -11,10 +11,4 @@ extern char *replication_slot;
1111
/* Connection kept global so we can disconnect easily */
1212
externPGconn*conn;
1313

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp