Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

pgarch.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int pgarch_start (void)

Function Documentation

int pgarch_start ( void   ) 

Definition at line 134 of file pgarch.c.

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

Referenced by reaper(), and ServerLoop().

{
    time_t      curtime;
    pid_t       pgArchPid;

    /*
     * Do nothing if no archiver needed
     */
    if (!XLogArchivingActive())
        return 0;

    /*
     * Do nothing if too soon since last archiver start.  This is a safety
     * valve to protect against continuous respawn attempts if the archiver is
     * dying immediately at launch. Note that since we will be re-called from
     * the postmaster main loop, we will get another chance later.
     */
    curtime = time(NULL);
    if ((unsigned int) (curtime - last_pgarch_start_time) <
        (unsigned int) PGARCH_RESTART_INTERVAL)
        return 0;
    last_pgarch_start_time = curtime;

#ifdef EXEC_BACKEND
    switch ((pgArchPid = pgarch_forkexec()))
#else
    switch ((pgArchPid = fork_process()))
#endif
    {
        case -1:
            ereport(LOG,
                    (errmsg("could not fork archiver: %m")));
            return 0;

#ifndef EXEC_BACKEND
        case 0:
            /* in postmaster child ... */
            /* Close the postmaster's sockets */
            ClosePostmasterPorts(false);

            /* Lose the postmaster's on-exit routines */
            on_exit_reset();

            /* Drop our connection to postmaster's shared memory, as well */
            PGSharedMemoryDetach();

            PgArchiverMain(0, NULL);
            break;
#endif

        default:
            return (int) pgArchPid;
    }

    /* shouldn't get here */
    return 0;
}