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:2023
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 2311 of file initdb.c.

References _, authwarning, and NULL.

Referenced by main().

2312 {
2313  if (*authmethod == NULL || strlen(*authmethod) == 0)
2314  {
2315  authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections\n"
2316  "You can change this by editing pg_hba.conf or using the option -A, or\n"
2317  "--auth-local and --auth-host, the next time you run initdb.\n");
2318  *authmethod = "trust";
2319  }
2320 }
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 2323 of file initdb.c.

References _, and progname.

Referenced by main().

2324 {
2325  const char *const *p;
2326 
2327  for (p = valid_methods; *p; p++)
2328  {
2329  if (strcmp(authmethod, *p) == 0)
2330  return;
2331  /* with space = param */
2332  if (strchr(authmethod, ' '))
2333  if (strncmp(authmethod, *p, (authmethod - strchr(authmethod, ' '))) == 0)
2334  return;
2335  }
2336 
2337  fprintf(stderr, _("%s: invalid authentication method \"%s\" for \"%s\" connections\n"),
2338  progname, authmethod, conntype);
2339  exit(1);
2340 }
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 2184 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().

2185 {
2186  int locale_enc;
2187 
2188  locale_enc = pg_get_encoding_from_locale(locale, true);
2189 
2190  /* See notes in createdb() to understand these tests */
2191  if (!(locale_enc == user_enc ||
2192  locale_enc == PG_SQL_ASCII ||
2193  locale_enc == -1 ||
2194 #ifdef WIN32
2195  user_enc == PG_UTF8 ||
2196 #endif
2197  user_enc == PG_SQL_ASCII))
2198  {
2199  fprintf(stderr, _("%s: encoding mismatch\n"), progname);
2200  fprintf(stderr,
2201  _("The encoding you selected (%s) and the encoding that the\n"
2202  "selected locale uses (%s) do not match. This would lead to\n"
2203  "misbehavior in various character string processing functions.\n"
2204  "Rerun %s and either do not specify an encoding explicitly,\n"
2205  "or choose a matching combination.\n"),
2206  pg_encoding_to_char(user_enc),
2207  pg_encoding_to_char(locale_enc),
2208  progname);
2209  return false;
2210  }
2211  return true;
2212 }
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 2120 of file initdb.c.

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

Referenced by setlocales().

2121 {
2122  char *save;
2123  char *res;
2124 
2125  if (canonname)
2126  *canonname = NULL; /* in case of failure */
2127 
2128  save = setlocale(category, NULL);
2129  if (!save)
2130  {
2131  fprintf(stderr, _("%s: setlocale() failed\n"),
2132  progname);
2133  exit(1);
2134  }
2135 
2136  /* save may be pointing at a modifiable scratch variable, so copy it. */
2137  save = pg_strdup(save);
2138 
2139  /* set the locale with setlocale, to see if it accepts it. */
2140  res = setlocale(category, locale);
2141 
2142  /* save canonical name if requested. */
2143  if (res && canonname)
2144  *canonname = pg_strdup(res);
2145 
2146  /* restore old value. */
2147  if (!setlocale(category, save))
2148  {
2149  fprintf(stderr, _("%s: failed to restore old locale \"%s\"\n"),
2150  progname, save);
2151  exit(1);
2152  }
2153  free(save);
2154 
2155  /* complain if locale wasn't valid */
2156  if (res == NULL)
2157  {
2158  if (*locale)
2159  fprintf(stderr, _("%s: invalid locale name \"%s\"\n"),
2160  progname, locale);
2161  else
2162  {
2163  /*
2164  * If no relevant switch was given on command line, locale is an
2165  * empty string, which is not too helpful to report. Presumably
2166  * setlocale() found something it did not like in the environment.
2167  * Ideally we'd report the bad environment variable, but since
2168  * setlocale's behavior is implementation-specific, it's hard to
2169  * be sure what it didn't like. Print a safe generic message.
2170  */
2171  fprintf(stderr, _("%s: invalid locale settings; check LANG and LC_* environment variables\n"),
2172  progname);
2173  }
2174  exit(1);
2175  }
2176 }
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 2343 of file initdb.c.

References _, progname, pwfilename, and pwprompt.

Referenced by main().

2344 {
2345  if ((strcmp(authmethodlocal, "md5") == 0 ||
2346  strcmp(authmethodlocal, "password") == 0 ||
2347  strcmp(authmethodlocal, "scram-sha-256") == 0) &&
2348  (strcmp(authmethodhost, "md5") == 0 ||
2349  strcmp(authmethodhost, "password") == 0 ||
2350  strcmp(authmethodhost, "scram-sha-256") == 0) &&
2351  !(pwprompt || pwfilename))
2352  {
2353  fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"), progname,
2354  (strcmp(authmethodlocal, "md5") == 0 ||
2355  strcmp(authmethodlocal, "password") == 0 ||
2356  strcmp(authmethodlocal, "scram-sha-256") == 0)
2357  ? authmethodlocal
2358  : authmethodhost);
2359  exit(1);
2360  }
2361 }
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 2023 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(), old_9_6_invalidate_hash_indexes(), prepare_new_cluster(), prepare_new_databases(), remove_new_subdir(), set_frozenxids(), setup_config(), and transfer_all_new_tablespaces().

2024 {
2025  if (caught_signal)
2026  {
2027  printf(_("caught signal\n"));
2028  fflush(stdout);
2029  exit_nicely();
2030  }
2031  else if (output_failed)
2032  {
2033  printf(_("could not write to child process: %s\n"),
2035  fflush(stdout);
2036  exit_nicely();
2037  }
2038  else
2039  {
2040  /* all seems well */
2041  printf(_("ok\n"));
2042  fflush(stdout);
2043  }
2044 }
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 2654 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().

2655 {
2656  int ret;
2657 
2658  switch ((ret = pg_check_dir(pg_data)))
2659  {
2660  case 0:
2661  /* PGDATA not there, must create it */
2662  printf(_("creating directory %s ... "),
2663  pg_data);
2664  fflush(stdout);
2665 
2666  if (pg_mkdir_p(pg_data, S_IRWXU) != 0)
2667  {
2668  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2669  progname, pg_data, strerror(errno));
2670  exit_nicely();
2671  }
2672  else
2673  check_ok();
2674 
2675  made_new_pgdata = true;
2676  break;
2677 
2678  case 1:
2679  /* Present but empty, fix permissions and use it */
2680  printf(_("fixing permissions on existing directory %s ... "),
2681  pg_data);
2682  fflush(stdout);
2683 
2684  if (chmod(pg_data, S_IRWXU) != 0)
2685  {
2686  fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
2687  progname, pg_data, strerror(errno));
2688  exit_nicely();
2689  }
2690  else
2691  check_ok();
2692 
2693  found_existing_pgdata = true;
2694  break;
2695 
2696  case 2:
2697  case 3:
2698  case 4:
2699  /* Present and not empty */
2700  fprintf(stderr,
2701  _("%s: directory \"%s\" exists but is not empty\n"),
2702  progname, pg_data);
2703  if (ret != 4)
2704  warn_on_mount_point(ret);
2705  else
2706  fprintf(stderr,
2707  _("If you want to create a new database system, either remove or empty\n"
2708  "the directory \"%s\" or run %s\n"
2709  "with an argument other than \"%s\".\n"),
2711  exit(1); /* no further message needed */
2712 
2713  default:
2714  /* Trouble accessing directory */
2715  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
2716  progname, pg_data, strerror(errno));
2717  exit_nicely();
2718  }
2719 }
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
void warn_on_mount_point(int error)
Definition: initdb.c:2833
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:2023
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 2724 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().

2725 {
2726  char *subdirloc;
2727 
2728  /* form name of the place for the subdirectory or symlink */
2729  subdirloc = psprintf("%s/pg_wal", pg_data);
2730 
2731  if (strcmp(xlog_dir, "") != 0)
2732  {
2733  int ret;
2734 
2735  /* clean up xlog directory name, check it's absolute */
2737  if (!is_absolute_path(xlog_dir))
2738  {
2739  fprintf(stderr, _("%s: WAL directory location must be an absolute path\n"), progname);
2740  exit_nicely();
2741  }
2742 
2743  /* check if the specified xlog directory exists/is empty */
2744  switch ((ret = pg_check_dir(xlog_dir)))
2745  {
2746  case 0:
2747  /* xlog directory not there, must create it */
2748  printf(_("creating directory %s ... "),
2749  xlog_dir);
2750  fflush(stdout);
2751 
2752  if (pg_mkdir_p(xlog_dir, S_IRWXU) != 0)
2753  {
2754  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2755  progname, xlog_dir, strerror(errno));
2756  exit_nicely();
2757  }
2758  else
2759  check_ok();
2760 
2761  made_new_xlogdir = true;
2762  break;
2763 
2764  case 1:
2765  /* Present but empty, fix permissions and use it */
2766  printf(_("fixing permissions on existing directory %s ... "),
2767  xlog_dir);
2768  fflush(stdout);
2769 
2770  if (chmod(xlog_dir, S_IRWXU) != 0)
2771  {
2772  fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
2773  progname, xlog_dir, strerror(errno));
2774  exit_nicely();
2775  }
2776  else
2777  check_ok();
2778 
2779  found_existing_xlogdir = true;
2780  break;
2781 
2782  case 2:
2783  case 3:
2784  case 4:
2785  /* Present and not empty */
2786  fprintf(stderr,
2787  _("%s: directory \"%s\" exists but is not empty\n"),
2788  progname, xlog_dir);
2789  if (ret != 4)
2790  warn_on_mount_point(ret);
2791  else
2792  fprintf(stderr,
2793  _("If you want to store the WAL there, either remove or empty the directory\n"
2794  "\"%s\".\n"),
2795  xlog_dir);
2796  exit_nicely();
2797 
2798  default:
2799  /* Trouble accessing directory */
2800  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
2801  progname, xlog_dir, strerror(errno));
2802  exit_nicely();
2803  }
2804 
2805 #ifdef HAVE_SYMLINK
2806  if (symlink(xlog_dir, subdirloc) != 0)
2807  {
2808  fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
2809  progname, subdirloc, strerror(errno));
2810  exit_nicely();
2811  }
2812 #else
2813  fprintf(stderr, _("%s: symlinks are not supported on this platform"));
2814  exit_nicely();
2815 #endif
2816  }
2817  else
2818  {
2819  /* Without -X option, just make the subdirectory normally */
2820  if (mkdir(subdirloc, S_IRWXU) < 0)
2821  {
2822  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2823  progname, subdirloc, strerror(errno));
2824  exit_nicely();
2825  }
2826  }
2827 
2828  free(subdirloc);
2829 }
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
void warn_on_mount_point(int error)
Definition: initdb.c:2833
#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:2023
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:1633
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:1633
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 WAL directory \"%s\"\n"),
567  progname, xlog_dir);
568  if (!rmtree(xlog_dir, true))
569  fprintf(stderr, _("%s: failed to remove WAL directory\n"),
570  progname);
571  }
572  else if (found_existing_xlogdir)
573  {
574  fprintf(stderr,
575  _("%s: removing contents of WAL directory \"%s\"\n"),
576  progname, xlog_dir);
577  if (!rmtree(xlog_dir, false))
578  fprintf(stderr, _("%s: failed to remove contents of WAL 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: WAL 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:1633
#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 2849 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().

2850 {
2851  PG_CMD_DECL;
2852  int i;
2853 
2854  setup_signals();
2855 
2856  umask(S_IRWXG | S_IRWXO);
2857 
2859 
2861 
2862  /* Create required subdirectories (other than pg_wal) */
2863  printf(_("creating subdirectories ... "));
2864  fflush(stdout);
2865 
2866  for (i = 0; i < lengthof(subdirs); i++)
2867  {
2868  char *path;
2869 
2870  path = psprintf("%s/%s", pg_data, subdirs[i]);
2871 
2872  /*
2873  * The parent directory already exists, so we only need mkdir() not
2874  * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
2875  */
2876  if (mkdir(path, S_IRWXU) < 0)
2877  {
2878  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
2879  progname, path, strerror(errno));
2880  exit_nicely();
2881  }
2882 
2883  free(path);
2884  }
2885 
2886  check_ok();
2887 
2888  /* Top level PG_VERSION is checked by bootstrapper, so make it first */
2890 
2891  /* Select suitable configuration settings */
2892  set_null_conf();
2894 
2895  /* Now create all the text config files */
2896  setup_config();
2897 
2898  /* Bootstrap template1 */
2900 
2901  /*
2902  * Make the per-database PG_VERSION for template1 only after init'ing it
2903  */
2904  write_version_file("base/1");
2905 
2906  /*
2907  * Create the stuff we don't need to use bootstrap mode for, using a
2908  * backend running in simple standalone mode.
2909  */
2910  fputs(_("performing post-bootstrap initialization ... "), stdout);
2911  fflush(stdout);
2912 
2913  snprintf(cmd, sizeof(cmd),
2914  "\"%s\" %s template1 >%s",
2916  DEVNULL);
2917 
2918  PG_CMD_OPEN;
2919 
2920  setup_auth(cmdfd);
2921 
2922  setup_depend(cmdfd);
2923 
2924  /*
2925  * Note that no objects created after setup_depend() will be "pinned".
2926  * They are all droppable at the whim of the DBA.
2927  */
2928 
2929  setup_sysviews(cmdfd);
2930 
2931  setup_description(cmdfd);
2932 
2933  setup_collation(cmdfd);
2934 
2935  setup_conversion(cmdfd);
2936 
2937  setup_dictionary(cmdfd);
2938 
2939  setup_privileges(cmdfd);
2940 
2941  setup_schema(cmdfd);
2942 
2943  load_plpgsql(cmdfd);
2944 
2945  vacuum_db(cmdfd);
2946 
2947  make_template0(cmdfd);
2948 
2949  make_postgres(cmdfd);
2950 
2951  PG_CMD_CLOSE;
2952 
2953  check_ok();
2954 }
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:1928
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:1675
void create_xlog_or_symlink(void)
Definition: initdb.c:2724
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:2625
#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:1919
static void setup_description(FILE *cmdfd)
Definition: initdb.c:1583
static char * pg_data
Definition: initdb.c:121
#define DEVNULL
Definition: port.h:119
static void check_ok(void)
Definition: initdb.c:2023
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:2654
#define PG_CMD_CLOSE
Definition: initdb.c:294
static void make_template0(FILE *cmdfd)
Definition: initdb.c:1938
static void setup_conversion(FILE *cmdfd)
Definition: initdb.c:1655
#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:1637
static void setup_schema(FILE *cmdfd)
Definition: initdb.c:1888
#define S_IRWXG
Definition: win32.h:451
static void setup_privileges(FILE *cmdfd)
Definition: initdb.c:1710
static void make_postgres(FILE *cmdfd)
Definition: initdb.c:1976
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:1563
#define _(x)
Definition: elog.c:84
static void load_plpgsql ( FILE *  cmdfd)
static

Definition at line 1919 of file initdb.c.

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

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

Definition at line 2057 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().

2058 {
2059  struct tm testtime;
2060  char buf[128];
2061  char *posD;
2062  char *posM;
2063  char *posY;
2064  char *save;
2065  size_t res;
2066  int result;
2067 
2068  result = DATEORDER_MDY; /* default */
2069 
2070  save = setlocale(LC_TIME, NULL);
2071  if (!save)
2072  return result;
2073  save = pg_strdup(save);
2074 
2075  setlocale(LC_TIME, locale);
2076 
2077  memset(&testtime, 0, sizeof(testtime));
2078  testtime.tm_mday = 22;
2079  testtime.tm_mon = 10; /* November, should come out as "11" */
2080  testtime.tm_year = 133; /* 2033 */
2081 
2082  res = my_strftime(buf, sizeof(buf), "%x", &testtime);
2083 
2084  setlocale(LC_TIME, save);
2085  free(save);
2086 
2087  if (res == 0)
2088  return result;
2089 
2090  posM = strstr(buf, "11");
2091  posD = strstr(buf, "22");
2092  posY = strstr(buf, "33");
2093 
2094  if (!posM || !posD || !posY)
2095  return result;
2096 
2097  if (posY < posM && posM < posD)
2098  result = DATEORDER_YMD;
2099  else if (posD < posM)
2100  result = DATEORDER_DMY;
2101  else
2102  result = DATEORDER_MDY;
2103 
2104  return result;
2105 }
return result
Definition: formatting.c:1633
static struct pg_tm tm
Definition: localtime.c:111
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:217
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
Definition: initdb.c:2048
#define DATEORDER_DMY
Definition: miscadmin.h:218
#define DATEORDER_MDY
Definition: miscadmin.h:219
#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 2958 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.

2959 {
2960  static struct option long_options[] = {
2961  {"pgdata", required_argument, NULL, 'D'},
2962  {"encoding", required_argument, NULL, 'E'},
2963  {"locale", required_argument, NULL, 1},
2964  {"lc-collate", required_argument, NULL, 2},
2965  {"lc-ctype", required_argument, NULL, 3},
2966  {"lc-monetary", required_argument, NULL, 4},
2967  {"lc-numeric", required_argument, NULL, 5},
2968  {"lc-time", required_argument, NULL, 6},
2969  {"lc-messages", required_argument, NULL, 7},
2970  {"no-locale", no_argument, NULL, 8},
2971  {"text-search-config", required_argument, NULL, 'T'},
2972  {"auth", required_argument, NULL, 'A'},
2973  {"auth-local", required_argument, NULL, 10},
2974  {"auth-host", required_argument, NULL, 11},
2975  {"pwprompt", no_argument, NULL, 'W'},
2976  {"pwfile", required_argument, NULL, 9},
2977  {"username", required_argument, NULL, 'U'},
2978  {"help", no_argument, NULL, '?'},
2979  {"version", no_argument, NULL, 'V'},
2980  {"debug", no_argument, NULL, 'd'},
2981  {"show", no_argument, NULL, 's'},
2982  {"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
2983  {"no-clean", no_argument, NULL, 'n'},
2984  {"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
2985  {"no-sync", no_argument, NULL, 'N'},
2986  {"sync-only", no_argument, NULL, 'S'},
2987  {"waldir", required_argument, NULL, 'X'},
2988  {"data-checksums", no_argument, NULL, 'k'},
2989  {NULL, 0, NULL, 0}
2990  };
2991 
2992  /*
2993  * options with no short version return a low integer, the rest return
2994  * their short version value
2995  */
2996  int c;
2997  int option_index;
2998  char *effective_user;
2999  PQExpBuffer start_db_cmd;
3000  char pg_ctl_path[MAXPGPATH];
3001 
3002  /*
3003  * Ensure that buffering behavior of stdout and stderr matches what it is
3004  * in interactive usage (at least on most platforms). This prevents
3005  * unexpected output ordering when, eg, output is redirected to a file.
3006  * POSIX says we must do this before any other usage of these files.
3007  */
3008  setvbuf(stdout, NULL, PG_IOLBF, 0);
3009  setvbuf(stderr, NULL, _IONBF, 0);
3010 
3011  progname = get_progname(argv[0]);
3012  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
3013 
3014  if (argc > 1)
3015  {
3016  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
3017  {
3018  usage(progname);
3019  exit(0);
3020  }
3021  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
3022  {
3023  puts("initdb (PostgreSQL) " PG_VERSION);
3024  exit(0);
3025  }
3026  }
3027 
3028  /* process command-line options */
3029 
3030  while ((c = getopt_long(argc, argv, "dD:E:kL:nNU:WA:sST:X:", long_options, &option_index)) != -1)
3031  {
3032  switch (c)
3033  {
3034  case 'A':
3036 
3037  /*
3038  * When ident is specified, use peer for local connections.
3039  * Mirrored, when peer is specified, use ident for TCP/IP
3040  * connections.
3041  */
3042  if (strcmp(authmethodhost, "ident") == 0)
3043  authmethodlocal = "peer";
3044  else if (strcmp(authmethodlocal, "peer") == 0)
3045  authmethodhost = "ident";
3046  break;
3047  case 10:
3049  break;
3050  case 11:
3052  break;
3053  case 'D':
3055  break;
3056  case 'E':
3058  break;
3059  case 'W':
3060  pwprompt = true;
3061  break;
3062  case 'U':
3064  break;
3065  case 'd':
3066  debug = true;
3067  printf(_("Running in debug mode.\n"));
3068  break;
3069  case 'n':
3070  noclean = true;
3071  printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3072  break;
3073  case 'N':
3074  do_sync = false;
3075  break;
3076  case 'S':
3077  sync_only = true;
3078  break;
3079  case 'k':
3080  data_checksums = true;
3081  break;
3082  case 'L':
3084  break;
3085  case 1:
3086  locale = pg_strdup(optarg);
3087  break;
3088  case 2:
3090  break;
3091  case 3:
3093  break;
3094  case 4:
3096  break;
3097  case 5:
3099  break;
3100  case 6:
3102  break;
3103  case 7:
3105  break;
3106  case 8:
3107  locale = "C";
3108  break;
3109  case 9:
3111  break;
3112  case 's':
3113  show_setting = true;
3114  break;
3115  case 'T':
3117  break;
3118  case 'X':
3120  break;
3121  default:
3122  /* getopt_long already emitted a complaint */
3123  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
3124  progname);
3125  exit(1);
3126  }
3127  }
3128 
3129 
3130  /*
3131  * Non-option argument specifies data directory as long as it wasn't
3132  * already specified with -D / --pgdata
3133  */
3134  if (optind < argc && strlen(pg_data) == 0)
3135  {
3136  pg_data = pg_strdup(argv[optind]);
3137  optind++;
3138  }
3139 
3140  if (optind < argc)
3141  {
3142  fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
3143  progname, argv[optind]);
3144  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
3145  progname);
3146  exit(1);
3147  }
3148 
3149  /* If we only need to fsync, just do it and exit */
3150  if (sync_only)
3151  {
3152  setup_pgdata();
3153 
3154  /* must check that directory is readable */
3155  if (pg_check_dir(pg_data) <= 0)
3156  {
3157  fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
3158  progname, pg_data, strerror(errno));
3159  exit_nicely();
3160  }
3161 
3162  fputs(_("syncing data to disk ... "), stdout);
3163  fflush(stdout);
3164  fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
3165  check_ok();
3166  return 0;
3167  }
3168 
3169  if (pwprompt && pwfilename)
3170  {
3171  fprintf(stderr, _("%s: password prompt and password file cannot be specified together\n"), progname);
3172  exit(1);
3173  }
3174 
3177 
3180 
3182 
3184 
3185  setup_pgdata();
3186 
3187  setup_bin_paths(argv[0]);
3188 
3189  effective_user = get_id();
3190  if (strlen(username) == 0)
3191  username = effective_user;
3192 
3193  if (strncmp(username, "pg_", 3) == 0)
3194  {
3195  fprintf(stderr, _("%s: superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"\n"), progname, username);
3196  exit(1);
3197  }
3198 
3199  printf(_("The files belonging to this database system will be owned "
3200  "by user \"%s\".\n"
3201  "This user must also own the server process.\n\n"),
3202  effective_user);
3203 
3204  set_info_version();
3205 
3207 
3209 
3211 
3212  printf("\n");
3213 
3214  if (data_checksums)
3215  printf(_("Data page checksums are enabled.\n"));
3216  else
3217  printf(_("Data page checksums are disabled.\n"));
3218 
3219  if (pwprompt || pwfilename)
3220  get_su_pwd();
3221 
3222  printf("\n");
3223 
3225 
3226  if (do_sync)
3227  {
3228  fputs(_("syncing data to disk ... "), stdout);
3229  fflush(stdout);
3230  fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
3231  check_ok();
3232  }
3233  else
3234  printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3235 
3236  if (authwarning != NULL)
3237  fprintf(stderr, "%s", authwarning);
3238 
3239  /*
3240  * Build up a shell command to tell the user how to start the server
3241  */
3242  start_db_cmd = createPQExpBuffer();
3243 
3244  /* Get directory specification used to start initdb ... */
3245  strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
3246  canonicalize_path(pg_ctl_path);
3247  get_parent_directory(pg_ctl_path);
3248  /* ... and tag on pg_ctl instead */
3249  join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl");
3250 
3251  /* path to pg_ctl, properly quoted */
3252  appendShellString(start_db_cmd, pg_ctl_path);
3253 
3254  /* add -D switch, with properly quoted data directory */
3255  appendPQExpBufferStr(start_db_cmd, " -D ");
3256  appendShellString(start_db_cmd, pgdata_native);
3257 
3258  /* add suggested -l switch and "start" command */
3259  /* translator: This is a placeholder in a shell command. */
3260  appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
3261 
3262  printf(_("\nSuccess. You can now start the database server using:\n\n"
3263  " %s\n\n"),
3264  start_db_cmd->data);
3265 
3266  destroyPQExpBuffer(start_db_cmd);
3267 
3268  return 0;
3269 }
static char * lc_monetary
Definition: initdb.c:126
void setup_data_file_paths(void)
Definition: initdb.c:2542
void setup_locale_encoding(void)
Definition: initdb.c:2453
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:2311
#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:2849
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:2023
void setup_bin_paths(const char *argv0)
Definition: initdb.c:2405
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:343
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:2590
#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:2271
const char * strerror(int errnum)
Definition: strerror.c:19
static void check_need_password(const char *authmethodlocal, const char *authmethodhost)
Definition: initdb.c:2343
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:2323
void setup_pgdata(void)
Definition: initdb.c:2365
#define _(x)
Definition: elog.c:84
static void set_info_version(void)
Definition: initdb.c:1861
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 1976 of file initdb.c.

References NULL, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

1977 {
1978  const char *const *line;
1979  static const char *const postgres_setup[] = {
1980  "CREATE DATABASE postgres;\n\n",
1981  "COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n",
1982  NULL
1983  };
1984 
1985  for (line = postgres_setup; *line; line++)
1986  PG_CMD_PUTS(*line);
1987 }
#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 1938 of file initdb.c.

References NULL, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

1939 {
1940  const char *const *line;
1941  static const char *const template0_setup[] = {
1942  "CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false;\n\n",
1943 
1944  /*
1945  * We use the OID of template0 to determine lastsysoid
1946  */
1947  "UPDATE pg_database SET datlastsysoid = "
1948  " (SELECT oid FROM pg_database "
1949  " WHERE datname = 'template0');\n\n",
1950 
1951  /*
1952  * Explicitly revoke public create-schema and create-temp-table
1953  * privileges in template1 and template0; else the latter would be on
1954  * by default
1955  */
1956  "REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n",
1957  "REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n",
1958 
1959  "COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n",
1960 
1961  /*
1962  * Finally vacuum to clean up dead rows in pg_database
1963  */
1964  "VACUUM pg_database;\n\n",
1965  NULL
1966  };
1967 
1968  for (line = template0_setup; *line; line++)
1969  PG_CMD_PUTS(*line);
1970 }
#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 2048 of file initdb.c.

Referenced by locale_date_order().

2049 {
2050  return strftime(s, max, fmt, tm);
2051 }
static struct pg_tm tm
Definition: localtime.c:111
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:1633
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:214
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:1633
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 1375 of file findtimezone.c.

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

Referenced by setup_config().

1376 {
1377  const char *tzname;
1378 
1379  /* Initialize timezone directory path, if needed */
1380 #ifndef SYSTEMTZDIR
1381  snprintf(tzdirpath, sizeof(tzdirpath), "%s/timezone", share_path);
1382 #endif
1383 
1384  /* Check TZ environment variable */
1385  tzname = getenv("TZ");
1386  if (validate_zone(tzname))
1387  return tzname;
1388 
1389  /* Nope, so try to identify the system timezone */
1390  tzname = identify_system_timezone();
1391  if (validate_zone(tzname))
1392  return tzname;
1393 
1394  return NULL;
1395 }
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 1861 of file initdb.c.

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

Referenced by main().

1862 {
1863  char *letterversion;
1864  long major = 0,
1865  minor = 0,
1866  micro = 0;
1867  char *endptr;
1868  char *vstr = pg_strdup(PG_VERSION);
1869  char *ptr;
1870 
1871  ptr = vstr + (strlen(vstr) - 1);
1872  while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
1873  ptr--;
1874  letterversion = ptr + 1;
1875  major = strtol(vstr, &endptr, 10);
1876  if (*endptr)
1877  minor = strtol(endptr + 1, &endptr, 10);
1878  if (*endptr)
1879  micro = strtol(endptr + 1, &endptr, 10);
1880  snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
1881  major, minor, micro, letterversion);
1882 }
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:89
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 2220 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().

2221 {
2222  char *canonname;
2223 
2224  /* set empty lc_* values to locale config if set */
2225 
2226  if (strlen(locale) > 0)
2227  {
2228  if (strlen(lc_ctype) == 0)
2229  lc_ctype = locale;
2230  if (strlen(lc_collate) == 0)
2231  lc_collate = locale;
2232  if (strlen(lc_numeric) == 0)
2233  lc_numeric = locale;
2234  if (strlen(lc_time) == 0)
2235  lc_time = locale;
2236  if (strlen(lc_monetary) == 0)
2237  lc_monetary = locale;
2238  if (strlen(lc_messages) == 0)
2239  lc_messages = locale;
2240  }
2241 
2242  /*
2243  * canonicalize locale names, and obtain any missing values from our
2244  * current environment
2245  */
2246 
2247  check_locale_name(LC_CTYPE, lc_ctype, &canonname);
2248  lc_ctype = canonname;
2249  check_locale_name(LC_COLLATE, lc_collate, &canonname);
2250  lc_collate = canonname;
2251  check_locale_name(LC_NUMERIC, lc_numeric, &canonname);
2252  lc_numeric = canonname;
2253  check_locale_name(LC_TIME, lc_time, &canonname);
2254  lc_time = canonname;
2255  check_locale_name(LC_MONETARY, lc_monetary, &canonname);
2256  lc_monetary = canonname;
2257 #if defined(LC_MESSAGES) && !defined(WIN32)
2258  check_locale_name(LC_MESSAGES, lc_messages, &canonname);
2259  lc_messages = canonname;
2260 #else
2261  /* when LC_MESSAGES is not available, use the LC_CTYPE setting */
2262  check_locale_name(LC_CTYPE, lc_messages, &canonname);
2263  lc_messages = canonname;
2264 #endif
2265 }
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:2120
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 2405 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().

2406 {
2407  int ret;
2408 
2409  if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
2410  backend_exec)) < 0)
2411  {
2412  char full_path[MAXPGPATH];
2413 
2414  if (find_my_exec(argv0, full_path) < 0)
2415  strlcpy(full_path, progname, sizeof(full_path));
2416 
2417  if (ret == -1)
2418  fprintf(stderr,
2419  _("The program \"postgres\" is needed by %s "
2420  "but was not found in the\n"
2421  "same directory as \"%s\".\n"
2422  "Check your installation.\n"),
2423  progname, full_path);
2424  else
2425  fprintf(stderr,
2426  _("The program \"postgres\" was found by \"%s\"\n"
2427  "but was not the same version as %s.\n"
2428  "Check your installation.\n"),
2429  full_path, progname);
2430  exit(1);
2431  }
2432 
2433  /* store binary directory */
2434  strcpy(bin_path, backend_exec);
2435  *last_dir_separator(bin_path) = '\0';
2437 
2438  if (!share_path)
2439  {
2442  }
2443  else if (!is_absolute_path(share_path))
2444  {
2445  fprintf(stderr, _("%s: input file location must be an absolute path\n"), progname);
2446  exit(1);
2447  }
2448 
2450 }
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:101
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void canonicalize_path(char *path)
Definition: path.c:254
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
#define PG_BACKEND_VERSIONSTR
Definition: port.h:102
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 1637 of file initdb.c.

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

Referenced by initialize_data_directory().

1638 {
1639  /*
1640  * Add an SQL-standard name. We don't want to pin this, so it doesn't go
1641  * in pg_collation.h. But add it before reading system collations, so
1642  * that it wins if libc defines a locale named ucs_basic.
1643  */
1644  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",
1646 
1647  /* Now import all collations we can find in the operating system */
1648  PG_CMD_PUTS("SELECT pg_import_system_collations('pg_catalog');\n\n");
1649 }
#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:102
#define COLLPROVIDER_LIBC
Definition: pg_collation.h:86
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:2023
#define DATEORDER_YMD
Definition: miscadmin.h:217
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:2057
#define DATEORDER_DMY
Definition: miscadmin.h:218
#define DATEORDER_MDY
Definition: miscadmin.h:219
#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 1655 of file initdb.c.

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

Referenced by initialize_data_directory().

1656 {
1657  char **line;
1658  char **conv_lines;
1659 
1660  conv_lines = readfile(conversion_file);
1661  for (line = conv_lines; *line != NULL; line++)
1662  {
1663  if (strstr(*line, "DROP CONVERSION") != *line)
1664  PG_CMD_PUTS(*line);
1665  free(*line);
1666  }
1667 
1668  free(conv_lines);
1669 }
#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 2542 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().

2543 {
2544  set_input(&bki_file, "postgres.bki");
2545  set_input(&desc_file, "postgres.description");
2546  set_input(&shdesc_file, "postgres.shdescription");
2547  set_input(&hba_file, "pg_hba.conf.sample");
2548  set_input(&ident_file, "pg_ident.conf.sample");
2549  set_input(&conf_file, "postgresql.conf.sample");
2550  set_input(&conversion_file, "conversion_create.sql");
2551  set_input(&dictionary_file, "snowball_create.sql");
2552  set_input(&info_schema_file, "information_schema.sql");
2553  set_input(&features_file, "sql_features.txt");
2554  set_input(&system_views_file, "system_views.sql");
2555 
2556  if (show_setting || debug)
2557  {
2558  fprintf(stderr,
2559  "VERSION=%s\n"
2560  "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2561  "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2562  "POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n"
2563  "POSTGRESQL_CONF_SAMPLE=%s\n"
2564  "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2565  PG_VERSION,
2567  username, bki_file,
2569  conf_file,
2570  hba_file, ident_file);
2571  if (show_setting)
2572  exit(0);
2573  }
2574 
2586 }
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  * Catalogs that are intentionally not scanned here are:
1482  *
1483  * pg_database: it's a feature, not a bug, that template1 is not
1484  * pinned.
1485  *
1486  * pg_extension: a pinned extension isn't really an extension, hmm?
1487  *
1488  * pg_tablespace: tablespaces don't participate in the dependency
1489  * code, and DropTableSpace() explicitly protects the built-in
1490  * tablespaces.
1491  *
1492  * First delete any already-made entries; PINs override all else, and
1493  * must be the only entries for their objects.
1494  */
1495  "DELETE FROM pg_depend;\n\n",
1496  "VACUUM pg_depend;\n\n",
1497  "DELETE FROM pg_shdepend;\n\n",
1498  "VACUUM pg_shdepend;\n\n",
1499 
1500  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1501  " FROM pg_class;\n\n",
1502  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1503  " FROM pg_proc;\n\n",
1504  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1505  " FROM pg_type;\n\n",
1506  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1507  " FROM pg_cast;\n\n",
1508  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1509  " FROM pg_constraint;\n\n",
1510  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1511  " FROM pg_conversion;\n\n",
1512  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1513  " FROM pg_attrdef;\n\n",
1514  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1515  " FROM pg_language;\n\n",
1516  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1517  " FROM pg_operator;\n\n",
1518  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1519  " FROM pg_opclass;\n\n",
1520  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1521  " FROM pg_opfamily;\n\n",
1522  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1523  " FROM pg_am;\n\n",
1524  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1525  " FROM pg_amop;\n\n",
1526  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1527  " FROM pg_amproc;\n\n",
1528  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1529  " FROM pg_rewrite;\n\n",
1530  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1531  " FROM pg_trigger;\n\n",
1532 
1533  /*
1534  * restriction here to avoid pinning the public namespace
1535  */
1536  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1537  " FROM pg_namespace "
1538  " WHERE nspname LIKE 'pg%';\n\n",
1539 
1540  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1541  " FROM pg_ts_parser;\n\n",
1542  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1543  " FROM pg_ts_dict;\n\n",
1544  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1545  " FROM pg_ts_template;\n\n",
1546  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1547  " FROM pg_ts_config;\n\n",
1548  "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' "
1549  " FROM pg_collation;\n\n",
1550  "INSERT INTO pg_shdepend SELECT 0,0,0,0, tableoid,oid, 'p' "
1551  " FROM pg_authid;\n\n",
1552  NULL
1553  };
1554 
1555  for (line = pg_depend_setup; *line != NULL; line++)
1556  PG_CMD_PUTS(*line);
1557 }
#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 1583 of file initdb.c.

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

Referenced by initialize_data_directory().

1584 {
1585  PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_description ( "
1586  " objoid oid, "
1587  " classname name, "
1588  " objsubid int4, "
1589  " description text) WITHOUT OIDS;\n\n");
1590 
1591  PG_CMD_PRINTF1("COPY tmp_pg_description FROM E'%s';\n\n",
1593 
1594  PG_CMD_PUTS("INSERT INTO pg_description "
1595  " SELECT t.objoid, c.oid, t.objsubid, t.description "
1596  " FROM tmp_pg_description t, pg_class c "
1597  " WHERE c.relname = t.classname;\n\n");
1598 
1599  PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( "
1600  " objoid oid, "
1601  " classname name, "
1602  " description text) WITHOUT OIDS;\n\n");
1603 
1604  PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM E'%s';\n\n",
1606 
1607  PG_CMD_PUTS("INSERT INTO pg_shdescription "
1608  " SELECT t.objoid, c.oid, t.description "
1609  " FROM tmp_pg_shdescription t, pg_class c "
1610  " WHERE c.relname = t.classname;\n\n");
1611 
1612  /* Create default descriptions for operator implementation functions */
1613  PG_CMD_PUTS("WITH funcdescs AS ( "
1614  "SELECT p.oid as p_oid, oprname, "
1615  "coalesce(obj_description(o.oid, 'pg_operator'),'') as opdesc "
1616  "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1617  "INSERT INTO pg_description "
1618  " SELECT p_oid, 'pg_proc'::regclass, 0, "
1619  " 'implementation of ' || oprname || ' operator' "
1620  " FROM funcdescs "
1621  " WHERE opdesc NOT LIKE 'deprecated%' AND "
1622  " NOT EXISTS (SELECT 1 FROM pg_description "
1623  " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass);\n\n");
1624 
1625  /*
1626  * Even though the tables are temp, drop them explicitly so they don't get
1627  * copied into template0/postgres databases.
1628  */
1629  PG_CMD_PUTS("DROP TABLE tmp_pg_description;\n\n");
1630  PG_CMD_PUTS("DROP TABLE tmp_pg_shdescription;\n\n");
1631 }
#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 1675 of file initdb.c.

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

Referenced by initialize_data_directory().

1676 {
1677  char **line;
1678  char **conv_lines;
1679 
1680  conv_lines = readfile(dictionary_file);
1681  for (line = conv_lines; *line != NULL; line++)
1682  {
1683  PG_CMD_PUTS(*line);
1684  free(*line);
1685  }
1686 
1687  free(conv_lines);
1688 }
#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 2453 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().

2454 {
2455  int user_enc;
2456 
2457  setlocales();
2458 
2459  if (strcmp(lc_ctype, lc_collate) == 0 &&
2460  strcmp(lc_ctype, lc_time) == 0 &&
2461  strcmp(lc_ctype, lc_numeric) == 0 &&
2462  strcmp(lc_ctype, lc_monetary) == 0 &&
2463  strcmp(lc_ctype, lc_messages) == 0)
2464  printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
2465  else
2466  {
2467  printf(_("The database cluster will be initialized with locales\n"
2468  " COLLATE: %s\n"
2469  " CTYPE: %s\n"
2470  " MESSAGES: %s\n"
2471  " MONETARY: %s\n"
2472  " NUMERIC: %s\n"
2473  " TIME: %s\n"),
2474  lc_collate,
2475  lc_ctype,
2476  lc_messages,
2477  lc_monetary,
2478  lc_numeric,
2479  lc_time);
2480  }
2481 
2482  if (strlen(encoding) == 0)
2483  {
2484  int ctype_enc;
2485 
2486  ctype_enc = pg_get_encoding_from_locale(lc_ctype, true);
2487 
2488  if (ctype_enc == -1)
2489  {
2490  /* Couldn't recognize the locale's codeset */
2491  fprintf(stderr, _("%s: could not find suitable encoding for locale \"%s\"\n"),
2492  progname, lc_ctype);
2493  fprintf(stderr, _("Rerun %s with the -E option.\n"), progname);
2494  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
2495  progname);
2496  exit(1);
2497  }
2498  else if (!pg_valid_server_encoding_id(ctype_enc))
2499  {
2500  /*
2501  * We recognized it, but it's not a legal server encoding. On
2502  * Windows, UTF-8 works with any locale, so we can fall back to
2503  * UTF-8.
2504  */
2505 #ifdef WIN32
2506  printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2507  "The default database encoding will be set to \"%s\" instead.\n"),
2508  pg_encoding_to_char(ctype_enc),
2510  ctype_enc = PG_UTF8;
2511  encodingid = encodingid_to_string(ctype_enc);
2512 #else
2513  fprintf(stderr,
2514  _("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
2515  progname, lc_ctype, pg_encoding_to_char(ctype_enc));
2516  fprintf(stderr,
2517  _("Encoding \"%s\" is not allowed as a server-side encoding.\n"
2518  "Rerun %s with a different locale selection.\n"),
2519  pg_encoding_to_char(ctype_enc), progname);
2520  exit(1);
2521 #endif
2522  }
2523  else
2524  {
2525  encodingid = encodingid_to_string(ctype_enc);
2526  printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2527  pg_encoding_to_char(ctype_enc));
2528  }
2529  }
2530  else
2532 
2533  user_enc = atoi(encodingid);
2534  if (!check_locale_encoding(lc_ctype, user_enc) ||
2535  !check_locale_encoding(lc_collate, user_enc))
2536  exit(1); /* check_locale_encoding printed the error */
2537 
2538 }
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:2184
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:2220
#define _(x)
Definition: elog.c:84
void setup_pgdata ( void  )

Definition at line 2365 of file initdb.c.

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

Referenced by main().

2366 {
2367  char *pgdata_get_env,
2368  *pgdata_set_env;
2369 
2370  if (strlen(pg_data) == 0)
2371  {
2372  pgdata_get_env = getenv("PGDATA");
2373  if (pgdata_get_env && strlen(pgdata_get_env))
2374  {
2375  /* PGDATA found */
2376  pg_data = pg_strdup(pgdata_get_env);
2377  }
2378  else
2379  {
2380  fprintf(stderr,
2381  _("%s: no data directory specified\n"
2382  "You must identify the directory where the data for this database system\n"
2383  "will reside. Do this with either the invocation option -D or the\n"
2384  "environment variable PGDATA.\n"),
2385  progname);
2386  exit(1);
2387  }
2388  }
2389 
2392 
2393  /*
2394  * we have to set PGDATA for postgres rather than pass it on the command
2395  * line to avoid dumb quoting problems on Windows, and we would especially
2396  * need quotes otherwise on Windows because paths there are most likely to
2397  * have embedded spaces.
2398  */
2399  pgdata_set_env = psprintf("PGDATA=%s", pg_data);
2400  putenv(pgdata_set_env);
2401 }
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 1710 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().

1711 {
1712  char **line;
1713  char **priv_lines;
1714  static char *privileges_setup[] = {
1715  "UPDATE pg_class "
1716  " SET relacl = (SELECT array_agg(a.acl) FROM "
1717  " (SELECT E'=r/\"$POSTGRES_SUPERUSERNAME\"' as acl "
1718  " UNION SELECT unnest(pg_catalog.acldefault("
1719  " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
1720  " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
1721  " ) as a) "
1722  " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1725  " AND relacl IS NULL;\n\n",
1726  "GRANT USAGE ON SCHEMA pg_catalog TO PUBLIC;\n\n",
1727  "GRANT CREATE, USAGE ON SCHEMA public TO PUBLIC;\n\n",
1728  "REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n",
1729  "INSERT INTO pg_init_privs "
1730  " (objoid, classoid, objsubid, initprivs, privtype)"
1731  " SELECT"
1732  " oid,"
1733  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1734  " 0,"
1735  " relacl,"
1736  " 'i'"
1737  " FROM"
1738  " pg_class"
1739  " WHERE"
1740  " relacl IS NOT NULL"
1741  " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1744  "INSERT INTO pg_init_privs "
1745  " (objoid, classoid, objsubid, initprivs, privtype)"
1746  " SELECT"
1747  " pg_class.oid,"
1748  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1749  " pg_attribute.attnum,"
1750  " pg_attribute.attacl,"
1751  " 'i'"
1752  " FROM"
1753  " pg_class"
1754  " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1755  " WHERE"
1756  " pg_attribute.attacl IS NOT NULL"
1757  " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1760  "INSERT INTO pg_init_privs "
1761  " (objoid, classoid, objsubid, initprivs, privtype)"
1762  " SELECT"
1763  " oid,"
1764  " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1765  " 0,"
1766  " proacl,"
1767  " 'i'"
1768  " FROM"
1769  " pg_proc"
1770  " WHERE"
1771  " proacl IS NOT NULL;",
1772  "INSERT INTO pg_init_privs "
1773  " (objoid, classoid, objsubid, initprivs, privtype)"
1774  " SELECT"
1775  " oid,"
1776  " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1777  " 0,"
1778  " typacl,"
1779  " 'i'"
1780  " FROM"
1781  " pg_type"
1782  " WHERE"
1783  " typacl IS NOT NULL;",
1784  "INSERT INTO pg_init_privs "
1785  " (objoid, classoid, objsubid, initprivs, privtype)"
1786  " SELECT"
1787  " oid,"
1788  " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1789  " 0,"
1790  " lanacl,"
1791  " 'i'"
1792  " FROM"
1793  " pg_language"
1794  " WHERE"
1795  " lanacl IS NOT NULL;",
1796  "INSERT INTO pg_init_privs "
1797  " (objoid, classoid, objsubid, initprivs, privtype)"
1798  " SELECT"
1799  " oid,"
1800  " (SELECT oid FROM pg_class WHERE "
1801  " relname = 'pg_largeobject_metadata'),"
1802  " 0,"
1803  " lomacl,"
1804  " 'i'"
1805  " FROM"
1806  " pg_largeobject_metadata"
1807  " WHERE"
1808  " lomacl IS NOT NULL;",
1809  "INSERT INTO pg_init_privs "
1810  " (objoid, classoid, objsubid, initprivs, privtype)"
1811  " SELECT"
1812  " oid,"
1813  " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1814  " 0,"
1815  " nspacl,"
1816  " 'i'"
1817  " FROM"
1818  " pg_namespace"
1819  " WHERE"
1820  " nspacl IS NOT NULL;",
1821  "INSERT INTO pg_init_privs "
1822  " (objoid, classoid, objsubid, initprivs, privtype)"
1823  " SELECT"
1824  " oid,"
1825  " (SELECT oid FROM pg_class WHERE "
1826  " relname = 'pg_foreign_data_wrapper'),"
1827  " 0,"
1828  " fdwacl,"
1829  " 'i'"
1830  " FROM"
1831  " pg_foreign_data_wrapper"
1832  " WHERE"
1833  " fdwacl IS NOT NULL;",
1834  "INSERT INTO pg_init_privs "
1835  " (objoid, classoid, objsubid, initprivs, privtype)"
1836  " SELECT"
1837  " oid,"
1838  " (SELECT oid FROM pg_class "
1839  " WHERE relname = 'pg_foreign_server'),"
1840  " 0,"
1841  " srvacl,"
1842  " 'i'"
1843  " FROM"
1844  " pg_foreign_server"
1845  " WHERE"
1846  " srvacl IS NOT NULL;",
1847  NULL
1848  };
1849 
1850  priv_lines = replace_token(privileges_setup, "$POSTGRES_SUPERUSERNAME",
1852  for (line = priv_lines; *line != NULL; line++)
1853  PG_CMD_PUTS(*line);
1854 }
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:102
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 1888 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().

1889 {
1890  char **line;
1891  char **lines;
1892 
1893  lines = readfile(info_schema_file);
1894 
1895  for (line = lines; *line != NULL; line++)
1896  {
1897  PG_CMD_PUTS(*line);
1898  free(*line);
1899  }
1900 
1901  free(lines);
1902 
1903  PG_CMD_PRINTF1("UPDATE information_schema.sql_implementation_info "
1904  " SET character_value = '%s' "
1905  " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
1906  infoversion);
1907 
1908  PG_CMD_PRINTF1("COPY information_schema.sql_features "
1909  " (feature_id, feature_name, sub_feature_id, "
1910  " sub_feature_name, is_supported, comments) "
1911  " FROM E'%s';\n\n",
1913 }
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 2625 of file initdb.c.

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

Referenced by initialize_data_directory().

2626 {
2627  /* some of these are not valid on Windows */
2628 #ifdef SIGHUP
2630 #endif
2631 #ifdef SIGINT
2632  pqsignal(SIGINT, trapsig);
2633 #endif
2634 #ifdef SIGQUIT
2636 #endif
2637 #ifdef SIGTERM
2638  pqsignal(SIGTERM, trapsig);
2639 #endif
2640 
2641  /* Ignore SIGPIPE when writing to backend, so we can clean up */
2642 #ifdef SIGPIPE
2644 #endif
2645 
2646  /* Prevent SIGSYS so we can probe for kernel calls that might not work */
2647 #ifdef SIGSYS
2648  pqsignal(SIGSYS, SIG_IGN);
2649 #endif
2650 }
#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:2012
static void setup_sysviews ( FILE *  cmdfd)
static

Definition at line 1563 of file initdb.c.

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

Referenced by initialize_data_directory().

1564 {
1565  char **line;
1566  char **sysviews_setup;
1567 
1568  sysviews_setup = readfile(system_views_file);
1569 
1570  for (line = sysviews_setup; *line != NULL; line++)
1571  {
1572  PG_CMD_PUTS(*line);
1573  free(*line);
1574  }
1575 
1576  free(sysviews_setup);
1577 }
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 2590 of file initdb.c.

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

Referenced by main().

2591 {
2592  if (strlen(default_text_search_config) == 0)
2593  {
2596  {
2597  printf(_("%s: could not find suitable text search configuration for locale \"%s\"\n"),
2598  progname, lc_ctype);
2599  default_text_search_config = "simple";
2600  }
2601  }
2602  else
2603  {
2604  const char *checkmatch = find_matching_ts_config(lc_ctype);
2605 
2606  if (checkmatch == NULL)
2607  {
2608  printf(_("%s: warning: suitable text search configuration for locale \"%s\" is unknown\n"),
2609  progname, lc_ctype);
2610  }
2611  else if (strcmp(checkmatch, default_text_search_config) != 0)
2612  {
2613  printf(_("%s: warning: specified text search configuration \"%s\" might not match locale \"%s\"\n"),
2615  }
2616  }
2617 
2618  printf(_("The default text search configuration will be set to \"%s\".\n"),
2620 
2621 }
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:119
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 2012 of file initdb.c.

References caught_signal, and pqsignal().

Referenced by setup_signals().

2013 {
2014  /* handle systems that reset the handler, like Windows (grr) */
2015  pqsignal(signum, trapsig);
2016  caught_signal = true;
2017 }
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:2012
static void usage ( const char *  progname)
static

Definition at line 2271 of file initdb.c.

References _.

Referenced by main().

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

Definition at line 1928 of file initdb.c.

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

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

Definition at line 2833 of file initdb.c.

References _.

Referenced by create_data_directory(), and create_xlog_or_symlink().

2834 {
2835  if (error == 2)
2836  fprintf(stderr,
2837  _("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.\n"));
2838  else if (error == 3)
2839  fprintf(stderr,
2840  _("It contains a lost+found directory, perhaps due to it being a mount point.\n"));
2841 
2842  fprintf(stderr,
2843  _("Using a mount point directly as the data directory is not recommended.\n"
2844  "Create a subdirectory under the mount point.\n"));
2845 }
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:106
#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().