PostgreSQL Source Code  git master
initdb.c File Reference
#include "postgres_fe.h"
#include <dirent.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include "sys/mman.h"
#include "access/xlog_internal.h"
#include "catalog/pg_authid_d.h"
#include "catalog/pg_class_d.h"
#include "catalog/pg_collation_d.h"
#include "catalog/pg_database_d.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/logging.h"
#include "common/pg_prng.h"
#include "common/restricted_token.h"
#include "common/string.h"
#include "common/username.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.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  _stringlist
 
struct  tsearch_config_match
 

Macros

#define AUTHTRUST_WARNING
 
#define PG_CMD_DECL   FILE *cmdfd
 
#define PG_CMD_OPEN(cmd)
 
#define PG_CMD_CLOSE()
 
#define PG_CMD_PUTS(line)
 
#define PG_CMD_PRINTF(fmt, ...)
 
#define LETTERS   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
#define DIGITS   "0123456789"
 
#define MIN_BUFS_FOR_CONNS(nconns)   ((nconns) * 10)
 

Typedefs

typedef struct _stringlist _stringlist
 

Functions

const char * select_default_timezone (const char *share_path)
 
static char ** replace_token (char **lines, const char *token, const char *replacement)
 
static char ** replace_guc_value (char **lines, const char *guc_name, const char *guc_value, bool mark_as_comment)
 
static bool guc_value_requires_quotes (const char *guc_value)
 
static char ** readfile (const char *path)
 
static void writefile (char *path, char **lines)
 
static FILE * popen_check (const char *command, const char *mode)
 
static char * get_id (void)
 
static int get_encoding_id (const char *encoding_name)
 
static void set_input (char **dest, const char *filename)
 
static void check_input (char *path)
 
static void write_version_file (const char *extrapath)
 
static void set_null_conf (void)
 
static void test_config_settings (void)
 
static bool test_specific_config_settings (int test_conns, int test_buffs)
 
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_run_file (FILE *cmdfd, const char *filename)
 
static void setup_description (FILE *cmdfd)
 
static void setup_collation (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 (SIGNAL_ARGS)
 
static void check_ok (void)
 
static char * escape_quotes (const char *src)
 
static char * escape_quotes_bki (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 user_enc)
 
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 void add_stringlist_item (_stringlist **listhead, const char *str)
 
static void cleanup_directories_atexit (void)
 
static char * encodingid_to_string (int enc)
 
static const char * find_matching_ts_config (const char *lc_type)
 
static const char * choose_dsm_implementation (void)
 
static char * pretty_wal_size (int segment_count)
 
static size_t my_strftime (char *s, size_t max, const char *fmt, const struct tm *tm)
 
static bool check_icu_locale_encoding (int user_enc)
 
static char * icu_language_tag (const char *loc_str)
 
static void icu_validate_locale (const char *loc_str)
 
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 = NULL
 
static char * encoding = NULL
 
static char * locale = NULL
 
static char * lc_collate = NULL
 
static char * lc_ctype = NULL
 
static char * lc_monetary = NULL
 
static char * lc_numeric = NULL
 
static char * lc_time = NULL
 
static char * lc_messages = NULL
 
static char locale_provider = COLLPROVIDER_LIBC
 
static bool builtin_locale_specified = false
 
static char * datlocale = NULL
 
static bool icu_locale_specified = false
 
static char * icu_rules = NULL
 
static const char * default_text_search_config = NULL
 
static char * username = NULL
 
static bool pwprompt = false
 
static char * pwfilename = NULL
 
static char * superuser_password = NULL
 
static const char * authmethodhost = NULL
 
static const char * authmethodlocal = NULL
 
static _stringlistextra_guc_names = NULL
 
static _stringlistextra_guc_values = NULL
 
static bool debug = false
 
static bool noclean = false
 
static bool noinstructions = 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 = NULL
 
static int wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024)
 
static DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC
 
static const char * progname
 
static int encodingid
 
static char * bki_file
 
static char * hba_file
 
static char * ident_file
 
static char * conf_file
 
static char * dictionary_file
 
static char * info_schema_file
 
static char * features_file
 
static char * system_constraints_file
 
static char * system_functions_file
 
static char * system_views_file
 
static bool success = false
 
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 const char * dynamic_shared_memory_type = NULL
 
static const char * default_timezone = NULL
 
static bool authwarning = false
 
static const char *const boot_options = "-F -c log_checkpoints=false"
 
static const char *const backend_options = "--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true -c log_checkpoints=false"
 
static char * extra_options = ""
 
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

◆ AUTHTRUST_WARNING

#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 206 of file initdb.c.

◆ DIGITS

#define DIGITS   "0123456789"

◆ LETTERS

#define LETTERS   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

◆ MIN_BUFS_FOR_CONNS

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

◆ PG_CMD_CLOSE

#define PG_CMD_CLOSE ( )
Value:
do { \
if (pclose_check(cmdfd)) \
exit(1); /* message already printed by pclose_check */ \
} while (0)
int pclose_check(FILE *stream)
Definition: exec.c:410

Definition at line 325 of file initdb.c.

◆ PG_CMD_DECL

#define PG_CMD_DECL   FILE *cmdfd

Definition at line 316 of file initdb.c.

◆ PG_CMD_OPEN

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

Definition at line 318 of file initdb.c.

◆ PG_CMD_PRINTF

#define PG_CMD_PRINTF (   fmt,
  ... 
)
Value:
do { \
if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)
static int output_errno
Definition: initdb.c:194
static void const char * fmt
static void const char fflush(stdout)
#define fprintf
Definition: port.h:242

Definition at line 337 of file initdb.c.

◆ PG_CMD_PUTS

#define PG_CMD_PUTS (   line)
Value:
do { \
if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
output_failed = true, output_errno = errno; \
} while (0)

Definition at line 331 of file initdb.c.

Typedef Documentation

◆ _stringlist

typedef struct _stringlist _stringlist

Function Documentation

◆ add_stringlist_item()

static void add_stringlist_item ( _stringlist **  listhead,
const char *  str 
)
static

Definition at line 387 of file initdb.c.

388 {
389  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
390  _stringlist *oldentry;
391 
392  newentry->str = pg_strdup(str);
393  newentry->next = NULL;
394  if (*listhead == NULL)
395  *listhead = newentry;
396  else
397  {
398  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
399  /* skip */ ;
400  oldentry->next = newentry;
401  }
402 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
const char * str
char * str
Definition: initdb.c:92
struct _stringlist * next
Definition: initdb.c:93

References _stringlist::next, pg_malloc(), pg_strdup(), _stringlist::str, and str.

Referenced by ecpg_start_test(), isolation_init(), isolation_start_test(), main(), psql_init(), and psql_start_test().

◆ bootstrap_template1()

static void bootstrap_template1 ( void  )
static

Definition at line 1472 of file initdb.c.

1473 {
1474  PG_CMD_DECL;
1475  PQExpBufferData cmd;
1476  char **line;
1477  char **bki_lines;
1478  char headerline[MAXPGPATH];
1479  char buf[64];
1480 
1481  printf(_("running bootstrap script ... "));
1482  fflush(stdout);
1483 
1484  bki_lines = readfile(bki_file);
1485 
1486  /* Check that bki file appears to be of the right version */
1487 
1488  snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
1489  PG_MAJORVERSION);
1490 
1491  if (strcmp(headerline, *bki_lines) != 0)
1492  {
1493  pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
1494  bki_file, PG_VERSION);
1495  pg_log_error_hint("Specify the correct path using the option -L.");
1496  exit(1);
1497  }
1498 
1499  /* Substitute for various symbols used in the BKI file */
1500 
1501  sprintf(buf, "%d", NAMEDATALEN);
1502  bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
1503 
1504  sprintf(buf, "%d", (int) sizeof(Pointer));
1505  bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
1506 
1507  bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
1508  (sizeof(Pointer) == 4) ? "i" : "d");
1509 
1510  bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
1511  FLOAT8PASSBYVAL ? "true" : "false");
1512 
1513  bki_lines = replace_token(bki_lines, "POSTGRES",
1515 
1516  bki_lines = replace_token(bki_lines, "ENCODING",
1518 
1519  bki_lines = replace_token(bki_lines, "LC_COLLATE",
1521 
1522  bki_lines = replace_token(bki_lines, "LC_CTYPE",
1524 
1525  bki_lines = replace_token(bki_lines, "DATLOCALE",
1526  datlocale ? escape_quotes_bki(datlocale) : "_null_");
1527 
1528  bki_lines = replace_token(bki_lines, "ICU_RULES",
1529  icu_rules ? escape_quotes_bki(icu_rules) : "_null_");
1530 
1531  sprintf(buf, "%c", locale_provider);
1532  bki_lines = replace_token(bki_lines, "LOCALE_PROVIDER", buf);
1533 
1534  /* Also ensure backend isn't confused by this environment var: */
1535  unsetenv("PGCLIENTENCODING");
1536 
1537  initPQExpBuffer(&cmd);
1538 
1539  printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options);
1540  appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024));
1541  if (data_checksums)
1542  appendPQExpBuffer(&cmd, " -k");
1543  if (debug)
1544  appendPQExpBuffer(&cmd, " -d 5");
1545 
1546 
1547  PG_CMD_OPEN(cmd.data);
1548 
1549  for (line = bki_lines; *line != NULL; line++)
1550  {
1551  PG_CMD_PUTS(*line);
1552  free(*line);
1553  }
1554 
1555  PG_CMD_CLOSE();
1556 
1557  termPQExpBuffer(&cmd);
1558  free(bki_lines);
1559 
1560  check_ok();
1561 }
char * Pointer
Definition: c.h:483
#define FLOAT8PASSBYVAL
Definition: c.h:635
#define _(x)
Definition: elog.c:90
#define free(a)
Definition: header.h:65
static char * escape_quotes_bki(const char *src)
Definition: initdb.c:364
#define PG_CMD_CLOSE()
Definition: initdb.c:325
static char * datlocale
Definition: initdb.c:149
static char * lc_collate
Definition: initdb.c:141
#define PG_CMD_PUTS(line)
Definition: initdb.c:331
static char * lc_ctype
Definition: initdb.c:142
static char ** readfile(const char *path)
Definition: initdb.c:618
static bool debug
Definition: initdb.c:161
static char backend_exec[MAXPGPATH]
Definition: initdb.c:258
static bool data_checksums
Definition: initdb.c:167
#define PG_CMD_DECL
Definition: initdb.c:316
static char locale_provider
Definition: initdb.c:147
static int wal_segment_size_mb
Definition: initdb.c:169
static char ** replace_token(char **lines, const char *token, const char *replacement)
Definition: initdb.c:415
static char * icu_rules
Definition: initdb.c:151
static char * username
Definition: initdb.c:153
static int encodingid
Definition: initdb.c:175
static char * encodingid_to_string(int enc)
Definition: initdb.c:776
static void check_ok(void)
Definition: initdb.c:2036
static char * extra_options
Definition: initdb.c:227
static const char *const boot_options
Definition: initdb.c:223
#define PG_CMD_OPEN(cmd)
Definition: initdb.c:318
static char * bki_file
Definition: initdb.c:176
exit(1)
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
#define NAMEDATALEN
#define MAXPGPATH
static char * buf
Definition: pg_test_fsync.c:73
#define sprintf
Definition: port.h:240
#define snprintf
Definition: port.h:238
#define printf(...)
Definition: port.h:244
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
#define unsetenv(x)
Definition: win32_port.h:538

References _, appendPQExpBuffer(), backend_exec, bki_file, boot_options, buf, check_ok(), PQExpBufferData::data, data_checksums, datlocale, debug, encodingid, encodingid_to_string(), escape_quotes_bki(), exit(), extra_options, fflush(), FLOAT8PASSBYVAL, free, icu_rules, initPQExpBuffer(), lc_collate, lc_ctype, locale_provider, MAXPGPATH, NAMEDATALEN, PG_CMD_CLOSE, PG_CMD_DECL, PG_CMD_OPEN, PG_CMD_PUTS, pg_log_error, pg_log_error_hint, printf, printfPQExpBuffer(), readfile(), replace_token(), snprintf, sprintf, generate_unaccent_rules::stdout, termPQExpBuffer(), unsetenv, username, and wal_segment_size_mb.

Referenced by initialize_data_directory().

◆ check_authmethod_unspecified()

static void check_authmethod_unspecified ( const char **  authmethod)
static

Definition at line 2497 of file initdb.c.

2498 {
2499  if (*authmethod == NULL)
2500  {
2501  authwarning = true;
2502  *authmethod = "trust";
2503  }
2504 }
static bool authwarning
Definition: initdb.c:211

References authwarning.

Referenced by main().

◆ check_authmethod_valid()

static void check_authmethod_valid ( const char *  authmethod,
const char *const *  valid_methods,
const char *  conntype 
)
static

Definition at line 2507 of file initdb.c.

2508 {
2509  const char *const *p;
2510 
2511  for (p = valid_methods; *p; p++)
2512  {
2513  if (strcmp(authmethod, *p) == 0)
2514  return;
2515  /* with space = param */
2516  if (strchr(authmethod, ' '))
2517  if (strncmp(authmethod, *p, (authmethod - strchr(authmethod, ' '))) == 0)
2518  return;
2519  }
2520 
2521  pg_fatal("invalid authentication method \"%s\" for \"%s\" connections",
2522  authmethod, conntype);
2523 }
#define pg_fatal(...)

References pg_fatal.

Referenced by main().

◆ check_icu_locale_encoding()

static bool check_icu_locale_encoding ( int  user_enc)
static

Definition at line 2229 of file initdb.c.

2230 {
2231  if (!(is_encoding_supported_by_icu(user_enc)))
2232  {
2233  pg_log_error("encoding mismatch");
2234  pg_log_error_detail("The encoding you selected (%s) is not supported with the ICU provider.",
2235  pg_encoding_to_char(user_enc));
2236  pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2237  "or choose a matching combination.",
2238  progname);
2239  return false;
2240  }
2241  return true;
2242 }
bool is_encoding_supported_by_icu(int encoding)
Definition: encnames.c:461
static const char * progname
Definition: initdb.c:174
#define pg_log_error_detail(...)
Definition: logging.h:109
#define pg_encoding_to_char
Definition: pg_wchar.h:630

References is_encoding_supported_by_icu(), pg_encoding_to_char, pg_log_error, pg_log_error_detail, pg_log_error_hint, and progname.

Referenced by setup_locale_encoding().

◆ check_input()

static void check_input ( char *  path)
static

Definition at line 933 of file initdb.c.

934 {
935  struct stat statbuf;
936 
937  if (stat(path, &statbuf) != 0)
938  {
939  if (errno == ENOENT)
940  {
941  pg_log_error("file \"%s\" does not exist", path);
942  pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
943  }
944  else
945  {
946  pg_log_error("could not access file \"%s\": %m", path);
947  pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
948  }
949  exit(1);
950  }
951  if (!S_ISREG(statbuf.st_mode))
952  {
953  pg_log_error("file \"%s\" is not a regular file", path);
954  pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
955  exit(1);
956  }
957 }
#define stat
Definition: win32_port.h:284
#define S_ISREG(m)
Definition: win32_port.h:328

References exit(), pg_log_error, pg_log_error_hint, S_ISREG, stat::st_mode, and stat.

Referenced by setup_data_file_paths().

◆ check_locale_encoding()

static bool check_locale_encoding ( const char *  locale,
int  user_enc 
)
static

Definition at line 2194 of file initdb.c.

2195 {
2196  int locale_enc;
2197 
2198  locale_enc = pg_get_encoding_from_locale(locale, true);
2199 
2200  /* See notes in createdb() to understand these tests */
2201  if (!(locale_enc == user_enc ||
2202  locale_enc == PG_SQL_ASCII ||
2203  locale_enc == -1 ||
2204 #ifdef WIN32
2205  user_enc == PG_UTF8 ||
2206 #endif
2207  user_enc == PG_SQL_ASCII))
2208  {
2209  pg_log_error("encoding mismatch");
2210  pg_log_error_detail("The encoding you selected (%s) and the encoding that the "
2211  "selected locale uses (%s) do not match. This would lead to "
2212  "misbehavior in various character string processing functions.",
2213  pg_encoding_to_char(user_enc),
2214  pg_encoding_to_char(locale_enc));
2215  pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2216  "or choose a matching combination.",
2217  progname);
2218  return false;
2219  }
2220  return true;
2221 }
static char * locale
Definition: initdb.c:140
@ PG_SQL_ASCII
Definition: pg_wchar.h:226
@ PG_UTF8
Definition: pg_wchar.h:232
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:428

References locale, pg_encoding_to_char, pg_get_encoding_from_locale(), pg_log_error, pg_log_error_detail, pg_log_error_hint, PG_SQL_ASCII, PG_UTF8, and progname.

Referenced by setup_locale_encoding().

◆ check_locale_name()

static void check_locale_name ( int  category,
const char *  locale,
char **  canonname 
)
static

Definition at line 2133 of file initdb.c.

2134 {
2135  char *save;
2136  char *res;
2137 
2138  if (canonname)
2139  *canonname = NULL; /* in case of failure */
2140 
2141  save = setlocale(category, NULL);
2142  if (!save)
2143  pg_fatal("setlocale() failed");
2144 
2145  /* save may be pointing at a modifiable scratch variable, so copy it. */
2146  save = pg_strdup(save);
2147 
2148  /* for setlocale() call */
2149  if (!locale)
2150  locale = "";
2151 
2152  /* set the locale with setlocale, to see if it accepts it. */
2153  res = setlocale(category, locale);
2154 
2155  /* save canonical name if requested. */
2156  if (res && canonname)
2157  *canonname = pg_strdup(res);
2158 
2159  /* restore old value. */
2160  if (!setlocale(category, save))
2161  pg_fatal("failed to restore old locale \"%s\"", save);
2162  free(save);
2163 
2164  /* complain if locale wasn't valid */
2165  if (res == NULL)
2166  {
2167  if (*locale)
2168  {
2169  pg_log_error("invalid locale name \"%s\"", locale);
2170  pg_log_error_hint("If the locale name is specific to ICU, use --icu-locale.");
2171  exit(1);
2172  }
2173  else
2174  {
2175  /*
2176  * If no relevant switch was given on command line, locale is an
2177  * empty string, which is not too helpful to report. Presumably
2178  * setlocale() found something it did not like in the environment.
2179  * Ideally we'd report the bad environment variable, but since
2180  * setlocale's behavior is implementation-specific, it's hard to
2181  * be sure what it didn't like. Print a safe generic message.
2182  */
2183  pg_fatal("invalid locale settings; check LANG and LC_* environment variables");
2184  }
2185  }
2186 }
#define setlocale(a, b)
Definition: win32_port.h:467

References exit(), free, locale, pg_fatal, pg_log_error, pg_log_error_hint, pg_strdup(), res, and setlocale.

Referenced by setlocales().

◆ check_need_password()

static void check_need_password ( const char *  authmethodlocal,
const char *  authmethodhost 
)
static

Definition at line 2526 of file initdb.c.

2527 {
2528  if ((strcmp(authmethodlocal, "md5") == 0 ||
2529  strcmp(authmethodlocal, "password") == 0 ||
2530  strcmp(authmethodlocal, "scram-sha-256") == 0) &&
2531  (strcmp(authmethodhost, "md5") == 0 ||
2532  strcmp(authmethodhost, "password") == 0 ||
2533  strcmp(authmethodhost, "scram-sha-256") == 0) &&
2534  !(pwprompt || pwfilename))
2535  pg_fatal("must specify a password for the superuser to enable password authentication");
2536 }
static const char * authmethodhost
Definition: initdb.c:157
static char * pwfilename
Definition: initdb.c:155
static bool pwprompt
Definition: initdb.c:154
static const char * authmethodlocal
Definition: initdb.c:158

References authmethodhost, authmethodlocal, pg_fatal, pwfilename, and pwprompt.

Referenced by main().

◆ check_ok()

static void check_ok ( void  )
static

Definition at line 2036 of file initdb.c.

2037 {
2038  if (caught_signal)
2039  {
2040  printf(_("caught signal\n"));
2041  fflush(stdout);
2042  exit(1);
2043  }
2044  else if (output_failed)
2045  {
2046  printf(_("could not write to child process: %s\n"),
2048  fflush(stdout);
2049  exit(1);
2050  }
2051  else
2052  {
2053  /* all seems well */
2054  printf(_("ok\n"));
2055  fflush(stdout);
2056  }
2057 }
static bool output_failed
Definition: initdb.c:193
static bool caught_signal
Definition: initdb.c:192
#define strerror
Definition: port.h:251

References _, caught_signal, exit(), fflush(), output_errno, output_failed, printf, generate_unaccent_rules::stdout, and strerror.

Referenced by adjust_data_dir(), bootstrap_template1(), check_cluster_versions(), check_for_data_types_usage(), check_for_incompatible_polymorphics(), check_for_isn_and_int8_passing_mismatch(), check_for_new_tablespace_dir(), check_for_pg_role_prefix(), check_for_prepared_transactions(), check_for_tables_with_oids(), check_for_user_defined_encoding_conversions(), check_for_user_defined_postfix_ops(), check_is_install_user(), check_loadable_libraries(), check_new_cluster_logical_replication_slots(), check_new_cluster_subscription_configuration(), check_old_cluster_for_valid_slots(), check_old_cluster_subscription_state(), check_proper_datallowconn(), copy_subdir_files(), copy_xact_xlog_xid(), create_data_directory(), create_logical_replication_slots(), create_new_objects(), create_script_for_old_cluster_deletion(), create_xlog_or_symlink(), disable_old_cluster(), generate_old_dump(), initialize_data_directory(), main(), old_9_6_invalidate_hash_indexes(), prepare_new_cluster(), prepare_new_globals(), remove_new_subdir(), report_extension_updates(), set_frozenxids(), set_locale_and_encoding(), setup_config(), and transfer_all_new_tablespaces().

◆ choose_dsm_implementation()

static const char* choose_dsm_implementation ( void  )
static

Definition at line 1016 of file initdb.c.

1017 {
1018 #if defined(HAVE_SHM_OPEN) && !defined(__sun__)
1019  int ntries = 10;
1021 
1022  /* Initialize prng; this function is its only user in this program. */
1023  pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
1024 
1025  while (ntries > 0)
1026  {
1027  uint32 handle;
1028  char name[64];
1029  int fd;
1030 
1031  handle = pg_prng_uint32(&prng_state);
1032  snprintf(name, 64, "/PostgreSQL.%u", handle);
1033  if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
1034  {
1035  close(fd);
1036  shm_unlink(name);
1037  return "posix";
1038  }
1039  if (errno != EEXIST)
1040  break;
1041  --ntries;
1042  }
1043 #endif
1044 
1045 #ifdef WIN32
1046  return "windows";
1047 #else
1048  return "sysv";
1049 #endif
1050 }
unsigned int uint32
Definition: c.h:506
#define close(a)
Definition: win32.h:12
uint32 pg_prng_uint32(pg_prng_state *state)
Definition: pg_prng.c:227
void pg_prng_seed(pg_prng_state *state, uint64 seed)
Definition: pg_prng.c:89
static int fd(const char *x, int i)
Definition: preproc-init.c:105
static pg_prng_state prng_state
const char * name

References close, fd(), name, pg_prng_seed(), pg_prng_uint32(), prng_state, and snprintf.

Referenced by test_config_settings().

◆ cleanup_directories_atexit()

static void cleanup_directories_atexit ( void  )
static

Definition at line 704 of file initdb.c.

705 {
706  if (success)
707  return;
708 
709  if (!noclean)
710  {
711  if (made_new_pgdata)
712  {
713  pg_log_info("removing data directory \"%s\"", pg_data);
714  if (!rmtree(pg_data, true))
715  pg_log_error("failed to remove data directory");
716  }
717  else if (found_existing_pgdata)
718  {
719  pg_log_info("removing contents of data directory \"%s\"",
720  pg_data);
721  if (!rmtree(pg_data, false))
722  pg_log_error("failed to remove contents of data directory");
723  }
724 
725  if (made_new_xlogdir)
726  {
727  pg_log_info("removing WAL directory \"%s\"", xlog_dir);
728  if (!rmtree(xlog_dir, true))
729  pg_log_error("failed to remove WAL directory");
730  }
731  else if (found_existing_xlogdir)
732  {
733  pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
734  if (!rmtree(xlog_dir, false))
735  pg_log_error("failed to remove contents of WAL directory");
736  }
737  /* otherwise died during startup, do nothing! */
738  }
739  else
740  {
742  pg_log_info("data directory \"%s\" not removed at user's request",
743  pg_data);
744 
746  pg_log_info("WAL directory \"%s\" not removed at user's request",
747  xlog_dir);
748  }
749 }
static bool noclean
Definition: initdb.c:162
static bool found_existing_pgdata
Definition: initdb.c:188
static bool found_existing_xlogdir
Definition: initdb.c:190
static char * xlog_dir
Definition: initdb.c:168
static bool success
Definition: initdb.c:186
static bool made_new_xlogdir
Definition: initdb.c:189
static char * pg_data
Definition: initdb.c:138
static bool made_new_pgdata
Definition: initdb.c:187
#define pg_log_info(...)
Definition: logging.h:124
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:50

References found_existing_pgdata, found_existing_xlogdir, made_new_pgdata, made_new_xlogdir, noclean, pg_data, pg_log_error, pg_log_info, rmtree(), success, and xlog_dir.

Referenced by main().

◆ create_data_directory()

void create_data_directory ( void  )

Definition at line 2826 of file initdb.c.

2827 {
2828  int ret;
2829 
2830  switch ((ret = pg_check_dir(pg_data)))
2831  {
2832  case 0:
2833  /* PGDATA not there, must create it */
2834  printf(_("creating directory %s ... "),
2835  pg_data);
2836  fflush(stdout);
2837 
2839  pg_fatal("could not create directory \"%s\": %m", pg_data);
2840  else
2841  check_ok();
2842 
2843  made_new_pgdata = true;
2844  break;
2845 
2846  case 1:
2847  /* Present but empty, fix permissions and use it */
2848  printf(_("fixing permissions on existing directory %s ... "),
2849  pg_data);
2850  fflush(stdout);
2851 
2852  if (chmod(pg_data, pg_dir_create_mode) != 0)
2853  pg_fatal("could not change permissions of directory \"%s\": %m",
2854  pg_data);
2855  else
2856  check_ok();
2857 
2858  found_existing_pgdata = true;
2859  break;
2860 
2861  case 2:
2862  case 3:
2863  case 4:
2864  /* Present and not empty */
2865  pg_log_error("directory \"%s\" exists but is not empty", pg_data);
2866  if (ret != 4)
2867  warn_on_mount_point(ret);
2868  else
2869  pg_log_error_hint("If you want to create a new database system, either remove or empty "
2870  "the directory \"%s\" or run %s "
2871  "with an argument other than \"%s\".",
2873  exit(1); /* no further message needed */
2874 
2875  default:
2876  /* Trouble accessing directory */
2877  pg_fatal("could not access directory \"%s\": %m", pg_data);
2878  }
2879 }
int pg_dir_create_mode
Definition: file_perm.c:18
void warn_on_mount_point(int error)
Definition: initdb.c:2967
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
int pg_check_dir(const char *dir)
Definition: pgcheckdir.c:33

References _, check_ok(), exit(), fflush(), found_existing_pgdata, made_new_pgdata, pg_check_dir(), pg_data, pg_dir_create_mode, pg_fatal, pg_log_error, pg_log_error_hint, pg_mkdir_p(), printf, progname, generate_unaccent_rules::stdout, and warn_on_mount_point().

Referenced by initialize_data_directory().

◆ create_xlog_or_symlink()

void create_xlog_or_symlink ( void  )

Definition at line 2884 of file initdb.c.

2885 {
2886  char *subdirloc;
2887 
2888  /* form name of the place for the subdirectory or symlink */
2889  subdirloc = psprintf("%s/pg_wal", pg_data);
2890 
2891  if (xlog_dir)
2892  {
2893  int ret;
2894 
2895  /* clean up xlog directory name, check it's absolute */
2897  if (!is_absolute_path(xlog_dir))
2898  pg_fatal("WAL directory location must be an absolute path");
2899 
2900  /* check if the specified xlog directory exists/is empty */
2901  switch ((ret = pg_check_dir(xlog_dir)))
2902  {
2903  case 0:
2904  /* xlog directory not there, must create it */
2905  printf(_("creating directory %s ... "),
2906  xlog_dir);
2907  fflush(stdout);
2908 
2910  pg_fatal("could not create directory \"%s\": %m",
2911  xlog_dir);
2912  else
2913  check_ok();
2914 
2915  made_new_xlogdir = true;
2916  break;
2917 
2918  case 1:
2919  /* Present but empty, fix permissions and use it */
2920  printf(_("fixing permissions on existing directory %s ... "),
2921  xlog_dir);
2922  fflush(stdout);
2923 
2924  if (chmod(xlog_dir, pg_dir_create_mode) != 0)
2925  pg_fatal("could not change permissions of directory \"%s\": %m",
2926  xlog_dir);
2927  else
2928  check_ok();
2929 
2930  found_existing_xlogdir = true;
2931  break;
2932 
2933  case 2:
2934  case 3:
2935  case 4:
2936  /* Present and not empty */
2937  pg_log_error("directory \"%s\" exists but is not empty", xlog_dir);
2938  if (ret != 4)
2939  warn_on_mount_point(ret);
2940  else
2941  pg_log_error_hint("If you want to store the WAL there, either remove or empty the directory \"%s\".",
2942  xlog_dir);
2943  exit(1);
2944 
2945  default:
2946  /* Trouble accessing directory */
2947  pg_fatal("could not access directory \"%s\": %m", xlog_dir);
2948  }
2949 
2950  if (symlink(xlog_dir, subdirloc) != 0)
2951  pg_fatal("could not create symbolic link \"%s\": %m",
2952  subdirloc);
2953  }
2954  else
2955  {
2956  /* Without -X option, just make the subdirectory normally */
2957  if (mkdir(subdirloc, pg_dir_create_mode) < 0)
2958  pg_fatal("could not create directory \"%s\": %m",
2959  subdirloc);
2960  }
2961 
2962  free(subdirloc);
2963 }
#define is_absolute_path(filename)
Definition: port.h:103
void canonicalize_path(char *path)
Definition: path.c:264
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define mkdir(a, b)
Definition: win32_port.h:80
#define symlink(oldpath, newpath)
Definition: win32_port.h:235

References _, canonicalize_path(), check_ok(), exit(), fflush(), found_existing_xlogdir, free, is_absolute_path, made_new_xlogdir, mkdir, pg_check_dir(), pg_data, pg_dir_create_mode, pg_fatal, pg_log_error, pg_log_error_hint, pg_mkdir_p(), printf, psprintf(), generate_unaccent_rules::stdout, symlink, warn_on_mount_point(), and xlog_dir.

Referenced by initialize_data_directory().

◆ encodingid_to_string()

static char* encodingid_to_string ( int  enc)
static

Definition at line 776 of file initdb.c.

777 {
778  char result[20];
779 
780  sprintf(result, "%d", enc);
781  return pg_strdup(result);
782 }
enc

References enc, pg_strdup(), and sprintf.

Referenced by bootstrap_template1().

◆ escape_quotes()

static char * escape_quotes ( const char *  src)
static

Definition at line 348 of file initdb.c.

349 {
350  char *result = escape_single_quotes_ascii(src);
351 
352  if (!result)
353  pg_fatal("out of memory");
354  return result;
355 }
char * escape_single_quotes_ascii(const char *src)
Definition: quotes.c:33

References escape_single_quotes_ascii(), and pg_fatal.

Referenced by escape_quotes_bki(), replace_guc_value(), setup_auth(), setup_privileges(), and setup_schema().

◆ escape_quotes_bki()

static char * escape_quotes_bki ( const char *  src)
static

Definition at line 364 of file initdb.c.

365 {
366  char *result;
367  char *data = escape_quotes(src);
368  char *resultp;
369  char *datap;
370 
371  result = (char *) pg_malloc(strlen(data) + 3);
372  resultp = result;
373  *resultp++ = '\'';
374  for (datap = data; *datap; datap++)
375  *resultp++ = *datap;
376  *resultp++ = '\'';
377  *resultp = '\0';
378 
379  free(data);
380  return result;
381 }
static char * escape_quotes(const char *src)
Definition: initdb.c:348
const void * data

References data, escape_quotes(), free, and pg_malloc().

Referenced by bootstrap_template1().

◆ find_matching_ts_config()

static const char* find_matching_ts_config ( const char *  lc_type)
static

Definition at line 878 of file initdb.c.

879 {
880  int i;
881  char *langname,
882  *ptr;
883 
884  /*
885  * Convert lc_ctype to a language name by stripping everything after an
886  * underscore (usual case) or a hyphen (Windows "locale name"; see
887  * comments at IsoLocaleName()).
888  *
889  * XXX Should ' ' be a stop character? This would select "norwegian" for
890  * the Windows locale "Norwegian (Nynorsk)_Norway.1252". If we do so, we
891  * should also accept the "nn" and "nb" Unix locales.
892  *
893  * Just for paranoia, we also stop at '.' or '@'.
894  */
895  if (lc_type == NULL)
896  langname = pg_strdup("");
897  else
898  {
899  ptr = langname = pg_strdup(lc_type);
900  while (*ptr &&
901  *ptr != '_' && *ptr != '-' && *ptr != '.' && *ptr != '@')
902  ptr++;
903  *ptr = '\0';
904  }
905 
906  for (i = 0; tsearch_config_languages[i].tsconfname; i++)
907  {
908  if (pg_strcasecmp(tsearch_config_languages[i].langname, langname) == 0)
909  {
910  free(langname);
912  }
913  }
914 
915  free(langname);
916  return NULL;
917 }
static const struct tsearch_config_match tsearch_config_languages[]
Definition: initdb.c:811
int i
Definition: isn.c:73
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * tsconfname
Definition: initdb.c:807

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

Referenced by setup_text_search().

◆ get_encoding_id()

static int get_encoding_id ( const char *  encoding_name)
static

Definition at line 788 of file initdb.c.

789 {
790  int enc;
791 
792  if (encoding_name && *encoding_name)
793  {
794  if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
795  return enc;
796  }
797  pg_fatal("\"%s\" is not a valid server encoding name",
798  encoding_name ? encoding_name : "(null)");
799 }
#define pg_valid_server_encoding
Definition: pg_wchar.h:631

References enc, pg_fatal, and pg_valid_server_encoding.

Referenced by setup_locale_encoding().

◆ get_id()

static char * get_id ( void  )
static

Definition at line 757 of file initdb.c.

758 {
759  const char *username;
760 
761 #ifndef WIN32
762  if (geteuid() == 0) /* 0 is root's uid */
763  {
764  pg_log_error("cannot be run as root");
765  pg_log_error_hint("Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
766  exit(1);
767  }
768 #endif
769 
771 
772  return pg_strdup(username);
773 }
const char * get_user_name_or_exit(const char *progname)
Definition: username.c:74

References exit(), get_user_name_or_exit(), pg_log_error, pg_log_error_hint, pg_strdup(), progname, and username.

Referenced by main().

◆ get_su_pwd()

static void get_su_pwd ( void  )
static

Definition at line 1584 of file initdb.c.

1585 {
1586  char *pwd1;
1587 
1588  if (pwprompt)
1589  {
1590  /*
1591  * Read password from terminal
1592  */
1593  char *pwd2;
1594 
1595  printf("\n");
1596  fflush(stdout);
1597  pwd1 = simple_prompt("Enter new superuser password: ", false);
1598  pwd2 = simple_prompt("Enter it again: ", false);
1599  if (strcmp(pwd1, pwd2) != 0)
1600  {
1601  fprintf(stderr, _("Passwords didn't match.\n"));
1602  exit(1);
1603  }
1604  free(pwd2);
1605  }
1606  else
1607  {
1608  /*
1609  * Read password from file
1610  *
1611  * Ideally this should insist that the file not be world-readable.
1612  * However, this option is mainly intended for use on Windows where
1613  * file permissions may not exist at all, so we'll skip the paranoia
1614  * for now.
1615  */
1616  FILE *pwf = fopen(pwfilename, "r");
1617 
1618  if (!pwf)
1619  pg_fatal("could not open file \"%s\" for reading: %m",
1620  pwfilename);
1621  pwd1 = pg_get_line(pwf, NULL);
1622  if (!pwd1)
1623  {
1624  if (ferror(pwf))
1625  pg_fatal("could not read password from file \"%s\": %m",
1626  pwfilename);
1627  else
1628  pg_fatal("password file \"%s\" is empty",
1629  pwfilename);
1630  }
1631  fclose(pwf);
1632 
1633  (void) pg_strip_crlf(pwd1);
1634  }
1635 
1636  superuser_password = pwd1;
1637 }
static char * superuser_password
Definition: initdb.c:156
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
Definition: pg_get_line.c:59
char * simple_prompt(const char *prompt, bool echo)
Definition: sprompt.c:38
int pg_strip_crlf(char *str)
Definition: string.c:155

References _, exit(), fflush(), fprintf, free, pg_fatal, pg_get_line(), pg_strip_crlf(), printf, pwfilename, pwprompt, simple_prompt(), generate_unaccent_rules::stdout, and superuser_password.

Referenced by main().

◆ guc_value_requires_quotes()

static bool guc_value_requires_quotes ( const char *  guc_value)
static

Definition at line 586 of file initdb.c.

587 {
588  /* Don't use <ctype.h> macros here, they might accept too much */
589 #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
590 #define DIGITS "0123456789"
591 
592  if (*guc_value == '\0')
593  return true; /* empty string must be quoted */
594  if (strchr(LETTERS, *guc_value))
595  {
596  if (strspn(guc_value, LETTERS DIGITS) == strlen(guc_value))
597  return false; /* it's an identifier */
598  return true; /* nope */
599  }
600  if (strchr(DIGITS, *guc_value))
601  {
602  /* skip over digits */
603  guc_value += strspn(guc_value, DIGITS);
604  /* there can be zero or more unit letters after the digits */
605  if (strspn(guc_value, LETTERS) == strlen(guc_value))
606  return false; /* it's a number, possibly with units */
607  return true; /* nope */
608  }
609  return true; /* all else must be quoted */
610 }
#define DIGITS
#define LETTERS

References DIGITS, and LETTERS.

Referenced by replace_guc_value().

◆ icu_language_tag()

static char* icu_language_tag ( const char *  loc_str)
static

Definition at line 2249 of file initdb.c.

2250 {
2251 #ifdef USE_ICU
2252  UErrorCode status;
2253  char *langtag;
2254  size_t buflen = 32; /* arbitrary starting buffer size */
2255  const bool strict = true;
2256 
2257  /*
2258  * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
2259  * RFC5646 section 4.4). Additionally, in older ICU versions,
2260  * uloc_toLanguageTag() doesn't always return the ultimate length on the
2261  * first call, necessitating a loop.
2262  */
2263  langtag = pg_malloc(buflen);
2264  while (true)
2265  {
2266  status = U_ZERO_ERROR;
2267  uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
2268 
2269  /* try again if the buffer is not large enough */
2270  if (status == U_BUFFER_OVERFLOW_ERROR ||
2271  status == U_STRING_NOT_TERMINATED_WARNING)
2272  {
2273  buflen = buflen * 2;
2274  langtag = pg_realloc(langtag, buflen);
2275  continue;
2276  }
2277 
2278  break;
2279  }
2280 
2281  if (U_FAILURE(status))
2282  {
2283  pg_free(langtag);
2284 
2285  pg_fatal("could not convert locale name \"%s\" to language tag: %s",
2286  loc_str, u_errorName(status));
2287  }
2288 
2289  return langtag;
2290 #else
2291  pg_fatal("ICU is not supported in this build");
2292  return NULL; /* keep compiler quiet */
2293 #endif
2294 }
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void pg_free(void *ptr)
Definition: fe_memutils.c:105

References pg_fatal, pg_free(), pg_malloc(), and pg_realloc().

Referenced by setlocales().

◆ icu_validate_locale()

static void icu_validate_locale ( const char *  loc_str)
static

Definition at line 2302 of file initdb.c.

2303 {
2304 #ifdef USE_ICU
2305  UErrorCode status;
2306  char lang[ULOC_LANG_CAPACITY];
2307  bool found = false;
2308 
2309  /* validate that we can extract the language */
2310  status = U_ZERO_ERROR;
2311  uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
2312  if (U_FAILURE(status))
2313  {
2314  pg_fatal("could not get language from locale \"%s\": %s",
2315  loc_str, u_errorName(status));
2316  return;
2317  }
2318 
2319  /* check for special language name */
2320  if (strcmp(lang, "") == 0 ||
2321  strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
2322  found = true;
2323 
2324  /* search for matching language within ICU */
2325  for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
2326  {
2327  const char *otherloc = uloc_getAvailable(i);
2328  char otherlang[ULOC_LANG_CAPACITY];
2329 
2330  status = U_ZERO_ERROR;
2331  uloc_getLanguage(otherloc, otherlang, ULOC_LANG_CAPACITY, &status);
2332  if (U_FAILURE(status))
2333  continue;
2334 
2335  if (strcmp(lang, otherlang) == 0)
2336  found = true;
2337  }
2338 
2339  if (!found)
2340  pg_fatal("locale \"%s\" has unknown language \"%s\"",
2341  loc_str, lang);
2342 #else
2343  pg_fatal("ICU is not supported in this build");
2344 #endif
2345 }

References i, and pg_fatal.

Referenced by setlocales().

◆ initialize_data_directory()

void initialize_data_directory ( void  )

Definition at line 2980 of file initdb.c.

2981 {
2982  PG_CMD_DECL;
2983  PQExpBufferData cmd;
2984  int i;
2985 
2986  setup_signals();
2987 
2988  /*
2989  * Set mask based on requested PGDATA permissions. pg_mode_mask, and
2990  * friends like pg_dir_create_mode, are set to owner-only by default and
2991  * then updated if -g is passed in by calling SetDataDirectoryCreatePerm()
2992  * when parsing our options (see above).
2993  */
2994  umask(pg_mode_mask);
2995 
2997 
2999 
3000  /* Create required subdirectories (other than pg_wal) */
3001  printf(_("creating subdirectories ... "));
3002  fflush(stdout);
3003 
3004  for (i = 0; i < lengthof(subdirs); i++)
3005  {
3006  char *path;
3007 
3008  path = psprintf("%s/%s", pg_data, subdirs[i]);
3009 
3010  /*
3011  * The parent directory already exists, so we only need mkdir() not
3012  * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
3013  */
3014  if (mkdir(path, pg_dir_create_mode) < 0)
3015  pg_fatal("could not create directory \"%s\": %m", path);
3016 
3017  free(path);
3018  }
3019 
3020  check_ok();
3021 
3022  /* Top level PG_VERSION is checked by bootstrapper, so make it first */
3023  write_version_file(NULL);
3024 
3025  /* Select suitable configuration settings */
3026  set_null_conf();
3028 
3029  /* Now create all the text config files */
3030  setup_config();
3031 
3032  /* Bootstrap template1 */
3034 
3035  /*
3036  * Make the per-database PG_VERSION for template1 only after init'ing it
3037  */
3038  write_version_file("base/1");
3039 
3040  /*
3041  * Create the stuff we don't need to use bootstrap mode for, using a
3042  * backend running in simple standalone mode.
3043  */
3044  fputs(_("performing post-bootstrap initialization ... "), stdout);
3045  fflush(stdout);
3046 
3047  initPQExpBuffer(&cmd);
3048  printfPQExpBuffer(&cmd, "\"%s\" %s %s template1 >%s",
3050 
3051  PG_CMD_OPEN(cmd.data);
3052 
3053  setup_auth(cmdfd);
3054 
3056 
3058 
3059  setup_depend(cmdfd);
3060 
3061  /*
3062  * Note that no objects created after setup_depend() will be "pinned".
3063  * They are all droppable at the whim of the DBA.
3064  */
3065 
3067 
3068  setup_description(cmdfd);
3069 
3070  setup_collation(cmdfd);
3071 
3073 
3074  setup_privileges(cmdfd);
3075 
3076  setup_schema(cmdfd);
3077 
3078  load_plpgsql(cmdfd);
3079 
3080  vacuum_db(cmdfd);
3081 
3082  make_template0(cmdfd);
3083 
3084  make_postgres(cmdfd);
3085 
3086  PG_CMD_CLOSE();
3087  termPQExpBuffer(&cmd);
3088 
3089  check_ok();
3090 }
#define lengthof(array)
Definition: c.h:788
int pg_mode_mask
Definition: file_perm.c:25
static void setup_depend(FILE *cmdfd)
Definition: initdb.c:1643
static void setup_collation(FILE *cmdfd)
Definition: initdb.c:1698
void create_data_directory(void)
Definition: initdb.c:2826
static void bootstrap_template1(void)
Definition: initdb.c:1472
static void setup_run_file(FILE *cmdfd, const char *filename)
Definition: initdb.c:1656
static void setup_auth(FILE *cmdfd)
Definition: initdb.c:1567
static void make_postgres(FILE *cmdfd)
Definition: initdb.c:1992
static void test_config_settings(void)
Definition: initdb.c:1058
static const char *const backend_options
Definition: initdb.c:224
static void setup_config(void)
Definition: initdb.c:1209
static void setup_privileges(FILE *cmdfd)
Definition: initdb.c:1731
static void write_version_file(const char *extrapath)
Definition: initdb.c:964
void setup_signals(void)
Definition: initdb.c:2797
static char * system_views_file
Definition: initdb.c:185
static void setup_description(FILE *cmdfd)
Definition: initdb.c:1677
static void vacuum_db(FILE *cmdfd)
Definition: initdb.c:1928
static const char *const subdirs[]
Definition: initdb.c:229
void create_xlog_or_symlink(void)
Definition: initdb.c:2884
static char * system_functions_file
Definition: initdb.c:184
static char * dictionary_file
Definition: initdb.c:180
static void setup_schema(FILE *cmdfd)
Definition: initdb.c:1899
static char * system_constraints_file
Definition: initdb.c:183
static void set_null_conf(void)
Definition: initdb.c:987
static void make_template0(FILE *cmdfd)
Definition: initdb.c:1938
static void load_plpgsql(FILE *cmdfd)
Definition: initdb.c:1919
#define DEVNULL
Definition: port.h:160

References _, backend_exec, backend_options, bootstrap_template1(), check_ok(), create_data_directory(), create_xlog_or_symlink(), PQExpBufferData::data, DEVNULL, dictionary_file, extra_options, fflush(), free, i, initPQExpBuffer(), lengthof, load_plpgsql(), make_postgres(), make_template0(), mkdir, PG_CMD_CLOSE, PG_CMD_DECL, PG_CMD_OPEN, pg_data, pg_dir_create_mode, pg_fatal, pg_mode_mask, printf, printfPQExpBuffer(), psprintf(), set_null_conf(), setup_auth(), setup_collation(), setup_config(), setup_depend(), setup_description(), setup_privileges(), setup_run_file(), setup_schema(), setup_signals(), generate_unaccent_rules::stdout, subdirs, system_constraints_file, system_functions_file, system_views_file, termPQExpBuffer(), test_config_settings(), vacuum_db(), and write_version_file().

Referenced by main().

◆ load_plpgsql()

static void load_plpgsql ( FILE *  cmdfd)
static

Definition at line 1919 of file initdb.c.

1920 {
1921  PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
1922 }

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ locale_date_order()

static int locale_date_order ( const char *  locale)
static

Definition at line 2070 of file initdb.c.

2071 {
2072  struct tm testtime;
2073  char buf[128];
2074  char *posD;
2075  char *posM;
2076  char *posY;
2077  char *save;
2078  size_t res;
2079  int result;
2080 
2081  result = DATEORDER_MDY; /* default */
2082 
2083  save = setlocale(LC_TIME, NULL);
2084  if (!save)
2085  return result;
2086  save = pg_strdup(save);
2087 
2088  setlocale(LC_TIME, locale);
2089 
2090  memset(&testtime, 0, sizeof(testtime));
2091  testtime.tm_mday = 22;
2092  testtime.tm_mon = 10; /* November, should come out as "11" */
2093  testtime.tm_year = 133; /* 2033 */
2094 
2095  res = my_strftime(buf, sizeof(buf), "%x", &testtime);
2096 
2097  setlocale(LC_TIME, save);
2098  free(save);
2099 
2100  if (res == 0)
2101  return result;
2102 
2103  posM = strstr(buf, "11");
2104  posD = strstr(buf, "22");
2105  posY = strstr(buf, "33");
2106 
2107  if (!posM || !posD || !posY)
2108  return result;
2109 
2110  if (posY < posM && posM < posD)
2111  result = DATEORDER_YMD;
2112  else if (posD < posM)
2113  result = DATEORDER_DMY;
2114  else
2115  result = DATEORDER_MDY;
2116 
2117  return result;
2118 }
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
Definition: initdb.c:2061
static struct pg_tm tm
Definition: localtime.c:104
#define DATEORDER_DMY
Definition: miscadmin.h:242
#define DATEORDER_MDY
Definition: miscadmin.h:243
#define DATEORDER_YMD
Definition: miscadmin.h:241

References buf, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, free, locale, my_strftime(), pg_strdup(), res, setlocale, and tm.

Referenced by setup_config().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 3094 of file initdb.c.

3095 {
3096  static struct option long_options[] = {
3097  {"pgdata", required_argument, NULL, 'D'},
3098  {"encoding", required_argument, NULL, 'E'},
3099  {"locale", required_argument, NULL, 1},
3100  {"lc-collate", required_argument, NULL, 2},
3101  {"lc-ctype", required_argument, NULL, 3},
3102  {"lc-monetary", required_argument, NULL, 4},
3103  {"lc-numeric", required_argument, NULL, 5},
3104  {"lc-time", required_argument, NULL, 6},
3105  {"lc-messages", required_argument, NULL, 7},
3106  {"no-locale", no_argument, NULL, 8},
3107  {"text-search-config", required_argument, NULL, 'T'},
3108  {"auth", required_argument, NULL, 'A'},
3109  {"auth-local", required_argument, NULL, 10},
3110  {"auth-host", required_argument, NULL, 11},
3111  {"pwprompt", no_argument, NULL, 'W'},
3112  {"pwfile", required_argument, NULL, 9},
3113  {"username", required_argument, NULL, 'U'},
3114  {"help", no_argument, NULL, '?'},
3115  {"version", no_argument, NULL, 'V'},
3116  {"debug", no_argument, NULL, 'd'},
3117  {"show", no_argument, NULL, 's'},
3118  {"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
3119  {"no-clean", no_argument, NULL, 'n'},
3120  {"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
3121  {"no-sync", no_argument, NULL, 'N'},
3122  {"no-instructions", no_argument, NULL, 13},
3123  {"set", required_argument, NULL, 'c'},
3124  {"sync-only", no_argument, NULL, 'S'},
3125  {"waldir", required_argument, NULL, 'X'},
3126  {"wal-segsize", required_argument, NULL, 12},
3127  {"data-checksums", no_argument, NULL, 'k'},
3128  {"allow-group-access", no_argument, NULL, 'g'},
3129  {"discard-caches", no_argument, NULL, 14},
3130  {"locale-provider", required_argument, NULL, 15},
3131  {"builtin-locale", required_argument, NULL, 16},
3132  {"icu-locale", required_argument, NULL, 17},
3133  {"icu-rules", required_argument, NULL, 18},
3134  {"sync-method", required_argument, NULL, 19},
3135  {NULL, 0, NULL, 0}
3136  };
3137 
3138  /*
3139  * options with no short version return a low integer, the rest return
3140  * their short version value
3141  */
3142  int c;
3143  int option_index;
3144  char *effective_user;
3145  PQExpBuffer start_db_cmd;
3146  char pg_ctl_path[MAXPGPATH];
3147 
3148  /*
3149  * Ensure that buffering behavior of stdout matches what it is in
3150  * interactive usage (at least on most platforms). This prevents
3151  * unexpected output ordering when, eg, output is redirected to a file.
3152  * POSIX says we must do this before any other usage of these files.
3153  */
3154  setvbuf(stdout, NULL, PG_IOLBF, 0);
3155 
3156  pg_logging_init(argv[0]);
3157  progname = get_progname(argv[0]);
3158  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
3159 
3160  if (argc > 1)
3161  {
3162  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
3163  {
3164  usage(progname);
3165  exit(0);
3166  }
3167  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
3168  {
3169  puts("initdb (PostgreSQL) " PG_VERSION);
3170  exit(0);
3171  }
3172  }
3173 
3174  /* process command-line options */
3175 
3176  while ((c = getopt_long(argc, argv, "A:c:dD:E:gkL:nNsST:U:WX:",
3177  long_options, &option_index)) != -1)
3178  {
3179  switch (c)
3180  {
3181  case 'A':
3183 
3184  /*
3185  * When ident is specified, use peer for local connections.
3186  * Mirrored, when peer is specified, use ident for TCP/IP
3187  * connections.
3188  */
3189  if (strcmp(authmethodhost, "ident") == 0)
3190  authmethodlocal = "peer";
3191  else if (strcmp(authmethodlocal, "peer") == 0)
3192  authmethodhost = "ident";
3193  break;
3194  case 10:
3196  break;
3197  case 11:
3199  break;
3200  case 'c':
3201  {
3202  char *buf = pg_strdup(optarg);
3203  char *equals = strchr(buf, '=');
3204 
3205  if (!equals)
3206  {
3207  pg_log_error("-c %s requires a value", buf);
3208  pg_log_error_hint("Try \"%s --help\" for more information.",
3209  progname);
3210  exit(1);
3211  }
3212  *equals++ = '\0'; /* terminate variable name */
3215  pfree(buf);
3216  }
3217  break;
3218  case 'D':
3220  break;
3221  case 'E':
3223  break;
3224  case 'W':
3225  pwprompt = true;
3226  break;
3227  case 'U':
3229  break;
3230  case 'd':
3231  debug = true;
3232  printf(_("Running in debug mode.\n"));
3233  break;
3234  case 'n':
3235  noclean = true;
3236  printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3237  break;
3238  case 'N':
3239  do_sync = false;
3240  break;
3241  case 'S':
3242  sync_only = true;
3243  break;
3244  case 'k':
3245  data_checksums = true;
3246  break;
3247  case 'L':
3249  break;
3250  case 1:
3251  locale = pg_strdup(optarg);
3252  break;
3253  case 2:
3255  break;
3256  case 3:
3258  break;
3259  case 4:
3261  break;
3262  case 5:
3264  break;
3265  case 6:
3267  break;
3268  case 7:
3270  break;
3271  case 8:
3272  locale = "C";
3273  break;
3274  case 9:
3276  break;
3277  case 's':
3278  show_setting = true;
3279  break;
3280  case 'T':
3282  break;
3283  case 'X':
3285  break;
3286  case 12:
3287  if (!option_parse_int(optarg, "--wal-segsize", 1, 1024, &wal_segment_size_mb))
3288  exit(1);
3289  break;
3290  case 13:
3291  noinstructions = true;
3292  break;
3293  case 'g':
3295  break;
3296  case 14:
3297  extra_options = psprintf("%s %s",
3298  extra_options,
3299  "-c debug_discard_caches=1");
3300  break;
3301  case 15:
3302  if (strcmp(optarg, "builtin") == 0)
3303  locale_provider = COLLPROVIDER_BUILTIN;
3304  else if (strcmp(optarg, "icu") == 0)
3305  locale_provider = COLLPROVIDER_ICU;
3306  else if (strcmp(optarg, "libc") == 0)
3307  locale_provider = COLLPROVIDER_LIBC;
3308  else
3309  pg_fatal("unrecognized locale provider: %s", optarg);
3310  break;
3311  case 16:
3313  builtin_locale_specified = true;
3314  break;
3315  case 17:
3317  icu_locale_specified = true;
3318  break;
3319  case 18:
3321  break;
3322  case 19:
3324  exit(1);
3325  break;
3326  default:
3327  /* getopt_long already emitted a complaint */
3328  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3329  exit(1);
3330  }
3331  }
3332 
3333 
3334  /*
3335  * Non-option argument specifies data directory as long as it wasn't
3336  * already specified with -D / --pgdata
3337  */
3338  if (optind < argc && !pg_data)
3339  {
3340  pg_data = pg_strdup(argv[optind]);
3341  optind++;
3342  }
3343 
3344  if (optind < argc)
3345  {
3346  pg_log_error("too many command-line arguments (first is \"%s\")",
3347  argv[optind]);
3348  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3349  exit(1);
3350  }
3351 
3352  if (builtin_locale_specified && locale_provider != COLLPROVIDER_BUILTIN)
3353  pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3354  "--builtin-locale", "builtin");
3355 
3356  if (icu_locale_specified && locale_provider != COLLPROVIDER_ICU)
3357  pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3358  "--icu-locale", "icu");
3359 
3360  if (icu_rules && locale_provider != COLLPROVIDER_ICU)
3361  pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3362  "--icu-rules", "icu");
3363 
3365 
3366  /* If we only need to sync, just do it and exit */
3367  if (sync_only)
3368  {
3369  setup_pgdata();
3370 
3371  /* must check that directory is readable */
3372  if (pg_check_dir(pg_data) <= 0)
3373  pg_fatal("could not access directory \"%s\": %m", pg_data);
3374 
3375  fputs(_("syncing data to disk ... "), stdout);
3376  fflush(stdout);
3377  sync_pgdata(pg_data, PG_VERSION_NUM, sync_method);
3378  check_ok();
3379  return 0;
3380  }
3381 
3382  if (pwprompt && pwfilename)
3383  pg_fatal("password prompt and password file cannot be specified together");
3384 
3387 
3390 
3392 
3393  if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
3394  pg_fatal("argument of %s must be a power of two between 1 and 1024", "--wal-segsize");
3395 
3397 
3398  setup_pgdata();
3399 
3400  setup_bin_paths(argv[0]);
3401 
3402  effective_user = get_id();
3403  if (!username)
3404  username = effective_user;
3405 
3406  if (strncmp(username, "pg_", 3) == 0)
3407  pg_fatal("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
3408 
3409  printf(_("The files belonging to this database system will be owned "
3410  "by user \"%s\".\n"
3411  "This user must also own the server process.\n\n"),
3412  effective_user);
3413 
3414  set_info_version();
3415 
3417 
3419 
3421 
3422  printf("\n");
3423 
3424  if (data_checksums)
3425  printf(_("Data page checksums are enabled.\n"));
3426  else
3427  printf(_("Data page checksums are disabled.\n"));
3428 
3429  if (pwprompt || pwfilename)
3430  get_su_pwd();
3431 
3432  printf("\n");
3433 
3435 
3436  if (do_sync)
3437  {
3438  fputs(_("syncing data to disk ... "), stdout);
3439  fflush(stdout);
3440  sync_pgdata(pg_data, PG_VERSION_NUM, sync_method);
3441  check_ok();
3442  }
3443  else
3444  printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3445 
3446  if (authwarning)
3447  {
3448  printf("\n");
3449  pg_log_warning("enabling \"trust\" authentication for local connections");
3450  pg_log_warning_hint("You can change this by editing pg_hba.conf or using the option -A, or "
3451  "--auth-local and --auth-host, the next time you run initdb.");
3452  }
3453 
3454  if (!noinstructions)
3455  {
3456  /*
3457  * Build up a shell command to tell the user how to start the server
3458  */
3459  start_db_cmd = createPQExpBuffer();
3460 
3461  /* Get directory specification used to start initdb ... */
3462  strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
3465  /* ... and tag on pg_ctl instead */
3467 
3468  /* Convert the path to use native separators */
3470 
3471  /* path to pg_ctl, properly quoted */
3472  appendShellString(start_db_cmd, pg_ctl_path);
3473 
3474  /* add -D switch, with properly quoted data directory */
3475  appendPQExpBufferStr(start_db_cmd, " -D ");
3476  appendShellString(start_db_cmd, pgdata_native);
3477 
3478  /* add suggested -l switch and "start" command */
3479  /* translator: This is a placeholder in a shell command. */
3480  appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
3481 
3482  printf(_("\nSuccess. You can now start the database server using:\n\n"
3483  " %s\n\n"),
3484  start_db_cmd->data);
3485 
3486  destroyPQExpBuffer(start_db_cmd);
3487  }
3488 
3489 
3490  success = true;
3491  return 0;
3492 }
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1214
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:448
void SetDataDirectoryCreatePerm(int dataDirMode)
Definition: file_perm.c:34
#define PG_DIR_MODE_GROUP
Definition: file_perm.h:35
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:60
#define no_argument
Definition: getopt_long.h:24
#define required_argument
Definition: getopt_long.h:25
static void usage(const char *progname)
Definition: initdb.c:2444
static char * lc_time
Definition: initdb.c:145
static char * get_id(void)
Definition: initdb.c:757
static char * pgdata_native
Definition: initdb.c:195
static void check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
Definition: initdb.c:2507
static bool icu_locale_specified
Definition: initdb.c:150
static bool noinstructions
Definition: initdb.c:163
void initialize_data_directory(void)
Definition: initdb.c:2980
void setup_text_search(void)
Definition: initdb.c:2763
static char * share_path
Definition: initdb.c:135
void setup_bin_paths(const char *argv0)
Definition: initdb.c:2577
static void check_authmethod_unspecified(const char **authmethod)
Definition: initdb.c:2497
static const char *const auth_methods_host[]
Definition: initdb.c:96
void setup_locale_encoding(void)
Definition: initdb.c:2614
static const char *const auth_methods_local[]
Definition: initdb.c:118
static bool sync_only
Definition: initdb.c:165
static void check_need_password(const char *authmethodlocal, const char *authmethodhost)
Definition: initdb.c:2526
static bool do_sync
Definition: initdb.c:164
static void cleanup_directories_atexit(void)
Definition: initdb.c:704
static char * lc_messages
Definition: initdb.c:146
static bool builtin_locale_specified
Definition: initdb.c:148
static void set_info_version(void)
Definition: initdb.c:1872
void setup_data_file_paths(void)
Definition: initdb.c:2719
static char * encoding
Definition: initdb.c:139
static DataDirSyncMethod sync_method
Definition: initdb.c:170
static _stringlist * extra_guc_names
Definition: initdb.c:159
static void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: initdb.c:387
static _stringlist * extra_guc_values
Definition: initdb.c:160
static char * lc_numeric
Definition: initdb.c:144
void setup_pgdata(void)
Definition: initdb.c:2540
static bool show_setting
Definition: initdb.c:166
static const char * default_text_search_config
Definition: initdb.c:152
static char * lc_monetary
Definition: initdb.c:143
static void get_su_pwd(void)
Definition: initdb.c:1584
void pg_logging_init(const char *argv0)
Definition: logging.c:83
#define pg_log_warning_hint(...)
Definition: logging.h:121
void pfree(void *pointer)
Definition: mcxt.c:1520
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
Definition: option_utils.c:50
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
Definition: option_utils.c:90
static char * pg_ctl_path
PGDLLIMPORT int optind
Definition: getopt.c:50
PGDLLIMPORT char * optarg
Definition: getopt.c:52
#define pg_log_warning(...)
Definition: pgfnames.c:24
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition: path.c:219
#define PG_IOLBF
Definition: port.h:361
void get_parent_directory(char *path)
Definition: path.c:976
const char * get_progname(const char *argv0)
Definition: path.c:574
void make_native_path(char *filename)
Definition: path.c:167
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
char * c
void get_restricted_token(void)
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:429
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:96

References _, add_stringlist_item(), appendPQExpBuffer(), appendPQExpBufferStr(), appendShellString(), auth_methods_host, auth_methods_local, authmethodhost, authmethodlocal, authwarning, buf, builtin_locale_specified, canonicalize_path(), check_authmethod_unspecified(), check_authmethod_valid(), check_need_password(), check_ok(), cleanup_directories_atexit(), createPQExpBuffer(), PQExpBufferData::data, data_checksums, datlocale, debug, default_text_search_config, destroyPQExpBuffer(), do_sync, encoding, exit(), extra_guc_names, extra_guc_values, extra_options, fflush(), get_id(), get_parent_directory(), get_progname(), get_restricted_token(), get_su_pwd(), getopt_long(), icu_locale_specified, icu_rules, initialize_data_directory(), IsValidWalSegSize, join_path_components(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, locale, locale_provider, make_native_path(), MAXPGPATH, no_argument, noclean, noinstructions, optarg, optind, option_parse_int(), parse_sync_method(), pfree(), pg_check_dir(), pg_ctl_path, pg_data, PG_DIR_MODE_GROUP, pg_fatal, PG_IOLBF, pg_log_error, pg_log_error_hint, pg_log_warning, pg_log_warning_hint, pg_logging_init(), pg_strdup(), PG_TEXTDOMAIN, pgdata_native, printf, progname, psprintf(), pwfilename, pwprompt, required_argument, set_info_version(), set_pglocale_pgservice(), SetDataDirectoryCreatePerm(), setup_bin_paths(), setup_data_file_paths(), setup_locale_encoding(), setup_pgdata(), setup_text_search(), share_path, show_setting, generate_unaccent_rules::stdout, strlcpy(), success, sync_method, sync_only, usage(), username, wal_segment_size_mb, and xlog_dir.

◆ make_postgres()

static void make_postgres ( FILE *  cmdfd)
static

Definition at line 1992 of file initdb.c.

1993 {
1994  /*
1995  * Just as we did for template0, and for the same reasons, assign a fixed
1996  * OID to postgres and select the file_copy strategy.
1997  */
1998  PG_CMD_PUTS("CREATE DATABASE postgres OID = " CppAsString2(PostgresDbOid)
1999  " STRATEGY = file_copy;\n\n");
2000  PG_CMD_PUTS("COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
2001 }
#define CppAsString2(x)
Definition: c.h:327

References CppAsString2, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ make_template0()

static void make_template0 ( FILE *  cmdfd)
static

Definition at line 1938 of file initdb.c.

1939 {
1940  /*
1941  * pg_upgrade tries to preserve database OIDs across upgrades. It's smart
1942  * enough to drop and recreate a conflicting database with the same name,
1943  * but if the same OID were used for one system-created database in the
1944  * old cluster and a different system-created database in the new cluster,
1945  * it would fail. To avoid that, assign a fixed OID to template0 rather
1946  * than letting the server choose one.
1947  *
1948  * (Note that, while the user could have dropped and recreated these
1949  * objects in the old cluster, the problem scenario only exists if the OID
1950  * that is in use in the old cluster is also used in the new cluster - and
1951  * the new cluster should be the result of a fresh initdb.)
1952  *
1953  * We use "STRATEGY = file_copy" here because checkpoints during initdb
1954  * are cheap. "STRATEGY = wal_log" would generate more WAL, which would be
1955  * a little bit slower and make the new cluster a little bit bigger.
1956  */
1957  PG_CMD_PUTS("CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
1958  " OID = " CppAsString2(Template0DbOid)
1959  " STRATEGY = file_copy;\n\n");
1960 
1961  /*
1962  * template0 shouldn't have any collation-dependent objects, so unset the
1963  * collation version. This disables collation version checks when making
1964  * a new database from it.
1965  */
1966  PG_CMD_PUTS("UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
1967 
1968  /*
1969  * While we are here, do set the collation version on template1.
1970  */
1971  PG_CMD_PUTS("UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
1972 
1973  /*
1974  * Explicitly revoke public create-schema and create-temp-table privileges
1975  * in template1 and template0; else the latter would be on by default
1976  */
1977  PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
1978  PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
1979 
1980  PG_CMD_PUTS("COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
1981 
1982  /*
1983  * Finally vacuum to clean up dead rows in pg_database
1984  */
1985  PG_CMD_PUTS("VACUUM pg_database;\n\n");
1986 }

References CppAsString2, and PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ my_strftime()

static size_t my_strftime ( char *  s,
size_t  max,
const char *  fmt,
const struct tm tm 
)
inlinestatic

Definition at line 2061 of file initdb.c.

2062 {
2063  return strftime(s, max, fmt, tm);
2064 }

References fmt, and tm.

Referenced by locale_date_order().

◆ popen_check()

static FILE * popen_check ( const char *  command,
const char *  mode 
)
static

Definition at line 687 of file initdb.c.

688 {
689  FILE *cmdfd;
690 
691  fflush(NULL);
692  errno = 0;
693  cmdfd = popen(command, mode);
694  if (cmdfd == NULL)
695  pg_log_error("could not execute command \"%s\": %m", command);
696  return cmdfd;
697 }
static PgChecksumMode mode
Definition: pg_checksums.c:56

References fflush(), mode, and pg_log_error.

◆ pretty_wal_size()

static char* pretty_wal_size ( int  segment_count)
static

Definition at line 1192 of file initdb.c.

1193 {
1194  int sz = wal_segment_size_mb * segment_count;
1195  char *result = pg_malloc(14);
1196 
1197  if ((sz % 1024) == 0)
1198  snprintf(result, 14, "%dGB", sz / 1024);
1199  else
1200  snprintf(result, 14, "%dMB", sz);
1201 
1202  return result;
1203 }

References pg_malloc(), snprintf, and wal_segment_size_mb.

Referenced by setup_config().

◆ readfile()

static char ** readfile ( const char *  path)
static

Definition at line 618 of file initdb.c.

619 {
620  char **result;
621  FILE *infile;
622  StringInfoData line;
623  int maxlines;
624  int n;
625 
626  if ((infile = fopen(path, "r")) == NULL)
627  pg_fatal("could not open file \"%s\" for reading: %m", path);
628 
629  initStringInfo(&line);
630 
631  maxlines = 1024;
632  result = (char **) pg_malloc(maxlines * sizeof(char *));
633 
634  n = 0;
635  while (pg_get_line_buf(infile, &line))
636  {
637  /* make sure there will be room for a trailing NULL pointer */
638  if (n >= maxlines - 1)
639  {
640  maxlines *= 2;
641  result = (char **) pg_realloc(result, maxlines * sizeof(char *));
642  }
643 
644  result[n++] = pg_strdup(line.data);
645  }
646  result[n] = NULL;
647 
648  pfree(line.data);
649 
650  fclose(infile);
651 
652  return result;
653 }
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition: pg_get_line.c:95
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
static void infile(const char *name)
Definition: zic.c:1243

References StringInfoData::data, infile(), initStringInfo(), pfree(), pg_fatal, pg_get_line_buf(), pg_malloc(), pg_realloc(), and pg_strdup().

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

◆ replace_guc_value()

static char ** replace_guc_value ( char **  lines,
const char *  guc_name,
const char *  guc_value,
bool  mark_as_comment 
)
static

Definition at line 470 of file initdb.c.

472 {
473  int namelen = strlen(guc_name);
475  int i;
476 
477  /* prepare the replacement line, except for possible comment and newline */
478  if (mark_as_comment)
480  appendPQExpBuffer(newline, "%s = ", guc_name);
481  if (guc_value_requires_quotes(guc_value))
482  appendPQExpBuffer(newline, "'%s'", escape_quotes(guc_value));
483  else
484  appendPQExpBufferStr(newline, guc_value);
485 
486  for (i = 0; lines[i]; i++)
487  {
488  const char *where;
489  const char *namestart;
490 
491  /*
492  * Look for a line assigning to guc_name. Typically it will be
493  * preceded by '#', but that might not be the case if a -c switch
494  * overrides a previous assignment. We allow leading whitespace too,
495  * although normally there wouldn't be any.
496  */
497  where = lines[i];
498  while (*where == '#' || isspace((unsigned char) *where))
499  where++;
500  if (pg_strncasecmp(where, guc_name, namelen) != 0)
501  continue;
502  namestart = where;
503  where += namelen;
504  while (isspace((unsigned char) *where))
505  where++;
506  if (*where != '=')
507  continue;
508 
509  /* found it -- let's use the canonical casing shown in the file */
510  memcpy(&newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
511 
512  /* now append the original comment if any */
513  where = strrchr(where, '#');
514  if (where)
515  {
516  /*
517  * We try to preserve original indentation, which is tedious.
518  * oldindent and newindent are measured in de-tab-ified columns.
519  */
520  const char *ptr;
521  int oldindent = 0;
522  int newindent;
523 
524  for (ptr = lines[i]; ptr < where; ptr++)
525  {
526  if (*ptr == '\t')
527  oldindent += 8 - (oldindent % 8);
528  else
529  oldindent++;
530  }
531  /* ignore the possibility of tabs in guc_value */
532  newindent = newline->len;
533  /* append appropriate tabs and spaces, forcing at least one */
534  oldindent = Max(oldindent, newindent + 1);
535  while (newindent < oldindent)
536  {
537  int newindent_if_tab = newindent + 8 - (newindent % 8);
538 
539  if (newindent_if_tab <= oldindent)
540  {
542  newindent = newindent_if_tab;
543  }
544  else
545  {
547  newindent++;
548  }
549  }
550  /* and finally append the old comment */
552  /* we'll have appended the original newline; don't add another */
553  }
554  else
556 
557  free(lines[i]);
558  lines[i] = newline->data;
559 
560  break; /* assume there's only one match */
561  }
562 
563  if (lines[i] == NULL)
564  {
565  /*
566  * No match, so append a new entry. (We rely on the bootstrap server
567  * to complain if it's not a valid GUC name.)
568  */
570  lines = pg_realloc_array(lines, char *, i + 2);
571  lines[i++] = newline->data;
572  lines[i] = NULL; /* keep the array null-terminated */
573  }
574 
575  free(newline); /* but don't free newline->data */
576 
577  return lines;
578 }
#define Max(x, y)
Definition: c.h:998
#define pg_realloc_array(pointer, type, count)
Definition: fe_memutils.h:51
#define newline
Definition: indent_codes.h:35
static bool guc_value_requires_quotes(const char *guc_value)
Definition: initdb.c:586
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), createPQExpBuffer(), escape_quotes(), free, guc_value_requires_quotes(), i, Max, newline, pg_realloc_array, and pg_strncasecmp().

Referenced by setup_config().

◆ replace_token()

static char ** replace_token ( char **  lines,
const char *  token,
const char *  replacement 
)
static

Definition at line 415 of file initdb.c.

416 {
417  int toklen,
418  replen,
419  diff;
420 
421  toklen = strlen(token);
422  replen = strlen(replacement);
423  diff = replen - toklen;
424 
425  for (int i = 0; lines[i]; i++)
426  {
427  char *where;
428  char *newline;
429  int pre;
430 
431  /* nothing to do if no change needed */
432  if ((where = strstr(lines[i], token)) == NULL)
433  continue;
434 
435  /* if we get here a change is needed - set up new line */
436 
437  newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
438 
439  pre = where - lines[i];
440 
441  memcpy(newline, lines[i], pre);
442 
443  memcpy(newline + pre, replacement, replen);
444 
445  strcpy(newline + pre + replen, lines[i] + pre + toklen);
446 
447  free(lines[i]);
448  lines[i] = newline;
449  }
450 
451  return lines;
452 }
#define token
Definition: indent_globs.h:126

References free, i, newline, pg_malloc(), and token.

Referenced by bootstrap_template1(), and setup_config().

◆ select_default_timezone()

const char* select_default_timezone ( const char *  share_path)

Definition at line 1757 of file findtimezone.c.

1758 {
1759  const char *tzname;
1760 
1761  /* Initialize timezone directory path, if needed */
1762 #ifndef SYSTEMTZDIR
1763  snprintf(tzdirpath, sizeof(tzdirpath), "%s/timezone", share_path);
1764 #endif
1765 
1766  /* Check TZ environment variable */
1767  tzname = getenv("TZ");
1768  if (validate_zone(tzname))
1769  return tzname;
1770 
1771  /* Nope, so try to identify the system timezone */
1772  tzname = identify_system_timezone();
1773  if (validate_zone(tzname))
1774  return tzname;
1775 
1776  return NULL;
1777 }
static const char * identify_system_timezone(void)
Definition: findtimezone.c:331
static bool validate_zone(const char *tzname)
static char tzdirpath[MAXPGPATH]
Definition: findtimezone.c:27

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

Referenced by test_config_settings().

◆ set_info_version()

static void set_info_version ( void  )
static

Definition at line 1872 of file initdb.c.

1873 {
1874  char *letterversion;
1875  long major = 0,
1876  minor = 0,
1877  micro = 0;
1878  char *endptr;
1879  char *vstr = pg_strdup(PG_VERSION);
1880  char *ptr;
1881 
1882  ptr = vstr + (strlen(vstr) - 1);
1883  while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
1884  ptr--;
1885  letterversion = ptr + 1;
1886  major = strtol(vstr, &endptr, 10);
1887  if (*endptr)
1888  minor = strtol(endptr + 1, &endptr, 10);
1889  if (*endptr)
1890  micro = strtol(endptr + 1, &endptr, 10);
1891  snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
1892  major, minor, micro, letterversion);
1893 }
static char infoversion[100]
Definition: initdb.c:191

References infoversion, pg_strdup(), and snprintf.

Referenced by main().

◆ set_input()

static void set_input ( char **  dest,
const char *  filename 
)
static

Definition at line 924 of file initdb.c.

925 {
926  *dest = psprintf("%s/%s", share_path, filename);
927 }
static char * filename
Definition: pg_dumpall.c:119

References generate_unaccent_rules::dest, filename, psprintf(), and share_path.

Referenced by setup_data_file_paths().

◆ set_null_conf()

static void set_null_conf ( void  )
static

Definition at line 987 of file initdb.c.

988 {
989  FILE *conf_file;
990  char *path;
991 
992  path = psprintf("%s/postgresql.conf", pg_data);
993  conf_file = fopen(path, PG_BINARY_W);
994  if (conf_file == NULL)
995  pg_fatal("could not open file \"%s\" for writing: %m", path);
996  if (fclose(conf_file))
997  pg_fatal("could not write file \"%s\": %m", path);
998  free(path);
999 }
#define PG_BINARY_W
Definition: c.h:1276
static char * conf_file
Definition: initdb.c:179

References conf_file, free, PG_BINARY_W, pg_data, pg_fatal, and psprintf().

Referenced by initialize_data_directory().

◆ setlocales()

static void setlocales ( void  )
static

Definition at line 2353 of file initdb.c.

2354 {
2355  char *canonname;
2356 
2357  /* set empty lc_* and datlocale values to locale config if set */
2358 
2359  if (locale)
2360  {
2361  if (!lc_ctype)
2362  lc_ctype = locale;
2363  if (!lc_collate)
2364  lc_collate = locale;
2365  if (!lc_numeric)
2366  lc_numeric = locale;
2367  if (!lc_time)
2368  lc_time = locale;
2369  if (!lc_monetary)
2370  lc_monetary = locale;
2371  if (!lc_messages)
2372  lc_messages = locale;
2373  if (!datlocale && locale_provider != COLLPROVIDER_LIBC)
2374  datlocale = locale;
2375  }
2376 
2377  /*
2378  * canonicalize locale names, and obtain any missing values from our
2379  * current environment
2380  */
2381  check_locale_name(LC_CTYPE, lc_ctype, &canonname);
2382  lc_ctype = canonname;
2383  check_locale_name(LC_COLLATE, lc_collate, &canonname);
2384  lc_collate = canonname;
2385  check_locale_name(LC_NUMERIC, lc_numeric, &canonname);
2386  lc_numeric = canonname;
2387  check_locale_name(LC_TIME, lc_time, &canonname);
2388  lc_time = canonname;
2389  check_locale_name(LC_MONETARY, lc_monetary, &canonname);
2390  lc_monetary = canonname;
2391 #if defined(LC_MESSAGES) && !defined(WIN32)
2392  check_locale_name(LC_MESSAGES, lc_messages, &canonname);
2393  lc_messages = canonname;
2394 #else
2395  /* when LC_MESSAGES is not available, use the LC_CTYPE setting */
2396  check_locale_name(LC_CTYPE, lc_messages, &canonname);
2397  lc_messages = canonname;
2398 #endif
2399 
2400  if (locale_provider != COLLPROVIDER_LIBC && datlocale == NULL)
2401  pg_fatal("locale must be specified if provider is %s",
2402  collprovider_name(locale_provider));
2403 
2404  if (locale_provider == COLLPROVIDER_BUILTIN)
2405  {
2406  if (strcmp(datlocale, "C") == 0)
2407  canonname = "C";
2408  else if (strcmp(datlocale, "C.UTF-8") == 0 ||
2409  strcmp(datlocale, "C.UTF8") == 0)
2410  canonname = "C.UTF-8";
2411  else
2412  pg_fatal("invalid locale name \"%s\" for builtin provider",
2413  datlocale);
2414 
2415  datlocale = canonname;
2416  }
2417  else if (locale_provider == COLLPROVIDER_ICU)
2418  {
2419  char *langtag;
2420 
2421  /* canonicalize to a language tag */
2422  langtag = icu_language_tag(datlocale);
2423  printf(_("Using language tag \"%s\" for ICU locale \"%s\".\n"),
2424  langtag, datlocale);
2425  pg_free(datlocale);
2426  datlocale = langtag;
2427 
2429 
2430  /*
2431  * In supported builds, the ICU locale ID will be opened during
2432  * post-bootstrap initialization, which will perform extra checks.
2433  */
2434 #ifndef USE_ICU
2435  pg_fatal("ICU is not supported in this build");
2436 #endif
2437  }
2438 }
static char * icu_language_tag(const char *loc_str)
Definition: initdb.c:2249
static void check_locale_name(int category, const char *locale, char **canonname)
Definition: initdb.c:2133
static void icu_validate_locale(const char *loc_str)
Definition: initdb.c:2302

References _, check_locale_name(), datlocale, icu_language_tag(), icu_validate_locale(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, locale, locale_provider, pg_fatal, pg_free(), and printf.

Referenced by setup_locale_encoding().

◆ setup_auth()

static void setup_auth ( FILE *  cmdfd)
static

Definition at line 1567 of file initdb.c.

1568 {
1569  /*
1570  * The authid table shouldn't be readable except through views, to ensure
1571  * passwords are not publicly visible.
1572  */
1573  PG_CMD_PUTS("REVOKE ALL ON pg_authid FROM public;\n\n");
1574 
1575  if (superuser_password)
1576  PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1578 }
#define PG_CMD_PRINTF(fmt,...)
Definition: initdb.c:337

References escape_quotes(), PG_CMD_PRINTF, PG_CMD_PUTS, superuser_password, and username.

Referenced by initialize_data_directory().

◆ setup_bin_paths()

void setup_bin_paths ( const char *  argv0)

Definition at line 2577 of file initdb.c.

2578 {
2579  int ret;
2580 
2581  if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
2582  backend_exec)) < 0)
2583  {
2584  char full_path[MAXPGPATH];
2585 
2586  if (find_my_exec(argv0, full_path) < 0)
2587  strlcpy(full_path, progname, sizeof(full_path));
2588 
2589  if (ret == -1)
2590  pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
2591  "postgres", progname, full_path);
2592  else
2593  pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
2594  "postgres", full_path, progname);
2595  }
2596 
2597  /* store binary directory */
2598  strcpy(bin_path, backend_exec);
2599  *last_dir_separator(bin_path) = '\0';
2601 
2602  if (!share_path)
2603  {
2606  }
2607  else if (!is_absolute_path(share_path))
2608  pg_fatal("input file location must be an absolute path");
2609 
2611 }
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:160
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:329
static char bin_path[MAXPGPATH]
Definition: initdb.c:257
static char * argv0
Definition: pg_ctl.c:92
void get_share_path(const char *my_exec_path, char *ret_path)
Definition: path.c:824
char * last_dir_separator(const char *filename)
Definition: path.c:139
#define PG_BACKEND_VERSIONSTR
Definition: port.h:143

References argv0, 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_fatal, pg_malloc(), progname, share_path, and strlcpy().

Referenced by main().

◆ setup_collation()

static void setup_collation ( FILE *  cmdfd)
static

Definition at line 1698 of file initdb.c.

1699 {
1700  /*
1701  * Set the collation version for collations defined in pg_collation.dat,
1702  * but not the ones where we know that the collation behavior will never
1703  * change.
1704  */
1705  PG_CMD_PUTS("UPDATE pg_collation SET collversion = pg_collation_actual_version(oid) WHERE collname = 'unicode';\n\n");
1706 
1707  /* Import all collations we can find in the operating system */
1708  PG_CMD_PUTS("SELECT pg_import_system_collations('pg_catalog');\n\n");
1709 }

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_config()

static void setup_config ( void  )
static

Definition at line 1209 of file initdb.c.

1210 {
1211  char **conflines;
1212  char repltok[MAXPGPATH];
1213  char path[MAXPGPATH];
1214  _stringlist *gnames,
1215  *gvalues;
1216 
1217  fputs(_("creating configuration files ... "), stdout);
1218  fflush(stdout);
1219 
1220  /* postgresql.conf */
1221 
1222  conflines = readfile(conf_file);
1223 
1224  snprintf(repltok, sizeof(repltok), "%d", n_connections);
1225  conflines = replace_guc_value(conflines, "max_connections",
1226  repltok, false);
1227 
1228  if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1229  snprintf(repltok, sizeof(repltok), "%dMB",
1230  (n_buffers * (BLCKSZ / 1024)) / 1024);
1231  else
1232  snprintf(repltok, sizeof(repltok), "%dkB",
1233  n_buffers * (BLCKSZ / 1024));
1234  conflines = replace_guc_value(conflines, "shared_buffers",
1235  repltok, false);
1236 
1237  conflines = replace_guc_value(conflines, "lc_messages",
1238  lc_messages, false);
1239 
1240  conflines = replace_guc_value(conflines, "lc_monetary",
1241  lc_monetary, false);
1242 
1243  conflines = replace_guc_value(conflines, "lc_numeric",
1244  lc_numeric, false);
1245 
1246  conflines = replace_guc_value(conflines, "lc_time",
1247  lc_time, false);
1248 
1249  switch (locale_date_order(lc_time))
1250  {
1251  case DATEORDER_YMD:
1252  strcpy(repltok, "iso, ymd");
1253  break;
1254  case DATEORDER_DMY:
1255  strcpy(repltok, "iso, dmy");
1256  break;
1257  case DATEORDER_MDY:
1258  default:
1259  strcpy(repltok, "iso, mdy");
1260  break;
1261  }
1262  conflines = replace_guc_value(conflines, "datestyle",
1263  repltok, false);
1264 
1265  snprintf(repltok, sizeof(repltok), "pg_catalog.%s",
1267  conflines = replace_guc_value(conflines, "default_text_search_config",
1268  repltok, false);
1269 
1270  if (default_timezone)
1271  {
1272  conflines = replace_guc_value(conflines, "timezone",
1273  default_timezone, false);
1274  conflines = replace_guc_value(conflines, "log_timezone",
1275  default_timezone, false);
1276  }
1277 
1278  conflines = replace_guc_value(conflines, "dynamic_shared_memory_type",
1280 
1281  /* Caution: these depend on wal_segment_size_mb, they're not constants */
1282  conflines = replace_guc_value(conflines, "min_wal_size",
1284 
1285  conflines = replace_guc_value(conflines, "max_wal_size",
1287 
1288  /*
1289  * Fix up various entries to match the true compile-time defaults. Since
1290  * these are indeed defaults, keep the postgresql.conf lines commented.
1291  */
1292  conflines = replace_guc_value(conflines, "unix_socket_directories",
1293  DEFAULT_PGSOCKET_DIR, true);
1294 
1295  conflines = replace_guc_value(conflines, "port",
1296  DEF_PGPORT_STR, true);
1297 
1298 #if DEFAULT_BACKEND_FLUSH_AFTER > 0
1299  snprintf(repltok, sizeof(repltok), "%dkB",
1300  DEFAULT_BACKEND_FLUSH_AFTER * (BLCKSZ / 1024));
1301  conflines = replace_guc_value(conflines, "backend_flush_after",
1302  repltok, true);
1303 #endif
1304 
1305 #if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1306  snprintf(repltok, sizeof(repltok), "%dkB",
1307  DEFAULT_BGWRITER_FLUSH_AFTER * (BLCKSZ / 1024));
1308  conflines = replace_guc_value(conflines, "bgwriter_flush_after",
1309  repltok, true);
1310 #endif
1311 
1312 #if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1313  snprintf(repltok, sizeof(repltok), "%dkB",
1314  DEFAULT_CHECKPOINT_FLUSH_AFTER * (BLCKSZ / 1024));
1315  conflines = replace_guc_value(conflines, "checkpoint_flush_after",
1316  repltok, true);
1317 #endif
1318 
1319 #ifndef USE_PREFETCH
1320  conflines = replace_guc_value(conflines, "effective_io_concurrency",
1321  "0", true);
1322 #endif
1323 
1324 #ifdef WIN32
1325  conflines = replace_guc_value(conflines, "update_process_title",
1326  "off", true);
1327 #endif
1328 
1329  /*
1330  * Change password_encryption setting to md5 if md5 was chosen as an
1331  * authentication method, unless scram-sha-256 was also chosen.
1332  */
1333  if ((strcmp(authmethodlocal, "md5") == 0 &&
1334  strcmp(authmethodhost, "scram-sha-256") != 0) ||
1335  (strcmp(authmethodhost, "md5") == 0 &&
1336  strcmp(authmethodlocal, "scram-sha-256") != 0))
1337  {
1338  conflines = replace_guc_value(conflines, "password_encryption",
1339  "md5", false);
1340  }
1341 
1342  /*
1343  * If group access has been enabled for the cluster then it makes sense to
1344  * ensure that the log files also allow group access. Otherwise a backup
1345  * from a user in the group would fail if the log files were not
1346  * relocated.
1347  */
1349  {
1350  conflines = replace_guc_value(conflines, "log_file_mode",
1351  "0640", false);
1352  }
1353 
1354  /*
1355  * Now replace anything that's overridden via -c switches.
1356  */
1357  for (gnames = extra_guc_names, gvalues = extra_guc_values;
1358  gnames != NULL; /* assume lists have the same length */
1359  gnames = gnames->next, gvalues = gvalues->next)
1360  {
1361  conflines = replace_guc_value(conflines, gnames->str,
1362  gvalues->str, false);
1363  }
1364 
1365  /* ... and write out the finished postgresql.conf file */
1366  snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
1367 
1368  writefile(path, conflines);
1369  if (chmod(path, pg_file_create_mode) != 0)
1370  pg_fatal("could not change permissions of \"%s\": %m", path);
1371 
1372 
1373  /* postgresql.auto.conf */
1374 
1375  conflines = pg_malloc_array(char *, 3);
1376  conflines[0] = pg_strdup("# Do not edit this file manually!\n");
1377  conflines[1] = pg_strdup("# It will be overwritten by the ALTER SYSTEM command.\n");
1378  conflines[2] = NULL;
1379 
1380  sprintf(path, "%s/postgresql.auto.conf", pg_data);
1381 
1382  writefile(path, conflines);
1383  if (chmod(path, pg_file_create_mode) != 0)
1384  pg_fatal("could not change permissions of \"%s\": %m", path);
1385 
1386 
1387  /* pg_hba.conf */
1388 
1389  conflines = readfile(hba_file);
1390 
1391  conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
1392 
1393 
1394  /*
1395  * Probe to see if there is really any platform support for IPv6, and
1396  * comment out the relevant pg_hba line if not. This avoids runtime
1397  * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
1398  * useful on Windows, where executables built on a machine with IPv6 may
1399  * have to run on a machine without.
1400  */
1401  {
1402  struct addrinfo *gai_result;
1403  struct addrinfo hints;
1404  int err = 0;
1405 
1406 #ifdef WIN32
1407  /* need to call WSAStartup before calling getaddrinfo */
1408  WSADATA wsaData;
1409 
1410  err = WSAStartup(MAKEWORD(2, 2), &wsaData);
1411 #endif
1412 
1413  /* for best results, this code should match parse_hba_line() */
1414  hints.ai_flags = AI_NUMERICHOST;
1415  hints.ai_family = AF_UNSPEC;
1416  hints.ai_socktype = 0;
1417  hints.ai_protocol = 0;
1418  hints.ai_addrlen = 0;
1419  hints.ai_canonname = NULL;
1420  hints.ai_addr = NULL;
1421  hints.ai_next = NULL;
1422 
1423  if (err != 0 ||
1424  getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
1425  {
1426  conflines = replace_token(conflines,
1427  "host all all ::1",
1428  "#host all all ::1");
1429  conflines = replace_token(conflines,
1430  "host replication all ::1",
1431  "#host replication all ::1");
1432  }
1433  }
1434 
1435  /* Replace default authentication methods */
1436  conflines = replace_token(conflines,
1437  "@authmethodhost@",
1438  authmethodhost);
1439  conflines = replace_token(conflines,
1440  "@authmethodlocal@",
1441  authmethodlocal);
1442 
1443  conflines = replace_token(conflines,
1444  "@authcomment@",
1445  (strcmp(authmethodlocal, "trust") == 0 || strcmp(authmethodhost, "trust") == 0) ? AUTHTRUST_WARNING : "");
1446 
1447  snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
1448 
1449  writefile(path, conflines);
1450  if (chmod(path, pg_file_create_mode) != 0)
1451  pg_fatal("could not change permissions of \"%s\": %m", path);
1452 
1453 
1454  /* pg_ident.conf */
1455 
1456  conflines = readfile(ident_file);
1457 
1458  snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
1459 
1460  writefile(path, conflines);
1461  if (chmod(path, pg_file_create_mode) != 0)
1462  pg_fatal("could not change permissions of \"%s\": %m", path);
1463 
1464  check_ok();
1465 }
void err(int eval, const char *fmt,...)
Definition: err.c:43
#define pg_malloc_array(type, count)
Definition: fe_memutils.h:44
int pg_file_create_mode
Definition: file_perm.c:19
static const char * default_timezone
Definition: initdb.c:201
static char * hba_file
Definition: initdb.c:177
static int n_connections
Definition: initdb.c:198
static int n_buffers
Definition: initdb.c:199
static char * ident_file
Definition: initdb.c:178
static int locale_date_order(const char *locale)
Definition: initdb.c:2070
static char ** replace_guc_value(char **lines, const char *guc_name, const char *guc_value, bool mark_as_comment)
Definition: initdb.c:470
static const char * dynamic_shared_memory_type
Definition: initdb.c:200
#define AUTHTRUST_WARNING
Definition: initdb.c:206
static void writefile(char *path, char **lines)
Definition: initdb.c:665
static char * pretty_wal_size(int segment_count)
Definition: initdb.c:1192
#define DEFAULT_PGSOCKET_DIR
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
#define DEFAULT_BGWRITER_FLUSH_AFTER
#define DEFAULT_MAX_WAL_SEGS
Definition: xlog_internal.h:92
#define DEFAULT_MIN_WAL_SEGS
Definition: xlog_internal.h:91

References _, 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_MAX_WAL_SEGS, DEFAULT_MIN_WAL_SEGS, DEFAULT_PGSOCKET_DIR, default_text_search_config, default_timezone, dynamic_shared_memory_type, err(), extra_guc_names, extra_guc_values, fflush(), hba_file, ident_file, lc_messages, lc_monetary, lc_numeric, lc_time, locale_date_order(), MAXPGPATH, n_buffers, n_connections, _stringlist::next, pg_data, pg_dir_create_mode, PG_DIR_MODE_GROUP, pg_fatal, pg_file_create_mode, pg_malloc_array, pg_strdup(), pretty_wal_size(), readfile(), replace_guc_value(), replace_token(), snprintf, sprintf, generate_unaccent_rules::stdout, _stringlist::str, and writefile().

Referenced by initialize_data_directory().

◆ setup_data_file_paths()

void setup_data_file_paths ( void  )

Definition at line 2719 of file initdb.c.

2720 {
2721  set_input(&bki_file, "postgres.bki");
2722  set_input(&hba_file, "pg_hba.conf.sample");
2723  set_input(&ident_file, "pg_ident.conf.sample");
2724  set_input(&conf_file, "postgresql.conf.sample");
2725  set_input(&dictionary_file, "snowball_create.sql");
2726  set_input(&info_schema_file, "information_schema.sql");
2727  set_input(&features_file, "sql_features.txt");
2728  set_input(&system_constraints_file, "system_constraints.sql");
2729  set_input(&system_functions_file, "system_functions.sql");
2730  set_input(&system_views_file, "system_views.sql");
2731 
2732  if (show_setting || debug)
2733  {
2734  fprintf(stderr,
2735  "VERSION=%s\n"
2736  "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2737  "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2738  "POSTGRESQL_CONF_SAMPLE=%s\n"
2739  "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2740  PG_VERSION,
2742  username, bki_file,
2743  conf_file,
2744  hba_file, ident_file);
2745  if (show_setting)
2746  exit(0);
2747  }
2748 
2759 }
static char * features_file
Definition: initdb.c:182
static void set_input(char **dest, const char *filename)
Definition: initdb.c:924
static void check_input(char *path)
Definition: initdb.c:933
static char * info_schema_file
Definition: initdb.c:181

References bin_path, bki_file, check_input(), conf_file, debug, dictionary_file, exit(), features_file, fprintf, hba_file, ident_file, info_schema_file, pg_data, set_input(), share_path, show_setting, system_constraints_file, system_functions_file, system_views_file, and username.

Referenced by main().

◆ setup_depend()

static void setup_depend ( FILE *  cmdfd)
static

Definition at line 1643 of file initdb.c.

1644 {
1645  /*
1646  * Advance the OID counter so that subsequently-created objects aren't
1647  * pinned.
1648  */
1649  PG_CMD_PUTS("SELECT pg_stop_making_pinned_objects();\n\n");
1650 }

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_description()

static void setup_description ( FILE *  cmdfd)
static

Definition at line 1677 of file initdb.c.

1678 {
1679  /* Create default descriptions for operator implementation functions */
1680  PG_CMD_PUTS("WITH funcdescs AS ( "
1681  "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
1682  "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1683  "INSERT INTO pg_description "
1684  " SELECT p_oid, 'pg_proc'::regclass, 0, "
1685  " 'implementation of ' || oprname || ' operator' "
1686  " FROM funcdescs "
1687  " WHERE NOT EXISTS (SELECT 1 FROM pg_description "
1688  " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
1689  " AND NOT EXISTS (SELECT 1 FROM pg_description "
1690  " WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
1691  " AND description LIKE 'deprecated%');\n\n");
1692 }

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_locale_encoding()

void setup_locale_encoding ( void  )

Definition at line 2614 of file initdb.c.

2615 {
2616  setlocales();
2617 
2618  if (locale_provider == COLLPROVIDER_LIBC &&
2619  strcmp(lc_ctype, lc_collate) == 0 &&
2620  strcmp(lc_ctype, lc_time) == 0 &&
2621  strcmp(lc_ctype, lc_numeric) == 0 &&
2622  strcmp(lc_ctype, lc_monetary) == 0 &&
2623  strcmp(lc_ctype, lc_messages) == 0 &&
2624  (!datlocale || strcmp(lc_ctype, datlocale) == 0))
2625  printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
2626  else
2627  {
2628  printf(_("The database cluster will be initialized with this locale configuration:\n"));
2629  printf(_(" locale provider: %s\n"), collprovider_name(locale_provider));
2630  if (locale_provider != COLLPROVIDER_LIBC)
2631  printf(_(" default collation: %s\n"), datlocale);
2632  printf(_(" LC_COLLATE: %s\n"
2633  " LC_CTYPE: %s\n"
2634  " LC_MESSAGES: %s\n"
2635  " LC_MONETARY: %s\n"
2636  " LC_NUMERIC: %s\n"
2637  " LC_TIME: %s\n"),
2638  lc_collate,
2639  lc_ctype,
2640  lc_messages,
2641  lc_monetary,
2642  lc_numeric,
2643  lc_time);
2644  }
2645 
2646  if (!encoding)
2647  {
2648  int ctype_enc;
2649 
2650  ctype_enc = pg_get_encoding_from_locale(lc_ctype, true);
2651 
2652  /*
2653  * If ctype_enc=SQL_ASCII, it's compatible with any encoding. ICU does
2654  * not support SQL_ASCII, so select UTF-8 instead.
2655  */
2656  if (locale_provider == COLLPROVIDER_ICU && ctype_enc == PG_SQL_ASCII)
2657  ctype_enc = PG_UTF8;
2658 
2659  if (ctype_enc == -1)
2660  {
2661  /* Couldn't recognize the locale's codeset */
2662  pg_log_error("could not find suitable encoding for locale \"%s\"",
2663  lc_ctype);
2664  pg_log_error_hint("Rerun %s with the -E option.", progname);
2665  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2666  exit(1);
2667  }
2668  else if (!pg_valid_server_encoding_id(ctype_enc))
2669  {
2670  /*
2671  * We recognized it, but it's not a legal server encoding. On
2672  * Windows, UTF-8 works with any locale, so we can fall back to
2673  * UTF-8.
2674  */
2675 #ifdef WIN32
2676  encodingid = PG_UTF8;
2677  printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2678  "The default database encoding will be set to \"%s\" instead.\n"),
2679  pg_encoding_to_char(ctype_enc),
2681 #else
2682  pg_log_error("locale \"%s\" requires unsupported encoding \"%s\"",
2683  lc_ctype, pg_encoding_to_char(ctype_enc));
2684  pg_log_error_detail("Encoding \"%s\" is not allowed as a server-side encoding.",
2685  pg_encoding_to_char(ctype_enc));
2686  pg_log_error_hint("Rerun %s with a different locale selection.",
2687  progname);
2688  exit(1);
2689 #endif
2690  }
2691  else
2692  {
2693  encodingid = ctype_enc;
2694  printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2696  }
2697  }
2698  else
2700 
2703  exit(1); /* check_locale_encoding printed the error */
2704 
2705  if (locale_provider == COLLPROVIDER_BUILTIN)
2706  {
2707  if (strcmp(datlocale, "C.UTF-8") == 0 && encodingid != PG_UTF8)
2708  pg_fatal("builtin provider locale \"%s\" requires encoding \"%s\"",
2709  datlocale, "UTF-8");
2710  }
2711 
2712  if (locale_provider == COLLPROVIDER_ICU &&
2714  exit(1);
2715 }
static bool check_icu_locale_encoding(int user_enc)
Definition: initdb.c:2229
static int get_encoding_id(const char *encoding_name)
Definition: initdb.c:788
static bool check_locale_encoding(const char *locale, int user_enc)
Definition: initdb.c:2194
static void setlocales(void)
Definition: initdb.c:2353
#define pg_valid_server_encoding_id
Definition: pg_wchar.h:632

References _, check_icu_locale_encoding(), check_locale_encoding(), datlocale, encoding, encodingid, exit(), get_encoding_id(), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, locale_provider, pg_encoding_to_char, pg_fatal, pg_get_encoding_from_locale(), pg_log_error, pg_log_error_detail, pg_log_error_hint, PG_SQL_ASCII, PG_UTF8, pg_valid_server_encoding_id, printf, progname, and setlocales().

Referenced by main().

◆ setup_pgdata()

void setup_pgdata ( void  )

Definition at line 2540 of file initdb.c.

2541 {
2542  char *pgdata_get_env;
2543 
2544  if (!pg_data)
2545  {
2546  pgdata_get_env = getenv("PGDATA");
2547  if (pgdata_get_env && strlen(pgdata_get_env))
2548  {
2549  /* PGDATA found */
2550  pg_data = pg_strdup(pgdata_get_env);
2551  }
2552  else
2553  {
2554  pg_log_error("no data directory specified");
2555  pg_log_error_hint("You must identify the directory where the data for this database system "
2556  "will reside. Do this with either the invocation option -D or the "
2557  "environment variable PGDATA.");
2558  exit(1);
2559  }
2560  }
2561 
2564 
2565  /*
2566  * we have to set PGDATA for postgres rather than pass it on the command
2567  * line to avoid dumb quoting problems on Windows, and we would especially
2568  * need quotes otherwise on Windows because paths there are most likely to
2569  * have embedded spaces.
2570  */
2571  if (setenv("PGDATA", pg_data, 1) != 0)
2572  pg_fatal("could not set environment");
2573 }
#define setenv(x, y, z)
Definition: win32_port.h:537

References canonicalize_path(), exit(), pg_data, pg_fatal, pg_log_error, pg_log_error_hint, pg_strdup(), pgdata_native, and setenv.

Referenced by main().

◆ setup_privileges()

static void setup_privileges ( FILE *  cmdfd)
static

Definition at line 1731 of file initdb.c.

1732 {
1733  PG_CMD_PRINTF("UPDATE pg_class "
1734  " SET relacl = (SELECT array_agg(a.acl) FROM "
1735  " (SELECT E'=r/\"%s\"' as acl "
1736  " UNION SELECT unnest(pg_catalog.acldefault("
1737  " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
1738  " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
1739  " ) as a) "
1740  " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1741  CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
1742  CppAsString2(RELKIND_SEQUENCE) ")"
1743  " AND relacl IS NULL;\n\n",
1745  PG_CMD_PUTS("GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
1746  PG_CMD_PUTS("REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
1747  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1748  " (objoid, classoid, objsubid, initprivs, privtype)"
1749  " SELECT"
1750  " oid,"
1751  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1752  " 0,"
1753  " relacl,"
1754  " 'i'"
1755  " FROM"
1756  " pg_class"
1757  " WHERE"
1758  " relacl IS NOT NULL"
1759  " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1760  CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
1761  CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1762  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1763  " (objoid, classoid, objsubid, initprivs, privtype)"
1764  " SELECT"
1765  " pg_class.oid,"
1766  " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1767  " pg_attribute.attnum,"
1768  " pg_attribute.attacl,"
1769  " 'i'"
1770  " FROM"
1771  " pg_class"
1772  " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1773  " WHERE"
1774  " pg_attribute.attacl IS NOT NULL"
1775  " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1776  CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
1777  CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1778  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1779  " (objoid, classoid, objsubid, initprivs, privtype)"
1780  " SELECT"
1781  " oid,"
1782  " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1783  " 0,"
1784  " proacl,"
1785  " 'i'"
1786  " FROM"
1787  " pg_proc"
1788  " WHERE"
1789  " proacl IS NOT NULL;\n\n");
1790  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1791  " (objoid, classoid, objsubid, initprivs, privtype)"
1792  " SELECT"
1793  " oid,"
1794  " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1795  " 0,"
1796  " typacl,"
1797  " 'i'"
1798  " FROM"
1799  " pg_type"
1800  " WHERE"
1801  " typacl IS NOT NULL;\n\n");
1802  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1803  " (objoid, classoid, objsubid, initprivs, privtype)"
1804  " SELECT"
1805  " oid,"
1806  " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1807  " 0,"
1808  " lanacl,"
1809  " 'i'"
1810  " FROM"
1811  " pg_language"
1812  " WHERE"
1813  " lanacl IS NOT NULL;\n\n");
1814  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1815  " (objoid, classoid, objsubid, initprivs, privtype)"
1816  " SELECT"
1817  " oid,"
1818  " (SELECT oid FROM pg_class WHERE "
1819  " relname = 'pg_largeobject_metadata'),"
1820  " 0,"
1821  " lomacl,"
1822  " 'i'"
1823  " FROM"
1824  " pg_largeobject_metadata"
1825  " WHERE"
1826  " lomacl IS NOT NULL;\n\n");
1827  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1828  " (objoid, classoid, objsubid, initprivs, privtype)"
1829  " SELECT"
1830  " oid,"
1831  " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1832  " 0,"
1833  " nspacl,"
1834  " 'i'"
1835  " FROM"
1836  " pg_namespace"
1837  " WHERE"
1838  " nspacl IS NOT NULL;\n\n");
1839  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1840  " (objoid, classoid, objsubid, initprivs, privtype)"
1841  " SELECT"
1842  " oid,"
1843  " (SELECT oid FROM pg_class WHERE "
1844  " relname = 'pg_foreign_data_wrapper'),"
1845  " 0,"
1846  " fdwacl,"
1847  " 'i'"
1848  " FROM"
1849  " pg_foreign_data_wrapper"
1850  " WHERE"
1851  " fdwacl IS NOT NULL;\n\n");
1852  PG_CMD_PUTS("INSERT INTO pg_init_privs "
1853  " (objoid, classoid, objsubid, initprivs, privtype)"
1854  " SELECT"
1855  " oid,"
1856  " (SELECT oid FROM pg_class "
1857  " WHERE relname = 'pg_foreign_server'),"
1858  " 0,"
1859  " srvacl,"
1860  " 'i'"
1861  " FROM"
1862  " pg_foreign_server"
1863  " WHERE"
1864  " srvacl IS NOT NULL;\n\n");
1865 }

References CppAsString2, escape_quotes(), PG_CMD_PRINTF, PG_CMD_PUTS, and username.

Referenced by initialize_data_directory().

◆ setup_run_file()

static void setup_run_file ( FILE *  cmdfd,
const char *  filename 
)
static

Definition at line 1656 of file initdb.c.

1657 {
1658  char **lines;
1659 
1660  lines = readfile(filename);
1661 
1662  for (char **line = lines; *line != NULL; line++)
1663  {
1664  PG_CMD_PUTS(*line);
1665  free(*line);
1666  }
1667 
1668  PG_CMD_PUTS("\n\n");
1669 
1670  free(lines);
1671 }

References filename, free, PG_CMD_PUTS, and readfile().

Referenced by initialize_data_directory(), and setup_schema().

◆ setup_schema()

static void setup_schema ( FILE *  cmdfd)
static

Definition at line 1899 of file initdb.c.

1900 {
1902 
1903  PG_CMD_PRINTF("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_PRINTF("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 }

References escape_quotes(), features_file, info_schema_file, infoversion, PG_CMD_PRINTF, and setup_run_file().

Referenced by initialize_data_directory().

◆ setup_signals()

void setup_signals ( void  )

Definition at line 2797 of file initdb.c.

2798 {
2799  /* some of these are not valid on Windows */
2800 #ifdef SIGHUP
2802 #endif
2803 #ifdef SIGINT
2804  pqsignal(SIGINT, trapsig);
2805 #endif
2806 #ifdef SIGQUIT
2808 #endif
2809 #ifdef SIGTERM
2810  pqsignal(SIGTERM, trapsig);
2811 #endif
2812 
2813  /* Ignore SIGPIPE when writing to backend, so we can clean up */
2814 #ifdef SIGPIPE
2816 #endif
2817 
2818  /* Prevent SIGSYS so we can probe for kernel calls that might not work */
2819 #ifdef SIGSYS
2820  pqsignal(SIGSYS, SIG_IGN);
2821 #endif
2822 }
static void trapsig(SIGNAL_ARGS)
Definition: initdb.c:2025
pqsigfunc pqsignal(int signo, pqsigfunc func)
#define SIGHUP
Definition: win32_port.h:168
#define SIGPIPE
Definition: win32_port.h:173
#define SIGQUIT
Definition: win32_port.h:169
#define SIG_IGN
Definition: win32_port.h:165

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

Referenced by initialize_data_directory().

◆ setup_text_search()

void setup_text_search ( void  )

Definition at line 2763 of file initdb.c.

2764 {
2766  {
2769  {
2770  pg_log_info("could not find suitable text search configuration for locale \"%s\"",
2771  lc_ctype);
2772  default_text_search_config = "simple";
2773  }
2774  }
2775  else
2776  {
2777  const char *checkmatch = find_matching_ts_config(lc_ctype);
2778 
2779  if (checkmatch == NULL)
2780  {
2781  pg_log_warning("suitable text search configuration for locale \"%s\" is unknown",
2782  lc_ctype);
2783  }
2784  else if (strcmp(checkmatch, default_text_search_config) != 0)
2785  {
2786  pg_log_warning("specified text search configuration \"%s\" might not match locale \"%s\"",
2788  }
2789  }
2790 
2791  printf(_("The default text search configuration will be set to \"%s\".\n"),
2793 }
static const char * find_matching_ts_config(const char *lc_type)
Definition: initdb.c:878

References _, default_text_search_config, find_matching_ts_config(), lc_ctype, pg_log_info, pg_log_warning, and printf.

Referenced by main().

◆ test_config_settings()

static void test_config_settings ( void  )
static

Definition at line 1058 of file initdb.c.

1059 {
1060  /*
1061  * This macro defines the minimum shared_buffers we want for a given
1062  * max_connections value. The arrays show the settings to try.
1063  */
1064 #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
1065 
1066  static const int trial_conns[] = {
1067  100, 50, 40, 30, 20
1068  };
1069  static const int trial_bufs[] = {
1070  16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
1071  1000, 900, 800, 700, 600, 500,
1072  400, 300, 200, 100, 50
1073  };
1074 
1075  const int connslen = sizeof(trial_conns) / sizeof(int);
1076  const int bufslen = sizeof(trial_bufs) / sizeof(int);
1077  int i,
1078  test_conns,
1079  test_buffs,
1080  ok_buffers = 0;
1081 
1082  /*
1083  * Need to determine working DSM implementation first so that subsequent
1084  * tests don't fail because DSM setting doesn't work.
1085  */
1086  printf(_("selecting dynamic shared memory implementation ... "));
1087  fflush(stdout);
1090 
1091  /*
1092  * Probe for max_connections before shared_buffers, since it is subject to
1093  * more constraints than shared_buffers.
1094  */
1095  printf(_("selecting default max_connections ... "));
1096  fflush(stdout);
1097 
1098  for (i = 0; i < connslen; i++)
1099  {
1100  test_conns = trial_conns[i];
1101  test_buffs = MIN_BUFS_FOR_CONNS(test_conns);
1102 
1103  if (test_specific_config_settings(test_conns, test_buffs))
1104  {
1105  ok_buffers = test_buffs;
1106  break;
1107  }
1108  }
1109  if (i >= connslen)
1110  i = connslen - 1;
1111  n_connections = trial_conns[i];
1112 
1113  printf("%d\n", n_connections);
1114 
1115  printf(_("selecting default shared_buffers ... "));
1116  fflush(stdout);
1117 
1118  for (i = 0; i < bufslen; i++)
1119  {
1120  /* Use same amount of memory, independent of BLCKSZ */
1121  test_buffs = (trial_bufs[i] * 8192) / BLCKSZ;
1122  if (test_buffs <= ok_buffers)
1123  {
1124  test_buffs = ok_buffers;
1125  break;
1126  }
1127 
1129  break;
1130  }
1131  n_buffers = test_buffs;
1132 
1133  if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1134  printf("%dMB\n", (n_buffers * (BLCKSZ / 1024)) / 1024);
1135  else
1136  printf("%dkB\n", n_buffers * (BLCKSZ / 1024));
1137 
1138  printf(_("selecting default time zone ... "));
1139  fflush(stdout);
1141  printf("%s\n", default_timezone ? default_timezone : "GMT");
1142 }
const char * select_default_timezone(const char *share_path)
static const char * choose_dsm_implementation(void)
Definition: initdb.c:1016
#define MIN_BUFS_FOR_CONNS(nconns)
static bool test_specific_config_settings(int test_conns, int test_buffs)
Definition: initdb.c:1148

References _, choose_dsm_implementation(), default_timezone, dynamic_shared_memory_type, fflush(), i, MIN_BUFS_FOR_CONNS, n_buffers, n_connections, printf, select_default_timezone(), share_path, generate_unaccent_rules::stdout, and test_specific_config_settings().

Referenced by initialize_data_directory().

◆ test_specific_config_settings()

static bool test_specific_config_settings ( int  test_conns,
int  test_buffs 
)
static

Definition at line 1148 of file initdb.c.

1149 {
1150  PQExpBufferData cmd;
1151  _stringlist *gnames,
1152  *gvalues;
1153  int status;
1154 
1155  initPQExpBuffer(&cmd);
1156 
1157  /* Set up the test postmaster invocation */
1158  printfPQExpBuffer(&cmd,
1159  "\"%s\" --check %s %s "
1160  "-c max_connections=%d "
1161  "-c shared_buffers=%d "
1162  "-c dynamic_shared_memory_type=%s",
1164  test_conns, test_buffs,
1166 
1167  /* Add any user-given setting overrides */
1168  for (gnames = extra_guc_names, gvalues = extra_guc_values;
1169  gnames != NULL; /* assume lists have the same length */
1170  gnames = gnames->next, gvalues = gvalues->next)
1171  {
1172  appendPQExpBuffer(&cmd, " -c %s=", gnames->str);
1173  appendShellString(&cmd, gvalues->str);
1174  }
1175 
1176  appendPQExpBuffer(&cmd,
1177  " < \"%s\" > \"%s\" 2>&1",
1178  DEVNULL, DEVNULL);
1179 
1180  fflush(NULL);
1181  status = system(cmd.data);
1182 
1183  termPQExpBuffer(&cmd);
1184 
1185  return (status == 0);
1186 }

References appendPQExpBuffer(), appendShellString(), backend_exec, boot_options, PQExpBufferData::data, DEVNULL, dynamic_shared_memory_type, extra_guc_names, extra_guc_values, extra_options, fflush(), initPQExpBuffer(), _stringlist::next, printfPQExpBuffer(), _stringlist::str, and termPQExpBuffer().

Referenced by test_config_settings().

◆ trapsig()

static void trapsig ( SIGNAL_ARGS  )
static

Definition at line 2025 of file initdb.c.

2026 {
2027  /* handle systems that reset the handler, like Windows (grr) */
2028  pqsignal(postgres_signal_arg, trapsig);
2029  caught_signal = true;
2030 }

References caught_signal, and pqsignal().

Referenced by setup_signals().

◆ usage()

static void usage ( const char *  progname)
static

Definition at line 2444 of file initdb.c.

2445 {
2446  printf(_("%s initializes a PostgreSQL database cluster.\n\n"), progname);
2447  printf(_("Usage:\n"));
2448  printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
2449  printf(_("\nOptions:\n"));
2450  printf(_(" -A, --auth=METHOD default authentication method for local connections\n"));
2451  printf(_(" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
2452  printf(_(" --auth-local=METHOD default authentication method for local-socket connections\n"));
2453  printf(_(" [-D, --pgdata=]DATADIR location for this database cluster\n"));
2454  printf(_(" -E, --encoding=ENCODING set default encoding for new databases\n"));
2455  printf(_(" -g, --allow-group-access allow group read/execute on data directory\n"));
2456  printf(_(" --icu-locale=LOCALE set ICU locale ID for new databases\n"));
2457  printf(_(" --icu-rules=RULES set additional ICU collation rules for new databases\n"));
2458  printf(_(" -k, --data-checksums use data page checksums\n"));
2459  printf(_(" --locale=LOCALE set default locale for new databases\n"));
2460  printf(_(" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
2461  " --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
2462  " set default locale in the respective category for\n"
2463  " new databases (default taken from environment)\n"));
2464  printf(_(" --no-locale equivalent to --locale=C\n"));
2465  printf(_(" --builtin-locale=LOCALE\n"
2466  " set builtin locale name for new databases\n"));
2467  printf(_(" --locale-provider={builtin|libc|icu}\n"
2468  " set default locale provider for new databases\n"));
2469  printf(_(" --pwfile=FILE read password for the new superuser from file\n"));
2470  printf(_(" -T, --text-search-config=CFG\n"
2471  " default text search configuration\n"));
2472  printf(_(" -U, --username=NAME database superuser name\n"));
2473  printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
2474  printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
2475  printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
2476  printf(_("\nLess commonly used options:\n"));
2477  printf(_(" -c, --set NAME=VALUE override default setting for server parameter\n"));
2478  printf(_(" -d, --debug generate lots of debugging output\n"));
2479  printf(_(" --discard-caches set debug_discard_caches=1\n"));
2480  printf(_(" -L DIRECTORY where to find the input files\n"));
2481  printf(_(" -n, --no-clean do not clean up after errors\n"));
2482  printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
2483  printf(_(" --no-instructions do not print instructions for next steps\n"));
2484  printf(_(" -s, --show show internal settings\n"));
2485  printf(_(" --sync-method=METHOD set method for syncing files to disk\n"));
2486  printf(_(" -S, --sync-only only sync database files to disk, then exit\n"));
2487  printf(_("\nOther options:\n"));
2488  printf(_(" -V, --version output version information, then exit\n"));
2489  printf(_(" -?, --help show this help, then exit\n"));
2490  printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"
2491  "is used.\n"));
2492  printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2493  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2494 }

References _, printf, and progname.

Referenced by main().

◆ vacuum_db()

static void vacuum_db ( FILE *  cmdfd)
static

Definition at line 1928 of file initdb.c.

1929 {
1930  /* Run analyze before VACUUM so the statistics are frozen. */
1931  PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
1932 }

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ warn_on_mount_point()

void warn_on_mount_point ( int  error)

Definition at line 2967 of file initdb.c.

2968 {
2969  if (error == 2)
2970  pg_log_error_detail("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
2971  else if (error == 3)
2972  pg_log_error_detail("It contains a lost+found directory, perhaps due to it being a mount point.");
2973 
2974  pg_log_error_hint("Using a mount point directly as the data directory is not recommended.\n"
2975  "Create a subdirectory under the mount point.");
2976 }
static void error(void)
Definition: sql-dyntest.c:147

References error(), pg_log_error_detail, and pg_log_error_hint.

Referenced by create_data_directory(), and create_xlog_or_symlink().

◆ write_version_file()

static void write_version_file ( const char *  extrapath)
static

Definition at line 964 of file initdb.c.

965 {
966  FILE *version_file;
967  char *path;
968 
969  if (extrapath == NULL)
970  path = psprintf("%s/PG_VERSION", pg_data);
971  else
972  path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
973 
974  if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
975  pg_fatal("could not open file \"%s\" for writing: %m", path);
976  if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
977  fclose(version_file))
978  pg_fatal("could not write file \"%s\": %m", path);
979  free(path);
980 }
static char version_file[MAXPGPATH]
Definition: pg_ctl.c:97

References fprintf, free, PG_BINARY_W, pg_data, pg_fatal, psprintf(), and version_file.

Referenced by initialize_data_directory().

◆ writefile()

static void writefile ( char *  path,
char **  lines 
)
static

Definition at line 665 of file initdb.c.

666 {
667  FILE *out_file;
668  char **line;
669 
670  if ((out_file = fopen(path, "w")) == NULL)
671  pg_fatal("could not open file \"%s\" for writing: %m", path);
672  for (line = lines; *line != NULL; line++)
673  {
674  if (fputs(*line, out_file) < 0)
675  pg_fatal("could not write file \"%s\": %m", path);
676  free(*line);
677  }
678  if (fclose(out_file))
679  pg_fatal("could not close file \"%s\": %m", path);
680  free(lines);
681 }

References free, and pg_fatal.

Referenced by setup_config().

Variable Documentation

◆ auth_methods_host

const char* const auth_methods_host[]
static
Initial value:
= {
"trust", "reject", "scram-sha-256", "md5", "password", "ident", "radius",
NULL
}

Definition at line 96 of file initdb.c.

Referenced by main().

◆ auth_methods_local

const char* const auth_methods_local[]
static
Initial value:
= {
"trust", "reject", "scram-sha-256", "md5", "password", "peer", "radius",
NULL
}

Definition at line 118 of file initdb.c.

Referenced by main().

◆ authmethodhost

const char* authmethodhost = NULL
static

Definition at line 157 of file initdb.c.

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

◆ authmethodlocal

const char* authmethodlocal = NULL
static

Definition at line 158 of file initdb.c.

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

◆ authwarning

bool authwarning = false
static

Definition at line 211 of file initdb.c.

Referenced by check_authmethod_unspecified(), and main().

◆ backend_exec

char backend_exec[MAXPGPATH]
static

◆ backend_options

const char* const backend_options = "--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true -c log_checkpoints=false"
static

Definition at line 224 of file initdb.c.

Referenced by initialize_data_directory().

◆ bin_path

char bin_path[MAXPGPATH]
static

Definition at line 257 of file initdb.c.

Referenced by make_relative_path(), setup_bin_paths(), and setup_data_file_paths().

◆ bki_file

char* bki_file
static

Definition at line 176 of file initdb.c.

Referenced by bootstrap_template1(), and setup_data_file_paths().

◆ boot_options

const char* const boot_options = "-F -c log_checkpoints=false"
static

Definition at line 223 of file initdb.c.

Referenced by bootstrap_template1(), and test_specific_config_settings().

◆ builtin_locale_specified

bool builtin_locale_specified = false
static

Definition at line 148 of file initdb.c.

Referenced by main().

◆ caught_signal

bool caught_signal = false
static

Definition at line 192 of file initdb.c.

Referenced by check_ok(), and trapsig().

◆ conf_file

char* conf_file
static

Definition at line 179 of file initdb.c.

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

◆ data_checksums

bool data_checksums = false
static

Definition at line 167 of file initdb.c.

Referenced by bootstrap_template1(), and main().

◆ datlocale

char* datlocale = NULL
static

◆ debug

◆ default_text_search_config

const char* default_text_search_config = NULL
static

Definition at line 152 of file initdb.c.

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

◆ default_timezone

const char* default_timezone = NULL
static

Definition at line 201 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ dictionary_file

char* dictionary_file
static

Definition at line 180 of file initdb.c.

Referenced by initialize_data_directory(), and setup_data_file_paths().

◆ do_sync

bool do_sync = true
static

Definition at line 164 of file initdb.c.

Referenced by main(), sync_target_dir(), and update_controlfile().

◆ dynamic_shared_memory_type

const char* dynamic_shared_memory_type = NULL
static

Definition at line 200 of file initdb.c.

Referenced by setup_config(), test_config_settings(), and test_specific_config_settings().

◆ encoding

char* encoding = NULL
static

Definition at line 139 of file initdb.c.

Referenced by main(), and setup_locale_encoding().

◆ encodingid

int encodingid
static

Definition at line 175 of file initdb.c.

Referenced by bootstrap_template1(), and setup_locale_encoding().

◆ extra_guc_names

_stringlist* extra_guc_names = NULL
static

Definition at line 159 of file initdb.c.

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

◆ extra_guc_values

_stringlist* extra_guc_values = NULL
static

Definition at line 160 of file initdb.c.

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

◆ extra_options

char* extra_options = ""
static

◆ features_file

char* features_file
static

Definition at line 182 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_schema().

◆ found_existing_pgdata

bool found_existing_pgdata = false
static

Definition at line 188 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_data_directory().

◆ found_existing_xlogdir

bool found_existing_xlogdir = false
static

Definition at line 190 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_xlog_or_symlink().

◆ hba_file

char* hba_file
static

Definition at line 177 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

◆ icu_locale_specified

bool icu_locale_specified = false
static

Definition at line 150 of file initdb.c.

Referenced by main().

◆ icu_rules

char* icu_rules = NULL
static

Definition at line 151 of file initdb.c.

Referenced by bootstrap_template1(), and main().

◆ ident_file

char* ident_file
static

Definition at line 178 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

◆ info_schema_file

char* info_schema_file
static

Definition at line 181 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_schema().

◆ infoversion

char infoversion[100]
static

Definition at line 191 of file initdb.c.

Referenced by set_info_version(), and setup_schema().

◆ lc_collate

char* lc_collate = NULL
static

◆ lc_ctype

char* lc_ctype = NULL
static

◆ lc_messages

char* lc_messages = NULL
static

Definition at line 146 of file initdb.c.

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

◆ lc_monetary

char* lc_monetary = NULL
static

Definition at line 143 of file initdb.c.

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

◆ lc_numeric

char* lc_numeric = NULL
static

Definition at line 144 of file initdb.c.

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

◆ lc_time

char* lc_time = NULL
static

Definition at line 145 of file initdb.c.

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

◆ locale

◆ locale_provider

char locale_provider = COLLPROVIDER_LIBC
static

Definition at line 147 of file initdb.c.

Referenced by bootstrap_template1(), main(), setlocales(), and setup_locale_encoding().

◆ made_new_pgdata

bool made_new_pgdata = false
static

Definition at line 187 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_data_directory().

◆ made_new_xlogdir

bool made_new_xlogdir = false
static

Definition at line 189 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_xlog_or_symlink().

◆ n_buffers

int n_buffers = 50
static

Definition at line 199 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ n_connections

int n_connections = 10
static

Definition at line 198 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ noclean

bool noclean = false
static

Definition at line 162 of file initdb.c.

Referenced by cleanup_directories_atexit(), and main().

◆ noinstructions

bool noinstructions = false
static

Definition at line 163 of file initdb.c.

Referenced by main().

◆ output_errno

int output_errno = 0
static

Definition at line 194 of file initdb.c.

Referenced by check_ok().

◆ output_failed

bool output_failed = false
static

Definition at line 193 of file initdb.c.

Referenced by check_ok().

◆ pg_data

◆ pgdata_native

char* pgdata_native
static

Definition at line 195 of file initdb.c.

Referenced by main(), and setup_pgdata().

◆ progname

◆ pwfilename

char* pwfilename = NULL
static

Definition at line 155 of file initdb.c.

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

◆ pwprompt

bool pwprompt = false
static

Definition at line 154 of file initdb.c.

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

◆ share_path

char* share_path = NULL
static

◆ show_setting

bool show_setting = false
static

Definition at line 166 of file initdb.c.

Referenced by main(), and setup_data_file_paths().

◆ subdirs

const char* const subdirs[]
static
Initial value:
= {
"global",
"pg_wal/archive_status",
"pg_wal/summaries",
"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 229 of file initdb.c.

Referenced by initialize_data_directory().

◆ success

◆ superuser_password

char* superuser_password = NULL
static

Definition at line 156 of file initdb.c.

Referenced by get_su_pwd(), and setup_auth().

◆ sync_method

Definition at line 170 of file initdb.c.

Referenced by _allocAH(), CreateArchive(), main(), parse_sync_method(), and sync_target_dir().

◆ sync_only

bool sync_only = false
static

Definition at line 165 of file initdb.c.

Referenced by main().

◆ system_constraints_file

char* system_constraints_file
static

Definition at line 183 of file initdb.c.

Referenced by initialize_data_directory(), and setup_data_file_paths().

◆ system_functions_file

char* system_functions_file
static

Definition at line 184 of file initdb.c.

Referenced by initialize_data_directory(), and setup_data_file_paths().

◆ system_views_file

char* system_views_file
static

Definition at line 185 of file initdb.c.

Referenced by initialize_data_directory(), and setup_data_file_paths().

◆ tsearch_config_languages

const struct tsearch_config_match tsearch_config_languages[]
static

Definition at line 788 of file initdb.c.

Referenced by find_matching_ts_config().

◆ username

char* username = NULL
static

◆ wal_segment_size_mb

int wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024)
static

Definition at line 169 of file initdb.c.

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

◆ xlog_dir

char* xlog_dir = NULL
static

Definition at line 168 of file initdb.c.

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