PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgarch.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MIN_XFN_CHARS   16
 
#define MAX_XFN_CHARS   40
 
#define VALID_XFN_CHARS   "0123456789ABCDEF.history.backup.partial"
 

Functions

int pgarch_start (void)
 

Macro Definition Documentation

#define MAX_XFN_CHARS   40

Definition at line 26 of file pgarch.h.

Referenced by pgarch_ArchiverCopyLoop(), and pgarch_readyXlog().

#define MIN_XFN_CHARS   16

Definition at line 25 of file pgarch.h.

Referenced by pgarch_readyXlog().

#define VALID_XFN_CHARS   "0123456789ABCDEF.history.backup.partial"

Definition at line 27 of file pgarch.h.

Referenced by pgarch_readyXlog().

Function Documentation

int pgarch_start ( void  )

Definition at line 118 of file pgarch.c.

References ClosePostmasterPorts(), dsm_detach_all(), ereport, errmsg(), fork_process(), InitPostmasterChild(), last_pgarch_start_time, LOG, NULL, PGARCH_RESTART_INTERVAL, PgArchiverMain(), PGSharedMemoryDetach(), and XLogArchivingActive.

Referenced by reaper(), ServerLoop(), and sigusr1_handler().

119 {
120  time_t curtime;
121  pid_t pgArchPid;
122 
123  /*
124  * Do nothing if no archiver needed
125  */
126  if (!XLogArchivingActive())
127  return 0;
128 
129  /*
130  * Do nothing if too soon since last archiver start. This is a safety
131  * valve to protect against continuous respawn attempts if the archiver is
132  * dying immediately at launch. Note that since we will be re-called from
133  * the postmaster main loop, we will get another chance later.
134  */
135  curtime = time(NULL);
136  if ((unsigned int) (curtime - last_pgarch_start_time) <
137  (unsigned int) PGARCH_RESTART_INTERVAL)
138  return 0;
139  last_pgarch_start_time = curtime;
140 
141 #ifdef EXEC_BACKEND
142  switch ((pgArchPid = pgarch_forkexec()))
143 #else
144  switch ((pgArchPid = fork_process()))
145 #endif
146  {
147  case -1:
148  ereport(LOG,
149  (errmsg("could not fork archiver: %m")));
150  return 0;
151 
152 #ifndef EXEC_BACKEND
153  case 0:
154  /* in postmaster child ... */
156 
157  /* Close the postmaster's sockets */
158  ClosePostmasterPorts(false);
159 
160  /* Drop our connection to postmaster's shared memory, as well */
161  dsm_detach_all();
163 
164  PgArchiverMain(0, NULL);
165  break;
166 #endif
167 
168  default:
169  return (int) pgArchPid;
170  }
171 
172  /* shouldn't get here */
173  return 0;
174 }
void InitPostmasterChild(void)
Definition: miscinit.c:175
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:60
pid_t fork_process(void)
Definition: fork_process.c:31
static time_t last_pgarch_start_time
Definition: pgarch.c:70
#define LOG
Definition: elog.h:26
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2414
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:768
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:226
#define XLogArchivingActive()
Definition: xlog.h:134
void dsm_detach_all(void)
Definition: dsm.c:655
int errmsg(const char *fmt,...)
Definition: elog.c:797
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgarch.c:216