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 125 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().

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