@@ -3654,7 +3654,7 @@ get_stats_option_name(const char *arg)
36543654
36553655/* ----------------------------------------------------------------
36563656 * process_postgres_switches
3657- * Parse command line arguments for PostgresMain
3657+ * Parse command line arguments for backends
36583658 *
36593659 * This is called twice, once for the "secure" options coming from the
36603660 * postmaster or command line, and once for the "insecure" options coming
@@ -3915,40 +3915,30 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
39153915}
39163916
39173917
3918- /* ----------------------------------------------------------------
3919- * PostgresMain
3920- * postgres main loop -- all backends, interactive or otherwise start here
3918+ /*
3919+ * PostgresSingleUserMain
3920+ * Entry point for single user mode. argc/argv are the command line
3921+ * arguments to be used.
39213922 *
3922- * argc/argv are the command line arguments to be used. (When being forked
3923- * by the postmaster, these are not the original argv array of the process.)
3924- * dbname is the name of the database to connect to, or NULL if the database
3925- * name should be extracted from the command line arguments or defaulted.
3926- * username is the PostgreSQL user name to be used for the session.
3927- * ----------------------------------------------------------------
3923+ * Performs single user specific setup then calls PostgresMain() to actually
3924+ * process queries. Single user mode specific setup should go here, rather
3925+ * than PostgresMain() or InitPostgres() when reasonably possible.
39283926 */
39293927void
3930- PostgresMain (int argc , char * argv [],
3931- const char * dbname ,
3932- const char * username )
3928+ PostgresSingleUserMain (int argc , char * argv [],
3929+ const char * username )
39333930{
3934- int firstchar ;
3935- StringInfoData input_message ;
3936- sigjmp_buf local_sigjmp_buf ;
3937- volatile bool send_ready_for_query = true;
3938- bool idle_in_transaction_timeout_enabled = false;
3939- bool idle_session_timeout_enabled = false;
3931+ const char * dbname = NULL ;
39403932
3941- /* Initialize startup process environment if necessary. */
3942- if (!IsUnderPostmaster )
3943- InitStandaloneProcess (argv [0 ]);
3933+ Assert (!IsUnderPostmaster );
39443934
3945- SetProcessingMode (InitProcessing );
3935+ /* Initialize startup process environment. */
3936+ InitStandaloneProcess (argv [0 ]);
39463937
39473938 /*
39483939 * Set default values for command-line options.
39493940 */
3950- if (!IsUnderPostmaster )
3951- InitializeGUCOptions ();
3941+ InitializeGUCOptions ();
39523942
39533943 /*
39543944 * Parse command-line options.
@@ -3966,12 +3956,75 @@ PostgresMain(int argc, char *argv[],
39663956 progname )));
39673957 }
39683958
3969- /* Acquire configuration parameters, unless inherited from postmaster */
3970- if (!IsUnderPostmaster )
3971- {
3972- if (!SelectConfigFiles (userDoption , progname ))
3973- proc_exit (1 );
3974- }
3959+ /* Acquire configuration parameters */
3960+ if (!SelectConfigFiles (userDoption , progname ))
3961+ proc_exit (1 );
3962+
3963+ /*
3964+ * Validate we have been given a reasonable-looking DataDir and change
3965+ * into it.
3966+ */
3967+ checkDataDir ();
3968+ ChangeToDataDir ();
3969+
3970+ /*
3971+ * Create lockfile for data directory.
3972+ */
3973+ CreateDataDirLockFile (false);
3974+
3975+ /* read control file (error checking and contains config ) */
3976+ LocalProcessControlFile (false);
3977+
3978+ /* Initialize MaxBackends */
3979+ InitializeMaxBackends ();
3980+
3981+ CreateSharedMemoryAndSemaphores ();
3982+
3983+ /*
3984+ * Remember stand-alone backend startup time,roughly at the same point
3985+ * during startup that postmaster does so.
3986+ */
3987+ PgStartTime = GetCurrentTimestamp ();
3988+
3989+ /*
3990+ * Create a per-backend PGPROC struct in shared memory. We must do this
3991+ * before we can use LWLocks.
3992+ */
3993+ InitProcess ();
3994+
3995+ /*
3996+ * Now that sufficient infrastructure has been initialized, PostgresMain()
3997+ * can do the rest.
3998+ */
3999+ PostgresMain (dbname , username );
4000+ }
4001+
4002+
4003+ /* ----------------------------------------------------------------
4004+ * PostgresMain
4005+ * postgres main loop -- all backends, interactive or otherwise loop here
4006+ *
4007+ * dbname is the name of the database to connect to, username is the
4008+ * PostgreSQL user name to be used for the session.
4009+ *
4010+ * NB: Single user mode specific setup should go to PostgresSingleUserMain()
4011+ * if reasonably possible.
4012+ * ----------------------------------------------------------------
4013+ */
4014+ void
4015+ PostgresMain (const char * dbname , const char * username )
4016+ {
4017+ int firstchar ;
4018+ StringInfoData input_message ;
4019+ sigjmp_buf local_sigjmp_buf ;
4020+ volatile bool send_ready_for_query = true;
4021+ bool idle_in_transaction_timeout_enabled = false;
4022+ bool idle_session_timeout_enabled = false;
4023+
4024+ AssertArg (dbname != NULL );
4025+ AssertArg (username != NULL );
4026+
4027+ SetProcessingMode (InitProcessing );
39754028
39764029 /*
39774030 * Set up signal handlers. (InitPostmasterChild or InitStandaloneProcess
@@ -4029,43 +4082,6 @@ PostgresMain(int argc, char *argv[],
40294082 * platforms */
40304083 }
40314084
4032- if (!IsUnderPostmaster )
4033- {
4034- /*
4035- * Validate we have been given a reasonable-looking DataDir (if under
4036- * postmaster, assume postmaster did this already).
4037- */
4038- checkDataDir ();
4039-
4040- /* Change into DataDir (if under postmaster, was done already) */
4041- ChangeToDataDir ();
4042-
4043- /*
4044- * Create lockfile for data directory.
4045- */
4046- CreateDataDirLockFile (false);
4047-
4048- /* read control file (error checking and contains config ) */
4049- LocalProcessControlFile (false);
4050-
4051- /* Initialize MaxBackends (if under postmaster, was done already) */
4052- InitializeMaxBackends ();
4053-
4054- CreateSharedMemoryAndSemaphores ();
4055-
4056- /*
4057- * Remember stand-alone backend startup time, roughly at the same
4058- * point during startup that postmaster does so.
4059- */
4060- PgStartTime = GetCurrentTimestamp ();
4061-
4062- /*
4063- * Create a per-backend PGPROC struct in shared memory. We must do
4064- * this before we can use LWLocks.
4065- */
4066- InitProcess ();
4067- }
4068-
40694085 /* Early initialization */
40704086 BaseInit ();
40714087
0 commit comments