aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tcop/postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r--src/backend/tcop/postgres.c152
1 files changed, 84 insertions, 68 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index d85e10d9cef..0775abe35de 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3654,7 +3654,7 @@ get_stats_option_name(const char *arg)
/* ----------------------------------------------------------------
* process_postgres_switches
- * Parse command line arguments for PostgresMain
+ * Parse command line arguments for backends
*
* This is called twice, once for the "secure" options coming from the
* postmaster or command line, and once for the "insecure" options coming
@@ -3915,40 +3915,30 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
}
-/* ----------------------------------------------------------------
- * PostgresMain
- * postgres main loop -- all backends, interactive or otherwise start here
+/*
+ * PostgresSingleUserMain
+ * Entry point for single user mode. argc/argv are the command line
+ * arguments to be used.
*
- * argc/argv are the command line arguments to be used. (When being forked
- * by the postmaster, these are not the original argv array of the process.)
- * dbname is the name of the database to connect to, or NULL if the database
- * name should be extracted from the command line arguments or defaulted.
- * username is the PostgreSQL user name to be used for the session.
- * ----------------------------------------------------------------
+ * Performs single user specific setup then calls PostgresMain() to actually
+ * process queries. Single user mode specific setup should go here, rather
+ * than PostgresMain() or InitPostgres() when reasonably possible.
*/
void
-PostgresMain(int argc, char *argv[],
- const char *dbname,
- const char *username)
+PostgresSingleUserMain(int argc, char *argv[],
+ const char *username)
{
- int firstchar;
- StringInfoData input_message;
- sigjmp_buf local_sigjmp_buf;
- volatile bool send_ready_for_query = true;
- bool idle_in_transaction_timeout_enabled = false;
- bool idle_session_timeout_enabled = false;
+ const char *dbname = NULL;
- /* Initialize startup process environment if necessary. */
- if (!IsUnderPostmaster)
- InitStandaloneProcess(argv[0]);
+ Assert(!IsUnderPostmaster);
- SetProcessingMode(InitProcessing);
+ /* Initialize startup process environment. */
+ InitStandaloneProcess(argv[0]);
/*
* Set default values for command-line options.
*/
- if (!IsUnderPostmaster)
- InitializeGUCOptions();
+ InitializeGUCOptions();
/*
* Parse command-line options.
@@ -3966,12 +3956,75 @@ PostgresMain(int argc, char *argv[],
progname)));
}
- /* Acquire configuration parameters, unless inherited from postmaster */
- if (!IsUnderPostmaster)
- {
- if (!SelectConfigFiles(userDoption, progname))
- proc_exit(1);
- }
+ /* Acquire configuration parameters */
+ if (!SelectConfigFiles(userDoption, progname))
+ proc_exit(1);
+
+ /*
+ * Validate we have been given a reasonable-looking DataDir and change
+ * into it.
+ */
+ checkDataDir();
+ ChangeToDataDir();
+
+ /*
+ * Create lockfile for data directory.
+ */
+ CreateDataDirLockFile(false);
+
+ /* read control file (error checking and contains config ) */
+ LocalProcessControlFile(false);
+
+ /* Initialize MaxBackends */
+ InitializeMaxBackends();
+
+ CreateSharedMemoryAndSemaphores();
+
+ /*
+ * Remember stand-alone backend startup time,roughly at the same point
+ * during startup that postmaster does so.
+ */
+ PgStartTime = GetCurrentTimestamp();
+
+ /*
+ * Create a per-backend PGPROC struct in shared memory. We must do this
+ * before we can use LWLocks.
+ */
+ InitProcess();
+
+ /*
+ * Now that sufficient infrastructure has been initialized, PostgresMain()
+ * can do the rest.
+ */
+ PostgresMain(dbname, username);
+}
+
+
+/* ----------------------------------------------------------------
+ * PostgresMain
+ * postgres main loop -- all backends, interactive or otherwise loop here
+ *
+ * dbname is the name of the database to connect to, username is the
+ * PostgreSQL user name to be used for the session.
+ *
+ * NB: Single user mode specific setup should go to PostgresSingleUserMain()
+ * if reasonably possible.
+ * ----------------------------------------------------------------
+ */
+void
+PostgresMain(const char *dbname, const char *username)
+{
+ int firstchar;
+ StringInfoData input_message;
+ sigjmp_buf local_sigjmp_buf;
+ volatile bool send_ready_for_query = true;
+ bool idle_in_transaction_timeout_enabled = false;
+ bool idle_session_timeout_enabled = false;
+
+ AssertArg(dbname != NULL);
+ AssertArg(username != NULL);
+
+ SetProcessingMode(InitProcessing);
/*
* Set up signal handlers. (InitPostmasterChild or InitStandaloneProcess
@@ -4029,43 +4082,6 @@ PostgresMain(int argc, char *argv[],
* platforms */
}
- if (!IsUnderPostmaster)
- {
- /*
- * Validate we have been given a reasonable-looking DataDir (if under
- * postmaster, assume postmaster did this already).
- */
- checkDataDir();
-
- /* Change into DataDir (if under postmaster, was done already) */
- ChangeToDataDir();
-
- /*
- * Create lockfile for data directory.
- */
- CreateDataDirLockFile(false);
-
- /* read control file (error checking and contains config ) */
- LocalProcessControlFile(false);
-
- /* Initialize MaxBackends (if under postmaster, was done already) */
- InitializeMaxBackends();
-
- CreateSharedMemoryAndSemaphores();
-
- /*
- * Remember stand-alone backend startup time, roughly at the same
- * point during startup that postmaster does so.
- */
- PgStartTime = GetCurrentTimestamp();
-
- /*
- * Create a per-backend PGPROC struct in shared memory. We must do
- * this before we can use LWLocks.
- */
- InitProcess();
- }
-
/* Early initialization */
BaseInit();