PostgreSQL Source Code git master
Loading...
Searching...
No Matches
shell_archive.c File Reference
#include "postgres.h"
#include <sys/wait.h>
#include "access/xlog.h"
#include "archive/archive_module.h"
#include "archive/shell_archive.h"
#include "common/percentrepl.h"
#include "pgstat.h"
#include "utils/wait_event.h"
Include dependency graph for shell_archive.c:

Go to the source code of this file.

Functions

static bool shell_archive_configured (ArchiveModuleState *state)
 
static bool shell_archive_file (ArchiveModuleState *state, const char *file, const char *path)
 
static void shell_archive_shutdown (ArchiveModuleState *state)
 
const ArchiveModuleCallbacksshell_archive_init (void)
 

Variables

static const ArchiveModuleCallbacks shell_archive_callbacks
 

Function Documentation

◆ shell_archive_configured()

static bool shell_archive_configured ( ArchiveModuleState state)
static

Definition at line 47 of file shell_archive.c.

48{
49 if (XLogArchiveCommand[0] != '\0')
50 return true;
51
52 arch_module_check_errdetail("\"%s\" is not set.",
53 "archive_command");
54 return false;
55}
#define arch_module_check_errdetail
char * XLogArchiveCommand
Definition xlog.c:124

References arch_module_check_errdetail, and XLogArchiveCommand.

◆ shell_archive_file()

static bool shell_archive_file ( ArchiveModuleState state,
const char file,
const char path 
)
static

Definition at line 58 of file shell_archive.c.

60{
61 char *xlogarchcmd;
62 char *nativePath = NULL;
63 int rc;
64
65 if (path)
66 {
67 nativePath = pstrdup(path);
69 }
70
72 "archive_command", "fp",
73 file, nativePath);
74
76 (errmsg_internal("executing archive command \"%s\"",
77 xlogarchcmd)));
78
79 fflush(NULL);
81 rc = system(xlogarchcmd);
83
84 if (rc != 0)
85 {
86 /*
87 * If either the shell itself, or a called command, died on a signal,
88 * abort the archiver. We do this because system() ignores SIGINT and
89 * SIGQUIT while waiting; so a signal is very likely something that
90 * should have interrupted us too. Also die if the shell got a hard
91 * "command not found" type of error. If we overreact it's no big
92 * deal, the postmaster will just start the archiver again.
93 */
94 int lev = wait_result_is_any_signal(rc, true) ? FATAL : LOG;
95
96 if (WIFEXITED(rc))
97 {
99 (errmsg("archive command failed with exit code %d",
100 WEXITSTATUS(rc)),
101 errdetail("The failed archive command was: %s",
102 xlogarchcmd)));
103 }
104 else if (WIFSIGNALED(rc))
105 {
106#if defined(WIN32)
107 ereport(lev,
108 (errmsg("archive command was terminated by exception 0x%X",
109 WTERMSIG(rc)),
110 errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
111 errdetail("The failed archive command was: %s",
112 xlogarchcmd)));
113#else
114 ereport(lev,
115 (errmsg("archive command was terminated by signal %d: %s",
116 WTERMSIG(rc), pg_strsignal(WTERMSIG(rc))),
117 errdetail("The failed archive command was: %s",
118 xlogarchcmd)));
119#endif
120 }
121 else
122 {
123 ereport(lev,
124 (errmsg("archive command exited with unrecognized status %d",
125 rc),
126 errdetail("The failed archive command was: %s",
127 xlogarchcmd)));
128 }
130
131 return false;
132 }
134
135 elog(DEBUG1, "archived write-ahead log file \"%s\"", file);
136 return true;
137}
#define LOG
Definition elog.h:31
int errhint(const char *fmt,...) pg_attribute_printf(1
#define DEBUG3
Definition elog.h:28
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define FATAL
Definition elog.h:41
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG1
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
static char * errmsg
char * replace_percent_placeholders(const char *instr, const char *param_name, const char *letters,...)
Definition percentrepl.c:59
const char * pg_strsignal(int signum)
Definition pgstrsignal.c:39
void make_native_path(char *filename)
Definition path.c:236
static int fb(int x)
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
Definition wait_error.c:121
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition wait_event.h:69
static void pgstat_report_wait_end(void)
Definition wait_event.h:85
#define WIFEXITED(w)
Definition win32_port.h:150
#define WIFSIGNALED(w)
Definition win32_port.h:151
#define WTERMSIG(w)
Definition win32_port.h:153
#define WEXITSTATUS(w)
Definition win32_port.h:152

References DEBUG1, DEBUG3, elog, ereport, errdetail(), errhint(), errmsg, errmsg_internal(), FATAL, fb(), LOG, make_native_path(), pfree(), pg_strsignal(), pgstat_report_wait_end(), pgstat_report_wait_start(), pstrdup(), replace_percent_placeholders(), wait_result_is_any_signal(), WEXITSTATUS, WIFEXITED, WIFSIGNALED, WTERMSIG, and XLogArchiveCommand.

◆ shell_archive_init()

const ArchiveModuleCallbacks * shell_archive_init ( void  )

Definition at line 41 of file shell_archive.c.

42{
44}
static const ArchiveModuleCallbacks shell_archive_callbacks

References shell_archive_callbacks.

Referenced by LoadArchiveLibrary().

◆ shell_archive_shutdown()

static void shell_archive_shutdown ( ArchiveModuleState state)
static

Definition at line 140 of file shell_archive.c.

141{
142 elog(DEBUG1, "archiver process shutting down");
143}

References DEBUG1, and elog.

Variable Documentation

◆ shell_archive_callbacks

const ArchiveModuleCallbacks shell_archive_callbacks
static
Initial value:
= {
.startup_cb = NULL,
.check_configured_cb = shell_archive_configured,
.archive_file_cb = shell_archive_file,
.shutdown_cb = shell_archive_shutdown
}
static void shell_archive_shutdown(ArchiveModuleState *state)
static bool shell_archive_configured(ArchiveModuleState *state)
static bool shell_archive_file(ArchiveModuleState *state, const char *file, const char *path)

Definition at line 33 of file shell_archive.c.

33 {
34 .startup_cb = NULL,
35 .check_configured_cb = shell_archive_configured,
36 .archive_file_cb = shell_archive_file,
37 .shutdown_cb = shell_archive_shutdown
38};

Referenced by shell_archive_init().