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

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