Header And Logo

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

Defines | Functions | Variables

postmaster.h File Reference

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

Go to the source code of this file.

Defines

#define POSTMASTER_FD_WATCH   0
#define POSTMASTER_FD_OWN   1
#define MAX_BACKENDS   0x7fffff

Functions

void PostmasterMain (int argc, char *argv[]) __attribute__((noreturn))
void ClosePostmasterPorts (bool am_syslogger)
int MaxLivePostmasterChildren (void)
int GetNumShmemAttachedBgworkers (void)

Variables

bool EnableSSL
int ReservedBackends
int PostPortNumber
int Unix_socket_permissions
char * Unix_socket_group
char * Unix_socket_directories
char * ListenAddresses
bool ClientAuthInProgress
int PreAuthDelay
int AuthenticationTimeout
bool Log_connections
bool log_hostname
bool enable_bonjour
char * bonjour_name
bool restart_after_crash
int postmaster_alive_fds [2]
const char * progname

Define Documentation

#define MAX_BACKENDS   0x7fffff
#define POSTMASTER_FD_OWN   1

Definition at line 44 of file postmaster.h.

Referenced by ClosePostmasterPorts().

#define POSTMASTER_FD_WATCH   0

Function Documentation

void ClosePostmasterPorts ( bool  am_syslogger  ) 

Definition at line 2199 of file postmaster.c.

References close, ereport, errcode_for_file_access(), errmsg_internal(), FATAL, ListenSocket, PGINVALID_SOCKET, POSTMASTER_FD_OWN, StreamClose(), and syslogPipe.

Referenced by BackendStartup(), pgarch_start(), pgstat_start(), start_bgworker(), StartAutoVacLauncher(), StartAutoVacWorker(), StartChildProcess(), and SysLogger_Start().

{
    int         i;

#ifndef WIN32

    /*
     * Close the write end of postmaster death watch pipe. It's important to
     * do this as early as possible, so that if postmaster dies, others won't
     * think that it's still running because we're holding the pipe open.
     */
    if (close(postmaster_alive_fds[POSTMASTER_FD_OWN]))
        ereport(FATAL,
                (errcode_for_file_access(),
                 errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
    postmaster_alive_fds[POSTMASTER_FD_OWN] = -1;
#endif

    /* Close the listen sockets */
    for (i = 0; i < MAXLISTEN; i++)
    {
        if (ListenSocket[i] != PGINVALID_SOCKET)
        {
            StreamClose(ListenSocket[i]);
            ListenSocket[i] = PGINVALID_SOCKET;
        }
    }

    /* If using syslogger, close the read side of the pipe */
    if (!am_syslogger)
    {
#ifndef WIN32
        if (syslogPipe[0] >= 0)
            close(syslogPipe[0]);
        syslogPipe[0] = -1;
#else
        if (syslogPipe[0])
            CloseHandle(syslogPipe[0]);
        syslogPipe[0] = 0;
#endif
    }

#ifdef USE_BONJOUR
    /* If using Bonjour, close the connection to the mDNS daemon */
    if (bonjour_sdref)
        close(DNSServiceRefSockFD(bonjour_sdref));
#endif
}

int GetNumShmemAttachedBgworkers ( void   ) 
int MaxLivePostmasterChildren ( void   ) 
void PostmasterMain ( int  argc,
char *  argv[] 
)

Definition at line 557 of file postmaster.c.

References AddToDataDirLockFile(), ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE, ALLOCSET_DEFAULT_MINSIZE, AllocSetContextCreate(), Assert, autovac_init(), BlockSig, bonjour_name, ChangeToDataDir(), checkDataDir(), CheckDateTokenTables(), CreateDataDirLockFile(), CreateOptsFile(), DEBUG3, dummy_handler(), elog, enable_bonjour, EnableSSL, environ, ereport, errcode(), errmsg(), errmsg_internal(), ERROR, ExitPostmaster(), external_pid_file, ExtraOptions, FATAL, free, get_stats_option_name(), GetConfigOption(), GetCurrentTimestamp(), getInstallationPaths(), getopt(), gettimeofday(), i, InitializeGUCOptions(), InitializeMaxBackends(), InitPostmasterDeathWatchHandle(), IsBinaryUpgrade, IsPostmasterEnvironment, lfirst, list_free(), list_free_deep(), ListenAddresses, ListenSocket, load_hba(), load_ident(), LOCK_FILE_LINE_LISTEN_ADDR, LOCK_FILE_LINE_SOCKET_DIR, LOG, max_wal_senders, MaxConnections, MemoryContextInit(), MemoryContextSwitchTo(), my_exec_path, MyProcPid, MyStartTime, name, NIL, NULL, on_proc_exit(), optarg, opterr, optind, output_config_variable, ParseLongOption(), pfree(), PG_SETMASK, PGC_POSTMASTER, PGC_S_ARGV, PGINVALID_SOCKET, PgStartTime, pgstat_init(), pmdie(), pmState, PostmasterContext, PostmasterPid, PostPortNumber, pqinitmask(), pqsignal(), process_shared_preload_libraries(), progname, pstrdup(), random_start_time, reaper(), Reinit, RemovePgTempFiles(), ReservedBackends, reset_shared(), S_IRGRP, S_IROTH, S_IRWXG, S_IRWXO, secure_initialize(), SelectConfigFiles(), SendStop, ServerLoop(), set_debug_options(), set_max_safe_fds(), set_plan_disabling_options(), set_stack_base(), SetConfigOption(), SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SIGHUP_handler(), SIGPIPE, SIGQUIT, SIGTTIN, SIGTTOU, SIGUSR1, sigusr1_handler(), SIGUSR2, snprintf(), SplitDirectoriesString(), SplitIdentifierString(), StartOneBackgroundWorker(), StartupDataBase, StartupPID, STATUS_OK, StreamServerPort(), strerror(), SysLogger_Start(), SysLoggerPID, TopMemoryContext, Unix_socket_directories, unlink_external_pid_file(), userDoption, value, wal_level, WAL_LEVEL_MINIMAL, WARNING, whereToSendOutput, write_stderr, and XLogArchiveMode.

Referenced by main().

{
    int         opt;
    int         status;
    char       *userDoption = NULL;
    bool        listen_addr_saved = false;
    int         i;

    MyProcPid = PostmasterPid = getpid();

    MyStartTime = time(NULL);

    IsPostmasterEnvironment = true;

    /*
     * for security, no dir or file created can be group or other accessible
     */
    umask(S_IRWXG | S_IRWXO);

    /*
     * Fire up essential subsystems: memory management
     */
    MemoryContextInit();

    /*
     * By default, palloc() requests in the postmaster will be allocated in
     * the PostmasterContext, which is space that can be recycled by backends.
     * Allocated data that needs to be available to backends should be
     * allocated in TopMemoryContext.
     */
    PostmasterContext = AllocSetContextCreate(TopMemoryContext,
                                              "Postmaster",
                                              ALLOCSET_DEFAULT_MINSIZE,
                                              ALLOCSET_DEFAULT_INITSIZE,
                                              ALLOCSET_DEFAULT_MAXSIZE);
    MemoryContextSwitchTo(PostmasterContext);

    /* Initialize paths to installation files */
    getInstallationPaths(argv[0]);

    /*
     * Options setup
     */
    InitializeGUCOptions();

    opterr = 1;

    /*
     * Parse command-line options.  CAUTION: keep this in sync with
     * tcop/postgres.c (the option sets should not conflict) and with the
     * common help() function in main/main.c.
     */
    while ((opt = getopt(argc, argv, "A:B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1)
    {
        switch (opt)
        {
            case 'A':
                SetConfigOption("debug_assertions", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'B':
                SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'b':
                /* Undocumented flag used for binary upgrades */
                IsBinaryUpgrade = true;
                break;

            case 'C':
                output_config_variable = strdup(optarg);
                break;

            case 'D':
                userDoption = strdup(optarg);
                break;

            case 'd':
                set_debug_options(atoi(optarg), PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'E':
                SetConfigOption("log_statement", "all", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'e':
                SetConfigOption("datestyle", "euro", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'F':
                SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'f':
                if (!set_plan_disabling_options(optarg, PGC_POSTMASTER, PGC_S_ARGV))
                {
                    write_stderr("%s: invalid argument for option -f: \"%s\"\n",
                                 progname, optarg);
                    ExitPostmaster(1);
                }
                break;

            case 'h':
                SetConfigOption("listen_addresses", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'i':
                SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'j':
                /* only used by interactive backend */
                break;

            case 'k':
                SetConfigOption("unix_socket_directories", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'l':
                SetConfigOption("ssl", "true", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'N':
                SetConfigOption("max_connections", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'n':
                /* Don't reinit shared mem after abnormal exit */
                Reinit = false;
                break;

            case 'O':
                SetConfigOption("allow_system_table_mods", "true", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'o':
                /* Other options to pass to the backend on the command line */
                snprintf(ExtraOptions + strlen(ExtraOptions),
                         sizeof(ExtraOptions) - strlen(ExtraOptions),
                         " %s", optarg);
                break;

            case 'P':
                SetConfigOption("ignore_system_indexes", "true", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'p':
                SetConfigOption("port", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'r':
                /* only used by single-user backend */
                break;

            case 'S':
                SetConfigOption("work_mem", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 's':
                SetConfigOption("log_statement_stats", "true", PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'T':

                /*
                 * In the event that some backend dumps core, send SIGSTOP,
                 * rather than SIGQUIT, to all its peers.  This lets the wily
                 * post_hacker collect core dumps from everyone.
                 */
                SendStop = true;
                break;

            case 't':
                {
                    const char *tmp = get_stats_option_name(optarg);

                    if (tmp)
                    {
                        SetConfigOption(tmp, "true", PGC_POSTMASTER, PGC_S_ARGV);
                    }
                    else
                    {
                        write_stderr("%s: invalid argument for option -t: \"%s\"\n",
                                     progname, optarg);
                        ExitPostmaster(1);
                    }
                    break;
                }

            case 'W':
                SetConfigOption("post_auth_delay", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                break;

            case 'c':
            case '-':
                {
                    char       *name,
                               *value;

                    ParseLongOption(optarg, &name, &value);
                    if (!value)
                    {
                        if (opt == '-')
                            ereport(ERROR,
                                    (errcode(ERRCODE_SYNTAX_ERROR),
                                     errmsg("--%s requires a value",
                                            optarg)));
                        else
                            ereport(ERROR,
                                    (errcode(ERRCODE_SYNTAX_ERROR),
                                     errmsg("-c %s requires a value",
                                            optarg)));
                    }

                    SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
                    free(name);
                    if (value)
                        free(value);
                    break;
                }

            default:
                write_stderr("Try \"%s --help\" for more information.\n",
                             progname);
                ExitPostmaster(1);
        }
    }

    /*
     * Postmaster accepts no non-option switch arguments.
     */
    if (optind < argc)
    {
        write_stderr("%s: invalid argument: \"%s\"\n",
                     progname, argv[optind]);
        write_stderr("Try \"%s --help\" for more information.\n",
                     progname);
        ExitPostmaster(1);
    }

    /*
     * Locate the proper configuration files and data directory, and read
     * postgresql.conf for the first time.
     */
    if (!SelectConfigFiles(userDoption, progname))
        ExitPostmaster(2);

    if (output_config_variable != NULL)
    {
        /*
         * permission is handled because the user is reading inside the data
         * dir
         */
        puts(GetConfigOption(output_config_variable, false, false));
        ExitPostmaster(0);
    }

    /* Verify that DataDir looks reasonable */
    checkDataDir();

    /* And switch working directory into it */
    ChangeToDataDir();

    /*
     * Check for invalid combinations of GUC settings.
     */
    if (ReservedBackends >= MaxConnections)
    {
        write_stderr("%s: superuser_reserved_connections must be less than max_connections\n", progname);
        ExitPostmaster(1);
    }
    if (max_wal_senders >= MaxConnections)
    {
        write_stderr("%s: max_wal_senders must be less than max_connections\n", progname);
        ExitPostmaster(1);
    }
    if (XLogArchiveMode && wal_level == WAL_LEVEL_MINIMAL)
        ereport(ERROR,
                (errmsg("WAL archival (archive_mode=on) requires wal_level \"archive\" or \"hot_standby\"")));
    if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
        ereport(ERROR,
                (errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"archive\" or \"hot_standby\"")));

    /*
     * Other one-time internal sanity checks can go here, if they are fast.
     * (Put any slow processing further down, after postmaster.pid creation.)
     */
    if (!CheckDateTokenTables())
    {
        write_stderr("%s: invalid datetoken tables, please fix\n", progname);
        ExitPostmaster(1);
    }

    /*
     * Now that we are done processing the postmaster arguments, reset
     * getopt(3) library so that it will work correctly in subprocesses.
     */
    optind = 1;
#ifdef HAVE_INT_OPTRESET
    optreset = 1;               /* some systems need this too */
#endif

    /* For debugging: display postmaster environment */
    {
        extern char **environ;
        char      **p;

        ereport(DEBUG3,
            (errmsg_internal("%s: PostmasterMain: initial environment dump:",
                             progname)));
        ereport(DEBUG3,
             (errmsg_internal("-----------------------------------------")));
        for (p = environ; *p; ++p)
            ereport(DEBUG3,
                    (errmsg_internal("\t%s", *p)));
        ereport(DEBUG3,
             (errmsg_internal("-----------------------------------------")));
    }

    /*
     * Create lockfile for data directory.
     *
     * We want to do this before we try to grab the input sockets, because the
     * data directory interlock is more reliable than the socket-file
     * interlock (thanks to whoever decided to put socket files in /tmp :-().
     * For the same reason, it's best to grab the TCP socket(s) before the
     * Unix socket(s).
     */
    CreateDataDirLockFile(true);

    /*
     * Initialize SSL library, if specified.
     */
#ifdef USE_SSL
    if (EnableSSL)
        secure_initialize();
#endif

    /*
     * process any libraries that should be preloaded at postmaster start
     */
    process_shared_preload_libraries();

    /*
     * Now that loadable modules have had their chance to register background
     * workers, calculate MaxBackends.
     */
    InitializeMaxBackends();

    /*
     * Establish input sockets.
     */
    for (i = 0; i < MAXLISTEN; i++)
        ListenSocket[i] = PGINVALID_SOCKET;

    if (ListenAddresses)
    {
        char       *rawstring;
        List       *elemlist;
        ListCell   *l;
        int         success = 0;

        /* Need a modifiable copy of ListenAddresses */
        rawstring = pstrdup(ListenAddresses);

        /* Parse string into list of hostnames */
        if (!SplitIdentifierString(rawstring, ',', &elemlist))
        {
            /* syntax error in list */
            ereport(FATAL,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("invalid list syntax for \"listen_addresses\"")));
        }

        foreach(l, elemlist)
        {
            char       *curhost = (char *) lfirst(l);

            if (strcmp(curhost, "*") == 0)
                status = StreamServerPort(AF_UNSPEC, NULL,
                                          (unsigned short) PostPortNumber,
                                          NULL,
                                          ListenSocket, MAXLISTEN);
            else
                status = StreamServerPort(AF_UNSPEC, curhost,
                                          (unsigned short) PostPortNumber,
                                          NULL,
                                          ListenSocket, MAXLISTEN);

            if (status == STATUS_OK)
            {
                success++;
                /* record the first successful host addr in lockfile */
                if (!listen_addr_saved)
                {
                    AddToDataDirLockFile(LOCK_FILE_LINE_LISTEN_ADDR, curhost);
                    listen_addr_saved = true;
                }
            }
            else
                ereport(WARNING,
                        (errmsg("could not create listen socket for \"%s\"",
                                curhost)));
        }

        if (!success && elemlist != NIL)
            ereport(FATAL,
                    (errmsg("could not create any TCP/IP sockets")));

        list_free(elemlist);
        pfree(rawstring);
    }

#ifdef USE_BONJOUR
    /* Register for Bonjour only if we opened TCP socket(s) */
    if (enable_bonjour && ListenSocket[0] != PGINVALID_SOCKET)
    {
        DNSServiceErrorType err;

        /*
         * We pass 0 for interface_index, which will result in registering on
         * all "applicable" interfaces.  It's not entirely clear from the
         * DNS-SD docs whether this would be appropriate if we have bound to
         * just a subset of the available network interfaces.
         */
        err = DNSServiceRegister(&bonjour_sdref,
                                 0,
                                 0,
                                 bonjour_name,
                                 "_postgresql._tcp.",
                                 NULL,
                                 NULL,
                                 htons(PostPortNumber),
                                 0,
                                 NULL,
                                 NULL,
                                 NULL);
        if (err != kDNSServiceErr_NoError)
            elog(LOG, "DNSServiceRegister() failed: error code %ld",
                 (long) err);

        /*
         * We don't bother to read the mDNS daemon's reply, and we expect that
         * it will automatically terminate our registration when the socket is
         * closed at postmaster termination.  So there's nothing more to be
         * done here.  However, the bonjour_sdref is kept around so that
         * forked children can close their copies of the socket.
         */
    }
#endif

#ifdef HAVE_UNIX_SOCKETS
    if (Unix_socket_directories)
    {
        char       *rawstring;
        List       *elemlist;
        ListCell   *l;
        int         success = 0;

        /* Need a modifiable copy of Unix_socket_directories */
        rawstring = pstrdup(Unix_socket_directories);

        /* Parse string into list of directories */
        if (!SplitDirectoriesString(rawstring, ',', &elemlist))
        {
            /* syntax error in list */
            ereport(FATAL,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("invalid list syntax for \"unix_socket_directories\"")));
        }

        foreach(l, elemlist)
        {
            char       *socketdir = (char *) lfirst(l);

            status = StreamServerPort(AF_UNIX, NULL,
                                      (unsigned short) PostPortNumber,
                                      socketdir,
                                      ListenSocket, MAXLISTEN);

            if (status == STATUS_OK)
            {
                success++;
                /* record the first successful Unix socket in lockfile */
                if (success == 1)
                    AddToDataDirLockFile(LOCK_FILE_LINE_SOCKET_DIR, socketdir);
            }
            else
                ereport(WARNING,
                        (errmsg("could not create Unix-domain socket in directory \"%s\"",
                                socketdir)));
        }

        if (!success && elemlist != NIL)
            ereport(FATAL,
                    (errmsg("could not create any Unix-domain sockets")));

        list_free_deep(elemlist);
        pfree(rawstring);
    }
#endif

    /*
     * check that we have some socket to listen on
     */
    if (ListenSocket[0] == PGINVALID_SOCKET)
        ereport(FATAL,
                (errmsg("no socket created for listening")));

    /*
     * If no valid TCP ports, write an empty line for listen address,
     * indicating the Unix socket must be used.  Note that this line is not
     * added to the lock file until there is a socket backing it.
     */
    if (!listen_addr_saved)
        AddToDataDirLockFile(LOCK_FILE_LINE_LISTEN_ADDR, "");

    /*
     * Set up shared memory and semaphores.
     */
    reset_shared(PostPortNumber);

    /*
     * Estimate number of openable files.  This must happen after setting up
     * semaphores, because on some platforms semaphores count as open files.
     */
    set_max_safe_fds();

    /*
     * Set reference point for stack-depth checking.
     */
    set_stack_base();

    /*
     * Initialize pipe (or process handle on Windows) that allows children to
     * wake up from sleep on postmaster death.
     */
    InitPostmasterDeathWatchHandle();

#ifdef WIN32

    /*
     * Initialize I/O completion port used to deliver list of dead children.
     */
    win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
    if (win32ChildQueue == NULL)
        ereport(FATAL,
           (errmsg("could not create I/O completion port for child queue")));
#endif

    /*
     * Record postmaster options.  We delay this till now to avoid recording
     * bogus options (eg, NBuffers too high for available memory).
     */
    if (!CreateOptsFile(argc, argv, my_exec_path))
        ExitPostmaster(1);

#ifdef EXEC_BACKEND
    /* Write out nondefault GUC settings for child processes to use */
    write_nondefault_variables(PGC_POSTMASTER);
#endif

    /*
     * Write the external PID file if requested
     */
    if (external_pid_file)
    {
        FILE       *fpidfile = fopen(external_pid_file, "w");

        if (fpidfile)
        {
            fprintf(fpidfile, "%d\n", MyProcPid);
            fclose(fpidfile);

            /* Make PID file world readable */
            if (chmod(external_pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0)
                write_stderr("%s: could not change permissions of external PID file \"%s\": %s\n",
                             progname, external_pid_file, strerror(errno));
        }
        else
            write_stderr("%s: could not write external PID file \"%s\": %s\n",
                         progname, external_pid_file, strerror(errno));

        on_proc_exit(unlink_external_pid_file, 0);
    }

    /*
     * Set up signal handlers for the postmaster process.
     *
     * CAUTION: when changing this list, check for side-effects on the signal
     * handling setup of child processes.  See tcop/postgres.c,
     * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
     * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
     * postmaster/syslogger.c, postmaster/bgworker.c and
     * postmaster/checkpointer.c.
     */
    pqinitmask();
    PG_SETMASK(&BlockSig);

    pqsignal(SIGHUP, SIGHUP_handler);   /* reread config file and have
                                         * children do same */
    pqsignal(SIGINT, pmdie);    /* send SIGTERM and shut down */
    pqsignal(SIGQUIT, pmdie);   /* send SIGQUIT and die */
    pqsignal(SIGTERM, pmdie);   /* wait for children and shut down */
    pqsignal(SIGALRM, SIG_IGN); /* ignored */
    pqsignal(SIGPIPE, SIG_IGN); /* ignored */
    pqsignal(SIGUSR1, sigusr1_handler); /* message from child process */
    pqsignal(SIGUSR2, dummy_handler);   /* unused, reserve for children */
    pqsignal(SIGCHLD, reaper);  /* handle child termination */
    pqsignal(SIGTTIN, SIG_IGN); /* ignored */
    pqsignal(SIGTTOU, SIG_IGN); /* ignored */
    /* ignore SIGXFSZ, so that ulimit violations work like disk full */
#ifdef SIGXFSZ
    pqsignal(SIGXFSZ, SIG_IGN); /* ignored */
#endif

    /*
     * If enabled, start up syslogger collection subprocess
     */
    SysLoggerPID = SysLogger_Start();

    /*
     * Reset whereToSendOutput from DestDebug (its starting state) to
     * DestNone. This stops ereport from sending log messages to stderr unless
     * Log_destination permits.  We don't do this until the postmaster is
     * fully launched, since startup failures may as well be reported to
     * stderr.
     */
    whereToSendOutput = DestNone;

    /*
     * Initialize stats collection subsystem (this does NOT start the
     * collector process!)
     */
    pgstat_init();

    /*
     * Initialize the autovacuum subsystem (again, no process start yet)
     */
    autovac_init();

    /*
     * Load configuration files for client authentication.
     */
    if (!load_hba())
    {
        /*
         * It makes no sense to continue if we fail to load the HBA file,
         * since there is no way to connect to the database in this case.
         */
        ereport(FATAL,
                (errmsg("could not load pg_hba.conf")));
    }
    if (!load_ident())
    {
        /*
         * We can start up without the IDENT file, although it means that you
         * cannot log in using any of the authentication methods that need a
         * user name mapping. load_ident() already logged the details of
         * error to the log.
         */
    }


    /*
     * Remove old temporary files.  At this point there can be no other
     * Postgres processes running in this directory, so this should be safe.
     */
    RemovePgTempFiles();

    /*
     * Remember postmaster startup time
     */
    PgStartTime = GetCurrentTimestamp();
    /* PostmasterRandom wants its own copy */
    gettimeofday(&random_start_time, NULL);

    /*
     * We're ready to rock and roll...
     */
    StartupPID = StartupDataBase();
    Assert(StartupPID != 0);
    pmState = PM_STARTUP;

    /* Some workers may be scheduled to start now */
    StartOneBackgroundWorker();

    status = ServerLoop();

    /*
     * ServerLoop probably shouldn't ever return, but if it does, close down.
     */
    ExitPostmaster(status != STATUS_OK);

    abort();                    /* not reached */
}


Variable Documentation

Definition at line 249 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

char* bonjour_name

Definition at line 256 of file postmaster.c.

Referenced by PostmasterMain().

Definition at line 255 of file postmaster.c.

Referenced by PostmasterMain().

Definition at line 246 of file postmaster.c.

Referenced by parse_hba_line(), PostmasterMain(), and ProcessStartupPacket().

Definition at line 213 of file postmaster.c.

Referenced by PostmasterMain().

Definition at line 252 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

Definition at line 251 of file postmaster.c.

Referenced by BackendInitialize().

Definition at line 547 of file postmaster.c.

Referenced by PostmasterIsAlive(), and WaitLatchOrSocket().

Definition at line 209 of file postmaster.c.

Referenced by CreateLockFile(), PostmasterMain(), and PostmasterStateMachine().

Definition at line 248 of file postmaster.c.

Referenced by BackendInitialize().

const char* progname

Definition at line 35 of file pg_archivecleanup.c.

Referenced by _check_database_version(), _connectDB(), adjust_data_dir(), advice(), AuxiliaryProcessMain(), BackendRun(), BaseBackup(), bootstrap_template1(), check_authmethod_valid(), check_input(), check_locale_encoding(), check_locale_name(), check_need_password(), checkDataDir(), CheckServerVersionForStreaming(), CleanupPriorWALFiles(), close_walfile(), connectDatabase(), ConnectDatabase(), convert_sourcefiles_in(), create_data_directory(), create_xlog_symlink(), CustomizableCleanupPriorWALFiles(), CustomizableInitialize(), do_advice(), do_help(), do_init(), do_kill(), do_promote(), do_reload(), do_restart(), do_start(), do_status(), do_stop(), dolink(), dumpCreateDB(), dumpDatabases(), dumpTablespaces(), eitol(), escape_quotes(), executeCommand(), executeQuery(), existsTimeLineHistoryFile(), exit_nicely(), fatal_error(), file_line_count(), file_size(), find_other_exec_or_die(), FindEndOfXLOG(), FindStreamingStart(), fsync_fname(), GenerateRecoveryConf(), get_encoding_id(), get_id(), get_opts(), get_pgpid(), get_progname(), get_restricted_token(), get_set_pwd(), GetConnection(), handle_args(), HandleCopyStream(), help(), infile(), Initialize(), KillExistingArchiveStatus(), KillExistingXLOG(), load_resultmap(), main(), make_directory(), memcheck(), mkdatadir(), mkdirs(), open_result_files(), open_walfile(), popen_check(), PostgresMain(), PostmasterMain(), pre_sync_fname(), process_postgres_switches(), reached_end_position(), read_post_opts(), ReadControlFile(), readfile(), ReceiveAndUnpackTarFile(), ReceiveTarFile(), ReceiveXlogStream(), regression_main(), RewriteControlFile(), rulesub(), run_schedule(), runPgDump(), sendFeedback(), set_dump_section(), set_mode(), set_null_conf(), set_sig(), setup_bin_paths(), setup_collation(), setup_locale_encoding(), setup_pgdata(), setup_text_search(), SetWALFileNameForCleanup(), spawn_process(), StartLogStreamer(), stop_postmaster(), stop_streaming(), StreamLog(), test_postmaster_connection(), usage(), verify_dir_is_empty_or_create(), vwrite_msg(), walkdir(), write_version_file(), WriteEmptyXLOG(), writefile(), WriteRecoveryConf(), writeTarData(), writeTimeLineHistoryFile(), writezone(), and yearistype().

Definition at line 224 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

Definition at line 257 of file postmaster.c.

Referenced by PostmasterStateMachine().

Definition at line 211 of file postmaster.c.

Referenced by PostmasterMain().

Definition at line 103 of file pqcomm.c.

Definition at line 102 of file pqcomm.c.

Referenced by show_unix_socket_permissions().