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

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