PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
initdb.c File Reference
#include "postgres_fe.h"
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include "catalog/catalog.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_class.h"
#include "catalog/pg_collation.h"
#include "common/file_utils.h"
#include "common/restricted_token.h"
#include "common/username.h"
#include "fe_utils/string_utils.h"
#include "getaddrinfo.h"
#include "getopt_long.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
Include dependency graph for initdb.c:

Go to the source code of this file.

Data Structures

struct  tsearch_config_match
 

Macros

#define AUTHTRUST_WARNING
 
#define PG_CMD_DECL   char cmd[MAXPGPATH]; FILE *cmdfd
 
#define PG_CMD_OPEN
 
#define PG_CMD_CLOSE
 
#define PG_CMD_PUTS(line)
 
#define PG_CMD_PRINTF1(fmt, arg1)
 
#define PG_CMD_PRINTF2(fmt, arg1, arg2)
 
#define PG_CMD_PRINTF3(fmt, arg1, arg2, arg3)
 
#define MIN_BUFS_FOR_CONNS(nconns)   ((nconns) * 10)
 

Functions

const char * select_default_timezone (const char *share_path)
 
static char ** replace_token (char **lines, const char *token, const char *replacement)
 
static char ** filter_lines_with_token (char **lines, const char *token)
 
static char ** readfile (const char *path)
 
static void writefile (char *path, char **lines)
 
static FILE * popen_check (const char *command, const char *mode)
 
static void exit_nicely (void)
 
static char * get_id (void)
 
static char * get_encoding_id (char *encoding_name)
 
static void set_input (char **dest, char *filename)
 
static void check_input (char *path)
 
static void write_version_file (char *extrapath)
 
static void set_null_conf (void)
 
static void test_config_settings (void)
 
static void setup_config (void)
 
static void bootstrap_template1 (void)
 
static void setup_auth (FILE *cmdfd)
 
static void get_su_pwd (void)
 
static void setup_depend (FILE *cmdfd)
 
static void setup_sysviews (FILE *cmdfd)
 
static void setup_description (FILE *cmdfd)
 
static void setup_collation (FILE *cmdfd)
 
static void setup_conversion (FILE *cmdfd)
 
static void setup_dictionary (FILE *cmdfd)
 
static void setup_privileges (FILE *cmdfd)
 
static void set_info_version (void)
 
static void setup_schema (FILE *cmdfd)
 
static void load_plpgsql (FILE *cmdfd)
 
static void vacuum_db (FILE *cmdfd)
 
static void make_template0 (FILE *cmdfd)
 
static void make_postgres (FILE *cmdfd)
 
static void trapsig (int signum)
 
static void check_ok (void)
 
static char * escape_quotes (const char *src)
 
static int locale_date_order (const char *locale)
 
static void check_locale_name (int category, const char *locale, char **canonname)
 
static bool check_locale_encoding (const char *locale, int encoding)
 
static void setlocales (void)
 
static void usage (const char *progname)
 
void setup_pgdata (void)
 
void setup_bin_paths (const char *argv0)
 
void setup_data_file_paths (void)
 
void setup_locale_encoding (void)
 
void setup_signals (void)
 
void setup_text_search (void)
 
void create_data_directory (void)
 
void create_xlog_or_symlink (void)
 
void warn_on_mount_point (int error)
 
void initialize_data_directory (void)
 
static char * encodingid_to_string (int enc)
 
static const char * find_matching_ts_config (const char *lc_type)
 
static char * choose_dsm_implementation (void)
 
static size_t my_strftime (char *s, size_t max, const char *fmt, const struct tm *tm)
 
static void check_authmethod_unspecified (const char **authmethod)
 
static void check_authmethod_valid (const char *authmethod, const char *const *valid_methods, const char *conntype)
 
static void check_need_password (const char *authmethodlocal, const char *authmethodhost)
 
int main (int argc, char *argv[])
 

Variables

static const char *const auth_methods_host []
 
static const char *const auth_methods_local []
 
static char * share_path = NULL
 
static char * pg_data = ""
 
static char * encoding = ""
 
static char * locale = ""
 
static char * lc_collate = ""
 
static char * lc_ctype = ""
 
static char * lc_monetary = ""
 
static char * lc_numeric = ""
 
static char * lc_time = ""
 
static char * lc_messages = ""
 
static const char * default_text_search_config = ""
 
static char * username = ""
 
static bool pwprompt = false
 
static char * pwfilename = NULL
 
static char * superuser_password = NULL
 
static const char * authmethodhost = ""
 
static const char * authmethodlocal = ""
 
static bool debug = false
 
static bool noclean = false
 
static bool do_sync = true
 
static bool sync_only = false
 
static bool show_setting = false
 
static bool data_checksums = false
 
static char * xlog_dir = ""
 
static const char * progname
 
static char * encodingid = "0"
 
static char * bki_file
 
static char * desc_file
 
static char * shdesc_file
 
static char * hba_file
 
static char * ident_file
 
static char * conf_file
 
static char * conversion_file
 
static char * dictionary_file
 
static char * info_schema_file
 
static char * features_file
 
static char * system_views_file
 
static bool made_new_pgdata = false
 
static bool found_existing_pgdata = false
 
static bool made_new_xlogdir = false
 
static bool found_existing_xlogdir = false
 
static char infoversion [100]
 
static bool caught_signal = false
 
static bool output_failed = false
 
static int output_errno = 0
 
static char * pgdata_native
 
static int n_connections = 10
 
static int n_buffers = 50
 
static char * dynamic_shared_memory_type = NULL
 
static char * authwarning = NULL
 
static const char * boot_options = "-F"
 
static const char * backend_options = "--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true"
 
static const char *const subdirs []
 
static char bin_path [MAXPGPATH]
 
static char backend_exec [MAXPGPATH]
 
static const struct
tsearch_config_match 
tsearch_config_languages []
 

Macro Definition Documentation

#define AUTHTRUST_WARNING
Value:
"# CAUTION: Configuring the system for local \"trust\" authentication\n" \
"# allows any local user to connect as any PostgreSQL user, including\n" \
"# the database superuser. If you do not trust all your local users,\n" \
"# use another authentication method.\n"

Definition at line 178 of file initdb.c.

Referenced by setup_config().

#define MIN_BUFS_FOR_CONNS (   nconns)    ((nconns) * 10)

Referenced by test_config_settings().

#define PG_CMD_CLOSE
Value:
do { \
if (pclose_check(cmdfd)) \
exit_nicely(); /* message already printed by pclose_check */ \
} while (0)
static void exit_nicely(void)
Definition: initdb.c:542
int pclose_check(FILE *stream)
Definition: exec.c:510

Definition at line 294 of file initdb.c.

Referenced by bootstrap_template1(), and initialize_data_directory().

#define PG_CMD_DECL   char cmd[MAXPGPATH]; FILE *cmdfd

Definition at line 285 of file initdb.c.

Referenced by bootstrap_template1(), and initialize_data_directory().

#define PG_CMD_OPEN
Value:
do { \
cmdfd = popen_check(cmd, "w"); \
if (cmdfd == NULL) \
exit_nicely(); /* message already printed by popen_check */ \
} while (0)
static FILE * popen_check(const char *command, const char *mode)
Definition: initdb.c:523
static void exit_nicely(void)
Definition: initdb.c:542
#define NULL
Definition: c.h:229

Definition at line 287 of file initdb.c.

Referenced by bootstrap_template1(), and initialize_data_directory().

#define PG_CMD_PRINTF1 (   fmt,
  arg1 
)
Value:
do { \
if (fprintf(cmdfd, fmt, arg1) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)
static bool output_failed
Definition: initdb.c:166
static int output_errno
Definition: initdb.c:167

Definition at line 306 of file initdb.c.

Referenced by setup_description(), and setup_schema().

#define PG_CMD_PRINTF2 (   fmt,
  arg1,
  arg2 
)
Value:
do { \
if (fprintf(cmdfd, fmt, arg1, arg2) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)
static bool output_failed
Definition: initdb.c:166
static int output_errno
Definition: initdb.c:167

Definition at line 312 of file initdb.c.

Referenced by setup_auth().

#define PG_CMD_PRINTF3 (   fmt,
  arg1,
  arg2,
  arg3 
)
Value:
do { \
if (fprintf(cmdfd, fmt, arg1, arg2, arg3) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)
static bool output_failed
Definition: initdb.c:166
static int output_errno
Definition: initdb.c:167

Definition at line 318 of file initdb.c.

Referenced by setup_collation().

#define PG_CMD_PUTS (   line)
Value:
do { \
if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)
static bool output_failed
Definition: initdb.c:166
static int output_errno
Definition: initdb.c:167

Definition at line 300 of file initdb.c.

Referenced by bootstrap_template1(), load_plpgsql(), make_postgres(), make_template0(), setup_auth(), setup_collation(), setup_conversion(), setup_depend(), setup_description(), setup_dictionary(), setup_privileges(), setup_schema(), setup_sysviews(), and vacuum_db().

Function Documentation

static void bootstrap_template1 ( void  )
static

Definition at line 1284 of file initdb.c.

References _, backend_exec, bki_file, boot_options, buf, check_ok(), data_checksums, debug, encodingid, escape_quotes(), exit_nicely(), free, lc_collate, lc_ctype, MAXPGPATH, NAMEDATALEN, NULL, PG_CMD_CLOSE, PG_CMD_DECL, PG_CMD_OPEN, PG_CMD_PUTS, pg_strdup(), progname, putenv, readfile(), replace_token(), snprintf(), unsetenv, and username.

Referenced by initialize_data_directory().

1285 {
1286  PG_CMD_DECL;
1287  char **line;
1288  char *talkargs = "";
1289  char **bki_lines;
1290  char headerline[MAXPGPATH];
1291  char buf[64];
1292 
1293  printf(_("running bootstrap script ... "));
1294  fflush(stdout);
1295 
1296  if (debug)
1297  talkargs = "-d 5";
1298 
1299  bki_lines = readfile(bki_file);
1300 
1301  /* Check that bki file appears to be of the right version */
1302 
1303  snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
1304  PG_MAJORVERSION);
1305 
1306  if (strcmp(headerline, *bki_lines) != 0)
1307  {
1308  fprintf(stderr,
1309  _("%s: input file \"%s\" does not belong to PostgreSQL %s\n"
1310  "Check your installation or specify the correct path "
1311  "using the option -L.\n"),
1312  progname, bki_file, PG_VERSION);
1313  exit_nicely();
1314  }
1315 
1316  /* Substitute for various symbols used in the BKI file */
1317 
1318  sprintf(buf, "%d", NAMEDATALEN);
1319  bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
1320 
1321  sprintf(buf, "%d", (int) sizeof(Pointer));
1322  bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
1323 
1324  bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
1325  (sizeof(Pointer) == 4) ? "i" : "d");
1326 
1327  bki_lines = replace_token(bki_lines, "FLOAT4PASSBYVAL",
1328  FLOAT4PASSBYVAL ? "true" : "false");
1329 
1330  bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
1331  FLOAT8PASSBYVAL ? "true" : "false");
1332 
1333  bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username));
1334 
1335  bki_lines = replace_token(bki_lines, "ENCODING", encodingid);
1336 
1337  bki_lines = replace_token(bki_lines, "LC_COLLATE", escape_quotes(lc_collate));
1338 
1339  bki_lines = replace_token(bki_lines, "LC_CTYPE", escape_quotes(lc_ctype));
1340 
1341  /*
1342  * Pass correct LC_xxx environment to bootstrap.
1343  *
1344  * The shell script arranged to restore the LC settings afterwards, but
1345  * there doesn't seem to be any compelling reason to do that.
1346  */
1347  snprintf(cmd, sizeof(cmd), "LC_COLLATE=%s", lc_collate);
1348  putenv(pg_strdup(cmd));
1349 
1350  snprintf(cmd, sizeof(cmd), "LC_CTYPE=%s", lc_ctype);
1351  putenv(pg_strdup(cmd));
1352 
1353  unsetenv("LC_ALL");
1354 
1355  /* Also ensure backend isn't confused by this environment var: */
1356  unsetenv("PGCLIENTENCODING");
1357 
1358  snprintf(cmd, sizeof(cmd),
1359  "\"%s\" --boot -x1 %s %s %s",
1360  backend_exec,
1361  data_checksums ? "-k" : "",
1362  boot_options, talkargs);
1363 
1364  PG_CMD_OPEN;
1365 
1366  for (line = bki_lines; *line != NULL; line++)
1367  {
1368  PG_CMD_PUTS(*line);
1369  free(*line);
1370  }
1371 
1372  PG_CMD_CLOSE;
1373 
1374  free(bki_lines);
1375 
1376  check_ok();
1377 }
static char ** replace_token(char **lines, const char *token, const char *replacement)
Definition: initdb.c:345
static bool debug
Definition: initdb.c:137
static char * lc_collate
Definition: initdb.c:124
static void exit_nicely(void)
Definition: initdb.c:542
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define putenv(x)
Definition: win32.h:411
static char * encodingid
Definition: initdb.c:148
#define NAMEDATALEN
char * Pointer
Definition: c.h:245
#define PG_CMD_DECL
Definition: initdb.c:285
#define MAXPGPATH
static char * lc_ctype
Definition: initdb.c:125
#define PG_CMD_OPEN
Definition: initdb.c:287
static char * buf
Definition: pg_test_fsync.c:66
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void check_ok(void)
Definition: initdb.c:2008
static const char * progname
Definition: initdb.c:147
#define PG_CMD_CLOSE
Definition: initdb.c:294
static const char * boot_options
Definition: initdb.c:195
static bool data_checksums
Definition: initdb.c:142
static char * username
Definition: initdb.c:131
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define unsetenv(x)
Definition: win32.h:412
static char * escape_quotes(const char *src)
Definition: initdb.c:325
static char backend_exec[MAXPGPATH]
Definition: initdb.c:226
static char ** readfile(const char *path)
Definition: initdb.c:428
static char * bki_file
Definition: initdb.c:149
#define _(x)
Definition: elog.c:84
static void check_authmethod_unspecified ( const char **  authmethod)
static

Definition at line 2296 of file initdb.c.

References _, authwarning, and NULL.

Referenced by main().

2297 {
2298  if (*authmethod == NULL || strlen(*authmethod) == 0)
2299  {
2300  authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections\n"
2301  "You can change this by editing pg_hba.conf or using the option -A, or\n"
2302  "--auth-local and --auth-host, the next time you run initdb.\n");
2303  *authmethod = "trust";
2304  }
2305 }
static char * authwarning
Definition: initdb.c:183
#define NULL
Definition: c.h:229
#define _(x)
Definition: elog.c:84
static void check_authmethod_valid ( const char *  authmethod,
const char *const *  valid_methods,
const char *  conntype 
)
static

Definition at line 2308 of file initdb.c.

References _, and progname.

Referenced by main().

2309 {
2310  const char *const * p;
2311 
2312  for (p = valid_methods; *p; p++)
2313  {
2314  if (strcmp(authmethod, *p) == 0)
2315  return;
2316  /* with space = param */
2317  if (strchr(authmethod, ' '))
2318  if (strncmp(authmethod, *p, (authmethod - strchr(authmethod, ' '))) == 0)
2319  return;
2320  }
2321 
2322  fprintf(stderr, _("%s: invalid authentication method \"%s\" for \"%s\" connections\n"),
2323  progname, authmethod, conntype);
2324  exit(1);
2325 }
static const char * progname
Definition: initdb.c:147
#define _(x)
Definition: elog.c:84
static void check_input ( char *  path)
static

Definition at line 760 of file initdb.c.

References _, progname, and strerror().

Referenced by setup_data_file_paths().

761 {
762  struct stat statbuf;
763 
764  if (stat(path, &statbuf) != 0)
765  {
766  if (errno == ENOENT)
767  {
768  fprintf(stderr,
769  _("%s: file \"%s\" does not exist\n"), progname, path);
770  fprintf(stderr,
771  _("This might mean you have a corrupted installation or identified\n"
772  "the wrong directory with the invocation option -L.\n"));
773  }
774  else
775  {
776  fprintf(stderr,
777  _("%s: could not access file \"%s\": %s\n"), progname, path,
778  strerror(errno));
779  fprintf(stderr,
780  _("This might mean you have a corrupted installation or identified\n"
781  "the wrong directory with the invocation option -L.\n"));
782  }
783  exit(1);
784  }
785  if (!S_ISREG(statbuf.st_mode))
786  {
787  fprintf(stderr,
788  _("%s: file \"%s\" is not a regular file\n"), progname, path);
789  fprintf(stderr,
790  _("This might mean you have a corrupted installation or identified\n"
791  "the wrong directory with the invocation option -L.\n"));
792  exit(1);
793  }
794 }
static const char * progname
Definition: initdb.c:147
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static bool check_locale_encoding ( const char *  locale,
int  encoding 
)
static

Definition at line 2169 of file initdb.c.

References _, pg_encoding_to_char(), pg_get_encoding_from_locale(), PG_SQL_ASCII, PG_UTF8, and progname.

Referenced by setup_locale_encoding().

2170 {
2171  int locale_enc;
2172 
2173  locale_enc = pg_get_encoding_from_locale(locale, true);
2174 
2175  /* See notes in createdb() to understand these tests */
2176  if (!(locale_enc == user_enc ||
2177  locale_enc == PG_SQL_ASCII ||
2178  locale_enc == -1 ||
2179 #ifdef WIN32
2180  user_enc == PG_UTF8 ||
2181 #endif
2182  user_enc == PG_SQL_ASCII))
2183  {
2184  fprintf(stderr, _("%s: encoding mismatch\n"), progname);
2185  fprintf(stderr,
2186  _("The encoding you selected (%s) and the encoding that the\n"
2187  "selected locale uses (%s) do not match. This would lead to\n"
2188  "misbehavior in various character string processing functions.\n"
2189  "Rerun %s and either do not specify an encoding explicitly,\n"
2190  "or choose a matching combination.\n"),
2191  pg_encoding_to_char(user_enc),
2192  pg_encoding_to_char(locale_enc),
2193  progname);
2194  return false;
2195  }
2196  return true;
2197 }
static const char * progname
Definition: initdb.c:147
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:433
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
static char * locale
Definition: initdb.c:123
#define _(x)
Definition: elog.c:84
static void check_locale_name ( int  category,
const char *  locale,
char **  canonname 
)
static

Definition at line 2105 of file initdb.c.

References _, free, NULL, pg_strdup(), and progname.

Referenced by setlocales().

2106 {
2107  char *save;
2108  char *res;
2109 
2110  if (canonname)
2111  *canonname = NULL; /* in case of failure */
2112 
2113  save = setlocale(category, NULL);
2114  if (!save)
2115  {
2116  fprintf(stderr, _("%s: setlocale() failed\n"),
2117  progname);
2118  exit(1);
2119  }
2120 
2121  /* save may be pointing at a modifiable scratch variable, so copy it. */
2122  save = pg_strdup(save);
2123 
2124  /* set the locale with setlocale, to see if it accepts it. */
2125  res = setlocale(category, locale);
2126 
2127  /* save canonical name if requested. */
2128  if (res && canonname)
2129  *canonname = pg_strdup(res);
2130 
2131  /* restore old value. */
2132  if (!setlocale(category, save))
2133  {
2134  fprintf(stderr, _("%s: failed to restore old locale \"%s\"\n"),
2135  progname, save);
2136  exit(1);
2137  }
2138  free(save);
2139 
2140  /* complain if locale wasn't valid */
2141  if (res == NULL)
2142  {
2143  if (*locale)
2144  fprintf(stderr, _("%s: invalid locale name \"%s\"\n"),
2145  progname, locale);
2146  else
2147  {
2148  /*
2149  * If no relevant switch was given on command line, locale is an
2150  * empty string, which is not too helpful to report. Presumably
2151  * setlocale() found something it did not like in the environment.
2152  * Ideally we'd report the bad environment variable, but since
2153  * setlocale's behavior is implementation-specific, it's hard to
2154  * be sure what it didn't like. Print a safe generic message.
2155  */
2156  fprintf(stderr, _("%s: invalid locale settings; check LANG and LC_* environment variables\n"),
2157  progname);
2158  }
2159  exit(1);
2160  }
2161 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static const char * progname
Definition: initdb.c:147
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char * locale
Definition: initdb.c:123
#define _(x)
Definition: elog.c:84
static void check_need_password ( const char *  authmethodlocal,
const char *  authmethodhost 
)
static

Definition at line 2328 of file initdb.c.

References _, progname, pwfilename, and pwprompt.

Referenced by main().

2329 {
2330  if ((strcmp(authmethodlocal, "md5") == 0 ||
2331  strcmp(authmethodlocal, "password") == 0 ||
2332  strcmp(authmethodlocal, "scram-sha-256") == 0) &&
2333  (strcmp(authmethodhost, "md5") == 0 ||
2334  strcmp(authmethodhost, "password") == 0 ||
2335  strcmp(authmethodhost, "scram-sha-256") == 0) &&
2336  !(pwprompt || pwfilename))
2337  {
2338  fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"), progname,
2339  (strcmp(authmethodlocal, "md5") == 0 ||
2340  strcmp(authmethodlocal, "password") == 0 ||
2341  strcmp(authmethodlocal, "scram-sha-256") == 0)
2342  ? authmethodlocal
2343  : authmethodhost);
2344  exit(1);
2345  }
2346 }
static bool pwprompt
Definition: initdb.c:132
static const char * authmethodlocal
Definition: initdb.c:136
static char * pwfilename
Definition: initdb.c:133
static const char * progname
Definition: initdb.c:147
static const char * authmethodhost
Definition: initdb.c:135
#define _(x)
Definition: elog.c:84
static void check_ok ( void  )
static

Definition at line 2008 of file initdb.c.

References _, caught_signal, exit_nicely(), output_errno, output_failed, and strerror().

Referenced by adjust_data_dir(), bootstrap_template1(), check_cluster_versions(), check_for_isn_and_int8_passing_mismatch(), check_for_jsonb_9_4_usage(), check_for_pg_role_prefix(), check_for_prepared_transactions(), check_for_reg_data_type_usage(), check_is_install_user(), check_loadable_libraries(), check_proper_datallowconn(), copy_subdir_files(), copy_xact_xlog_xid(), create_data_directory(), create_new_objects(), create_script_for_cluster_analyze(), create_script_for_old_cluster_deletion(), create_xlog_or_symlink(), disable_old_cluster(), generate_old_dump(), initialize_data_directory(), main(), new_9_0_populate_pg_largeobject_metadata(), old_9_3_check_for_line_data_type_usage(), old_9_6_check_for_unknown_data_type_usage(), prepare_new_cluster(), prepare_new_databases(), remove_new_subdir(), set_frozenxids(), setup_config(), and transfer_all_new_tablespaces().

2009 {
2010  if (caught_signal)
2011  {
2012  printf(_("caught signal\n"));
2013  fflush(stdout);
2014  exit_nicely();
2015  }
2016  else if (output_failed)
2017  {
2018  printf(_("could not write to child process: %s\n"),
2020  fflush(stdout);
2021  exit_nicely();
2022  }
2023  else
2024  {
2025  /* all seems well */
2026  printf(_("ok\n"));
2027  fflush(stdout);
2028  }
2029 }
static bool caught_signal
Definition: initdb.c:165
static void exit_nicely(void)
Definition: initdb.c:542
static bool output_failed
Definition: initdb.c:166
static int output_errno
Definition: initdb.c:167
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static char* choose_dsm_implementation ( void  )
static

Definition at line 866 of file initdb.c.

References close, fd(), name, random(), and snprintf().

Referenced by test_config_settings().

867 {
868 #ifdef HAVE_SHM_OPEN
869  int ntries = 10;
870 
871  while (ntries > 0)
872  {
873  uint32 handle;
874  char name[64];
875  int fd;
876 
877  handle = random();
878  snprintf(name, 64, "/PostgreSQL.%u", handle);
879  if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
880  {
881  close(fd);
882  shm_unlink(name);
883  return "posix";
884  }
885  if (errno != EEXIST)
886  break;
887  --ntries;
888  }
889 #endif
890 
891 #ifdef WIN32
892  return "windows";
893 #else
894  return "sysv";
895 #endif
896 }
long random(void)
Definition: random.c:22
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static int fd(const char *x, int i)
Definition: preproc-init.c:105
unsigned int uint32
Definition: c.h:268
const char * name
Definition: encode.c:521
#define close(a)
Definition: win32.h:12
void create_data_directory ( void  )

Definition at line 2639 of file initdb.c.

References _, check_ok(), exit_nicely(), found_existing_pgdata, made_new_pgdata, pg_check_dir(), pg_data, pg_mkdir_p(), progname, strerror(), and warn_on_mount_point().

Referenced by initialize_data_directory().

2640 {
2641  int ret;
2642 
2643  switch ((ret = pg_check_dir(pg_data)))
2644  {
2645  case 0:
2646  /* PGDATA not there, must create it */
2647  printf(_("creating directory %s ... "),
2648  pg_data);
2649  fflush(stdout);
2650 
2651  if (pg_mkdir_p(pg_data, S_IRWXU) != 0)
2652  {
2653  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2654  progname, pg_data, strerror(errno));
2655  exit_nicely();
2656  }
2657  else
2658  check_ok();
2659 
2660  made_new_pgdata = true;
2661  break;
2662 
2663  case 1:
2664  /* Present but empty, fix permissions and use it */
2665  printf(_("fixing permissions on existing directory %s ... "),
2666  pg_data);
2667  fflush(stdout);
2668 
2669  if (chmod(pg_data, S_IRWXU) != 0)
2670  {
2671  fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
2672  progname, pg_data, strerror(errno));
2673  exit_nicely();
2674  }
2675  else
2676  check_ok();
2677 
2678  found_existing_pgdata = true;
2679  break;
2680 
2681  case 2:
2682  case 3:
2683  case 4:
2684  /* Present and not empty */
2685  fprintf(stderr,
2686  _("%s: directory \"%s\" exists but is not empty\n"),
2687  progname, pg_data);
2688  if (ret != 4)
2689  warn_on_mount_point(ret);
2690  else
2691  fprintf(stderr,
2692  _("If you want to create a new database system, either remove or empty\n"
2693  "the directory \"%s\" or run %s\n"
2694  "with an argument other than \"%s\".\n"),
2696  exit(1); /* no further message needed */
2697 
2698  default:
2699  /* Trouble accessing directory */
2700  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
2701  progname, pg_data, strerror(errno));
2702  exit_nicely();
2703  }
2704 }
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
void warn_on_mount_point(int error)
Definition: initdb.c:2818
static void exit_nicely(void)
Definition: initdb.c:542
static bool found_existing_pgdata
Definition: initdb.c:161
static char * pg_data
Definition: initdb.c:121
static void check_ok(void)
Definition: initdb.c:2008
static bool made_new_pgdata
Definition: initdb.c:160
static const char * progname
Definition: initdb.c:147
int pg_check_dir(const char *dir)
Definition: pgcheckdir.c:31
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
void create_xlog_or_symlink ( void  )

Definition at line 2709 of file initdb.c.

References _, canonicalize_path(), check_ok(), exit_nicely(), found_existing_xlogdir, free, is_absolute_path, made_new_xlogdir, mkdir, pg_check_dir(), pg_data, pg_mkdir_p(), progname, psprintf(), strerror(), warn_on_mount_point(), and xlog_dir.

Referenced by initialize_data_directory().

2710 {
2711  char *subdirloc;
2712 
2713  /* form name of the place for the subdirectory or symlink */
2714  subdirloc = psprintf("%s/pg_wal", pg_data);
2715 
2716  if (strcmp(xlog_dir, "") != 0)
2717  {
2718  int ret;
2719 
2720  /* clean up xlog directory name, check it's absolute */
2722  if (!is_absolute_path(xlog_dir))
2723  {
2724  fprintf(stderr, _("%s: transaction log directory location must be an absolute path\n"), progname);
2725  exit_nicely();
2726  }
2727 
2728  /* check if the specified xlog directory exists/is empty */
2729  switch ((ret = pg_check_dir(xlog_dir)))
2730  {
2731  case 0:
2732  /* xlog directory not there, must create it */
2733  printf(_("creating directory %s ... "),
2734  xlog_dir);
2735  fflush(stdout);
2736 
2737  if (pg_mkdir_p(xlog_dir, S_IRWXU) != 0)
2738  {
2739  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2740  progname, xlog_dir, strerror(errno));
2741  exit_nicely();
2742  }
2743  else
2744  check_ok();
2745 
2746  made_new_xlogdir = true;
2747  break;
2748 
2749  case 1:
2750  /* Present but empty, fix permissions and use it */
2751  printf(_("fixing permissions on existing directory %s ... "),
2752  xlog_dir);
2753  fflush(stdout);
2754 
2755  if (chmod(xlog_dir, S_IRWXU) != 0)
2756  {
2757  fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
2758  progname, xlog_dir, strerror(errno));
2759  exit_nicely();
2760  }
2761  else
2762  check_ok();
2763 
2764  found_existing_xlogdir = true;
2765  break;
2766 
2767  case 2:
2768  case 3:
2769  case 4:
2770  /* Present and not empty */
2771  fprintf(stderr,
2772  _("%s: directory \"%s\" exists but is not empty\n"),
2773  progname, xlog_dir);
2774  if (ret != 4)
2775  warn_on_mount_point(ret);
2776  else
2777  fprintf(stderr,
2778  _("If you want to store the transaction log there, either\n"
2779  "remove or empty the directory \"%s\".\n"),
2780  xlog_dir);
2781  exit_nicely();
2782 
2783  default:
2784  /* Trouble accessing directory */
2785  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
2786  progname, xlog_dir, strerror(errno));
2787  exit_nicely();
2788  }
2789 
2790 #ifdef HAVE_SYMLINK
2791  if (symlink(xlog_dir, subdirloc) != 0)
2792  {
2793  fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
2794  progname, subdirloc, strerror(errno));
2795  exit_nicely();
2796  }
2797 #else
2798  fprintf(stderr, _("%s: symlinks are not supported on this platform"));
2799  exit_nicely();
2800 #endif
2801  }
2802  else
2803  {
2804  /* Without -X option, just make the subdirectory normally */
2805  if (mkdir(subdirloc, S_IRWXU) < 0)
2806  {
2807  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2808  progname, subdirloc, strerror(errno));
2809  exit_nicely();
2810  }
2811  }
2812 
2813  free(subdirloc);
2814 }
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
void warn_on_mount_point(int error)
Definition: initdb.c:2818
#define mkdir(a, b)
Definition: win32.h:57
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static bool made_new_xlogdir
Definition: initdb.c:162
void canonicalize_path(char *path)
Definition: path.c:254
static void exit_nicely(void)
Definition: initdb.c:542
#define is_absolute_path(filename)
Definition: port.h:77
static char * pg_data
Definition: initdb.c:121
static void check_ok(void)
Definition: initdb.c:2008
static bool found_existing_xlogdir
Definition: initdb.c:163
static const char * progname
Definition: initdb.c:147
static char * xlog_dir
Definition: initdb.c:143
#define free(a)
Definition: header.h:65
int pg_check_dir(const char *dir)
Definition: pgcheckdir.c:31
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static char* encodingid_to_string ( int  enc)
static

Definition at line 628 of file initdb.c.

References pg_strdup(), and result.

Referenced by get_encoding_id(), and setup_locale_encoding().

629 {
630  char result[20];
631 
632  sprintf(result, "%d", enc);
633  return pg_strdup(result);
634 }
return result
Definition: formatting.c:1618
struct pg_encoding enc
Definition: encode.c:522
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * escape_quotes ( const char *  src)
static

Definition at line 325 of file initdb.c.

References _, escape_single_quotes_ascii(), progname, and result.

Referenced by bootstrap_template1(), setup_auth(), setup_config(), setup_description(), setup_privileges(), and setup_schema().

326 {
327  char *result = escape_single_quotes_ascii(src);
328 
329  if (!result)
330  {
331  fprintf(stderr, _("%s: out of memory\n"), progname);
332  exit(1);
333  }
334  return result;
335 }
return result
Definition: formatting.c:1618
char * escape_single_quotes_ascii(const char *src)
Definition: quotes.c:33
static const char * progname
Definition: initdb.c:147
#define _(x)
Definition: elog.c:84
static void exit_nicely ( void  )
static

Definition at line 542 of file initdb.c.

References _, found_existing_pgdata, found_existing_xlogdir, made_new_pgdata, made_new_xlogdir, noclean, pg_data, progname, rmtree(), and xlog_dir.

Referenced by bootstrap_template1(), check_ok(), create_data_directory(), create_xlog_or_symlink(), get_su_pwd(), initialize_data_directory(), main(), readfile(), set_null_conf(), setup_config(), write_version_file(), and writefile().

543 {
544  if (!noclean)
545  {
546  if (made_new_pgdata)
547  {
548  fprintf(stderr, _("%s: removing data directory \"%s\"\n"),
549  progname, pg_data);
550  if (!rmtree(pg_data, true))
551  fprintf(stderr, _("%s: failed to remove data directory\n"),
552  progname);
553  }
554  else if (found_existing_pgdata)
555  {
556  fprintf(stderr,
557  _("%s: removing contents of data directory \"%s\"\n"),
558  progname, pg_data);
559  if (!rmtree(pg_data, false))
560  fprintf(stderr, _("%s: failed to remove contents of data directory\n"),
561  progname);
562  }
563 
564  if (made_new_xlogdir)
565  {
566  fprintf(stderr, _("%s: removing transaction log directory \"%s\"\n"),
567  progname, xlog_dir);
568  if (!rmtree(xlog_dir, true))
569  fprintf(stderr, _("%s: failed to remove transaction log directory\n"),
570  progname);
571  }
572  else if (found_existing_xlogdir)
573  {
574  fprintf(stderr,
575  _("%s: removing contents of transaction log directory \"%s\"\n"),
576  progname, xlog_dir);
577  if (!rmtree(xlog_dir, false))
578  fprintf(stderr, _("%s: failed to remove contents of transaction log directory\n"),
579  progname);
580  }
581  /* otherwise died during startup, do nothing! */
582  }
583  else
584  {
586  fprintf(stderr,
587  _("%s: data directory \"%s\" not removed at user's request\n"),
588  progname, pg_data);
589 
591  fprintf(stderr,
592  _("%s: transaction log directory \"%s\" not removed at user's request\n"),
593  progname, xlog_dir);
594  }
595 
596  exit(1);
597 }
static bool made_new_xlogdir
Definition: initdb.c:162
static bool found_existing_pgdata
Definition: initdb.c:161
static char * pg_data
Definition: initdb.c:121
static bool found_existing_xlogdir
Definition: initdb.c:163
static bool made_new_pgdata
Definition: initdb.c:160
static const char * progname
Definition: initdb.c:147
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:36
static char * xlog_dir
Definition: initdb.c:143
#define _(x)
Definition: elog.c:84
static bool noclean
Definition: initdb.c:138
static char ** filter_lines_with_token ( char **  lines,
const char *  token 
)
static

Definition at line 401 of file initdb.c.

References i, NULL, pg_malloc(), and result.

Referenced by setup_config().

402 {
403  int numlines = 1;
404  int i,
405  src,
406  dst;
407  char **result;
408 
409  for (i = 0; lines[i]; i++)
410  numlines++;
411 
412  result = (char **) pg_malloc(numlines * sizeof(char *));
413 
414  for (src = 0, dst = 0; src < numlines; src++)
415  {
416  if (lines[src] == NULL || strstr(lines[src], token) == NULL)
417  result[dst++] = lines[src];
418  }
419 
420  return result;
421 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
return result
Definition: formatting.c:1618
#define NULL
Definition: c.h:229
int i
static const char* find_matching_ts_config ( const char *  lc_type)
static

Definition at line 705 of file initdb.c.

References free, i, tsearch_config_match::langname, NULL, pg_strcasecmp(), pg_strdup(), and tsearch_config_match::tsconfname.

Referenced by setup_text_search().

706 {
707  int i;
708  char *langname,
709  *ptr;
710 
711  /*
712  * Convert lc_ctype to a language name by stripping everything after an
713  * underscore (usual case) or a hyphen (Windows "locale name"; see
714  * comments at IsoLocaleName()).
715  *
716  * XXX Should ' ' be a stop character? This would select "norwegian" for
717  * the Windows locale "Norwegian (Nynorsk)_Norway.1252". If we do so, we
718  * should also accept the "nn" and "nb" Unix locales.
719  *
720  * Just for paranoia, we also stop at '.' or '@'.
721  */
722  if (lc_type == NULL)
723  langname = pg_strdup("");
724  else
725  {
726  ptr = langname = pg_strdup(lc_type);
727  while (*ptr &&
728  *ptr != '_' && *ptr != '-' && *ptr != '.' && *ptr != '@')
729  ptr++;
730  *ptr = '\0';
731  }
732 
733  for (i = 0; tsearch_config_languages[i].tsconfname; i++)
734  {
735  if (pg_strcasecmp(tsearch_config_languages[i].langname, langname) == 0)
736  {
737  free(langname);
739  }
740  }
741 
742  free(langname);
743  return NULL;
744 }
static const struct tsearch_config_match tsearch_config_languages[]
Definition: initdb.c:664
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * tsconfname
Definition: initdb.c:660
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
int i
static char * get_encoding_id ( char *  encoding_name)
static

Definition at line 640 of file initdb.c.

References _, enc, encodingid_to_string(), pg_valid_server_encoding(), and progname.

Referenced by setup_locale_encoding().

641 {
642  int enc;
643 
644  if (encoding_name && *encoding_name)
645  {
646  if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
647  return encodingid_to_string(enc);
648  }
649  fprintf(stderr, _("%s: \"%s\" is not a valid server encoding name\n"),
650  progname, encoding_name ? encoding_name : "(null)");
651  exit(1);
652 }
static char * encodingid_to_string(int enc)
Definition: initdb.c:628
int pg_valid_server_encoding(const char *name)
Definition: encnames.c:501
struct pg_encoding enc
Definition: encode.c:522
static const char * progname
Definition: initdb.c:147
#define _(x)
Definition: elog.c:84
static char * get_id ( void  )
static

Definition at line 605 of file initdb.c.

References _, get_user_name_or_exit(), pg_strdup(), progname, and username.

Referenced by main().

606 {
607  const char *username;
608 
609 #ifndef WIN32
610  if (geteuid() == 0) /* 0 is root's uid */
611  {
612  fprintf(stderr,
613  _("%s: cannot be run as root\n"
614  "Please log in (using, e.g., \"su\") as the "
615  "(unprivileged) user that will\n"
616  "own the server process.\n"),
617  progname);
618  exit(1);
619  }
620 #endif
621 
622  username = get_user_name_or_exit(progname);
623 
624  return pg_strdup(username);
625 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static const char * progname
Definition: initdb.c:147
static char * username
Definition: initdb.c:131
#define _(x)
Definition: elog.c:84
const char * get_user_name_or_exit(const char *progname)
Definition: username.c:74
static void get_su_pwd ( void  )
static

Definition at line 1407 of file initdb.c.

References _, exit_nicely(), i, pg_strdup(), progname, pwfilename, pwprompt, simple_prompt(), strerror(), and superuser_password.

Referenced by main().

1408 {
1409  char pwd1[100];
1410  char pwd2[100];
1411 
1412  if (pwprompt)
1413  {
1414  /*
1415  * Read password from terminal
1416  */
1417  printf("\n");
1418  fflush(stdout);
1419  simple_prompt("Enter new superuser password: ", pwd1, sizeof(pwd1), false);
1420  simple_prompt("Enter it again: ", pwd2, sizeof(pwd2), false);
1421  if (strcmp(pwd1, pwd2) != 0)
1422  {
1423  fprintf(stderr, _("Passwords didn't match.\n"));
1424  exit_nicely();
1425  }
1426  }
1427  else
1428  {
1429  /*
1430  * Read password from file
1431  *
1432  * Ideally this should insist that the file not be world-readable.
1433  * However, this option is mainly intended for use on Windows where
1434  * file permissions may not exist at all, so we'll skip the paranoia
1435  * for now.
1436  */
1437  FILE *pwf = fopen(pwfilename, "r");
1438  int i;
1439 
1440  if (!pwf)
1441  {
1442  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
1443  progname, pwfilename, strerror(errno));
1444  exit_nicely();
1445  }
1446  if (!fgets(pwd1, sizeof(pwd1), pwf))
1447  {
1448  if (ferror(pwf))
1449  fprintf(stderr, _("%s: could not read password from file \"%s\": %s\n"),
1450  progname, pwfilename, strerror(errno));
1451  else
1452  fprintf(stderr, _("%s: password file \"%s\" is empty\n"),
1453  progname, pwfilename);
1454  exit_nicely();
1455  }
1456  fclose(pwf);
1457 
1458  i = strlen(pwd1);
1459  while (i > 0 && (pwd1[i - 1] == '\r' || pwd1[i - 1] == '\n'))
1460  pwd1[--i] = '\0';
1461  }
1462 
1463  superuser_password = pg_strdup(pwd1);
1464 }
static void exit_nicely(void)
Definition: initdb.c:542
static bool pwprompt
Definition: initdb.c:132
void simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo)
Definition: sprompt.c:37
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * pwfilename
Definition: initdb.c:133
static const char * progname
Definition: initdb.c:147
static char * superuser_password
Definition: initdb.c:134
int i
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
void initialize_data_directory ( void  )

Definition at line 2834 of file initdb.c.

References _, backend_exec, backend_options, bootstrap_template1(), check_ok(), create_data_directory(), create_xlog_or_symlink(), DEVNULL, exit_nicely(), free, i, lengthof, load_plpgsql(), make_postgres(), make_template0(), mkdir, NULL, PG_CMD_CLOSE, PG_CMD_DECL, PG_CMD_OPEN, pg_data, progname, psprintf(), S_IRWXG, S_IRWXO, set_null_conf(), setup_auth(), setup_collation(), setup_config(), setup_conversion(), setup_depend(), setup_description(), setup_dictionary(), setup_privileges(), setup_schema(), setup_signals(), setup_sysviews(), snprintf(), strerror(), subdirs, test_config_settings(), vacuum_db(), and write_version_file().

Referenced by main().

2835 {
2836  PG_CMD_DECL;
2837  int i;
2838 
2839  setup_signals();
2840 
2841  umask(S_IRWXG | S_IRWXO);
2842 
2844 
2846 
2847  /* Create required subdirectories (other than pg_wal) */
2848  printf(_("creating subdirectories ... "));
2849  fflush(stdout);
2850 
2851  for (i = 0; i < lengthof(subdirs); i++)
2852  {
2853  char *path;
2854 
2855  path = psprintf("%s/%s", pg_data, subdirs[i]);
2856 
2857  /*
2858  * The parent directory already exists, so we only need mkdir() not
2859  * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
2860  */
2861  if (mkdir(path, S_IRWXU) < 0)
2862  {
2863  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2864  progname, path, strerror(errno));
2865  exit_nicely();
2866  }
2867 
2868  free(path);
2869  }
2870 
2871  check_ok();
2872 
2873  /* Top level PG_VERSION is checked by bootstrapper, so make it first */
2875 
2876  /* Select suitable configuration settings */
2877  set_null_conf();
2879 
2880  /* Now create all the text config files */
2881  setup_config();
2882 
2883  /* Bootstrap template1 */
2885 
2886  /*
2887  * Make the per-database PG_VERSION for template1 only after init'ing it
2888  */
2889  write_version_file("base/1");
2890 
2891  /*
2892  * Create the stuff we don't need to use bootstrap mode for, using a
2893  * backend running in simple standalone mode.
2894  */
2895  fputs(_("performing post-bootstrap initialization ... "), stdout);
2896  fflush(stdout);
2897 
2898  snprintf(cmd, sizeof(cmd),
2899  "\"%s\" %s template1 >%s",
2901  DEVNULL);
2902 
2903  PG_CMD_OPEN;
2904 
2905  setup_auth(cmdfd);
2906 
2907  setup_depend(cmdfd);
2908 
2909  setup_sysviews(cmdfd);
2910 
2911  setup_description(cmdfd);
2912 
2913  setup_collation(cmdfd);
2914 
2915  setup_conversion(cmdfd);
2916 
2917  setup_dictionary(cmdfd);
2918 
2919  setup_privileges(cmdfd);
2920 
2921  setup_schema(cmdfd);
2922 
2923  load_plpgsql(cmdfd);
2924 
2925  vacuum_db(cmdfd);
2926 
2927  make_template0(cmdfd);
2928 
2929  make_postgres(cmdfd);
2930 
2931  PG_CMD_CLOSE;
2932 
2933  check_ok();
2934 }
static void write_version_file(char *extrapath)
Definition: initdb.c:801
static void setup_depend(FILE *cmdfd)
Definition: initdb.c:1470
static void vacuum_db(FILE *cmdfd)
Definition: initdb.c:1913
static const char * backend_options
Definition: initdb.c:196
#define mkdir(a, b)
Definition: win32.h:57
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static void setup_auth(FILE *cmdfd)
Definition: initdb.c:1383
static void setup_dictionary(FILE *cmdfd)
Definition: initdb.c:1660
void create_xlog_or_symlink(void)
Definition: initdb.c:2709
static void bootstrap_template1(void)
Definition: initdb.c:1284
static void exit_nicely(void)
Definition: initdb.c:542
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void setup_signals(void)
Definition: initdb.c:2610
#define lengthof(array)
Definition: c.h:562
static void set_null_conf(void)
Definition: initdb.c:832
#define PG_CMD_DECL
Definition: initdb.c:285
static const char *const subdirs[]
Definition: initdb.c:198
#define PG_CMD_OPEN
Definition: initdb.c:287
static void setup_config(void)
Definition: initdb.c:1006
static void load_plpgsql(FILE *cmdfd)
Definition: initdb.c:1904
static void setup_description(FILE *cmdfd)
Definition: initdb.c:1574
static char * pg_data
Definition: initdb.c:121
#define DEVNULL
Definition: port.h:116
static void check_ok(void)
Definition: initdb.c:2008
static void test_config_settings(void)
Definition: initdb.c:906
static const char * progname
Definition: initdb.c:147
void create_data_directory(void)
Definition: initdb.c:2639
#define PG_CMD_CLOSE
Definition: initdb.c:294
static void make_template0(FILE *cmdfd)
Definition: initdb.c:1923
static void setup_conversion(FILE *cmdfd)
Definition: initdb.c:1640
#define S_IRWXO
Definition: win32.h:455
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static void setup_collation(FILE *cmdfd)
Definition: initdb.c:1628
static void setup_schema(FILE *cmdfd)
Definition: initdb.c:1873
#define S_IRWXG
Definition: win32.h:451
static void setup_privileges(FILE *cmdfd)
Definition: initdb.c:1695
static void make_postgres(FILE *cmdfd)
Definition: initdb.c:1961
int i
const char * strerror(int errnum)
Definition: strerror.c:19
static char backend_exec[MAXPGPATH]
Definition: initdb.c:226
static void setup_sysviews(FILE *cmdfd)
Definition: initdb.c:1554
#define _(x)
Definition: elog.c:84
static void load_plpgsql ( FILE *  cmdfd)
static

Definition at line 1904 of file initdb.c.

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

1905 {
1906  PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
1907 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
static int locale_date_order ( const char *  locale)
static

Definition at line 2042 of file initdb.c.

References buf, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, free, my_strftime(), NULL, pg_strdup(), result, and tm.

Referenced by setup_config().

2043 {
2044  struct tm testtime;
2045  char buf[128];
2046  char *posD;
2047  char *posM;
2048  char *posY;
2049  char *save;
2050  size_t res;
2051  int result;
2052 
2053  result = DATEORDER_MDY; /* default */
2054 
2055  save = setlocale(LC_TIME, NULL);
2056  if (!save)
2057  return result;
2058  save = pg_strdup(save);
2059 
2060  setlocale(LC_TIME, locale);
2061 
2062  memset(&testtime, 0, sizeof(testtime));
2063  testtime.tm_mday = 22;
2064  testtime.tm_mon = 10; /* November, should come out as "11" */
2065  testtime.tm_year = 133; /* 2033 */
2066 
2067  res = my_strftime(buf, sizeof(buf), "%x", &testtime);
2068 
2069  setlocale(LC_TIME, save);
2070  free(save);
2071 
2072  if (res == 0)
2073  return result;
2074 
2075  posM = strstr(buf, "11");
2076  posD = strstr(buf, "22");
2077  posY = strstr(buf, "33");
2078 
2079  if (!posM || !posD || !posY)
2080  return result;
2081 
2082  if (posY < posM && posM < posD)
2083  result = DATEORDER_YMD;
2084  else if (posD < posM)
2085  result = DATEORDER_DMY;
2086  else
2087  result = DATEORDER_MDY;
2088 
2089  return result;
2090 }
return result
Definition: formatting.c:1618
static struct pg_tm tm
Definition: localtime.c:103
static char * buf
Definition: pg_test_fsync.c:66
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define DATEORDER_YMD
Definition: miscadmin.h:216
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
Definition: initdb.c:2033
#define DATEORDER_DMY
Definition: miscadmin.h:217
#define DATEORDER_MDY
Definition: miscadmin.h:218
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char * locale
Definition: initdb.c:123
int main ( int  argc,
char *  argv[] 
)

Definition at line 2938 of file initdb.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), appendShellString(), auth_methods_host, auth_methods_local, authmethodhost, authmethodlocal, authwarning, canonicalize_path(), check_authmethod_unspecified(), check_authmethod_valid(), check_need_password(), check_ok(), createPQExpBuffer(), PQExpBufferData::data, data_checksums, debug, default_text_search_config, destroyPQExpBuffer(), do_sync, encoding, exit_nicely(), fsync_pgdata(), get_id(), get_parent_directory(), get_progname(), get_restricted_token(), get_su_pwd(), getopt_long(), initialize_data_directory(), join_path_components(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, locale, MAXPGPATH, no_argument, noclean, NULL, optarg, optind, pg_check_dir(), pg_data, PG_IOLBF, pg_strdup(), PG_TEXTDOMAIN, pgdata_native, progname, pwfilename, pwprompt, required_argument, set_info_version(), set_pglocale_pgservice(), setup_bin_paths(), setup_data_file_paths(), setup_locale_encoding(), setup_pgdata(), setup_text_search(), share_path, show_setting, strerror(), strlcpy(), sync_only, usage(), username, and xlog_dir.

2939 {
2940  static struct option long_options[] = {
2941  {"pgdata", required_argument, NULL, 'D'},
2942  {"encoding", required_argument, NULL, 'E'},
2943  {"locale", required_argument, NULL, 1},
2944  {"lc-collate", required_argument, NULL, 2},
2945  {"lc-ctype", required_argument, NULL, 3},
2946  {"lc-monetary", required_argument, NULL, 4},
2947  {"lc-numeric", required_argument, NULL, 5},
2948  {"lc-time", required_argument, NULL, 6},
2949  {"lc-messages", required_argument, NULL, 7},
2950  {"no-locale", no_argument, NULL, 8},
2951  {"text-search-config", required_argument, NULL, 'T'},
2952  {"auth", required_argument, NULL, 'A'},
2953  {"auth-local", required_argument, NULL, 10},
2954  {"auth-host", required_argument, NULL, 11},
2955  {"pwprompt", no_argument, NULL, 'W'},
2956  {"pwfile", required_argument, NULL, 9},
2957  {"username", required_argument, NULL, 'U'},
2958  {"help", no_argument, NULL, '?'},
2959  {"version", no_argument, NULL, 'V'},
2960  {"debug", no_argument, NULL, 'd'},
2961  {"show", no_argument, NULL, 's'},
2962  {"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
2963  {"no-clean", no_argument, NULL, 'n'},
2964  {"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
2965  {"no-sync", no_argument, NULL, 'N'},
2966  {"sync-only", no_argument, NULL, 'S'},
2967  {"waldir", required_argument, NULL, 'X'},
2968  {"data-checksums", no_argument, NULL, 'k'},
2969  {NULL, 0, NULL, 0}
2970  };
2971 
2972  /*
2973  * options with no short version return a low integer, the rest return
2974  * their short version value
2975  */
2976  int c;
2977  int option_index;
2978  char *effective_user;
2979  PQExpBuffer start_db_cmd;
2980  char pg_ctl_path[MAXPGPATH];
2981 
2982  /*
2983  * Ensure that buffering behavior of stdout and stderr matches what it is
2984  * in interactive usage (at least on most platforms). This prevents
2985  * unexpected output ordering when, eg, output is redirected to a file.
2986  * POSIX says we must do this before any other usage of these files.
2987  */
2988  setvbuf(stdout, NULL, PG_IOLBF, 0);
2989  setvbuf(stderr, NULL, _IONBF, 0);
2990 
2991  progname = get_progname(argv[0]);
2992  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
2993 
2994  if (argc > 1)
2995  {
2996  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
2997  {
2998  usage(progname);
2999  exit(0);
3000  }
3001  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
3002  {
3003  puts("initdb (PostgreSQL) " PG_VERSION);
3004  exit(0);
3005  }
3006  }
3007 
3008  /* process command-line options */
3009 
3010  while ((c = getopt_long(argc, argv, "dD:E:kL:nNU:WA:sST:X:", long_options, &option_index)) != -1)
3011  {
3012  switch (c)
3013  {
3014  case 'A':
3016 
3017  /*
3018  * When ident is specified, use peer for local connections.
3019  * Mirrored, when peer is specified, use ident for TCP/IP
3020  * connections.
3021  */
3022  if (strcmp(authmethodhost, "ident") == 0)
3023  authmethodlocal = "peer";
3024  else if (strcmp(authmethodlocal, "peer") == 0)
3025  authmethodhost = "ident";
3026  break;
3027  case 10:
3029  break;
3030  case 11:
3032  break;
3033  case 'D':
3035  break;
3036  case 'E':
3038  break;
3039  case 'W':
3040  pwprompt = true;
3041  break;
3042  case 'U':
3044  break;
3045  case 'd':
3046  debug = true;
3047  printf(_("Running in debug mode.\n"));
3048  break;
3049  case 'n':
3050  noclean = true;
3051  printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3052  break;
3053  case 'N':
3054  do_sync = false;
3055  break;
3056  case 'S':
3057  sync_only = true;
3058  break;
3059  case 'k':
3060  data_checksums = true;
3061  break;
3062  case 'L':
3064  break;
3065  case 1:
3066  locale = pg_strdup(optarg);
3067  break;
3068  case 2:
3070  break;
3071  case 3:
3073  break;
3074  case 4:
3076  break;
3077  case 5:
3079  break;
3080  case 6:
3082  break;
3083  case 7:
3085  break;
3086  case 8:
3087  locale = "C";
3088  break;
3089  case 9:
3091  break;
3092  case 's':
3093  show_setting = true;
3094  break;
3095  case 'T':
3097  break;
3098  case 'X':
3100  break;
3101  default:
3102  /* getopt_long already emitted a complaint */
3103  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
3104  progname);
3105  exit(1);
3106  }
3107  }
3108 
3109 
3110  /*
3111  * Non-option argument specifies data directory as long as it wasn't
3112  * already specified with -D / --pgdata
3113  */
3114  if (optind < argc && strlen(pg_data) == 0)
3115  {
3116  pg_data = pg_strdup(argv[optind]);
3117  optind++;
3118  }
3119 
3120  if (optind < argc)
3121  {
3122  fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
3123  progname, argv[optind]);
3124  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
3125  progname);
3126  exit(1);
3127  }
3128 
3129  /* If we only need to fsync, just do it and exit */
3130  if (sync_only)
3131  {
3132  setup_pgdata();
3133 
3134  /* must check that directory is readable */
3135  if (pg_check_dir(pg_data) <= 0)
3136  {
3137  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
3138  progname, pg_data, strerror(errno));
3139  exit_nicely();
3140  }
3141 
3142  fputs(_("syncing data to disk ... "), stdout);
3143  fflush(stdout);
3144  fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
3145  check_ok();
3146  return 0;
3147  }
3148 
3149  if (pwprompt && pwfilename)
3150  {
3151  fprintf(stderr, _("%s: password prompt and password file cannot be specified together\n"), progname);
3152  exit(1);
3153  }
3154 
3157 
3160 
3162 
3164 
3165  setup_pgdata();
3166 
3167  setup_bin_paths(argv[0]);
3168 
3169  effective_user = get_id();
3170  if (strlen(username) == 0)
3171  username = effective_user;
3172 
3173  if (strncmp(username, "pg_", 3) == 0)
3174  {
3175  fprintf(stderr, _("%s: superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"\n"), progname, username);
3176  exit(1);
3177  }
3178 
3179  printf(_("The files belonging to this database system will be owned "
3180  "by user \"%s\".\n"
3181  "This user must also own the server process.\n\n"),
3182  effective_user);
3183 
3184  set_info_version();
3185 
3187 
3189 
3191 
3192  printf("\n");
3193 
3194  if (data_checksums)
3195  printf(_("Data page checksums are enabled.\n"));
3196  else
3197  printf(_("Data page checksums are disabled.\n"));
3198 
3199  if (pwprompt || pwfilename)
3200  get_su_pwd();
3201 
3202  printf("\n");
3203 
3205 
3206  if (do_sync)
3207  {
3208  fputs(_("syncing data to disk ... "), stdout);
3209  fflush(stdout);
3210  fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
3211  check_ok();
3212  }
3213  else
3214  printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3215 
3216  if (authwarning != NULL)
3217  fprintf(stderr, "%s", authwarning);
3218 
3219  /*
3220  * Build up a shell command to tell the user how to start the server
3221  */
3222  start_db_cmd = createPQExpBuffer();
3223 
3224  /* Get directory specification used to start initdb ... */
3225  strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
3226  canonicalize_path(pg_ctl_path);
3227  get_parent_directory(pg_ctl_path);
3228  /* ... and tag on pg_ctl instead */
3229  join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl");
3230 
3231  /* path to pg_ctl, properly quoted */
3232  appendShellString(start_db_cmd, pg_ctl_path);
3233 
3234  /* add -D switch, with properly quoted data directory */
3235  appendPQExpBufferStr(start_db_cmd, " -D ");
3236  appendShellString(start_db_cmd, pgdata_native);
3237 
3238  /* add suggested -l switch and "start" command */
3239  /* translator: This is a placeholder in a shell command. */
3240  appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
3241 
3242  printf(_("\nSuccess. You can now start the database server using:\n\n"
3243  " %s\n\n"),
3244  start_db_cmd->data);
3245 
3246  destroyPQExpBuffer(start_db_cmd);
3247 
3248  return 0;
3249 }
static char * lc_monetary
Definition: initdb.c:126
void setup_data_file_paths(void)
Definition: initdb.c:2527
void setup_locale_encoding(void)
Definition: initdb.c:2438
void fsync_pgdata(const char *pg_data, const char *progname, int serverVersion)
Definition: file_utils.c:58
static bool debug
Definition: initdb.c:137
static char * lc_collate
Definition: initdb.c:124
const char * get_progname(const char *argv0)
Definition: path.c:453
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
void canonicalize_path(char *path)
Definition: path.c:254
static void exit_nicely(void)
Definition: initdb.c:542
static bool pwprompt
Definition: initdb.c:132
static char * pgdata_native
Definition: initdb.c:168
static void get_su_pwd(void)
Definition: initdb.c:1407
static char * get_id(void)
Definition: initdb.c:605
static char * share_path
Definition: initdb.c:118
void get_restricted_token(const char *progname)
static const char * authmethodlocal
Definition: initdb.c:136
static char * lc_time
Definition: initdb.c:128
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
static void check_authmethod_unspecified(const char **authmethod)
Definition: initdb.c:2296
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:51
static char * lc_messages
Definition: initdb.c:129
#define MAXPGPATH
static const char * default_text_search_config
Definition: initdb.c:130
static char * lc_ctype
Definition: initdb.c:125
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * lc_numeric
Definition: initdb.c:127
char * c
void initialize_data_directory(void)
Definition: initdb.c:2834
void get_parent_directory(char *path)
Definition: path.c:854
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * pg_data
Definition: initdb.c:121
static char * pwfilename
Definition: initdb.c:133
static void check_ok(void)
Definition: initdb.c:2008
void setup_bin_paths(const char *argv0)
Definition: initdb.c:2390
static const char * progname
Definition: initdb.c:147
#define no_argument
Definition: getopt_long.h:24
static char * xlog_dir
Definition: initdb.c:143
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1012
static bool data_checksums
Definition: initdb.c:142
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define PG_IOLBF
Definition: port.h:340
static char * username
Definition: initdb.c:131
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:434
static char * encoding
Definition: initdb.c:122
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static char * authwarning
Definition: initdb.c:183
void setup_text_search(void)
Definition: initdb.c:2575
#define NULL
Definition: c.h:229
static bool do_sync
Definition: initdb.c:139
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition: path.c:218
static const char *const auth_methods_host[]
Definition: initdb.c:79
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:550
char * optarg
Definition: getopt.c:53
int pg_check_dir(const char *dir)
Definition: pgcheckdir.c:31
static void usage(const char *progname)
Definition: initdb.c:2256
const char * strerror(int errnum)
Definition: strerror.c:19
static void check_need_password(const char *authmethodlocal, const char *authmethodhost)
Definition: initdb.c:2328
static char * locale
Definition: initdb.c:123
static const char * authmethodhost
Definition: initdb.c:135
static bool sync_only
Definition: initdb.c:140
static const char *const auth_methods_local[]
Definition: initdb.c:101
static void check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
Definition: initdb.c:2308
void setup_pgdata(void)
Definition: initdb.c:2350
#define _(x)
Definition: elog.c:84
static void set_info_version(void)
Definition: initdb.c:1846
static bool show_setting
Definition: initdb.c:141
static bool noclean
Definition: initdb.c:138
static void make_postgres ( FILE *  cmdfd)
static

Definition at line 1961 of file initdb.c.

References NULL, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

1962 {
1963  const char *const * line;
1964  static const char *const postgres_setup[] = {
1965  "CREATE DATABASE postgres;\n\n",
1966  "COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n",
1967  NULL
1968  };
1969 
1970  for (line = postgres_setup; *line; line++)
1971  PG_CMD_PUTS(*line);
1972 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define NULL
Definition: c.h:229
static void make_template0 ( FILE *  cmdfd)
static

Definition at line 1923 of file initdb.c.

References NULL, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

1924 {
1925  const char *const * line;
1926  static const char *const template0_setup[] = {
1927  "CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false;\n\n",
1928 
1929  /*
1930  * We use the OID of template0 to determine lastsysoid
1931  */
1932  "UPDATE pg_database SET datlastsysoid = "
1933  " (SELECT oid FROM pg_database "
1934  " WHERE datname = 'template0');\n\n",
1935 
1936  /*
1937  * Explicitly revoke public create-schema and create-temp-table
1938  * privileges in template1 and template0; else the latter would be on
1939  * by default
1940  */
1941  "REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n",
1942  "REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n",
1943 
1944  "COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n",
1945 
1946  /*
1947  * Finally vacuum to clean up dead rows in pg_database
1948  */
1949  "VACUUM pg_database;\n\n",
1950  NULL
1951  };
1952 
1953  for (line = template0_setup; *line; line++)
1954  PG_CMD_PUTS(*line);
1955 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define NULL
Definition: c.h:229
static size_t my_strftime ( char *  s,
size_t  max,
const char *  fmt,
const struct tm tm 
)
inlinestatic

Definition at line 2033 of file initdb.c.

Referenced by locale_date_order().

2034 {
2035  return strftime(s, max, fmt, tm);
2036 }
static struct pg_tm tm
Definition: localtime.c:103
static FILE * popen_check ( const char *  command,
const char *  mode 
)
static

Definition at line 523 of file initdb.c.

References _, NULL, progname, and strerror().

524 {
525  FILE *cmdfd;
526 
527  fflush(stdout);
528  fflush(stderr);
529  errno = 0;
530  cmdfd = popen(command, mode);
531  if (cmdfd == NULL)
532  fprintf(stderr, _("%s: could not execute command \"%s\": %s\n"),
533  progname, command, strerror(errno));
534  return cmdfd;
535 }
static const char * progname
Definition: initdb.c:147
#define NULL
Definition: c.h:229
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static char ** readfile ( const char *  path)
static

Definition at line 428 of file initdb.c.

References _, buffer, exit_nicely(), free, infile(), NULL, pg_malloc(), pg_strdup(), progname, result, and strerror().

Referenced by bootstrap_template1(), setup_config(), setup_conversion(), setup_dictionary(), setup_schema(), and setup_sysviews().

429 {
430  FILE *infile;
431  int maxlength = 1,
432  linelen = 0;
433  int nlines = 0;
434  int n;
435  char **result;
436  char *buffer;
437  int c;
438 
439  if ((infile = fopen(path, "r")) == NULL)
440  {
441  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
442  progname, path, strerror(errno));
443  exit_nicely();
444  }
445 
446  /* pass over the file twice - the first time to size the result */
447 
448  while ((c = fgetc(infile)) != EOF)
449  {
450  linelen++;
451  if (c == '\n')
452  {
453  nlines++;
454  if (linelen > maxlength)
455  maxlength = linelen;
456  linelen = 0;
457  }
458  }
459 
460  /* handle last line without a terminating newline (yuck) */
461  if (linelen)
462  nlines++;
463  if (linelen > maxlength)
464  maxlength = linelen;
465 
466  /* set up the result and the line buffer */
467  result = (char **) pg_malloc((nlines + 1) * sizeof(char *));
468  buffer = (char *) pg_malloc(maxlength + 1);
469 
470  /* now reprocess the file and store the lines */
471  rewind(infile);
472  n = 0;
473  while (fgets(buffer, maxlength + 1, infile) != NULL && n < nlines)
474  result[n++] = pg_strdup(buffer);
475 
476  fclose(infile);
477  free(buffer);
478  result[n] = NULL;
479 
480  return result;
481 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static void exit_nicely(void)
Definition: initdb.c:542
return result
Definition: formatting.c:1618
char * c
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static const char * progname
Definition: initdb.c:147
static void infile(const char *filename)
Definition: zic.c:1150
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static char ** replace_token ( char **  lines,
const char *  token,
const char *  replacement 
)
static

Definition at line 345 of file initdb.c.

References i, newline(), NULL, pg_malloc(), and result.

Referenced by bootstrap_template1(), setup_config(), and setup_privileges().

346 {
347  int numlines = 1;
348  int i;
349  char **result;
350  int toklen,
351  replen,
352  diff;
353 
354  for (i = 0; lines[i]; i++)
355  numlines++;
356 
357  result = (char **) pg_malloc(numlines * sizeof(char *));
358 
359  toklen = strlen(token);
360  replen = strlen(replacement);
361  diff = replen - toklen;
362 
363  for (i = 0; i < numlines; i++)
364  {
365  char *where;
366  char *newline;
367  int pre;
368 
369  /* just copy pointer if NULL or no change needed */
370  if (lines[i] == NULL || (where = strstr(lines[i], token)) == NULL)
371  {
372  result[i] = lines[i];
373  continue;
374  }
375 
376  /* if we get here a change is needed - set up new line */
377 
378  newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
379 
380  pre = where - lines[i];
381 
382  memcpy(newline, lines[i], pre);
383 
384  memcpy(newline + pre, replacement, replen);
385 
386  strcpy(newline + pre + replen, lines[i] + pre + toklen);
387 
388  result[i] = newline;
389  }
390 
391  return result;
392 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
return result
Definition: formatting.c:1618
static chr newline(void)
Definition: regc_lex.c:1137
#define NULL
Definition: c.h:229
int i
const char* select_default_timezone ( const char *  share_path)

Definition at line 1377 of file findtimezone.c.

References identify_system_timezone(), NULL, snprintf(), tzdirpath, and validate_zone().

Referenced by setup_config().

1378 {
1379  const char *tzname;
1380 
1381  /* Initialize timezone directory path, if needed */
1382 #ifndef SYSTEMTZDIR
1383  snprintf(tzdirpath, sizeof(tzdirpath), "%s/timezone", share_path);
1384 #endif
1385 
1386  /* Check TZ environment variable */
1387  tzname = getenv("TZ");
1388  if (validate_zone(tzname))
1389  return tzname;
1390 
1391  /* Nope, so try to identify the system timezone */
1392  tzname = identify_system_timezone();
1393  if (validate_zone(tzname))
1394  return tzname;
1395 
1396  return NULL;
1397 }
static bool validate_zone(const char *tzname)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static char * share_path
Definition: initdb.c:118
static char tzdirpath[MAXPGPATH]
Definition: findtimezone.c:26
#define NULL
Definition: c.h:229
static const char * identify_system_timezone(void)
Definition: findtimezone.c:310
static void set_info_version ( void  )
static

Definition at line 1846 of file initdb.c.

References infoversion, pg_strdup(), and snprintf().

Referenced by main().

1847 {
1848  char *letterversion;
1849  long major = 0,
1850  minor = 0,
1851  micro = 0;
1852  char *endptr;
1853  char *vstr = pg_strdup(PG_VERSION);
1854  char *ptr;
1855 
1856  ptr = vstr + (strlen(vstr) - 1);
1857  while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
1858  ptr--;
1859  letterversion = ptr + 1;
1860  major = strtol(vstr, &endptr, 10);
1861  if (*endptr)
1862  minor = strtol(endptr + 1, &endptr, 10);
1863  if (*endptr)
1864  micro = strtol(endptr + 1, &endptr, 10);
1865  snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
1866  major, minor, micro, letterversion);
1867 }
static char infoversion[100]
Definition: initdb.c:164
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void set_input ( char **  dest,
char *  filename 
)
static

Definition at line 751 of file initdb.c.

References psprintf(), and share_path.

Referenced by setup_data_file_paths().

752 {
753  *dest = psprintf("%s/%s", share_path, filename);
754 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static char * share_path
Definition: initdb.c:118
static char * filename
Definition: pg_dumpall.c:87
static void set_null_conf ( void  )
static

Definition at line 832 of file initdb.c.

References _, conf_file, exit_nicely(), free, NULL, PG_BINARY_W, pg_data, progname, psprintf(), and strerror().

Referenced by initialize_data_directory().

833 {
834  FILE *conf_file;
835  char *path;
836 
837  path = psprintf("%s/postgresql.conf", pg_data);
838  conf_file = fopen(path, PG_BINARY_W);
839  if (conf_file == NULL)
840  {
841  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
842  progname, path, strerror(errno));
843  exit_nicely();
844  }
845  if (fclose(conf_file))
846  {
847  fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
848  progname, path, strerror(errno));
849  exit_nicely();
850  }
851  free(path);
852 }
static char * conf_file
Definition: initdb.c:154
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define PG_BINARY_W
Definition: c.h:1041
static void exit_nicely(void)
Definition: initdb.c:542
static char * pg_data
Definition: initdb.c:121
static const char * progname
Definition: initdb.c:147
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void setlocales ( void  )
static

Definition at line 2205 of file initdb.c.

References check_locale_name(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, and locale.

Referenced by setup_locale_encoding().

2206 {
2207  char *canonname;
2208 
2209  /* set empty lc_* values to locale config if set */
2210 
2211  if (strlen(locale) > 0)
2212  {
2213  if (strlen(lc_ctype) == 0)
2214  lc_ctype = locale;
2215  if (strlen(lc_collate) == 0)
2216  lc_collate = locale;
2217  if (strlen(lc_numeric) == 0)
2218  lc_numeric = locale;
2219  if (strlen(lc_time) == 0)
2220  lc_time = locale;
2221  if (strlen(lc_monetary) == 0)
2222  lc_monetary = locale;
2223  if (strlen(lc_messages) == 0)
2224  lc_messages = locale;
2225  }
2226 
2227  /*
2228  * canonicalize locale names, and obtain any missing values from our
2229  * current environment
2230  */
2231 
2232  check_locale_name(LC_CTYPE, lc_ctype, &canonname);
2233  lc_ctype = canonname;
2234  check_locale_name(LC_COLLATE, lc_collate, &canonname);
2235  lc_collate = canonname;
2236  check_locale_name(LC_NUMERIC, lc_numeric, &canonname);
2237  lc_numeric = canonname;
2238  check_locale_name(LC_TIME, lc_time, &canonname);
2239  lc_time = canonname;
2240  check_locale_name(LC_MONETARY, lc_monetary, &canonname);
2241  lc_monetary = canonname;
2242 #if defined(LC_MESSAGES) && !defined(WIN32)
2243  check_locale_name(LC_MESSAGES, lc_messages, &canonname);
2244  lc_messages = canonname;
2245 #else
2246  /* when LC_MESSAGES is not available, use the LC_CTYPE setting */
2247  check_locale_name(LC_CTYPE, lc_messages, &canonname);
2248  lc_messages = canonname;
2249 #endif
2250 }
static char * lc_monetary
Definition: initdb.c:126
static char * lc_collate
Definition: initdb.c:124
static char * lc_time
Definition: initdb.c:128
static char * lc_messages
Definition: initdb.c:129
static char * lc_ctype
Definition: initdb.c:125
static char * lc_numeric
Definition: initdb.c:127
static void check_locale_name(int category, const char *locale, char **canonname)
Definition: initdb.c:2105
static char * locale
Definition: initdb.c:123
static void setup_auth ( FILE *  cmdfd)
static

Definition at line 1383 of file initdb.c.

References escape_quotes(), NULL, PG_CMD_PRINTF2, PG_CMD_PUTS, superuser_password, and username.

Referenced by initialize_data_directory().

1384 {
1385  const char *const * line;
1386  static const char *const pg_authid_setup[] = {
1387  /*
1388  * The authid table shouldn't be readable except through views, to
1389  * ensure passwords are not publicly visible.
1390  */
1391  "REVOKE ALL on pg_authid FROM public;\n\n",
1392  NULL
1393  };
1394 
1395  for (line = pg_authid_setup; *line != NULL; line++)
1396  PG_CMD_PUTS(*line);
1397 
1398  if (superuser_password)
1399  PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1401 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
static char * username
Definition: initdb.c:131
#define NULL
Definition: c.h:229
static char * superuser_password
Definition: initdb.c:134
static char * escape_quotes(const char *src)
Definition: initdb.c:325
#define PG_CMD_PRINTF2(fmt, arg1, arg2)
Definition: initdb.c:312
void setup_bin_paths ( const char *  argv0)

Definition at line 2390 of file initdb.c.

References _, backend_exec, bin_path, canonicalize_path(), find_my_exec(), find_other_exec(), get_share_path(), is_absolute_path, last_dir_separator(), MAXPGPATH, PG_BACKEND_VERSIONSTR, pg_malloc(), progname, share_path, and strlcpy().

Referenced by main().

2391 {
2392  int ret;
2393 
2394  if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
2395  backend_exec)) < 0)
2396  {
2397  char full_path[MAXPGPATH];
2398 
2399  if (find_my_exec(argv0, full_path) < 0)
2400  strlcpy(full_path, progname, sizeof(full_path));
2401 
2402  if (ret == -1)
2403  fprintf(stderr,
2404  _("The program \"postgres\" is needed by %s "
2405  "but was not found in the\n"
2406  "same directory as \"%s\".\n"
2407  "Check your installation.\n"),
2408  progname, full_path);
2409  else
2410  fprintf(stderr,
2411  _("The program \"postgres\" was found by \"%s\"\n"
2412  "but was not the same version as %s.\n"
2413  "Check your installation.\n"),
2414  full_path, progname);
2415  exit(1);
2416  }
2417 
2418  /* store binary directory */
2419  strcpy(bin_path, backend_exec);
2420  *last_dir_separator(bin_path) = '\0';
2422 
2423  if (!share_path)
2424  {
2427  }
2428  else if (!is_absolute_path(share_path))
2429  {
2430  fprintf(stderr, _("%s: input file location must be an absolute path\n"), progname);
2431  exit(1);
2432  }
2433 
2435 }
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:307
static char * argv0
Definition: pg_ctl.c:89
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void canonicalize_path(char *path)
Definition: path.c:254
#define PG_BACKEND_VERSIONSTR
Definition: miscadmin.h:29
static char * share_path
Definition: initdb.c:118
#define MAXPGPATH
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:119
#define is_absolute_path(filename)
Definition: port.h:77
static const char * progname
Definition: initdb.c:147
char * last_dir_separator(const char *filename)
Definition: path.c:138
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static char bin_path[MAXPGPATH]
Definition: initdb.c:225
static char backend_exec[MAXPGPATH]
Definition: initdb.c:226
void get_share_path(const char *my_exec_path, char *ret_path)
Definition: path.c:704
#define _(x)
Definition: elog.c:84
static void setup_collation ( FILE *  cmdfd)
static

Definition at line 1628 of file initdb.c.

References BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC, PG_CMD_PRINTF3, PG_CMD_PUTS, and PG_UTF8.

Referenced by initialize_data_directory().

1629 {
1630  PG_CMD_PUTS("SELECT pg_import_system_collations(if_not_exists => false, schema => 'pg_catalog');\n\n");
1631 
1632  /* Add an SQL-standard name */
1633  PG_CMD_PRINTF3("INSERT INTO pg_collation (collname, collnamespace, collowner, collprovider, collencoding, collcollate, collctype) VALUES ('ucs_basic', 'pg_catalog'::regnamespace, %u, '%c', %d, 'C', 'C');\n\n", BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC, PG_UTF8);
1634 }
#define PG_CMD_PRINTF3(fmt, arg1, arg2, arg3)
Definition: initdb.c:318
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define BOOTSTRAP_SUPERUSERID
Definition: pg_authid.h:108
#define COLLPROVIDER_LIBC
Definition: pg_collation.h:85
static void setup_config ( void  )
static

Definition at line 1006 of file initdb.c.

References _, addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_canonname, addrinfo::ai_family, addrinfo::ai_flags, addrinfo::ai_next, AI_NUMERICHOST, addrinfo::ai_protocol, addrinfo::ai_socktype, authmethodhost, authmethodlocal, AUTHTRUST_WARNING, check_ok(), conf_file, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, DEFAULT_BACKEND_FLUSH_AFTER, DEFAULT_BGWRITER_FLUSH_AFTER, DEFAULT_CHECKPOINT_FLUSH_AFTER, DEFAULT_PGSOCKET_DIR, default_text_search_config, dynamic_shared_memory_type, escape_quotes(), exit_nicely(), filter_lines_with_token(), free, getaddrinfo, hba_file, ident_file, lc_messages, lc_monetary, lc_numeric, lc_time, locale_date_order(), MAXPGPATH, n_buffers, n_connections, NULL, pg_data, pg_strdup(), progname, readfile(), replace_token(), select_default_timezone(), share_path, snprintf(), strerror(), and writefile().

Referenced by initialize_data_directory().

1007 {
1008  char **conflines;
1009  char repltok[MAXPGPATH];
1010  char path[MAXPGPATH];
1011  const char *default_timezone;
1012  char *autoconflines[3];
1013 
1014  fputs(_("creating configuration files ... "), stdout);
1015  fflush(stdout);
1016 
1017  /* postgresql.conf */
1018 
1019  conflines = readfile(conf_file);
1020 
1021  snprintf(repltok, sizeof(repltok), "max_connections = %d", n_connections);
1022  conflines = replace_token(conflines, "#max_connections = 100", repltok);
1023 
1024  if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1025  snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB",
1026  (n_buffers * (BLCKSZ / 1024)) / 1024);
1027  else
1028  snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB",
1029  n_buffers * (BLCKSZ / 1024));
1030  conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
1031 
1032 #ifdef HAVE_UNIX_SOCKETS
1033  snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
1035 #else
1036  snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
1037 #endif
1038  conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
1039  repltok);
1040 
1041 #if DEF_PGPORT != 5432
1042  snprintf(repltok, sizeof(repltok), "#port = %d", DEF_PGPORT);
1043  conflines = replace_token(conflines, "#port = 5432", repltok);
1044 #endif
1045 
1046  snprintf(repltok, sizeof(repltok), "lc_messages = '%s'",
1048  conflines = replace_token(conflines, "#lc_messages = 'C'", repltok);
1049 
1050  snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'",
1052  conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok);
1053 
1054  snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'",
1056  conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok);
1057 
1058  snprintf(repltok, sizeof(repltok), "lc_time = '%s'",
1060  conflines = replace_token(conflines, "#lc_time = 'C'", repltok);
1061 
1062  switch (locale_date_order(lc_time))
1063  {
1064  case DATEORDER_YMD:
1065  strcpy(repltok, "datestyle = 'iso, ymd'");
1066  break;
1067  case DATEORDER_DMY:
1068  strcpy(repltok, "datestyle = 'iso, dmy'");
1069  break;
1070  case DATEORDER_MDY:
1071  default:
1072  strcpy(repltok, "datestyle = 'iso, mdy'");
1073  break;
1074  }
1075  conflines = replace_token(conflines, "#datestyle = 'iso, mdy'", repltok);
1076 
1077  snprintf(repltok, sizeof(repltok),
1078  "default_text_search_config = 'pg_catalog.%s'",
1080  conflines = replace_token(conflines,
1081  "#default_text_search_config = 'pg_catalog.simple'",
1082  repltok);
1083 
1084  default_timezone = select_default_timezone(share_path);
1085  if (default_timezone)
1086  {
1087  snprintf(repltok, sizeof(repltok), "timezone = '%s'",
1088  escape_quotes(default_timezone));
1089  conflines = replace_token(conflines, "#timezone = 'GMT'", repltok);
1090  snprintf(repltok, sizeof(repltok), "log_timezone = '%s'",
1091  escape_quotes(default_timezone));
1092  conflines = replace_token(conflines, "#log_timezone = 'GMT'", repltok);
1093  }
1094 
1095  snprintf(repltok, sizeof(repltok), "dynamic_shared_memory_type = %s",
1097  conflines = replace_token(conflines, "#dynamic_shared_memory_type = posix",
1098  repltok);
1099 
1100 #if DEFAULT_BACKEND_FLUSH_AFTER > 0
1101  snprintf(repltok, sizeof(repltok), "#backend_flush_after = %dkB",
1102  DEFAULT_BACKEND_FLUSH_AFTER * (BLCKSZ / 1024));
1103  conflines = replace_token(conflines, "#backend_flush_after = 0",
1104  repltok);
1105 #endif
1106 
1107 #if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1108  snprintf(repltok, sizeof(repltok), "#bgwriter_flush_after = %dkB",
1109  DEFAULT_BGWRITER_FLUSH_AFTER * (BLCKSZ / 1024));
1110  conflines = replace_token(conflines, "#bgwriter_flush_after = 0",
1111  repltok);
1112 #endif
1113 
1114 #if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1115  snprintf(repltok, sizeof(repltok), "#checkpoint_flush_after = %dkB",
1116  DEFAULT_CHECKPOINT_FLUSH_AFTER * (BLCKSZ / 1024));
1117  conflines = replace_token(conflines, "#checkpoint_flush_after = 0",
1118  repltok);
1119 #endif
1120 
1121 #ifndef USE_PREFETCH
1122  conflines = replace_token(conflines,
1123  "#effective_io_concurrency = 1",
1124  "#effective_io_concurrency = 0");
1125 #endif
1126 
1127 #ifdef WIN32
1128  conflines = replace_token(conflines,
1129  "#update_process_title = on",
1130  "#update_process_title = off");
1131 #endif
1132 
1133  if (strcmp(authmethodlocal, "scram-sha-256") == 0 ||
1134  strcmp(authmethodhost, "scram-sha-256") == 0)
1135  {
1136  conflines = replace_token(conflines,
1137  "#password_encryption = md5",
1138  "password_encryption = scram-sha-256");
1139  }
1140 
1141  snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
1142 
1143  writefile(path, conflines);
1144  if (chmod(path, S_IRUSR | S_IWUSR) != 0)
1145  {
1146  fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
1147  progname, path, strerror(errno));
1148  exit_nicely();
1149  }
1150 
1151  /*
1152  * create the automatic configuration file to store the configuration
1153  * parameters set by ALTER SYSTEM command. The parameters present in this
1154  * file will override the value of parameters that exists before parse of
1155  * this file.
1156  */
1157  autoconflines[0] = pg_strdup("# Do not edit this file manually!\n");
1158  autoconflines[1] = pg_strdup("# It will be overwritten by the ALTER SYSTEM command.\n");
1159  autoconflines[2] = NULL;
1160 
1161  sprintf(path, "%s/postgresql.auto.conf", pg_data);
1162 
1163  writefile(path, autoconflines);
1164  if (chmod(path, S_IRUSR | S_IWUSR) != 0)
1165  {
1166  fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
1167  progname, path, strerror(errno));
1168  exit_nicely();
1169  }
1170 
1171  free(conflines);
1172 
1173 
1174  /* pg_hba.conf */
1175 
1176  conflines = readfile(hba_file);
1177 
1178 #ifndef HAVE_UNIX_SOCKETS
1179  conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
1180 #else
1181  conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
1182 #endif
1183 
1184 #ifdef HAVE_IPV6
1185 
1186  /*
1187  * Probe to see if there is really any platform support for IPv6, and
1188  * comment out the relevant pg_hba line if not. This avoids runtime
1189  * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
1190  * useful on Windows, where executables built on a machine with IPv6 may
1191  * have to run on a machine without.
1192  */
1193  {
1194  struct addrinfo *gai_result;
1195  struct addrinfo hints;
1196  int err = 0;
1197 
1198 #ifdef WIN32
1199  /* need to call WSAStartup before calling getaddrinfo */
1200  WSADATA wsaData;
1201 
1202  err = WSAStartup(MAKEWORD(2, 2), &wsaData);
1203 #endif
1204 
1205  /* for best results, this code should match parse_hba() */
1206  hints.ai_flags = AI_NUMERICHOST;
1207  hints.ai_family = AF_UNSPEC;
1208  hints.ai_socktype = 0;
1209  hints.ai_protocol = 0;
1210  hints.ai_addrlen = 0;
1211  hints.ai_canonname = NULL;
1212  hints.ai_addr = NULL;
1213  hints.ai_next = NULL;
1214 
1215  if (err != 0 ||
1216  getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
1217  {
1218  conflines = replace_token(conflines,
1219  "host all all ::1",
1220  "#host all all ::1");
1221  conflines = replace_token(conflines,
1222  "host replication all ::1",
1223  "#host replication all ::1");
1224  }
1225  }
1226 #else /* !HAVE_IPV6 */
1227  /* If we didn't compile IPV6 support at all, always comment it out */
1228  conflines = replace_token(conflines,
1229  "host all all ::1",
1230  "#host all all ::1");
1231  conflines = replace_token(conflines,
1232  "host replication all ::1",
1233  "#host replication all ::1");
1234 #endif /* HAVE_IPV6 */
1235 
1236  /* Replace default authentication methods */
1237  conflines = replace_token(conflines,
1238  "@authmethodhost@",
1239  authmethodhost);
1240  conflines = replace_token(conflines,
1241  "@authmethodlocal@",
1242  authmethodlocal);
1243 
1244  conflines = replace_token(conflines,
1245  "@authcomment@",
1246  (strcmp(authmethodlocal, "trust") == 0 || strcmp(authmethodhost, "trust") == 0) ? AUTHTRUST_WARNING : "");
1247 
1248  snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
1249 
1250  writefile(path, conflines);
1251  if (chmod(path, S_IRUSR | S_IWUSR) != 0)
1252  {
1253  fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
1254  progname, path, strerror(errno));
1255  exit_nicely();
1256  }
1257 
1258  free(conflines);
1259 
1260  /* pg_ident.conf */
1261 
1262  conflines = readfile(ident_file);
1263 
1264  snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
1265 
1266  writefile(path, conflines);
1267  if (chmod(path, S_IRUSR | S_IWUSR) != 0)
1268  {
1269  fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
1270  progname, path, strerror(errno));
1271  exit_nicely();
1272  }
1273 
1274  free(conflines);
1275 
1276  check_ok();
1277 }
static char * lc_monetary
Definition: initdb.c:126
#define getaddrinfo
Definition: getaddrinfo.h:136
static char ** replace_token(char **lines, const char *token, const char *replacement)
Definition: initdb.c:345
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
static char * conf_file
Definition: initdb.c:154
#define DEFAULT_BGWRITER_FLUSH_AFTER
#define AUTHTRUST_WARNING
Definition: initdb.c:178
static void exit_nicely(void)
Definition: initdb.c:542
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define AI_NUMERICHOST
Definition: getaddrinfo.h:73
static char * share_path
Definition: initdb.c:118
static const char * authmethodlocal
Definition: initdb.c:136
static char * lc_time
Definition: initdb.c:128
static int n_connections
Definition: initdb.c:171
static char * lc_messages
Definition: initdb.c:129
#define MAXPGPATH
static const char * default_text_search_config
Definition: initdb.c:130
static char * lc_numeric
Definition: initdb.c:127
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * pg_data
Definition: initdb.c:121
static void check_ok(void)
Definition: initdb.c:2008
#define DATEORDER_YMD
Definition: miscadmin.h:216
const char * select_default_timezone(const char *share_path)
static const char * progname
Definition: initdb.c:147
static int locale_date_order(const char *locale)
Definition: initdb.c:2042
#define DATEORDER_DMY
Definition: miscadmin.h:217
#define DATEORDER_MDY
Definition: miscadmin.h:218
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char ** filter_lines_with_token(char **lines, const char *token)
Definition: initdb.c:401
static int n_buffers
Definition: initdb.c:172
static char * escape_quotes(const char *src)
Definition: initdb.c:325
static void writefile(char *path, char **lines)
Definition: initdb.c:490
const char * strerror(int errnum)
Definition: strerror.c:19
static char * ident_file
Definition: initdb.c:153
static char ** readfile(const char *path)
Definition: initdb.c:428
static const char * authmethodhost
Definition: initdb.c:135
static char * dynamic_shared_memory_type
Definition: initdb.c:173
#define _(x)
Definition: elog.c:84
static char * hba_file
Definition: initdb.c:152
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_PGSOCKET_DIR
static void setup_conversion ( FILE *  cmdfd)
static

Definition at line 1640 of file initdb.c.

References conversion_file, free, NULL, PG_CMD_PUTS, and readfile().

Referenced by initialize_data_directory().

1641 {
1642  char **line;
1643  char **conv_lines;
1644 
1645  conv_lines = readfile(conversion_file);
1646  for (line = conv_lines; *line != NULL; line++)
1647  {
1648  if (strstr(*line, "DROP CONVERSION") != *line)
1649  PG_CMD_PUTS(*line);
1650  free(*line);
1651  }
1652 
1653  free(conv_lines);
1654 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
static char * conversion_file
Definition: initdb.c:155
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char ** readfile(const char *path)
Definition: initdb.c:428
void setup_data_file_paths ( void  )

Definition at line 2527 of file initdb.c.

References bin_path, bki_file, check_input(), conf_file, conversion_file, debug, desc_file, dictionary_file, features_file, hba_file, ident_file, info_schema_file, pg_data, set_input(), share_path, shdesc_file, show_setting, system_views_file, and username.

Referenced by main().

2528 {
2529  set_input(&bki_file, "postgres.bki");
2530  set_input(&desc_file, "postgres.description");
2531  set_input(&shdesc_file, "postgres.shdescription");
2532  set_input(&hba_file, "pg_hba.conf.sample");
2533  set_input(&ident_file, "pg_ident.conf.sample");
2534  set_input(&conf_file, "postgresql.conf.sample");
2535  set_input(&conversion_file, "conversion_create.sql");
2536  set_input(&dictionary_file, "snowball_create.sql");
2537  set_input(&info_schema_file, "information_schema.sql");
2538  set_input(&features_file, "sql_features.txt");
2539  set_input(&system_views_file, "system_views.sql");
2540 
2541  if (show_setting || debug)
2542  {
2543  fprintf(stderr,
2544  "VERSION=%s\n"
2545  "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2546  "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2547  "POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n"
2548  "POSTGRESQL_CONF_SAMPLE=%s\n"
2549  "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2550  PG_VERSION,
2552  username, bki_file,
2554  conf_file,
2555  hba_file, ident_file);
2556  if (show_setting)
2557  exit(0);
2558  }
2559 
2571 }
static bool debug
Definition: initdb.c:137
static char * system_views_file
Definition: initdb.c:159
static char * conf_file
Definition: initdb.c:154
static char * features_file
Definition: initdb.c:158
static char * share_path
Definition: initdb.c:118
static void check_input(char *path)
Definition: initdb.c:760
static char * desc_file
Definition: initdb.c:150
static char * conversion_file
Definition: initdb.c:155
static char * pg_data
Definition: initdb.c:121
static char * dictionary_file
Definition: initdb.c:156
static void set_input(char **dest, char *filename)
Definition: initdb.c:751
static char * info_schema_file
Definition: initdb.c:157
static char * username
Definition: initdb.c:131
static char bin_path[MAXPGPATH]
Definition: initdb.c:225
static char * ident_file
Definition: initdb.c:153
static char * shdesc_file
Definition: initdb.c:151
static char * bki_file
Definition: initdb.c:149
static char * hba_file
Definition: initdb.c:152
static bool show_setting
Definition: initdb.c:141
static void setup_depend ( FILE *  cmdfd)
static

Definition at line 1470 of file initdb.c.

References NULL, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

1471 {
1472  const char *const * line;
1473  static const char *const pg_depend_setup[] = {
1474  /*
1475  * Make PIN entries in pg_depend for all objects made so far in the
1476  * tables that the dependency code handles. This is overkill (the
1477  * system doesn't really depend on having every last weird datatype,
1478  * for instance) but generating only the minimum required set of
1479  * dependencies seems hard.
1480  *
1481  * Note that we deliberately do not pin the system views, which
1482  * haven't been created yet. Also, no conversions, databases, or
1483  * tablespaces are pinned.
1484  *
1485  * First delete any already-made entries; PINs override all else, and
1486  * must be the only entries for their objects.
1487  */
1488  "DELETE FROM pg_depend;\n\n",
1489  "VACUUM pg_depend;\n\n",
1490  "DELETE FROM pg_shdepend;\n\n",
1491  "VACUUM pg_shdepend;\n\n",
1492 
1493  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1494  " FROM pg_class;\n\n",
1495  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1496  " FROM pg_proc;\n\n",
1497  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1498  " FROM pg_type;\n\n",
1499  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1500  " FROM pg_cast;\n\n",
1501  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1502  " FROM pg_constraint;\n\n",
1503  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1504  " FROM pg_attrdef;\n\n",
1505  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1506  " FROM pg_language;\n\n",
1507  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1508  " FROM pg_operator;\n\n",
1509  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1510  " FROM pg_opclass;\n\n",
1511  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1512  " FROM pg_opfamily;\n\n",
1513  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1514  " FROM pg_am;\n\n",
1515  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1516  " FROM pg_amop;\n\n",
1517  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1518  " FROM pg_amproc;\n\n",
1519  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1520  " FROM pg_rewrite;\n\n",
1521  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1522  " FROM pg_trigger;\n\n",
1523 
1524  /*
1525  * restriction here to avoid pinning the public namespace
1526  */
1527  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1528  " FROM pg_namespace "
1529  " WHERE nspname LIKE 'pg%';\n\n",
1530 
1531  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1532  " FROM pg_ts_parser;\n\n",
1533  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1534  " FROM pg_ts_dict;\n\n",
1535  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1536  " FROM pg_ts_template;\n\n",
1537  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1538  " FROM pg_ts_config;\n\n",
1539  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1540  " FROM pg_collation;\n\n",
1541  "INSERT INTO pg_shdepend SELECT 0,0,0,0, tableoid,oid, 'p' "
1542  " FROM pg_authid;\n\n",
1543  NULL
1544  };
1545 
1546  for (line = pg_depend_setup; *line != NULL; line++)
1547  PG_CMD_PUTS(*line);
1548 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define NULL
Definition: c.h:229
static void setup_description ( FILE *  cmdfd)
static

Definition at line 1574 of file initdb.c.

References desc_file, escape_quotes(), PG_CMD_PRINTF1, PG_CMD_PUTS, and shdesc_file.

Referenced by initialize_data_directory().

1575 {
1576  PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_description ( "
1577  " objoid oid, "
1578  " classname name, "
1579  " objsubid int4, "
1580  " description text) WITHOUT OIDS;\n\n");
1581 
1582  PG_CMD_PRINTF1("COPY tmp_pg_description FROM E'%s';\n\n",
1584 
1585  PG_CMD_PUTS("INSERT INTO pg_description "
1586  " SELECT t.objoid, c.oid, t.objsubid, t.description "
1587  " FROM tmp_pg_description t, pg_class c "
1588  " WHERE c.relname = t.classname;\n\n");
1589 
1590  PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( "
1591  " objoid oid, "
1592  " classname name, "
1593  " description text) WITHOUT OIDS;\n\n");
1594 
1595  PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM E'%s';\n\n",
1597 
1598  PG_CMD_PUTS("INSERT INTO pg_shdescription "
1599  " SELECT t.objoid, c.oid, t.description "
1600  " FROM tmp_pg_shdescription t, pg_class c "
1601  " WHERE c.relname = t.classname;\n\n");
1602 
1603  /* Create default descriptions for operator implementation functions */
1604  PG_CMD_PUTS("WITH funcdescs AS ( "
1605  "SELECT p.oid as p_oid, oprname, "
1606  "coalesce(obj_description(o.oid, 'pg_operator'),'') as opdesc "
1607  "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1608  "INSERT INTO pg_description "
1609  " SELECT p_oid, 'pg_proc'::regclass, 0, "
1610  " 'implementation of ' || oprname || ' operator' "
1611  " FROM funcdescs "
1612  " WHERE opdesc NOT LIKE 'deprecated%' AND "
1613  " NOT EXISTS (SELECT 1 FROM pg_description "
1614  " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass);\n\n");
1615 
1616  /*
1617  * Even though the tables are temp, drop them explicitly so they don't get
1618  * copied into template0/postgres databases.
1619  */
1620  PG_CMD_PUTS("DROP TABLE tmp_pg_description;\n\n");
1621  PG_CMD_PUTS("DROP TABLE tmp_pg_shdescription;\n\n");
1622 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
static char * desc_file
Definition: initdb.c:150
#define PG_CMD_PRINTF1(fmt, arg1)
Definition: initdb.c:306
static char * escape_quotes(const char *src)
Definition: initdb.c:325
static char * shdesc_file
Definition: initdb.c:151
static void setup_dictionary ( FILE *  cmdfd)
static

Definition at line 1660 of file initdb.c.

References dictionary_file, free, NULL, PG_CMD_PUTS, and readfile().

Referenced by initialize_data_directory().

1661 {
1662  char **line;
1663  char **conv_lines;
1664 
1665  conv_lines = readfile(dictionary_file);
1666  for (line = conv_lines; *line != NULL; line++)
1667  {
1668  PG_CMD_PUTS(*line);
1669  free(*line);
1670  }
1671 
1672  free(conv_lines);
1673 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
static char * dictionary_file
Definition: initdb.c:156
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char ** readfile(const char *path)
Definition: initdb.c:428
void setup_locale_encoding ( void  )

Definition at line 2438 of file initdb.c.

References _, check_locale_encoding(), encoding, encodingid, encodingid_to_string(), get_encoding_id(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, pg_encoding_to_char(), pg_get_encoding_from_locale(), PG_UTF8, pg_valid_server_encoding_id(), progname, and setlocales().

Referenced by main().

2439 {
2440  int user_enc;
2441 
2442  setlocales();
2443 
2444  if (strcmp(lc_ctype, lc_collate) == 0 &&
2445  strcmp(lc_ctype, lc_time) == 0 &&
2446  strcmp(lc_ctype, lc_numeric) == 0 &&
2447  strcmp(lc_ctype, lc_monetary) == 0 &&
2448  strcmp(lc_ctype, lc_messages) == 0)
2449  printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
2450  else
2451  {
2452  printf(_("The database cluster will be initialized with locales\n"
2453  " COLLATE: %s\n"
2454  " CTYPE: %s\n"
2455  " MESSAGES: %s\n"
2456  " MONETARY: %s\n"
2457  " NUMERIC: %s\n"
2458  " TIME: %s\n"),
2459  lc_collate,
2460  lc_ctype,
2461  lc_messages,
2462  lc_monetary,
2463  lc_numeric,
2464  lc_time);
2465  }
2466 
2467  if (strlen(encoding) == 0)
2468  {
2469  int ctype_enc;
2470 
2471  ctype_enc = pg_get_encoding_from_locale(lc_ctype, true);
2472 
2473  if (ctype_enc == -1)
2474  {
2475  /* Couldn't recognize the locale's codeset */
2476  fprintf(stderr, _("%s: could not find suitable encoding for locale \"%s\"\n"),
2477  progname, lc_ctype);
2478  fprintf(stderr, _("Rerun %s with the -E option.\n"), progname);
2479  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
2480  progname);
2481  exit(1);
2482  }
2483  else if (!pg_valid_server_encoding_id(ctype_enc))
2484  {
2485  /*
2486  * We recognized it, but it's not a legal server encoding. On
2487  * Windows, UTF-8 works with any locale, so we can fall back to
2488  * UTF-8.
2489  */
2490 #ifdef WIN32
2491  printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2492  "The default database encoding will be set to \"%s\" instead.\n"),
2493  pg_encoding_to_char(ctype_enc),
2495  ctype_enc = PG_UTF8;
2496  encodingid = encodingid_to_string(ctype_enc);
2497 #else
2498  fprintf(stderr,
2499  _("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
2500  progname, lc_ctype, pg_encoding_to_char(ctype_enc));
2501  fprintf(stderr,
2502  _("Encoding \"%s\" is not allowed as a server-side encoding.\n"
2503  "Rerun %s with a different locale selection.\n"),
2504  pg_encoding_to_char(ctype_enc), progname);
2505  exit(1);
2506 #endif
2507  }
2508  else
2509  {
2510  encodingid = encodingid_to_string(ctype_enc);
2511  printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2512  pg_encoding_to_char(ctype_enc));
2513  }
2514  }
2515  else
2517 
2518  user_enc = atoi(encodingid);
2519  if (!check_locale_encoding(lc_ctype, user_enc) ||
2520  !check_locale_encoding(lc_collate, user_enc))
2521  exit(1); /* check_locale_encoding printed the error */
2522 
2523 }
static char * lc_monetary
Definition: initdb.c:126
static char * lc_collate
Definition: initdb.c:124
static char * encodingid_to_string(int enc)
Definition: initdb.c:628
int pg_valid_server_encoding_id(int encoding)
Definition: encnames.c:515
static char * encodingid
Definition: initdb.c:148
static char * lc_time
Definition: initdb.c:128
static char * lc_messages
Definition: initdb.c:129
static bool check_locale_encoding(const char *locale, int encoding)
Definition: initdb.c:2169
static char * lc_ctype
Definition: initdb.c:125
static char * lc_numeric
Definition: initdb.c:127
static const char * progname
Definition: initdb.c:147
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:433
static char * get_encoding_id(char *encoding_name)
Definition: initdb.c:640
static char * encoding
Definition: initdb.c:122
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
static void setlocales(void)
Definition: initdb.c:2205
#define _(x)
Definition: elog.c:84
void setup_pgdata ( void  )

Definition at line 2350 of file initdb.c.

References _, canonicalize_path(), pg_data, pg_strdup(), pgdata_native, progname, psprintf(), and putenv.

Referenced by main().

2351 {
2352  char *pgdata_get_env,
2353  *pgdata_set_env;
2354 
2355  if (strlen(pg_data) == 0)
2356  {
2357  pgdata_get_env = getenv("PGDATA");
2358  if (pgdata_get_env && strlen(pgdata_get_env))
2359  {
2360  /* PGDATA found */
2361  pg_data = pg_strdup(pgdata_get_env);
2362  }
2363  else
2364  {
2365  fprintf(stderr,
2366  _("%s: no data directory specified\n"
2367  "You must identify the directory where the data for this database system\n"
2368  "will reside. Do this with either the invocation option -D or the\n"
2369  "environment variable PGDATA.\n"),
2370  progname);
2371  exit(1);
2372  }
2373  }
2374 
2377 
2378  /*
2379  * we have to set PGDATA for postgres rather than pass it on the command
2380  * line to avoid dumb quoting problems on Windows, and we would especially
2381  * need quotes otherwise on Windows because paths there are most likely to
2382  * have embedded spaces.
2383  */
2384  pgdata_set_env = psprintf("PGDATA=%s", pg_data);
2385  putenv(pgdata_set_env);
2386 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void canonicalize_path(char *path)
Definition: path.c:254
static char * pgdata_native
Definition: initdb.c:168
#define putenv(x)
Definition: win32.h:411
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * pg_data
Definition: initdb.c:121
static const char * progname
Definition: initdb.c:147
#define _(x)
Definition: elog.c:84
static void setup_privileges ( FILE *  cmdfd)
static

Definition at line 1695 of file initdb.c.

References BOOTSTRAP_SUPERUSERID, CppAsString2, escape_quotes(), NULL, PG_CMD_PUTS, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, replace_token(), and username.

Referenced by initialize_data_directory().

1696 {
1697  char **line;
1698  char **priv_lines;
1699  static char *privileges_setup[] = {
1700  "UPDATE pg_class "
1701  " SET relacl = (SELECT array_agg(a.acl) FROM "
1702  " (SELECT E'=r/\"$POSTGRES_SUPERUSERNAME\"' as acl "
1703  " UNION SELECT unnest(pg_catalog.acldefault("
1704  " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
1705  " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
1706  " ) as a) "
1707  " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1710  " AND relacl IS NULL;\n\n",
1711  "GRANT USAGE ON SCHEMA pg_catalog TO PUBLIC;\n\n",
1712  "GRANT CREATE, USAGE ON SCHEMA public TO PUBLIC;\n\n",
1713  "REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n",
1714  "INSERT INTO pg_init_privs "
1715  " (objoid, classoid, objsubid, initprivs, privtype)"
1716  " SELECT"
1717  " oid,"
1718  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1719  " 0,"
1720  " relacl,"
1721  " 'i'"
1722  " FROM"
1723  " pg_class"
1724  " WHERE"
1725  " relacl IS NOT NULL"
1726  " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1729  "INSERT INTO pg_init_privs "
1730  " (objoid, classoid, objsubid, initprivs, privtype)"
1731  " SELECT"
1732  " pg_class.oid,"
1733  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1734  " pg_attribute.attnum,"
1735  " pg_attribute.attacl,"
1736  " 'i'"
1737  " FROM"
1738  " pg_class"
1739  " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1740  " WHERE"
1741  " pg_attribute.attacl IS NOT NULL"
1742  " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1745  "INSERT INTO pg_init_privs "
1746  " (objoid, classoid, objsubid, initprivs, privtype)"
1747  " SELECT"
1748  " oid,"
1749  " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1750  " 0,"
1751  " proacl,"
1752  " 'i'"
1753  " FROM"
1754  " pg_proc"
1755  " WHERE"
1756  " proacl IS NOT NULL;",
1757  "INSERT INTO pg_init_privs "
1758  " (objoid, classoid, objsubid, initprivs, privtype)"
1759  " SELECT"
1760  " oid,"
1761  " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1762  " 0,"
1763  " typacl,"
1764  " 'i'"
1765  " FROM"
1766  " pg_type"
1767  " WHERE"
1768  " typacl IS NOT NULL;",
1769  "INSERT INTO pg_init_privs "
1770  " (objoid, classoid, objsubid, initprivs, privtype)"
1771  " SELECT"
1772  " oid,"
1773  " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1774  " 0,"
1775  " lanacl,"
1776  " 'i'"
1777  " FROM"
1778  " pg_language"
1779  " WHERE"
1780  " lanacl IS NOT NULL;",
1781  "INSERT INTO pg_init_privs "
1782  " (objoid, classoid, objsubid, initprivs, privtype)"
1783  " SELECT"
1784  " oid,"
1785  " (SELECT oid FROM pg_class WHERE "
1786  " relname = 'pg_largeobject_metadata'),"
1787  " 0,"
1788  " lomacl,"
1789  " 'i'"
1790  " FROM"
1791  " pg_largeobject_metadata"
1792  " WHERE"
1793  " lomacl IS NOT NULL;",
1794  "INSERT INTO pg_init_privs "
1795  " (objoid, classoid, objsubid, initprivs, privtype)"
1796  " SELECT"
1797  " oid,"
1798  " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1799  " 0,"
1800  " nspacl,"
1801  " 'i'"
1802  " FROM"
1803  " pg_namespace"
1804  " WHERE"
1805  " nspacl IS NOT NULL;",
1806  "INSERT INTO pg_init_privs "
1807  " (objoid, classoid, objsubid, initprivs, privtype)"
1808  " SELECT"
1809  " oid,"
1810  " (SELECT oid FROM pg_class WHERE "
1811  " relname = 'pg_foreign_data_wrapper'),"
1812  " 0,"
1813  " fdwacl,"
1814  " 'i'"
1815  " FROM"
1816  " pg_foreign_data_wrapper"
1817  " WHERE"
1818  " fdwacl IS NOT NULL;",
1819  "INSERT INTO pg_init_privs "
1820  " (objoid, classoid, objsubid, initprivs, privtype)"
1821  " SELECT"
1822  " oid,"
1823  " (SELECT oid FROM pg_class "
1824  " WHERE relname = 'pg_foreign_server'),"
1825  " 0,"
1826  " srvacl,"
1827  " 'i'"
1828  " FROM"
1829  " pg_foreign_server"
1830  " WHERE"
1831  " srvacl IS NOT NULL;",
1832  NULL
1833  };
1834 
1835  priv_lines = replace_token(privileges_setup, "$POSTGRES_SUPERUSERNAME",
1837  for (line = priv_lines; *line != NULL; line++)
1838  PG_CMD_PUTS(*line);
1839 }
static char ** replace_token(char **lines, const char *token, const char *replacement)
Definition: initdb.c:345
#define RELKIND_MATVIEW
Definition: pg_class.h:165
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define CppAsString2(x)
Definition: c.h:162
static char * username
Definition: initdb.c:131
#define NULL
Definition: c.h:229
#define BOOTSTRAP_SUPERUSERID
Definition: pg_authid.h:108
static char * escape_quotes(const char *src)
Definition: initdb.c:325
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
static void setup_schema ( FILE *  cmdfd)
static

Definition at line 1873 of file initdb.c.

References escape_quotes(), features_file, free, info_schema_file, infoversion, NULL, PG_CMD_PRINTF1, PG_CMD_PUTS, and readfile().

Referenced by initialize_data_directory().

1874 {
1875  char **line;
1876  char **lines;
1877 
1878  lines = readfile(info_schema_file);
1879 
1880  for (line = lines; *line != NULL; line++)
1881  {
1882  PG_CMD_PUTS(*line);
1883  free(*line);
1884  }
1885 
1886  free(lines);
1887 
1888  PG_CMD_PRINTF1("UPDATE information_schema.sql_implementation_info "
1889  " SET character_value = '%s' "
1890  " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
1891  infoversion);
1892 
1893  PG_CMD_PRINTF1("COPY information_schema.sql_features "
1894  " (feature_id, feature_name, sub_feature_id, "
1895  " sub_feature_name, is_supported, comments) "
1896  " FROM E'%s';\n\n",
1898 }
static char infoversion[100]
Definition: initdb.c:164
static char * features_file
Definition: initdb.c:158
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define PG_CMD_PRINTF1(fmt, arg1)
Definition: initdb.c:306
static char * info_schema_file
Definition: initdb.c:157
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char * escape_quotes(const char *src)
Definition: initdb.c:325
static char ** readfile(const char *path)
Definition: initdb.c:428
void setup_signals ( void  )

Definition at line 2610 of file initdb.c.

References pqsignal(), SIG_IGN, SIGHUP, SIGPIPE, SIGQUIT, and trapsig().

Referenced by initialize_data_directory().

2611 {
2612  /* some of these are not valid on Windows */
2613 #ifdef SIGHUP
2615 #endif
2616 #ifdef SIGINT
2617  pqsignal(SIGINT, trapsig);
2618 #endif
2619 #ifdef SIGQUIT
2621 #endif
2622 #ifdef SIGTERM
2623  pqsignal(SIGTERM, trapsig);
2624 #endif
2625 
2626  /* Ignore SIGPIPE when writing to backend, so we can clean up */
2627 #ifdef SIGPIPE
2629 #endif
2630 
2631  /* Prevent SIGSYS so we can probe for kernel calls that might not work */
2632 #ifdef SIGSYS
2633  pqsignal(SIGSYS, SIG_IGN);
2634 #endif
2635 }
#define SIGQUIT
Definition: win32.h:189
#define SIG_IGN
Definition: win32.h:185
#define SIGPIPE
Definition: win32.h:193
#define SIGHUP
Definition: win32.h:188
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
static void trapsig(int signum)
Definition: initdb.c:1997
static void setup_sysviews ( FILE *  cmdfd)
static

Definition at line 1554 of file initdb.c.

References free, NULL, PG_CMD_PUTS, readfile(), and system_views_file.

Referenced by initialize_data_directory().

1555 {
1556  char **line;
1557  char **sysviews_setup;
1558 
1559  sysviews_setup = readfile(system_views_file);
1560 
1561  for (line = sysviews_setup; *line != NULL; line++)
1562  {
1563  PG_CMD_PUTS(*line);
1564  free(*line);
1565  }
1566 
1567  free(sysviews_setup);
1568 }
static char * system_views_file
Definition: initdb.c:159
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char ** readfile(const char *path)
Definition: initdb.c:428
void setup_text_search ( void  )

Definition at line 2575 of file initdb.c.

References _, default_text_search_config, find_matching_ts_config(), lc_ctype, NULL, and progname.

Referenced by main().

2576 {
2577  if (strlen(default_text_search_config) == 0)
2578  {
2581  {
2582  printf(_("%s: could not find suitable text search configuration for locale \"%s\"\n"),
2583  progname, lc_ctype);
2584  default_text_search_config = "simple";
2585  }
2586  }
2587  else
2588  {
2589  const char *checkmatch = find_matching_ts_config(lc_ctype);
2590 
2591  if (checkmatch == NULL)
2592  {
2593  printf(_("%s: warning: suitable text search configuration for locale \"%s\" is unknown\n"),
2594  progname, lc_ctype);
2595  }
2596  else if (strcmp(checkmatch, default_text_search_config) != 0)
2597  {
2598  printf(_("%s: warning: specified text search configuration \"%s\" might not match locale \"%s\"\n"),
2600  }
2601  }
2602 
2603  printf(_("The default text search configuration will be set to \"%s\".\n"),
2605 
2606 }
static const char * find_matching_ts_config(const char *lc_type)
Definition: initdb.c:705
static const char * default_text_search_config
Definition: initdb.c:130
static char * lc_ctype
Definition: initdb.c:125
static const char * progname
Definition: initdb.c:147
#define NULL
Definition: c.h:229
#define _(x)
Definition: elog.c:84
static void test_config_settings ( void  )
static

Definition at line 906 of file initdb.c.

References _, backend_exec, boot_options, choose_dsm_implementation(), DEVNULL, dynamic_shared_memory_type, i, MAXPGPATH, MIN_BUFS_FOR_CONNS, n_buffers, n_connections, snprintf(), and status().

Referenced by initialize_data_directory().

907 {
908  /*
909  * This macro defines the minimum shared_buffers we want for a given
910  * max_connections value. The arrays show the settings to try.
911  */
912 #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
913 
914  static const int trial_conns[] = {
915  100, 50, 40, 30, 20, 10
916  };
917  static const int trial_bufs[] = {
918  16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
919  1000, 900, 800, 700, 600, 500,
920  400, 300, 200, 100, 50
921  };
922 
923  char cmd[MAXPGPATH];
924  const int connslen = sizeof(trial_conns) / sizeof(int);
925  const int bufslen = sizeof(trial_bufs) / sizeof(int);
926  int i,
927  status,
928  test_conns,
929  test_buffs,
930  ok_buffers = 0;
931 
932 
933  printf(_("selecting default max_connections ... "));
934  fflush(stdout);
935 
936  for (i = 0; i < connslen; i++)
937  {
938  test_conns = trial_conns[i];
939  test_buffs = MIN_BUFS_FOR_CONNS(test_conns);
940 
941  snprintf(cmd, sizeof(cmd),
942  "\"%s\" --boot -x0 %s "
943  "-c max_connections=%d "
944  "-c shared_buffers=%d "
945  "-c dynamic_shared_memory_type=none "
946  "< \"%s\" > \"%s\" 2>&1",
948  test_conns, test_buffs,
949  DEVNULL, DEVNULL);
950  status = system(cmd);
951  if (status == 0)
952  {
953  ok_buffers = test_buffs;
954  break;
955  }
956  }
957  if (i >= connslen)
958  i = connslen - 1;
959  n_connections = trial_conns[i];
960 
961  printf("%d\n", n_connections);
962 
963  printf(_("selecting default shared_buffers ... "));
964  fflush(stdout);
965 
966  for (i = 0; i < bufslen; i++)
967  {
968  /* Use same amount of memory, independent of BLCKSZ */
969  test_buffs = (trial_bufs[i] * 8192) / BLCKSZ;
970  if (test_buffs <= ok_buffers)
971  {
972  test_buffs = ok_buffers;
973  break;
974  }
975 
976  snprintf(cmd, sizeof(cmd),
977  "\"%s\" --boot -x0 %s "
978  "-c max_connections=%d "
979  "-c shared_buffers=%d "
980  "-c dynamic_shared_memory_type=none "
981  "< \"%s\" > \"%s\" 2>&1",
983  n_connections, test_buffs,
984  DEVNULL, DEVNULL);
985  status = system(cmd);
986  if (status == 0)
987  break;
988  }
989  n_buffers = test_buffs;
990 
991  if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
992  printf("%dMB\n", (n_buffers * (BLCKSZ / 1024)) / 1024);
993  else
994  printf("%dkB\n", n_buffers * (BLCKSZ / 1024));
995 
996  printf(_("selecting dynamic shared memory implementation ... "));
997  fflush(stdout);
999  printf("%s\n", dynamic_shared_memory_type);
1000 }
#define MIN_BUFS_FOR_CONNS(nconns)
static char * choose_dsm_implementation(void)
Definition: initdb.c:866
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static int n_connections
Definition: initdb.c:171
#define MAXPGPATH
#define DEVNULL
Definition: port.h:116
static const char * boot_options
Definition: initdb.c:195
static int n_buffers
Definition: initdb.c:172
int i
static char backend_exec[MAXPGPATH]
Definition: initdb.c:226
static char * dynamic_shared_memory_type
Definition: initdb.c:173
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#define _(x)
Definition: elog.c:84
static void trapsig ( int  signum)
static

Definition at line 1997 of file initdb.c.

References caught_signal, and pqsignal().

Referenced by setup_signals().

1998 {
1999  /* handle systems that reset the handler, like Windows (grr) */
2000  pqsignal(signum, trapsig);
2001  caught_signal = true;
2002 }
static bool caught_signal
Definition: initdb.c:165
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
static void trapsig(int signum)
Definition: initdb.c:1997
static void usage ( const char *  progname)
static

Definition at line 2256 of file initdb.c.

References _.

Referenced by main().

2257 {
2258  printf(_("%s initializes a PostgreSQL database cluster.\n\n"), progname);
2259  printf(_("Usage:\n"));
2260  printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
2261  printf(_("\nOptions:\n"));
2262  printf(_(" -A, --auth=METHOD default authentication method for local connections\n"));
2263  printf(_(" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
2264  printf(_(" --auth-local=METHOD default authentication method for local-socket connections\n"));
2265  printf(_(" [-D, --pgdata=]DATADIR location for this database cluster\n"));
2266  printf(_(" -E, --encoding=ENCODING set default encoding for new databases\n"));
2267  printf(_(" --locale=LOCALE set default locale for new databases\n"));
2268  printf(_(" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
2269  " --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
2270  " set default locale in the respective category for\n"
2271  " new databases (default taken from environment)\n"));
2272  printf(_(" --no-locale equivalent to --locale=C\n"));
2273  printf(_(" --pwfile=FILE read password for the new superuser from file\n"));
2274  printf(_(" -T, --text-search-config=CFG\n"
2275  " default text search configuration\n"));
2276  printf(_(" -U, --username=NAME database superuser name\n"));
2277  printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
2278  printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
2279  printf(_("\nLess commonly used options:\n"));
2280  printf(_(" -d, --debug generate lots of debugging output\n"));
2281  printf(_(" -k, --data-checksums use data page checksums\n"));
2282  printf(_(" -L DIRECTORY where to find the input files\n"));
2283  printf(_(" -n, --no-clean do not clean up after errors\n"));
2284  printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
2285  printf(_(" -s, --show show internal settings\n"));
2286  printf(_(" -S, --sync-only only sync data directory\n"));
2287  printf(_("\nOther options:\n"));
2288  printf(_(" -V, --version output version information, then exit\n"));
2289  printf(_(" -?, --help show this help, then exit\n"));
2290  printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"
2291  "is used.\n"));
2292  printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
2293 }
static const char * progname
Definition: initdb.c:147
#define _(x)
Definition: elog.c:84
static void vacuum_db ( FILE *  cmdfd)
static

Definition at line 1913 of file initdb.c.

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

1914 {
1915  /* Run analyze before VACUUM so the statistics are frozen. */
1916  PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
1917 }
#define PG_CMD_PUTS(line)
Definition: initdb.c:300
void warn_on_mount_point ( int  error)

Definition at line 2818 of file initdb.c.

References _.

Referenced by create_data_directory(), and create_xlog_or_symlink().

2819 {
2820  if (error == 2)
2821  fprintf(stderr,
2822  _("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.\n"));
2823  else if (error == 3)
2824  fprintf(stderr,
2825  _("It contains a lost+found directory, perhaps due to it being a mount point.\n"));
2826 
2827  fprintf(stderr,
2828  _("Using a mount point directly as the data directory is not recommended.\n"
2829  "Create a subdirectory under the mount point.\n"));
2830 }
static void error(void)
Definition: sql-dyntest.c:147
#define _(x)
Definition: elog.c:84
static void write_version_file ( char *  extrapath)
static

Definition at line 801 of file initdb.c.

References _, exit_nicely(), free, NULL, PG_BINARY_W, pg_data, progname, psprintf(), strerror(), and version_file.

Referenced by initialize_data_directory().

802 {
803  FILE *version_file;
804  char *path;
805 
806  if (extrapath == NULL)
807  path = psprintf("%s/PG_VERSION", pg_data);
808  else
809  path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
810 
811  if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
812  {
813  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
814  progname, path, strerror(errno));
815  exit_nicely();
816  }
817  if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
818  fclose(version_file))
819  {
820  fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
821  progname, path, strerror(errno));
822  exit_nicely();
823  }
824  free(path);
825 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define PG_BINARY_W
Definition: c.h:1041
static void exit_nicely(void)
Definition: initdb.c:542
static char * pg_data
Definition: initdb.c:121
static const char * progname
Definition: initdb.c:147
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
const char * strerror(int errnum)
Definition: strerror.c:19
static char version_file[MAXPGPATH]
Definition: pg_ctl.c:94
#define _(x)
Definition: elog.c:84
static void writefile ( char *  path,
char **  lines 
)
static

Definition at line 490 of file initdb.c.

References _, exit_nicely(), free, NULL, progname, and strerror().

Referenced by setup_config().

491 {
492  FILE *out_file;
493  char **line;
494 
495  if ((out_file = fopen(path, "w")) == NULL)
496  {
497  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
498  progname, path, strerror(errno));
499  exit_nicely();
500  }
501  for (line = lines; *line != NULL; line++)
502  {
503  if (fputs(*line, out_file) < 0)
504  {
505  fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
506  progname, path, strerror(errno));
507  exit_nicely();
508  }
509  free(*line);
510  }
511  if (fclose(out_file))
512  {
513  fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
514  progname, path, strerror(errno));
515  exit_nicely();
516  }
517 }
static void exit_nicely(void)
Definition: initdb.c:542
static const char * progname
Definition: initdb.c:147
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84

Variable Documentation

const char* const auth_methods_host[]
static
Initial value:
= {
"trust", "reject", "scram-sha-256", "md5", "password", "ident", "radius",
}
#define NULL
Definition: c.h:229

Definition at line 79 of file initdb.c.

Referenced by main().

const char* const auth_methods_local[]
static
Initial value:
= {
"trust", "reject", "scram-sha-256", "md5", "password", "peer", "radius",
}
#define NULL
Definition: c.h:229

Definition at line 101 of file initdb.c.

Referenced by main().

const char* authmethodhost = ""
static

Definition at line 135 of file initdb.c.

Referenced by main(), and setup_config().

const char* authmethodlocal = ""
static

Definition at line 136 of file initdb.c.

Referenced by main(), and setup_config().

char* authwarning = NULL
static

Definition at line 183 of file initdb.c.

Referenced by check_authmethod_unspecified(), and main().

char backend_exec[MAXPGPATH]
static
const char* backend_options = "--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true"
static

Definition at line 196 of file initdb.c.

Referenced by initialize_data_directory().

char bin_path[MAXPGPATH]
static

Definition at line 225 of file initdb.c.

Referenced by setup_bin_paths(), and setup_data_file_paths().

char* bki_file
static

Definition at line 149 of file initdb.c.

Referenced by bootstrap_template1(), and setup_data_file_paths().

const char* boot_options = "-F"
static

Definition at line 195 of file initdb.c.

Referenced by bootstrap_template1(), and test_config_settings().

bool caught_signal = false
static

Definition at line 165 of file initdb.c.

Referenced by check_ok(), and trapsig().

char* conf_file
static

Definition at line 154 of file initdb.c.

Referenced by set_null_conf(), setup_config(), and setup_data_file_paths().

char* conversion_file
static

Definition at line 155 of file initdb.c.

Referenced by setup_conversion(), and setup_data_file_paths().

bool data_checksums = false
static

Definition at line 142 of file initdb.c.

Referenced by bootstrap_template1(), and main().

bool debug = false
static

Definition at line 137 of file initdb.c.

Referenced by bootstrap_template1(), main(), and setup_data_file_paths().

const char* default_text_search_config = ""
static

Definition at line 130 of file initdb.c.

Referenced by main(), setup_config(), and setup_text_search().

char* desc_file
static

Definition at line 150 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_description().

char* dictionary_file
static

Definition at line 156 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_dictionary().

bool do_sync = true
static

Definition at line 139 of file initdb.c.

Referenced by main().

char* dynamic_shared_memory_type = NULL
static

Definition at line 173 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

char* encodingid = "0"
static

Definition at line 148 of file initdb.c.

Referenced by bootstrap_template1(), and setup_locale_encoding().

char* features_file
static

Definition at line 158 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_schema().

bool found_existing_pgdata = false
static

Definition at line 161 of file initdb.c.

Referenced by create_data_directory(), and exit_nicely().

bool found_existing_xlogdir = false
static

Definition at line 163 of file initdb.c.

Referenced by create_xlog_or_symlink(), and exit_nicely().

char* hba_file
static

Definition at line 152 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

char* ident_file
static

Definition at line 153 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

char* info_schema_file
static

Definition at line 157 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_schema().

char infoversion[100]
static

Definition at line 164 of file initdb.c.

Referenced by set_info_version(), and setup_schema().

char* lc_collate = ""
static
char* lc_ctype = ""
static
char* lc_messages = ""
static

Definition at line 129 of file initdb.c.

Referenced by get_control_data(), main(), setlocales(), setup_config(), and setup_locale_encoding().

char* lc_monetary = ""
static

Definition at line 126 of file initdb.c.

Referenced by get_control_data(), main(), setlocales(), setup_config(), and setup_locale_encoding().

char* lc_numeric = ""
static

Definition at line 127 of file initdb.c.

Referenced by get_control_data(), main(), setlocales(), setup_config(), and setup_locale_encoding().

char* lc_time = ""
static

Definition at line 128 of file initdb.c.

Referenced by get_control_data(), main(), setlocales(), setup_config(), and setup_locale_encoding().

char* locale = ""
static
bool made_new_pgdata = false
static

Definition at line 160 of file initdb.c.

Referenced by create_data_directory(), and exit_nicely().

bool made_new_xlogdir = false
static

Definition at line 162 of file initdb.c.

Referenced by create_xlog_or_symlink(), and exit_nicely().

int n_buffers = 50
static

Definition at line 172 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

int n_connections = 10
static

Definition at line 171 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

bool noclean = false
static

Definition at line 138 of file initdb.c.

Referenced by exit_nicely(), and main().

int output_errno = 0
static

Definition at line 167 of file initdb.c.

Referenced by check_ok().

bool output_failed = false
static

Definition at line 166 of file initdb.c.

Referenced by check_ok().

char* pgdata_native
static

Definition at line 168 of file initdb.c.

Referenced by main(), and setup_pgdata().

char* pwfilename = NULL
static

Definition at line 133 of file initdb.c.

Referenced by check_need_password(), get_su_pwd(), and main().

bool pwprompt = false
static

Definition at line 132 of file initdb.c.

Referenced by check_need_password(), get_su_pwd(), and main().

char* share_path = NULL
static
char* shdesc_file
static

Definition at line 151 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_description().

bool show_setting = false
static

Definition at line 141 of file initdb.c.

Referenced by main(), and setup_data_file_paths().

const char* const subdirs[]
static
Initial value:
= {
"global",
"pg_wal/archive_status",
"pg_commit_ts",
"pg_dynshmem",
"pg_notify",
"pg_serial",
"pg_snapshots",
"pg_subtrans",
"pg_twophase",
"pg_multixact",
"pg_multixact/members",
"pg_multixact/offsets",
"base",
"base/1",
"pg_replslot",
"pg_tblspc",
"pg_stat",
"pg_stat_tmp",
"pg_xact",
"pg_logical",
"pg_logical/snapshots",
"pg_logical/mappings"
}

Definition at line 198 of file initdb.c.

Referenced by initialize_data_directory().

char* superuser_password = NULL
static

Definition at line 134 of file initdb.c.

Referenced by get_su_pwd(), and setup_auth().

bool sync_only = false
static

Definition at line 140 of file initdb.c.

Referenced by main().

char* system_views_file
static

Definition at line 159 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_sysviews().

const struct tsearch_config_match tsearch_config_languages[]
static

Definition at line 664 of file initdb.c.

char* xlog_dir = ""
static

Definition at line 143 of file initdb.c.

Referenced by create_xlog_or_symlink(), exit_nicely(), and main().