PostgreSQL Source Code  git master
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

◆ MAX_XFN_CHARS

#define MAX_XFN_CHARS   40

Definition at line 26 of file pgarch.h.

Referenced by pgarch_ArchiverCopyLoop(), and pgarch_readyXlog().

◆ MIN_XFN_CHARS

#define MIN_XFN_CHARS   16

Definition at line 25 of file pgarch.h.

Referenced by pgarch_readyXlog().

◆ VALID_XFN_CHARS

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

Definition at line 27 of file pgarch.h.

Referenced by pgarch_readyXlog().

Function Documentation

◆ pgarch_start()

int pgarch_start ( void  )

Definition at line 117 of file pgarch.c.

References Assert, av, ClosePostmasterPorts(), dsm_detach_all(), ereport, errmsg(), fork_process(), InitPostmasterChild(), last_pgarch_start_time, lengthof, LOG, NON_EXEC_STATIC, PGARCH_RESTART_INTERVAL, PgArchiverMain(), PGSharedMemoryDetach(), and XLogArchivingActive.

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

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