PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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)
 
#define AV_SLOTS_FOR_CONNS(nconns)   ((nconns) / 6)
 

Typedefs

typedef struct _stringlist _stringlist
 
typedef charsave_locale_t
 

Functions

const charselect_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 FILEpopen_check (const char *command, const char *mode)
 
static charget_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_av_slots, 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 charescape_quotes (const char *src)
 
static charescape_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 save_locale_t save_global_locale (int category)
 
static void restore_global_locale (int category, save_locale_t save)
 
static void add_stringlist_item (_stringlist **listhead, const char *str)
 
static void cleanup_directories_atexit (void)
 
static charencodingid_to_string (int enc)
 
static const charfind_matching_ts_config (const char *lc_type)
 
static const charchoose_dsm_implementation (void)
 
static charpretty_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 charicu_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 charshare_path = NULL
 
static charpg_data = NULL
 
static charencoding = NULL
 
static charlocale = NULL
 
static charlc_collate = NULL
 
static charlc_ctype = NULL
 
static charlc_monetary = NULL
 
static charlc_numeric = NULL
 
static charlc_time = NULL
 
static charlc_messages = NULL
 
static char locale_provider = COLLPROVIDER_LIBC
 
static bool builtin_locale_specified = false
 
static chardatlocale = NULL
 
static bool icu_locale_specified = false
 
static charicu_rules = NULL
 
static const chardefault_text_search_config = NULL
 
static charusername = NULL
 
static bool pwprompt = false
 
static charpwfilename = NULL
 
static charsuperuser_password = NULL
 
static const charauthmethodhost = NULL
 
static const charauthmethodlocal = 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 = true
 
static charxlog_dir = NULL
 
static int wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024)
 
static DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC
 
static bool sync_data_files = true
 
static const charprogname
 
static int encodingid
 
static charbki_file
 
static charhba_file
 
static charident_file
 
static charhosts_file
 
static charconf_file
 
static chardictionary_file
 
static charinfo_schema_file
 
static charfeatures_file
 
static charsystem_constraints_file
 
static charsystem_functions_file
 
static charsystem_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 charpgdata_native
 
static int n_connections = 10
 
static int n_av_slots = 16
 
static int n_buffers = 50
 
static const chardynamic_shared_memory_type = NULL
 
static const chardefault_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 charextra_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 209 of file initdb.c.

210 : Configuring the system for local \"trust\" authentication\n" \
211"# allows any local user to connect as any PostgreSQL user, including\n" \
212"# the database superuser. If you do not trust all your local users,\n" \
213"# use another authentication method.\n"
static int fb(int x)

◆ AV_SLOTS_FOR_CONNS

#define AV_SLOTS_FOR_CONNS (   nconns)    ((nconns) / 6)

◆ 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 { \
exit(1); /* message already printed by pclose_check */ \
} while (0)
int pclose_check(FILE *stream)
Definition exec.c:392

Definition at line 329 of file initdb.c.

330 { \
332 exit(1); /* message already printed by pclose_check */ \
333} while (0)

◆ PG_CMD_DECL

#define PG_CMD_DECL   FILE *cmdfd

Definition at line 320 of file initdb.c.

◆ PG_CMD_OPEN

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

Definition at line 322 of file initdb.c.

323 { \
324 cmdfd = popen_check(cmd, "w"); \
325 if (cmdfd == NULL) \
326 exit(1); /* message already printed by popen_check */ \
327} while (0)

◆ PG_CMD_PRINTF

#define PG_CMD_PRINTF (   fmt,
  ... 
)
Value:
do { \
} while (0)
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
static bool output_failed
Definition initdb.c:195
static int output_errno
Definition initdb.c:196

Definition at line 341 of file initdb.c.

342 { \
343 if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
344 output_failed = true, output_errno = errno; \
345} while (0)

◆ PG_CMD_PUTS

#define PG_CMD_PUTS (   line)
Value:
do { \
if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
} while (0)

Definition at line 335 of file initdb.c.

336 { \
337 if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
338 output_failed = true, output_errno = errno; \
339} while (0)

Typedef Documentation

◆ _stringlist

◆ save_locale_t

Definition at line 350 of file initdb.c.

Function Documentation

◆ add_stringlist_item()

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

Definition at line 446 of file initdb.c.

447{
450
452 newentry->next = NULL;
453 if (*listhead == NULL)
455 else
456 {
457 for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
458 /* skip */ ;
459 oldentry->next = newentry;
460 }
461}
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
#define pg_malloc_object(type)
Definition fe_memutils.h:50
const char * str
char * str
Definition initdb.c:92

References fb(), pg_malloc_object, 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 1571 of file initdb.c.

1572{
1574 PQExpBufferData cmd;
1575 char **line;
1576 char **bki_lines;
1577 char headerline[MAXPGPATH];
1578 char buf[64];
1579
1580 printf(_("running bootstrap script ... "));
1581 fflush(stdout);
1582
1584
1585 /* Check that bki file appears to be of the right version */
1586
1587 snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
1589
1590 if (strcmp(headerline, *bki_lines) != 0)
1591 {
1592 pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
1594 pg_log_error_hint("Specify the correct path using the option -L.");
1595 exit(1);
1596 }
1597
1598 /* Substitute for various symbols used in the BKI file */
1599
1600 sprintf(buf, "%d", NAMEDATALEN);
1601 bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
1602
1603 sprintf(buf, "%d", (int) sizeof(Pointer));
1604 bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
1605
1606 bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
1607 (sizeof(Pointer) == 4) ? "i" : "d");
1608
1609 bki_lines = replace_token(bki_lines, "POSTGRES",
1611
1612 bki_lines = replace_token(bki_lines, "ENCODING",
1614
1615 bki_lines = replace_token(bki_lines, "LC_COLLATE",
1617
1618 bki_lines = replace_token(bki_lines, "LC_CTYPE",
1620
1621 bki_lines = replace_token(bki_lines, "DATLOCALE",
1622 datlocale ? escape_quotes_bki(datlocale) : "_null_");
1623
1624 bki_lines = replace_token(bki_lines, "ICU_RULES",
1625 icu_rules ? escape_quotes_bki(icu_rules) : "_null_");
1626
1627 sprintf(buf, "%c", locale_provider);
1628 bki_lines = replace_token(bki_lines, "LOCALE_PROVIDER", buf);
1629
1630 /* Also ensure backend isn't confused by this environment var: */
1631 unsetenv("PGCLIENTENCODING");
1632
1633 initPQExpBuffer(&cmd);
1634
1635 printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options);
1636 appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024));
1637 if (data_checksums)
1638 appendPQExpBufferStr(&cmd, " -k");
1639 if (debug)
1640 appendPQExpBufferStr(&cmd, " -d 5");
1641
1642
1643 PG_CMD_OPEN(cmd.data);
1644
1645 for (line = bki_lines; *line != NULL; line++)
1646 {
1647 PG_CMD_PUTS(*line);
1648 free(*line);
1649 }
1650
1651 PG_CMD_CLOSE();
1652
1653 termPQExpBuffer(&cmd);
1654 free(bki_lines);
1655
1656 check_ok();
1657}
void * Pointer
Definition c.h:609
#define _(x)
Definition elog.c:95
static char * escape_quotes_bki(const char *src)
Definition initdb.c:423
static char * encodingid_to_string(int enc)
Definition initdb.c:848
#define PG_CMD_CLOSE()
Definition initdb.c:329
static char * datlocale
Definition initdb.c:149
static char * lc_collate
Definition initdb.c:141
#define PG_CMD_PUTS(line)
Definition initdb.c:335
static char * lc_ctype
Definition initdb.c:142
static char ** readfile(const char *path)
Definition initdb.c:690
static bool debug
Definition initdb.c:161
static char backend_exec[MAXPGPATH]
Definition initdb.c:261
static bool data_checksums
Definition initdb.c:167
#define PG_CMD_DECL
Definition initdb.c:320
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:475
static char * icu_rules
Definition initdb.c:151
static char * username
Definition initdb.c:153
static int encodingid
Definition initdb.c:176
static void check_ok(void)
Definition initdb.c:2132
static char * extra_options
Definition initdb.c:230
static const char *const boot_options
Definition initdb.c:226
#define PG_CMD_OPEN(cmd)
Definition initdb.c:322
static char * bki_file
Definition initdb.c:177
#define pg_log_error(...)
Definition logging.h:106
#define pg_log_error_hint(...)
Definition logging.h:112
#define NAMEDATALEN
#define MAXPGPATH
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define sprintf
Definition port.h:262
#define snprintf
Definition port.h:260
#define printf(...)
Definition port.h:266
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define free(a)
#define unsetenv(x)
Definition win32_port.h:543

References _, appendPQExpBuffer(), appendPQExpBufferStr(), backend_exec, bki_file, boot_options, buf, check_ok(), PQExpBufferData::data, data_checksums, datlocale, debug, encodingid, encodingid_to_string(), escape_quotes_bki(), extra_options, fb(), 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, 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 2595 of file initdb.c.

2596{
2597 if (*authmethod == NULL)
2598 {
2599 authwarning = true;
2600 *authmethod = "trust";
2601 }
2602}
static bool authwarning
Definition initdb.c:214

References authwarning, and fb().

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

2606{
2607 const char *const *p;
2608
2609 for (p = valid_methods; *p; p++)
2610 {
2611 if (strcmp(authmethod, *p) == 0)
2612 return;
2613 }
2614
2615 pg_fatal("invalid authentication method \"%s\" for \"%s\" connections",
2616 authmethod, conntype);
2617}
#define pg_fatal(...)

References fb(), and pg_fatal.

Referenced by main().

◆ check_icu_locale_encoding()

static bool check_icu_locale_encoding ( int  user_enc)
static

Definition at line 2323 of file initdb.c.

2324{
2326 {
2327 pg_log_error("encoding mismatch");
2328 pg_log_error_detail("The encoding you selected (%s) is not supported with the ICU provider.",
2330 pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2331 "or choose a matching combination.",
2332 progname);
2333 return false;
2334 }
2335 return true;
2336}
bool is_encoding_supported_by_icu(int encoding)
Definition encnames.c:461
static const char * progname
Definition initdb.c:175
#define pg_log_error_detail(...)
Definition logging.h:109
#define pg_encoding_to_char
Definition pg_wchar.h:630

References fb(), 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 1009 of file initdb.c.

1010{
1011 struct stat statbuf;
1012
1013 if (stat(path, &statbuf) != 0)
1014 {
1015 if (errno == ENOENT)
1016 {
1017 pg_log_error("file \"%s\" does not exist", path);
1018 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1019 }
1020 else
1021 {
1022 pg_log_error("could not access file \"%s\": %m", path);
1023 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1024 }
1025 exit(1);
1026 }
1027 if (!S_ISREG(statbuf.st_mode))
1028 {
1029 pg_log_error("file \"%s\" is not a regular file", path);
1030 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1031 exit(1);
1032 }
1033}
#define stat
Definition win32_port.h:74
#define S_ISREG(m)
Definition win32_port.h:318

References fb(), pg_log_error, pg_log_error_hint, S_ISREG, 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 2288 of file initdb.c.

2289{
2290 int locale_enc;
2291
2293
2294 /* See notes in createdb() to understand these tests */
2295 if (!(locale_enc == user_enc ||
2297 locale_enc == -1 ||
2298#ifdef WIN32
2299 user_enc == PG_UTF8 ||
2300#endif
2302 {
2303 pg_log_error("encoding mismatch");
2304 pg_log_error_detail("The encoding you selected (%s) and the encoding that the "
2305 "selected locale uses (%s) do not match. This would lead to "
2306 "misbehavior in various character string processing functions.",
2309 pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2310 "or choose a matching combination.",
2311 progname);
2312 return false;
2313 }
2314 return true;
2315}
static char * locale
Definition initdb.c:140
#define PG_UTF8
Definition mbprint.c:43
@ PG_SQL_ASCII
Definition pg_wchar.h:226
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition chklocale.c:301

References fb(), 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 2225 of file initdb.c.

2226{
2228 char *res;
2229
2230 /* Don't let Windows' non-ASCII locale names in. */
2231 if (locale && !pg_is_ascii(locale))
2232 pg_fatal("locale name \"%s\" contains non-ASCII characters", locale);
2233
2234 if (canonname)
2235 *canonname = NULL; /* in case of failure */
2236
2237 save = save_global_locale(category);
2238
2239 /* for setlocale() call */
2240 if (!locale)
2241 locale = "";
2242
2243 /* set the locale with setlocale, to see if it accepts it. */
2244 res = setlocale(category, locale);
2245
2246 /* save canonical name if requested. */
2247 if (res && canonname)
2248 *canonname = pg_strdup(res);
2249
2250 /* restore old value. */
2251 restore_global_locale(category, save);
2252
2253 /* complain if locale wasn't valid */
2254 if (res == NULL)
2255 {
2256 if (*locale)
2257 {
2258 pg_log_error("invalid locale name \"%s\"", locale);
2259 pg_log_error_hint("If the locale name is specific to ICU, use --icu-locale.");
2260 exit(1);
2261 }
2262 else
2263 {
2264 /*
2265 * If no relevant switch was given on command line, locale is an
2266 * empty string, which is not too helpful to report. Presumably
2267 * setlocale() found something it did not like in the environment.
2268 * Ideally we'd report the bad environment variable, but since
2269 * setlocale's behavior is implementation-specific, it's hard to
2270 * be sure what it didn't like. Print a safe generic message.
2271 */
2272 pg_fatal("invalid locale settings; check LANG and LC_* environment variables");
2273 }
2274 }
2275
2276 /* Don't let Windows' non-ASCII locale names out. */
2278 pg_fatal("locale name \"%s\" contains non-ASCII characters",
2279 *canonname);
2280}
static void restore_global_locale(int category, save_locale_t save)
Definition initdb.c:390
static save_locale_t save_global_locale(int category)
Definition initdb.c:366
char * save_locale_t
Definition initdb.c:350
bool pg_is_ascii(const char *str)
Definition string.c:132
#define setlocale(a, b)
Definition win32_port.h:472

References fb(), locale, pg_fatal, pg_is_ascii(), pg_log_error, pg_log_error_hint, pg_strdup(), restore_global_locale(), save_global_locale(), and setlocale.

Referenced by setlocales().

◆ check_need_password()

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

Definition at line 2620 of file initdb.c.

2621{
2622 if ((strcmp(authmethodlocal, "md5") == 0 ||
2623 strcmp(authmethodlocal, "password") == 0 ||
2624 strcmp(authmethodlocal, "scram-sha-256") == 0) &&
2625 (strcmp(authmethodhost, "md5") == 0 ||
2626 strcmp(authmethodhost, "password") == 0 ||
2627 strcmp(authmethodhost, "scram-sha-256") == 0) &&
2628 !(pwprompt || pwfilename))
2629 pg_fatal("must specify a password for the superuser to enable password authentication");
2630}
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, fb(), pg_fatal, pwfilename, and pwprompt.

Referenced by main().

◆ check_ok()

static void check_ok ( void  )
static

Definition at line 2132 of file initdb.c.

2133{
2134 if (caught_signal)
2135 {
2136 printf(_("caught signal\n"));
2137 fflush(stdout);
2138 exit(1);
2139 }
2140 else if (output_failed)
2141 {
2142 printf(_("could not write to child process: %s\n"),
2144 fflush(stdout);
2145 exit(1);
2146 }
2147 else
2148 {
2149 /* all seems well */
2150 printf(_("ok\n"));
2151 fflush(stdout);
2152 }
2153}
static bool caught_signal
Definition initdb.c:194
#define strerror
Definition port.h:273

References _, caught_signal, fb(), output_errno, output_failed, printf, and strerror.

Referenced by adjust_data_dir(), bootstrap_template1(), check_cluster_versions(), check_for_connection_status(), check_for_data_types_usage(), check_for_gist_inet_ops(), check_for_incompatible_polymorphics(), check_for_isn_and_int8_passing_mismatch(), check_for_new_tablespace_dir(), check_for_not_null_inheritance(), check_for_pg_role_prefix(), check_for_prepared_transactions(), check_for_tables_with_oids(), check_for_unicode_update(), check_for_user_defined_encoding_conversions(), check_for_user_defined_postfix_ops(), check_is_install_user(), check_loadable_libraries(), check_new_cluster_replication_slots(), check_new_cluster_subscription_configuration(), check_old_cluster_for_valid_slots(), check_old_cluster_global_names(), check_old_cluster_subscription_state(), copy_subdir_files(), copy_xact_xlog_xid(), create_conflict_detection_slot(), 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(), 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(), set_new_cluster_char_signedness(), setup_config(), and transfer_all_new_tablespaces().

◆ choose_dsm_implementation()

static const char * choose_dsm_implementation ( void  )
static

Definition at line 1092 of file initdb.c.

1093{
1094#if defined(HAVE_SHM_OPEN) && !defined(__sun__)
1095 int ntries = 10;
1097
1098 /* Initialize prng; this function is its only user in this program. */
1099 pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
1100
1101 while (ntries > 0)
1102 {
1103 uint32 handle;
1104 char name[64];
1105 int fd;
1106
1107 handle = pg_prng_uint32(&prng_state);
1108 snprintf(name, 64, "/PostgreSQL.%u", handle);
1109 if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
1110 {
1111 close(fd);
1113 return "posix";
1114 }
1115 if (errno != EEXIST)
1116 break;
1117 --ntries;
1118 }
1119#endif
1120
1121#ifdef WIN32
1122 return "windows";
1123#else
1124 return "sysv";
1125#endif
1126}
uint64_t uint64
Definition c.h:619
uint32_t uint32
Definition c.h:618
#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)
static pg_prng_state prng_state
const char * name

References close, fb(), 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 776 of file initdb.c.

777{
778 if (success)
779 return;
780
781 if (!noclean)
782 {
783 if (made_new_pgdata)
784 {
785 pg_log_info("removing data directory \"%s\"", pg_data);
786 if (!rmtree(pg_data, true))
787 pg_log_error("failed to remove data directory");
788 }
789 else if (found_existing_pgdata)
790 {
791 pg_log_info("removing contents of data directory \"%s\"",
792 pg_data);
793 if (!rmtree(pg_data, false))
794 pg_log_error("failed to remove contents of data directory");
795 }
796
798 {
799 pg_log_info("removing WAL directory \"%s\"", xlog_dir);
800 if (!rmtree(xlog_dir, true))
801 pg_log_error("failed to remove WAL directory");
802 }
803 else if (found_existing_xlogdir)
804 {
805 pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
806 if (!rmtree(xlog_dir, false))
807 pg_log_error("failed to remove contents of WAL directory");
808 }
809 /* otherwise died during startup, do nothing! */
810 }
811 else
812 {
814 pg_log_info("data directory \"%s\" not removed at user's request",
815 pg_data);
816
818 pg_log_info("WAL directory \"%s\" not removed at user's request",
819 xlog_dir);
820 }
821}
static bool noclean
Definition initdb.c:162
static bool found_existing_pgdata
Definition initdb.c:190
static bool found_existing_xlogdir
Definition initdb.c:192
static char * xlog_dir
Definition initdb.c:168
static bool success
Definition initdb.c:188
static bool made_new_xlogdir
Definition initdb.c:191
static char * pg_data
Definition initdb.c:138
static bool made_new_pgdata
Definition initdb.c:189
#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 2915 of file initdb.c.

2916{
2917 int ret;
2918
2919 switch ((ret = pg_check_dir(pg_data)))
2920 {
2921 case 0:
2922 /* PGDATA not there, must create it */
2923 printf(_("creating directory %s ... "),
2924 pg_data);
2925 fflush(stdout);
2926
2928 pg_fatal("could not create directory \"%s\": %m", pg_data);
2929 else
2930 check_ok();
2931
2932 made_new_pgdata = true;
2933 break;
2934
2935 case 1:
2936 /* Present but empty, fix permissions and use it */
2937 printf(_("fixing permissions on existing directory %s ... "),
2938 pg_data);
2939 fflush(stdout);
2940
2941 if (chmod(pg_data, pg_dir_create_mode) != 0)
2942 pg_fatal("could not change permissions of directory \"%s\": %m",
2943 pg_data);
2944 else
2945 check_ok();
2946
2947 found_existing_pgdata = true;
2948 break;
2949
2950 case 2:
2951 case 3:
2952 case 4:
2953 /* Present and not empty */
2954 pg_log_error("directory \"%s\" exists but is not empty", pg_data);
2955 if (ret != 4)
2957 else
2958 pg_log_error_hint("If you want to create a new database system, either remove or empty "
2959 "the directory \"%s\" or run %s "
2960 "with an argument other than \"%s\".",
2962 exit(1); /* no further message needed */
2963
2964 default:
2965 /* Trouble accessing directory */
2966 pg_fatal("could not access directory \"%s\": %m", pg_data);
2967 }
2968}
int pg_dir_create_mode
Definition file_perm.c:18
void warn_on_mount_point(int error)
Definition initdb.c:3056
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(), fb(), 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, and warn_on_mount_point().

Referenced by initialize_data_directory().

◆ create_xlog_or_symlink()

void create_xlog_or_symlink ( void  )

Definition at line 2973 of file initdb.c.

2974{
2975 char *subdirloc;
2976
2977 /* form name of the place for the subdirectory or symlink */
2978 subdirloc = psprintf("%s/pg_wal", pg_data);
2979
2980 if (xlog_dir)
2981 {
2982 int ret;
2983
2984 /* clean up xlog directory name, check it's absolute */
2987 pg_fatal("WAL directory location must be an absolute path");
2988
2989 /* check if the specified xlog directory exists/is empty */
2990 switch ((ret = pg_check_dir(xlog_dir)))
2991 {
2992 case 0:
2993 /* xlog directory not there, must create it */
2994 printf(_("creating directory %s ... "),
2995 xlog_dir);
2996 fflush(stdout);
2997
2999 pg_fatal("could not create directory \"%s\": %m",
3000 xlog_dir);
3001 else
3002 check_ok();
3003
3004 made_new_xlogdir = true;
3005 break;
3006
3007 case 1:
3008 /* Present but empty, fix permissions and use it */
3009 printf(_("fixing permissions on existing directory %s ... "),
3010 xlog_dir);
3011 fflush(stdout);
3012
3014 pg_fatal("could not change permissions of directory \"%s\": %m",
3015 xlog_dir);
3016 else
3017 check_ok();
3018
3020 break;
3021
3022 case 2:
3023 case 3:
3024 case 4:
3025 /* Present and not empty */
3026 pg_log_error("directory \"%s\" exists but is not empty", xlog_dir);
3027 if (ret != 4)
3029 else
3030 pg_log_error_hint("If you want to store the WAL there, either remove or empty the directory \"%s\".",
3031 xlog_dir);
3032 exit(1);
3033
3034 default:
3035 /* Trouble accessing directory */
3036 pg_fatal("could not access directory \"%s\": %m", xlog_dir);
3037 }
3038
3039 if (symlink(xlog_dir, subdirloc) != 0)
3040 pg_fatal("could not create symbolic link \"%s\": %m",
3041 subdirloc);
3042 }
3043 else
3044 {
3045 /* Without -X option, just make the subdirectory normally */
3047 pg_fatal("could not create directory \"%s\": %m",
3048 subdirloc);
3049 }
3050
3051 free(subdirloc);
3052}
#define is_absolute_path(filename)
Definition port.h:104
void canonicalize_path(char *path)
Definition path.c:337
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
#define mkdir(a, b)
Definition win32_port.h:80
#define symlink(oldpath, newpath)
Definition win32_port.h:225

References _, canonicalize_path(), check_ok(), fb(), 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(), 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 848 of file initdb.c.

849{
850 char result[20];
851
852 sprintf(result, "%d", enc);
853 return pg_strdup(result);
854}

References enc, pg_strdup(), and sprintf.

Referenced by bootstrap_template1().

◆ escape_quotes()

static char * escape_quotes ( const char src)
static

Definition at line 407 of file initdb.c.

408{
409 char *result = escape_single_quotes_ascii(src);
410
411 if (!result)
412 pg_fatal("out of memory");
413 return result;
414}
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(), main(), 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 423 of file initdb.c.

424{
425 char *result;
426 char *data = escape_quotes(src);
427 char *resultp;
428 char *datap;
429
430 result = (char *) pg_malloc(strlen(data) + 3);
431 resultp = result;
432 *resultp++ = '\'';
433 for (datap = data; *datap; datap++)
434 *resultp++ = *datap;
435 *resultp++ = '\'';
436 *resultp = '\0';
437
438 free(data);
439 return result;
440}
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
static char * escape_quotes(const char *src)
Definition initdb.c:407
const void * data

References data, escape_quotes(), fb(), 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 954 of file initdb.c.

955{
956 int i;
957 char *langname,
958 *ptr;
959
960 /*
961 * Convert lc_ctype to a language name by stripping everything after an
962 * underscore (usual case) or a hyphen (Windows "locale name"; see
963 * comments at IsoLocaleName()).
964 *
965 * XXX Should ' ' be a stop character? This would select "norwegian" for
966 * the Windows locale "Norwegian (Nynorsk)_Norway.1252". If we do so, we
967 * should also accept the "nn" and "nb" Unix locales.
968 *
969 * Just for paranoia, we also stop at '.' or '@'.
970 */
971 if (lc_type == NULL)
972 langname = pg_strdup("");
973 else
974 {
975 ptr = langname = pg_strdup(lc_type);
976 while (*ptr &&
977 *ptr != '_' && *ptr != '-' && *ptr != '.' && *ptr != '@')
978 ptr++;
979 *ptr = '\0';
980 }
981
983 {
984 if (pg_strcasecmp(tsearch_config_languages[i].langname, langname) == 0)
985 {
986 free(langname);
988 }
989 }
990
991 free(langname);
992 return NULL;
993}
static const struct tsearch_config_match tsearch_config_languages[]
Definition initdb.c:883
int i
Definition isn.c:77
int pg_strcasecmp(const char *s1, const char *s2)
const char * tsconfname
Definition initdb.c:879

References fb(), 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 860 of file initdb.c.

861{
862 int enc;
863
865 {
867 return enc;
868 }
869 pg_fatal("\"%s\" is not a valid server encoding name",
870 encoding_name ? encoding_name : "(null)");
871}
#define pg_valid_server_encoding
Definition pg_wchar.h:631

References enc, fb(), pg_fatal, and pg_valid_server_encoding.

Referenced by setup_locale_encoding().

◆ get_id()

static char * get_id ( void  )
static

Definition at line 829 of file initdb.c.

830{
831 const char *username;
832
833#ifndef WIN32
834 if (geteuid() == 0) /* 0 is root's uid */
835 {
836 pg_log_error("cannot be run as root");
837 pg_log_error_hint("Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
838 exit(1);
839 }
840#endif
841
843
844 return pg_strdup(username);
845}
const char * get_user_name_or_exit(const char *progname)
Definition username.c:74

References fb(), 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 1680 of file initdb.c.

1681{
1682 char *pwd1;
1683
1684 if (pwprompt)
1685 {
1686 /*
1687 * Read password from terminal
1688 */
1689 char *pwd2;
1690
1691 printf("\n");
1692 fflush(stdout);
1693 pwd1 = simple_prompt("Enter new superuser password: ", false);
1694 pwd2 = simple_prompt("Enter it again: ", false);
1695 if (strcmp(pwd1, pwd2) != 0)
1696 {
1697 fprintf(stderr, _("Passwords didn't match.\n"));
1698 exit(1);
1699 }
1700 free(pwd2);
1701 }
1702 else
1703 {
1704 /*
1705 * Read password from file
1706 *
1707 * Ideally this should insist that the file not be world-readable.
1708 * However, this option is mainly intended for use on Windows where
1709 * file permissions may not exist at all, so we'll skip the paranoia
1710 * for now.
1711 */
1712 FILE *pwf = fopen(pwfilename, "r");
1713
1714 if (!pwf)
1715 pg_fatal("could not open file \"%s\" for reading: %m",
1716 pwfilename);
1718 if (!pwd1)
1719 {
1720 if (ferror(pwf))
1721 pg_fatal("could not read password from file \"%s\": %m",
1722 pwfilename);
1723 else
1724 pg_fatal("password file \"%s\" is empty",
1725 pwfilename);
1726 }
1727 fclose(pwf);
1728
1730 }
1731
1733}
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:154

References _, fb(), fprintf, free, pg_fatal, pg_get_line(), pg_strip_crlf(), printf, pwfilename, pwprompt, simple_prompt(), and superuser_password.

Referenced by main().

◆ guc_value_requires_quotes()

static bool guc_value_requires_quotes ( const char guc_value)
static

Definition at line 658 of file initdb.c.

659{
660 /* Don't use <ctype.h> macros here, they might accept too much */
661#define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
662#define DIGITS "0123456789"
663
664 if (*guc_value == '\0')
665 return true; /* empty string must be quoted */
666 if (strchr(LETTERS, *guc_value))
667 {
669 return false; /* it's an identifier */
670 return true; /* nope */
671 }
672 if (strchr(DIGITS, *guc_value))
673 {
674 /* skip over digits */
676 /* there can be zero or more unit letters after the digits */
678 return false; /* it's a number, possibly with units */
679 return true; /* nope */
680 }
681 return true; /* all else must be quoted */
682}
#define DIGITS
#define LETTERS

References DIGITS, fb(), and LETTERS.

Referenced by replace_guc_value().

◆ icu_language_tag()

static char * icu_language_tag ( const char loc_str)
static

Definition at line 2343 of file initdb.c.

2344{
2345#ifdef USE_ICU
2346 UErrorCode status;
2347 char *langtag;
2348 size_t buflen = 32; /* arbitrary starting buffer size */
2349 const bool strict = true;
2350
2351 /*
2352 * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
2353 * RFC5646 section 4.4). Additionally, in older ICU versions,
2354 * uloc_toLanguageTag() doesn't always return the ultimate length on the
2355 * first call, necessitating a loop.
2356 */
2357 langtag = pg_malloc(buflen);
2358 while (true)
2359 {
2360 status = U_ZERO_ERROR;
2361 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
2362
2363 /* try again if the buffer is not large enough */
2364 if (status == U_BUFFER_OVERFLOW_ERROR ||
2366 {
2367 buflen = buflen * 2;
2368 langtag = pg_realloc(langtag, buflen);
2369 continue;
2370 }
2371
2372 break;
2373 }
2374
2375 if (U_FAILURE(status))
2376 {
2378
2379 pg_fatal("could not convert locale name \"%s\" to language tag: %s",
2380 loc_str, u_errorName(status));
2381 }
2382
2383 return langtag;
2384#else
2385 pg_fatal("ICU is not supported in this build");
2386 return NULL; /* keep compiler quiet */
2387#endif
2388}
void pg_free(void *ptr)
void * pg_realloc(void *ptr, size_t size)
Definition fe_memutils.c:65

References fb(), 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 2396 of file initdb.c.

2397{
2398#ifdef USE_ICU
2399 UErrorCode status;
2400 char lang[ULOC_LANG_CAPACITY];
2401 bool found = false;
2402
2403 /* validate that we can extract the language */
2404 status = U_ZERO_ERROR;
2406 if (U_FAILURE(status))
2407 {
2408 pg_fatal("could not get language from locale \"%s\": %s",
2409 loc_str, u_errorName(status));
2410 return;
2411 }
2412
2413 /* check for special language name */
2414 if (strcmp(lang, "") == 0 ||
2415 strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
2416 found = true;
2417
2418 /* search for matching language within ICU */
2419 for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
2420 {
2421 const char *otherloc = uloc_getAvailable(i);
2423
2424 status = U_ZERO_ERROR;
2426 if (U_FAILURE(status))
2427 continue;
2428
2429 if (strcmp(lang, otherlang) == 0)
2430 found = true;
2431 }
2432
2433 if (!found)
2434 pg_fatal("locale \"%s\" has unknown language \"%s\"",
2435 loc_str, lang);
2436#else
2437 pg_fatal("ICU is not supported in this build");
2438#endif
2439}

References fb(), i, and pg_fatal.

Referenced by setlocales().

◆ initialize_data_directory()

void initialize_data_directory ( void  )

Definition at line 3069 of file initdb.c.

3070{
3072 PQExpBufferData cmd;
3073 int i;
3074
3075 setup_signals();
3076
3077 /*
3078 * Set mask based on requested PGDATA permissions. pg_mode_mask, and
3079 * friends like pg_dir_create_mode, are set to owner-only by default and
3080 * then updated if -g is passed in by calling SetDataDirectoryCreatePerm()
3081 * when parsing our options (see above).
3082 */
3084
3086
3088
3089 /* Create required subdirectories (other than pg_wal) */
3090 printf(_("creating subdirectories ... "));
3091 fflush(stdout);
3092
3093 for (i = 0; i < lengthof(subdirs); i++)
3094 {
3095 char *path;
3096
3097 path = psprintf("%s/%s", pg_data, subdirs[i]);
3098
3099 /*
3100 * The parent directory already exists, so we only need mkdir() not
3101 * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
3102 */
3103 if (mkdir(path, pg_dir_create_mode) < 0)
3104 pg_fatal("could not create directory \"%s\": %m", path);
3105
3106 free(path);
3107 }
3108
3109 check_ok();
3110
3111 /* Top level PG_VERSION is checked by bootstrapper, so make it first */
3113
3114 /* Select suitable configuration settings */
3115 set_null_conf();
3117
3118 /* Now create all the text config files */
3119 setup_config();
3120
3121 /* Bootstrap template1 */
3123
3124 /*
3125 * Make the per-database PG_VERSION for template1 only after init'ing it
3126 */
3127 write_version_file("base/1");
3128
3129 /*
3130 * Create the stuff we don't need to use bootstrap mode for, using a
3131 * backend running in simple standalone mode.
3132 */
3133 fputs(_("performing post-bootstrap initialization ... "), stdout);
3134 fflush(stdout);
3135
3136 initPQExpBuffer(&cmd);
3137 printfPQExpBuffer(&cmd, "\"%s\" %s %s template1 >%s",
3139
3140 PG_CMD_OPEN(cmd.data);
3141
3143
3145
3147
3149
3150 /*
3151 * Note that no objects created after setup_depend() will be "pinned".
3152 * They are all droppable at the whim of the DBA.
3153 */
3154
3156
3158
3160
3162
3164
3166
3168
3170
3172
3174
3175 PG_CMD_CLOSE();
3176 termPQExpBuffer(&cmd);
3177
3178 check_ok();
3179}
#define lengthof(array)
Definition c.h:875
int pg_mode_mask
Definition file_perm.c:25
static void setup_depend(FILE *cmdfd)
Definition initdb.c:1739
static void setup_collation(FILE *cmdfd)
Definition initdb.c:1794
void create_data_directory(void)
Definition initdb.c:2915
static void bootstrap_template1(void)
Definition initdb.c:1571
static void setup_run_file(FILE *cmdfd, const char *filename)
Definition initdb.c:1752
static void setup_auth(FILE *cmdfd)
Definition initdb.c:1663
static void make_postgres(FILE *cmdfd)
Definition initdb.c:2088
static void test_config_settings(void)
Definition initdb.c:1134
static const char *const backend_options
Definition initdb.c:227
static void setup_config(void)
Definition initdb.c:1299
static void setup_privileges(FILE *cmdfd)
Definition initdb.c:1827
static void write_version_file(const char *extrapath)
Definition initdb.c:1040
void setup_signals(void)
Definition initdb.c:2895
static char * system_views_file
Definition initdb.c:187
static void setup_description(FILE *cmdfd)
Definition initdb.c:1773
static void vacuum_db(FILE *cmdfd)
Definition initdb.c:2024
static const char *const subdirs[]
Definition initdb.c:232
void create_xlog_or_symlink(void)
Definition initdb.c:2973
static char * system_functions_file
Definition initdb.c:186
static char * dictionary_file
Definition initdb.c:182
static void setup_schema(FILE *cmdfd)
Definition initdb.c:1995
static char * system_constraints_file
Definition initdb.c:185
static void set_null_conf(void)
Definition initdb.c:1063
static void make_template0(FILE *cmdfd)
Definition initdb.c:2034
static void load_plpgsql(FILE *cmdfd)
Definition initdb.c:2015
#define DEVNULL
Definition port.h:161

References _, backend_exec, backend_options, bootstrap_template1(), check_ok(), create_data_directory(), create_xlog_or_symlink(), PQExpBufferData::data, DEVNULL, dictionary_file, extra_options, fb(), 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(), 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 2015 of file initdb.c.

2016{
2017 PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
2018}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ locale_date_order()

static int locale_date_order ( const char locale)
static

Definition at line 2166 of file initdb.c.

2167{
2168 struct tm testtime;
2169 char buf[128];
2170 char *posD;
2171 char *posM;
2172 char *posY;
2174 size_t res;
2175 int result;
2176
2177 result = DATEORDER_MDY; /* default */
2178
2180
2182
2183 memset(&testtime, 0, sizeof(testtime));
2184 testtime.tm_mday = 22;
2185 testtime.tm_mon = 10; /* November, should come out as "11" */
2186 testtime.tm_year = 133; /* 2033 */
2187
2188 res = my_strftime(buf, sizeof(buf), "%x", &testtime);
2189
2191
2192 if (res == 0)
2193 return result;
2194
2195 posM = strstr(buf, "11");
2196 posD = strstr(buf, "22");
2197 posY = strstr(buf, "33");
2198
2199 if (!posM || !posD || !posY)
2200 return result;
2201
2202 if (posY < posM && posM < posD)
2203 result = DATEORDER_YMD;
2204 else if (posD < posM)
2205 result = DATEORDER_DMY;
2206 else
2207 result = DATEORDER_MDY;
2208
2209 return result;
2210}
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
Definition initdb.c:2157
static struct pg_tm tm
Definition localtime.c:104
#define DATEORDER_DMY
Definition miscadmin.h:244
#define DATEORDER_MDY
Definition miscadmin.h:245
#define DATEORDER_YMD
Definition miscadmin.h:243

References buf, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, fb(), locale, my_strftime(), restore_global_locale(), save_global_locale(), setlocale, and tm.

Referenced by setup_config().

◆ main()

int main ( int  argc,
char argv[] 
)

Definition at line 3183 of file initdb.c.

3184{
3185 static struct option long_options[] = {
3186 {"pgdata", required_argument, NULL, 'D'},
3187 {"encoding", required_argument, NULL, 'E'},
3188 {"locale", required_argument, NULL, 1},
3189 {"lc-collate", required_argument, NULL, 2},
3190 {"lc-ctype", required_argument, NULL, 3},
3191 {"lc-monetary", required_argument, NULL, 4},
3192 {"lc-numeric", required_argument, NULL, 5},
3193 {"lc-time", required_argument, NULL, 6},
3194 {"lc-messages", required_argument, NULL, 7},
3195 {"no-locale", no_argument, NULL, 8},
3196 {"text-search-config", required_argument, NULL, 'T'},
3197 {"auth", required_argument, NULL, 'A'},
3198 {"auth-local", required_argument, NULL, 10},
3199 {"auth-host", required_argument, NULL, 11},
3200 {"pwprompt", no_argument, NULL, 'W'},
3201 {"pwfile", required_argument, NULL, 9},
3202 {"username", required_argument, NULL, 'U'},
3203 {"help", no_argument, NULL, '?'},
3204 {"version", no_argument, NULL, 'V'},
3205 {"debug", no_argument, NULL, 'd'},
3206 {"show", no_argument, NULL, 's'},
3207 {"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
3208 {"no-clean", no_argument, NULL, 'n'},
3209 {"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
3210 {"no-sync", no_argument, NULL, 'N'},
3211 {"no-instructions", no_argument, NULL, 13},
3212 {"set", required_argument, NULL, 'c'},
3213 {"sync-only", no_argument, NULL, 'S'},
3214 {"waldir", required_argument, NULL, 'X'},
3215 {"wal-segsize", required_argument, NULL, 12},
3216 {"data-checksums", no_argument, NULL, 'k'},
3217 {"allow-group-access", no_argument, NULL, 'g'},
3218 {"discard-caches", no_argument, NULL, 14},
3219 {"locale-provider", required_argument, NULL, 15},
3220 {"builtin-locale", required_argument, NULL, 16},
3221 {"icu-locale", required_argument, NULL, 17},
3222 {"icu-rules", required_argument, NULL, 18},
3223 {"sync-method", required_argument, NULL, 19},
3224 {"no-data-checksums", no_argument, NULL, 20},
3225 {"no-sync-data-files", no_argument, NULL, 21},
3226 {NULL, 0, NULL, 0}
3227 };
3228
3229 /*
3230 * options with no short version return a low integer, the rest return
3231 * their short version value
3232 */
3233 int c;
3234 int option_index;
3235 char *effective_user;
3237 char pg_ctl_path[MAXPGPATH];
3238
3239 /*
3240 * Ensure that buffering behavior of stdout matches what it is in
3241 * interactive usage (at least on most platforms). This prevents
3242 * unexpected output ordering when, eg, output is redirected to a file.
3243 * POSIX says we must do this before any other usage of these files.
3244 */
3245 setvbuf(stdout, NULL, PG_IOLBF, 0);
3246
3247 pg_logging_init(argv[0]);
3248 progname = get_progname(argv[0]);
3249 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
3250
3251 if (argc > 1)
3252 {
3253 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
3254 {
3255 usage(progname);
3256 exit(0);
3257 }
3258 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
3259 {
3260 puts("initdb (PostgreSQL) " PG_VERSION);
3261 exit(0);
3262 }
3263 }
3264
3265 /* process command-line options */
3266
3267 while ((c = getopt_long(argc, argv, "A:c:dD:E:gkL:nNsST:U:WX:",
3268 long_options, &option_index)) != -1)
3269 {
3270 switch (c)
3271 {
3272 case 'A':
3274
3275 /*
3276 * When ident is specified, use peer for local connections.
3277 * Mirrored, when peer is specified, use ident for TCP/IP
3278 * connections.
3279 */
3280 if (strcmp(authmethodhost, "ident") == 0)
3281 authmethodlocal = "peer";
3282 else if (strcmp(authmethodlocal, "peer") == 0)
3283 authmethodhost = "ident";
3284 break;
3285 case 10:
3287 break;
3288 case 11:
3290 break;
3291 case 'c':
3292 {
3293 char *buf = pg_strdup(optarg);
3294 char *equals = strchr(buf, '=');
3295
3296 if (!equals)
3297 {
3298 pg_log_error("-c %s requires a value", buf);
3299 pg_log_error_hint("Try \"%s --help\" for more information.",
3300 progname);
3301 exit(1);
3302 }
3303 *equals++ = '\0'; /* terminate variable name */
3306 pfree(buf);
3307 }
3308 break;
3309 case 'D':
3311 break;
3312 case 'E':
3314 break;
3315 case 'W':
3316 pwprompt = true;
3317 break;
3318 case 'U':
3320 break;
3321 case 'd':
3322 debug = true;
3323 printf(_("Running in debug mode.\n"));
3324 break;
3325 case 'n':
3326 noclean = true;
3327 printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3328 break;
3329 case 'N':
3330 do_sync = false;
3331 break;
3332 case 'S':
3333 sync_only = true;
3334 break;
3335 case 'k':
3336 data_checksums = true;
3337 break;
3338 case 'L':
3340 break;
3341 case 1:
3343 break;
3344 case 2:
3346 break;
3347 case 3:
3349 break;
3350 case 4:
3352 break;
3353 case 5:
3355 break;
3356 case 6:
3358 break;
3359 case 7:
3361 break;
3362 case 8:
3363 locale = "C";
3364 break;
3365 case 9:
3367 break;
3368 case 's':
3369 show_setting = true;
3370 break;
3371 case 'T':
3373 break;
3374 case 'X':
3376 break;
3377 case 12:
3378 if (!option_parse_int(optarg, "--wal-segsize", 1, 1024, &wal_segment_size_mb))
3379 exit(1);
3380 break;
3381 case 13:
3382 noinstructions = true;
3383 break;
3384 case 'g':
3386 break;
3387 case 14:
3388 extra_options = psprintf("%s %s",
3390 "-c debug_discard_caches=1");
3391 break;
3392 case 15:
3393 if (strcmp(optarg, "builtin") == 0)
3395 else if (strcmp(optarg, "icu") == 0)
3397 else if (strcmp(optarg, "libc") == 0)
3399 else
3400 pg_fatal("unrecognized locale provider: %s", optarg);
3401 break;
3402 case 16:
3405 break;
3406 case 17:
3408 icu_locale_specified = true;
3409 break;
3410 case 18:
3412 break;
3413 case 19:
3415 exit(1);
3416 break;
3417 case 20:
3418 data_checksums = false;
3419 break;
3420 case 21:
3421 sync_data_files = false;
3422 break;
3423 default:
3424 /* getopt_long already emitted a complaint */
3425 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3426 exit(1);
3427 }
3428 }
3429
3430
3431 /*
3432 * Non-option argument specifies data directory as long as it wasn't
3433 * already specified with -D / --pgdata
3434 */
3435 if (optind < argc && !pg_data)
3436 {
3437 pg_data = pg_strdup(argv[optind]);
3438 optind++;
3439 }
3440
3441 if (optind < argc)
3442 {
3443 pg_log_error("too many command-line arguments (first is \"%s\")",
3444 argv[optind]);
3445 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3446 exit(1);
3447 }
3448
3450 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3451 "--builtin-locale", "builtin");
3452
3454 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3455 "--icu-locale", "icu");
3456
3458 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3459 "--icu-rules", "icu");
3460
3462
3463 /* If we only need to sync, just do it and exit */
3464 if (sync_only)
3465 {
3466 setup_pgdata();
3467
3468 /* must check that directory is readable */
3469 if (pg_check_dir(pg_data) <= 0)
3470 pg_fatal("could not access directory \"%s\": %m", pg_data);
3471
3472 fputs(_("syncing data to disk ... "), stdout);
3473 fflush(stdout);
3475 check_ok();
3476 return 0;
3477 }
3478
3479 if (pwprompt && pwfilename)
3480 pg_fatal("password prompt and password file cannot be specified together");
3481
3484
3487
3489
3490 if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
3491 pg_fatal("argument of %s must be a power of two between 1 and 1024", "--wal-segsize");
3492
3494
3495 setup_pgdata();
3496
3497 setup_bin_paths(argv[0]);
3498
3500 if (!username)
3502
3503 if (strncmp(username, "pg_", 3) == 0)
3504 pg_fatal("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
3505
3506 printf(_("The files belonging to this database system will be owned "
3507 "by user \"%s\".\n"
3508 "This user must also own the server process.\n\n"),
3510
3512
3514
3516
3518
3519 printf("\n");
3520
3521 if (data_checksums)
3522 printf(_("Data page checksums are enabled.\n"));
3523 else
3524 printf(_("Data page checksums are disabled.\n"));
3525
3526 if (pwprompt || pwfilename)
3527 get_su_pwd();
3528
3529 printf("\n");
3530
3532
3533 if (do_sync)
3534 {
3535 fputs(_("syncing data to disk ... "), stdout);
3536 fflush(stdout);
3538 check_ok();
3539 }
3540 else
3541 printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3542
3543 if (authwarning)
3544 {
3545 printf("\n");
3546 pg_log_warning("enabling \"trust\" authentication for local connections");
3547 pg_log_warning_hint("You can change this by editing pg_hba.conf or using the option -A, or "
3548 "--auth-local and --auth-host, the next time you run initdb.");
3549 }
3550
3551 if (!noinstructions)
3552 {
3553 /*
3554 * Build up a shell command to tell the user how to start the server
3555 */
3557
3558 /* Get directory specification used to start initdb ... */
3559 strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
3562 /* ... and tag on pg_ctl instead */
3564
3565 /* Convert the path to use native separators */
3567
3568 /* path to pg_ctl, properly quoted */
3570
3571 /* add -D switch, with properly quoted data directory */
3574
3575 /* add suggested -l switch and "start" command */
3576 /* translator: This is a placeholder in a shell command. */
3577 appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
3578
3579 printf(_("\nSuccess. You can now start the database server using:\n\n"
3580 " %s\n\n"),
3581 start_db_cmd->data);
3582
3584 }
3585
3586
3587 success = true;
3588 return 0;
3589}
#define PG_TEXTDOMAIN(domain)
Definition c.h:1305
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition exec.c:430
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:25
#define required_argument
Definition getopt_long.h:26
static char * lc_time
Definition initdb.c:145
static char * get_id(void)
Definition initdb.c:829
static char * pgdata_native
Definition initdb.c:197
static void check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
Definition initdb.c:2605
static bool sync_data_files
Definition initdb.c:171
static bool icu_locale_specified
Definition initdb.c:150
static bool noinstructions
Definition initdb.c:163
void initialize_data_directory(void)
Definition initdb.c:3069
void setup_text_search(void)
Definition initdb.c:2861
static char * share_path
Definition initdb.c:135
void setup_bin_paths(const char *argv0)
Definition initdb.c:2671
static void check_authmethod_unspecified(const char **authmethod)
Definition initdb.c:2595
static const char *const auth_methods_host[]
Definition initdb.c:96
void setup_locale_encoding(void)
Definition initdb.c:2708
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:2620
static bool do_sync
Definition initdb.c:164
static void cleanup_directories_atexit(void)
Definition initdb.c:776
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:1968
void setup_data_file_paths(void)
Definition initdb.c:2815
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:446
static _stringlist * extra_guc_values
Definition initdb.c:160
static char * lc_numeric
Definition initdb.c:144
void setup_pgdata(void)
Definition initdb.c:2634
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:1680
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:1616
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
static void usage(void)
static char * pg_ctl_path
PGDLLIMPORT int optind
Definition getopt.c:51
PGDLLIMPORT char * optarg
Definition getopt.c:53
#define pg_log_warning(...)
Definition pgfnames.c:24
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition path.c:286
#define PG_IOLBF
Definition port.h:409
void get_parent_directory(char *path)
Definition path.c:1068
void make_native_path(char *filename)
Definition path.c:236
const char * get_progname(const char *argv0)
Definition path.c:652
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)
char * c
void get_restricted_token(void)
void appendShellString(PQExpBuffer buf, const char *str)
#define IsValidWalSegSize(size)

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(), data_checksums, datlocale, debug, default_text_search_config, destroyPQExpBuffer(), do_sync, encoding, extra_guc_names, extra_guc_values, extra_options, fb(), 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, strlcpy(), success, sync_data_files, 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 2088 of file initdb.c.

2089{
2090 /*
2091 * Just as we did for template0, and for the same reasons, assign a fixed
2092 * OID to postgres and select the file_copy strategy.
2093 */
2094 PG_CMD_PUTS("CREATE DATABASE postgres OID = " CppAsString2(PostgresDbOid)
2095 " STRATEGY = file_copy;\n\n");
2096 PG_CMD_PUTS("COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
2097}
#define CppAsString2(x)
Definition c.h:500

References CppAsString2, fb(), and PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ make_template0()

static void make_template0 ( FILE cmdfd)
static

Definition at line 2034 of file initdb.c.

2035{
2036 /*
2037 * pg_upgrade tries to preserve database OIDs across upgrades. It's smart
2038 * enough to drop and recreate a conflicting database with the same name,
2039 * but if the same OID were used for one system-created database in the
2040 * old cluster and a different system-created database in the new cluster,
2041 * it would fail. To avoid that, assign a fixed OID to template0 rather
2042 * than letting the server choose one.
2043 *
2044 * (Note that, while the user could have dropped and recreated these
2045 * objects in the old cluster, the problem scenario only exists if the OID
2046 * that is in use in the old cluster is also used in the new cluster - and
2047 * the new cluster should be the result of a fresh initdb.)
2048 *
2049 * We use "STRATEGY = file_copy" here because checkpoints during initdb
2050 * are cheap. "STRATEGY = wal_log" would generate more WAL, which would be
2051 * a little bit slower and make the new cluster a little bit bigger.
2052 */
2053 PG_CMD_PUTS("CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
2054 " OID = " CppAsString2(Template0DbOid)
2055 " STRATEGY = file_copy;\n\n");
2056
2057 /*
2058 * template0 shouldn't have any collation-dependent objects, so unset the
2059 * collation version. This disables collation version checks when making
2060 * a new database from it.
2061 */
2062 PG_CMD_PUTS("UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
2063
2064 /*
2065 * While we are here, do set the collation version on template1.
2066 */
2067 PG_CMD_PUTS("UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
2068
2069 /*
2070 * Explicitly revoke public create-schema and create-temp-table privileges
2071 * in template1 and template0; else the latter would be on by default
2072 */
2073 PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
2074 PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
2075
2076 PG_CMD_PUTS("COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
2077
2078 /*
2079 * Finally vacuum to clean up dead rows in pg_database
2080 */
2081 PG_CMD_PUTS("VACUUM pg_database;\n\n");
2082}

References CppAsString2, fb(), 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 2157 of file initdb.c.

2158{
2159 return strftime(s, max, fmt, tm);
2160}

References fb(), and tm.

Referenced by locale_date_order().

◆ popen_check()

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

Definition at line 759 of file initdb.c.

760{
761 FILE *cmdfd;
762
763 fflush(NULL);
764 errno = 0;
765 cmdfd = popen(command, mode);
766 if (cmdfd == NULL)
767 pg_log_error("could not execute command \"%s\": %m", command);
768 return cmdfd;
769}
static PgChecksumMode mode

References fb(), mode, and pg_log_error.

◆ pretty_wal_size()

static char * pretty_wal_size ( int  segment_count)
static

Definition at line 1282 of file initdb.c.

1283{
1285 char *result = pg_malloc(14);
1286
1287 if ((sz % 1024) == 0)
1288 snprintf(result, 14, "%dGB", sz / 1024);
1289 else
1290 snprintf(result, 14, "%dMB", sz);
1291
1292 return result;
1293}

References fb(), pg_malloc(), snprintf, and wal_segment_size_mb.

Referenced by setup_config().

◆ readfile()

static char ** readfile ( const char path)
static

Definition at line 690 of file initdb.c.

691{
692 char **result;
693 FILE *infile;
694 StringInfoData line;
695 int maxlines;
696 int n;
697
698 if ((infile = fopen(path, "r")) == NULL)
699 pg_fatal("could not open file \"%s\" for reading: %m", path);
700
701 initStringInfo(&line);
702
703 maxlines = 1024;
704 result = pg_malloc_array(char *, maxlines);
705
706 n = 0;
707 while (pg_get_line_buf(infile, &line))
708 {
709 /* make sure there will be room for a trailing NULL pointer */
710 if (n >= maxlines - 1)
711 {
712 maxlines *= 2;
713 result = pg_realloc_array(result, char *, maxlines);
714 }
715
716 result[n++] = pg_strdup(line.data);
717 }
718 result[n] = NULL;
719
720 pfree(line.data);
721
722 fclose(infile);
723
724 return result;
725}
#define pg_realloc_array(pointer, type, count)
Definition fe_memutils.h:63
#define pg_malloc_array(type, count)
Definition fe_memutils.h:56
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition pg_get_line.c:95
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
static void infile(const char *name)
Definition zic.c:1257

References StringInfoData::data, fb(), infile(), initStringInfo(), pfree(), pg_fatal, pg_get_line_buf(), pg_malloc_array, pg_realloc_array, 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 542 of file initdb.c.

544{
545 int namelen = strlen(guc_name);
547 int i;
548
549 /* prepare the replacement line, except for possible comment and newline */
550 if (mark_as_comment)
555 else
557
558 for (i = 0; lines[i]; i++)
559 {
560 const char *where;
561 const char *namestart;
562
563 /*
564 * Look for a line assigning to guc_name. Typically it will be
565 * preceded by '#', but that might not be the case if a -c switch
566 * overrides a previous assignment. We allow leading whitespace too,
567 * although normally there wouldn't be any.
568 */
569 where = lines[i];
570 while (*where == '#' || isspace((unsigned char) *where))
571 where++;
572 if (pg_strncasecmp(where, guc_name, namelen) != 0)
573 continue;
575 where += namelen;
576 while (isspace((unsigned char) *where))
577 where++;
578 if (*where != '=')
579 continue;
580
581 /* found it -- let's use the canonical casing shown in the file */
582 memcpy(&newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
583
584 /* now append the original comment if any */
585 where = strrchr(where, '#');
586 if (where)
587 {
588 /*
589 * We try to preserve original indentation, which is tedious.
590 * oldindent and newindent are measured in de-tab-ified columns.
591 */
592 const char *ptr;
593 int oldindent = 0;
594 int newindent;
595
596 for (ptr = lines[i]; ptr < where; ptr++)
597 {
598 if (*ptr == '\t')
599 oldindent += 8 - (oldindent % 8);
600 else
601 oldindent++;
602 }
603 /* ignore the possibility of tabs in guc_value */
604 newindent = newline->len;
605 /* append appropriate tabs and spaces, forcing at least one */
607 while (newindent < oldindent)
608 {
609 int newindent_if_tab = newindent + 8 - (newindent % 8);
610
612 {
615 }
616 else
617 {
619 newindent++;
620 }
621 }
622 /* and finally append the old comment */
624 /* we'll have appended the original newline; don't add another */
625 }
626 else
628
629 free(lines[i]);
630 lines[i] = newline->data;
631
632 break; /* assume there's only one match */
633 }
634
635 if (lines[i] == NULL)
636 {
637 /*
638 * No match, so append a new entry. (We rely on the bootstrap server
639 * to complain if it's not a valid GUC name.)
640 */
642 lines = pg_realloc_array(lines, char *, i + 2);
643 lines[i++] = newline->data;
644 lines[i] = NULL; /* keep the array null-terminated */
645 }
646
647 free(newline); /* but don't free newline->data */
648
649 return lines;
650}
#define Max(x, y)
Definition c.h:1087
#define newline
static bool guc_value_requires_quotes(const char *guc_value)
Definition initdb.c:658
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void appendPQExpBufferChar(PQExpBuffer str, char ch)

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), createPQExpBuffer(), escape_quotes(), fb(), 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 475 of file initdb.c.

476{
477 int toklen,
478 replen,
479 diff;
480
482 replen = strlen(replacement);
483 diff = replen - toklen;
484
485 for (int i = 0; lines[i]; i++)
486 {
487 char *where;
488 char *endwhere;
489 char *newline;
490 int pre;
491
492 /* nothing to do if no change needed */
493 if ((where = strstr(lines[i], token)) == NULL)
494 continue;
495
496 /*
497 * Reject false match. Note a blind spot: we don't check for a valid
498 * match following a false match. That case can't occur at present,
499 * so not worth complicating this code for it.
500 */
501 if (!(where == lines[i] || isspace((unsigned char) where[-1])))
502 continue;
504 if (!(*endwhere == '\0' || isspace((unsigned char) *endwhere)))
505 continue;
506
507 /* if we get here a change is needed - set up new line */
508
509 newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
510
511 pre = where - lines[i];
512
513 memcpy(newline, lines[i], pre);
514
515 memcpy(newline + pre, replacement, replen);
516
517 strcpy(newline + pre + replen, lines[i] + pre + toklen);
518
519 free(lines[i]);
520 lines[i] = newline;
521 }
522
523 return lines;
524}

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

Referenced by bootstrap_template1(), and setup_config().

◆ restore_global_locale()

static void restore_global_locale ( int  category,
save_locale_t  save 
)
static

Definition at line 390 of file initdb.c.

391{
392#ifdef WIN32
393 if (!_wsetlocale(category, save))
394 pg_fatal("failed to restore old locale");
395#else
396 if (!setlocale(category, save))
397 pg_fatal("failed to restore old locale \"%s\"", save);
398#endif
399 free(save);
400}

References fb(), free, pg_fatal, and setlocale.

Referenced by check_locale_name(), and locale_date_order().

◆ save_global_locale()

static save_locale_t save_global_locale ( int  category)
static

Definition at line 366 of file initdb.c.

367{
369
370#ifdef WIN32
371 save = _wsetlocale(category, NULL);
372 if (!save)
373 pg_fatal("_wsetlocale() failed");
374 save = wcsdup(save);
375 if (!save)
376 pg_fatal("out of memory");
377#else
378 save = setlocale(category, NULL);
379 if (!save)
380 pg_fatal("setlocale() failed");
382#endif
383 return save;
384}

References fb(), pg_fatal, pg_strdup(), and setlocale.

Referenced by check_locale_name(), and locale_date_order().

◆ select_default_timezone()

const char * select_default_timezone ( const char share_path)
extern

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 */
1773 if (validate_zone(tzname))
1774 return tzname;
1775
1776 return NULL;
1777}
static const char * identify_system_timezone(void)
static bool validate_zone(const char *tzname)
static char tzdirpath[MAXPGPATH]

References fb(), 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 1968 of file initdb.c.

1969{
1970 char *letterversion;
1971 long major = 0,
1972 minor = 0,
1973 micro = 0;
1974 char *endptr;
1975 char *vstr = pg_strdup(PG_VERSION);
1976 char *ptr;
1977
1978 ptr = vstr + (strlen(vstr) - 1);
1979 while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
1980 ptr--;
1981 letterversion = ptr + 1;
1982 major = strtol(vstr, &endptr, 10);
1983 if (*endptr)
1984 minor = strtol(endptr + 1, &endptr, 10);
1985 if (*endptr)
1986 micro = strtol(endptr + 1, &endptr, 10);
1987 snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
1989}
static char infoversion[100]
Definition initdb.c:193

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

Referenced by main().

◆ set_input()

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

Definition at line 1000 of file initdb.c.

1001{
1002 *dest = psprintf("%s/%s", share_path, filename);
1003}
static char * filename
Definition pg_dumpall.c:133

References filename, psprintf(), and share_path.

Referenced by setup_data_file_paths().

◆ set_null_conf()

static void set_null_conf ( void  )
static

Definition at line 1063 of file initdb.c.

1064{
1065 FILE *conf_file;
1066 char *path;
1067
1068 path = psprintf("%s/postgresql.conf", pg_data);
1069 conf_file = fopen(path, PG_BINARY_W);
1070 if (conf_file == NULL)
1071 pg_fatal("could not open file \"%s\" for writing: %m", path);
1072 if (fclose(conf_file))
1073 pg_fatal("could not write file \"%s\": %m", path);
1074 free(path);
1075}
#define PG_BINARY_W
Definition c.h:1379
static char * conf_file
Definition initdb.c:181

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

Referenced by initialize_data_directory().

◆ setlocales()

static void setlocales ( void  )
static

Definition at line 2447 of file initdb.c.

2448{
2449 char *canonname;
2450
2451 /* set empty lc_* and datlocale values to locale config if set */
2452
2453 if (locale)
2454 {
2455 if (!lc_ctype)
2456 lc_ctype = locale;
2457 if (!lc_collate)
2459 if (!lc_numeric)
2461 if (!lc_time)
2462 lc_time = locale;
2463 if (!lc_monetary)
2465 if (!lc_messages)
2468 datlocale = locale;
2469 }
2470
2471 /*
2472 * canonicalize locale names, and obtain any missing values from our
2473 * current environment
2474 */
2485#if defined(LC_MESSAGES) && !defined(WIN32)
2488#else
2489 /* when LC_MESSAGES is not available, use the LC_CTYPE setting */
2492#endif
2493
2495 pg_fatal("locale must be specified if provider is %s",
2497
2499 {
2500 if (strcmp(datlocale, "C") == 0)
2501 canonname = "C";
2502 else if (strcmp(datlocale, "C.UTF-8") == 0 ||
2503 strcmp(datlocale, "C.UTF8") == 0)
2504 canonname = "C.UTF-8";
2505 else if (strcmp(datlocale, "PG_UNICODE_FAST") == 0)
2506 canonname = "PG_UNICODE_FAST";
2507 else
2508 pg_fatal("invalid locale name \"%s\" for builtin provider",
2509 datlocale);
2510
2512 }
2514 {
2515 char *langtag;
2516
2517 /* canonicalize to a language tag */
2519 printf(_("Using language tag \"%s\" for ICU locale \"%s\".\n"),
2523
2525
2526 /*
2527 * In supported builds, the ICU locale ID will be opened during
2528 * post-bootstrap initialization, which will perform extra checks.
2529 */
2530#ifndef USE_ICU
2531 pg_fatal("ICU is not supported in this build");
2532#endif
2533 }
2534}
static char * icu_language_tag(const char *loc_str)
Definition initdb.c:2343
static void check_locale_name(int category, const char *locale, char **canonname)
Definition initdb.c:2225
static void icu_validate_locale(const char *loc_str)
Definition initdb.c:2396

References _, check_locale_name(), datlocale, fb(), 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 1663 of file initdb.c.

1664{
1665 /*
1666 * The authid table shouldn't be readable except through views, to ensure
1667 * passwords are not publicly visible.
1668 */
1669 PG_CMD_PUTS("REVOKE ALL ON pg_authid FROM public;\n\n");
1670
1672 PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1674}
#define PG_CMD_PRINTF(fmt,...)
Definition initdb.c:341

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

2672{
2673 int ret;
2674
2675 if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
2676 backend_exec)) < 0)
2677 {
2678 char full_path[MAXPGPATH];
2679
2680 if (find_my_exec(argv0, full_path) < 0)
2682
2683 if (ret == -1)
2684 pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
2685 "postgres", progname, full_path);
2686 else
2687 pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
2688 "postgres", full_path, progname);
2689 }
2690
2691 /* store binary directory */
2695
2696 if (!share_path)
2697 {
2700 }
2701 else if (!is_absolute_path(share_path))
2702 pg_fatal("input file location must be an absolute path");
2703
2705}
int find_my_exec(const char *argv0, char *retpath)
Definition exec.c:161
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition exec.c:311
static char bin_path[MAXPGPATH]
Definition initdb.c:260
static char * argv0
Definition pg_ctl.c:94
void get_share_path(const char *my_exec_path, char *ret_path)
Definition path.c:902
char * last_dir_separator(const char *filename)
Definition path.c:145
#define PG_BACKEND_VERSIONSTR
Definition port.h:144

References argv0, backend_exec, bin_path, canonicalize_path(), fb(), 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 1794 of file initdb.c.

1795{
1796 /*
1797 * Set the collation version for collations defined in pg_collation.dat,
1798 * but not the ones where we know that the collation behavior will never
1799 * change.
1800 */
1801 PG_CMD_PUTS("UPDATE pg_collation SET collversion = pg_collation_actual_version(oid) WHERE collname = 'unicode';\n\n");
1802
1803 /* Import all collations we can find in the operating system */
1804 PG_CMD_PUTS("SELECT pg_import_system_collations('pg_catalog');\n\n");
1805}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_config()

static void setup_config ( void  )
static

Definition at line 1299 of file initdb.c.

1300{
1301 char **conflines;
1302 char repltok[MAXPGPATH];
1303 char path[MAXPGPATH];
1305 *gvalues;
1306
1307 fputs(_("creating configuration files ... "), stdout);
1308 fflush(stdout);
1309
1310 /* postgresql.conf */
1311
1313
1314 snprintf(repltok, sizeof(repltok), "%d", n_connections);
1315 conflines = replace_guc_value(conflines, "max_connections",
1316 repltok, false);
1317
1318 snprintf(repltok, sizeof(repltok), "%d", n_av_slots);
1319 conflines = replace_guc_value(conflines, "autovacuum_worker_slots",
1320 repltok, false);
1321
1322 if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1323 snprintf(repltok, sizeof(repltok), "%dMB",
1324 (n_buffers * (BLCKSZ / 1024)) / 1024);
1325 else
1326 snprintf(repltok, sizeof(repltok), "%dkB",
1327 n_buffers * (BLCKSZ / 1024));
1328 conflines = replace_guc_value(conflines, "shared_buffers",
1329 repltok, false);
1330
1331 conflines = replace_guc_value(conflines, "lc_messages",
1332 lc_messages, false);
1333
1334 conflines = replace_guc_value(conflines, "lc_monetary",
1335 lc_monetary, false);
1336
1337 conflines = replace_guc_value(conflines, "lc_numeric",
1338 lc_numeric, false);
1339
1341 lc_time, false);
1342
1343 switch (locale_date_order(lc_time))
1344 {
1345 case DATEORDER_YMD:
1346 strcpy(repltok, "iso, ymd");
1347 break;
1348 case DATEORDER_DMY:
1349 strcpy(repltok, "iso, dmy");
1350 break;
1351 case DATEORDER_MDY:
1352 default:
1353 strcpy(repltok, "iso, mdy");
1354 break;
1355 }
1356 conflines = replace_guc_value(conflines, "datestyle",
1357 repltok, false);
1358
1359 snprintf(repltok, sizeof(repltok), "pg_catalog.%s",
1361 conflines = replace_guc_value(conflines, "default_text_search_config",
1362 repltok, false);
1363
1364 if (default_timezone)
1365 {
1367 default_timezone, false);
1368 conflines = replace_guc_value(conflines, "log_timezone",
1369 default_timezone, false);
1370 }
1371
1372 conflines = replace_guc_value(conflines, "dynamic_shared_memory_type",
1374
1375 /* Caution: these depend on wal_segment_size_mb, they're not constants */
1376 conflines = replace_guc_value(conflines, "min_wal_size",
1378
1379 conflines = replace_guc_value(conflines, "max_wal_size",
1381
1382 /*
1383 * Fix up various entries to match the true compile-time defaults. Since
1384 * these are indeed defaults, keep the postgresql.conf lines commented.
1385 */
1386 conflines = replace_guc_value(conflines, "unix_socket_directories",
1387 DEFAULT_PGSOCKET_DIR, true);
1388
1390 DEF_PGPORT_STR, true);
1391
1392#if DEFAULT_BACKEND_FLUSH_AFTER > 0
1393 snprintf(repltok, sizeof(repltok), "%dkB",
1395 conflines = replace_guc_value(conflines, "backend_flush_after",
1396 repltok, true);
1397#endif
1398
1399#if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1400 snprintf(repltok, sizeof(repltok), "%dkB",
1402 conflines = replace_guc_value(conflines, "bgwriter_flush_after",
1403 repltok, true);
1404#endif
1405
1406#if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1407 snprintf(repltok, sizeof(repltok), "%dkB",
1409 conflines = replace_guc_value(conflines, "checkpoint_flush_after",
1410 repltok, true);
1411#endif
1412
1413#ifdef WIN32
1414 conflines = replace_guc_value(conflines, "update_process_title",
1415 "off", true);
1416#endif
1417
1418 /*
1419 * Change password_encryption setting to md5 if md5 was chosen as an
1420 * authentication method, unless scram-sha-256 was also chosen.
1421 */
1422 if ((strcmp(authmethodlocal, "md5") == 0 &&
1423 strcmp(authmethodhost, "scram-sha-256") != 0) ||
1424 (strcmp(authmethodhost, "md5") == 0 &&
1425 strcmp(authmethodlocal, "scram-sha-256") != 0))
1426 {
1427 conflines = replace_guc_value(conflines, "password_encryption",
1428 "md5", false);
1429 }
1430
1431 /*
1432 * If group access has been enabled for the cluster then it makes sense to
1433 * ensure that the log files also allow group access. Otherwise a backup
1434 * from a user in the group would fail if the log files were not
1435 * relocated.
1436 */
1438 {
1439 conflines = replace_guc_value(conflines, "log_file_mode",
1440 "0640", false);
1441 }
1442
1443#if USE_LZ4
1444 conflines = replace_guc_value(conflines, "default_toast_compression",
1445 "lz4", true);
1446#endif
1447
1448 /*
1449 * Now replace anything that's overridden via -c switches.
1450 */
1452 gnames != NULL; /* assume lists have the same length */
1454 {
1456 gvalues->str, false);
1457 }
1458
1459 /* ... and write out the finished postgresql.conf file */
1460 snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
1461
1462 writefile(path, conflines);
1463 if (chmod(path, pg_file_create_mode) != 0)
1464 pg_fatal("could not change permissions of \"%s\": %m", path);
1465
1466
1467 /* postgresql.auto.conf */
1468
1469 conflines = pg_malloc_array(char *, 3);
1470 conflines[0] = pg_strdup("# Do not edit this file manually!\n");
1471 conflines[1] = pg_strdup("# It will be overwritten by the ALTER SYSTEM command.\n");
1472 conflines[2] = NULL;
1473
1474 sprintf(path, "%s/postgresql.auto.conf", pg_data);
1475
1476 writefile(path, conflines);
1477 if (chmod(path, pg_file_create_mode) != 0)
1478 pg_fatal("could not change permissions of \"%s\": %m", path);
1479
1480
1481 /* pg_hba.conf */
1482
1484
1485 /*
1486 * Probe to see if there is really any platform support for IPv6, and
1487 * comment out the relevant pg_hba line if not. This avoids runtime
1488 * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
1489 * useful on Windows, where executables built on a machine with IPv6 may
1490 * have to run on a machine without.
1491 */
1492 {
1493 struct addrinfo *gai_result;
1494 struct addrinfo hints;
1495 int err = 0;
1496
1497#ifdef WIN32
1498 /* need to call WSAStartup before calling getaddrinfo */
1500
1501 err = WSAStartup(MAKEWORD(2, 2), &wsaData);
1502#endif
1503
1504 /* for best results, this code should match parse_hba_line() */
1505 hints.ai_flags = AI_NUMERICHOST;
1506 hints.ai_family = AF_UNSPEC;
1507 hints.ai_socktype = 0;
1508 hints.ai_protocol = 0;
1509 hints.ai_addrlen = 0;
1510 hints.ai_canonname = NULL;
1511 hints.ai_addr = NULL;
1512 hints.ai_next = NULL;
1513
1514 if (err != 0 ||
1515 getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
1516 {
1518 "host all all ::1/128",
1519 "#host all all ::1/128");
1521 "host replication all ::1/128",
1522 "#host replication all ::1/128");
1523 }
1524 }
1525
1526 /* Replace default authentication methods */
1528 "@authmethodhost@",
1531 "@authmethodlocal@",
1533
1535 "@authcomment@",
1536 (strcmp(authmethodlocal, "trust") == 0 || strcmp(authmethodhost, "trust") == 0) ? AUTHTRUST_WARNING : "");
1537
1538 snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
1539
1540 writefile(path, conflines);
1541 if (chmod(path, pg_file_create_mode) != 0)
1542 pg_fatal("could not change permissions of \"%s\": %m", path);
1543
1544
1545 /* pg_ident.conf */
1546
1548
1549 snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
1550
1551 writefile(path, conflines);
1552 if (chmod(path, pg_file_create_mode) != 0)
1553 pg_fatal("could not change permissions of \"%s\": %m", path);
1554
1555 /* pg_hosts.conf */
1557 snprintf(path, sizeof(path), "%s/pg_hosts.conf", pg_data);
1558
1559 writefile(path, conflines);
1560 if (chmod(path, pg_file_create_mode) != 0)
1561 pg_fatal("could not change permissions of \"%s\": %m", path);
1562
1563 check_ok();
1564}
void err(int eval, const char *fmt,...)
Definition err.c:43
int pg_file_create_mode
Definition file_perm.c:19
static const char * default_timezone
Definition initdb.c:204
static char * hba_file
Definition initdb.c:178
static int n_connections
Definition initdb.c:200
static int n_buffers
Definition initdb.c:202
static char * ident_file
Definition initdb.c:179
static char * hosts_file
Definition initdb.c:180
static int locale_date_order(const char *locale)
Definition initdb.c:2166
static int n_av_slots
Definition initdb.c:201
static char * pretty_wal_size(int segment_count)
Definition initdb.c:1282
static char ** replace_guc_value(char **lines, const char *guc_name, const char *guc_value, bool mark_as_comment)
Definition initdb.c:542
static const char * dynamic_shared_memory_type
Definition initdb.c:203
#define AUTHTRUST_WARNING
Definition initdb.c:209
static void writefile(char *path, char **lines)
Definition initdb.c:737
#define DEFAULT_PGSOCKET_DIR
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
#define DEFAULT_BGWRITER_FLUSH_AFTER
struct _stringlist * next
Definition initdb.c:93
#define DEFAULT_MAX_WAL_SEGS
#define DEFAULT_MIN_WAL_SEGS

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, fb(), hba_file, hosts_file, ident_file, lc_messages, lc_monetary, lc_numeric, lc_time, locale_date_order(), MAXPGPATH, n_av_slots, 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, and writefile().

Referenced by initialize_data_directory().

◆ setup_data_file_paths()

void setup_data_file_paths ( void  )

Definition at line 2815 of file initdb.c.

2816{
2817 set_input(&bki_file, "postgres.bki");
2818 set_input(&hba_file, "pg_hba.conf.sample");
2819 set_input(&ident_file, "pg_ident.conf.sample");
2820 set_input(&hosts_file, "pg_hosts.conf.sample");
2821 set_input(&conf_file, "postgresql.conf.sample");
2822 set_input(&dictionary_file, "snowball_create.sql");
2823 set_input(&info_schema_file, "information_schema.sql");
2824 set_input(&features_file, "sql_features.txt");
2825 set_input(&system_constraints_file, "system_constraints.sql");
2826 set_input(&system_functions_file, "system_functions.sql");
2827 set_input(&system_views_file, "system_views.sql");
2828
2829 if (show_setting || debug)
2830 {
2832 "VERSION=%s\n"
2833 "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2834 "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2835 "POSTGRESQL_CONF_SAMPLE=%s\n"
2836 "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\nPG_HOSTS_SAMPLE=%s\n",
2837 PG_VERSION,
2840 conf_file,
2842 if (show_setting)
2843 exit(0);
2844 }
2845
2857}
static char * features_file
Definition initdb.c:184
static void set_input(char **dest, const char *filename)
Definition initdb.c:1000
static void check_input(char *path)
Definition initdb.c:1009
static char * info_schema_file
Definition initdb.c:183

References bin_path, bki_file, check_input(), conf_file, debug, dictionary_file, fb(), features_file, fprintf, hba_file, hosts_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 1739 of file initdb.c.

1740{
1741 /*
1742 * Advance the OID counter so that subsequently-created objects aren't
1743 * pinned.
1744 */
1745 PG_CMD_PUTS("SELECT pg_stop_making_pinned_objects();\n\n");
1746}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_description()

static void setup_description ( FILE cmdfd)
static

Definition at line 1773 of file initdb.c.

1774{
1775 /* Create default descriptions for operator implementation functions */
1776 PG_CMD_PUTS("WITH funcdescs AS ( "
1777 "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
1778 "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1779 "INSERT INTO pg_description "
1780 " SELECT p_oid, 'pg_proc'::regclass, 0, "
1781 " 'implementation of ' || oprname || ' operator' "
1782 " FROM funcdescs "
1783 " WHERE NOT EXISTS (SELECT 1 FROM pg_description "
1784 " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
1785 " AND NOT EXISTS (SELECT 1 FROM pg_description "
1786 " WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
1787 " AND description LIKE 'deprecated%');\n\n");
1788}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_locale_encoding()

void setup_locale_encoding ( void  )

Definition at line 2708 of file initdb.c.

2709{
2710 setlocales();
2711
2713 strcmp(lc_ctype, lc_collate) == 0 &&
2714 strcmp(lc_ctype, lc_time) == 0 &&
2715 strcmp(lc_ctype, lc_numeric) == 0 &&
2716 strcmp(lc_ctype, lc_monetary) == 0 &&
2717 strcmp(lc_ctype, lc_messages) == 0 &&
2718 (!datlocale || strcmp(lc_ctype, datlocale) == 0))
2719 printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
2720 else
2721 {
2722 printf(_("The database cluster will be initialized with this locale configuration:\n"));
2723 printf(_(" locale provider: %s\n"), collprovider_name(locale_provider));
2725 printf(_(" default collation: %s\n"), datlocale);
2726 printf(_(" LC_COLLATE: %s\n"
2727 " LC_CTYPE: %s\n"
2728 " LC_MESSAGES: %s\n"
2729 " LC_MONETARY: %s\n"
2730 " LC_NUMERIC: %s\n"
2731 " LC_TIME: %s\n"),
2732 lc_collate,
2733 lc_ctype,
2736 lc_numeric,
2737 lc_time);
2738 }
2739
2740 if (!encoding)
2741 {
2742 int ctype_enc;
2743
2745
2746 /*
2747 * If ctype_enc=SQL_ASCII, it's compatible with any encoding. ICU does
2748 * not support SQL_ASCII, so select UTF-8 instead.
2749 */
2752
2753 if (ctype_enc == -1)
2754 {
2755 /* Couldn't recognize the locale's codeset */
2756 pg_log_error("could not find suitable encoding for locale \"%s\"",
2757 lc_ctype);
2758 pg_log_error_hint("Rerun %s with the -E option.", progname);
2759 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2760 exit(1);
2761 }
2763 {
2764 /*
2765 * We recognized it, but it's not a legal server encoding. On
2766 * Windows, UTF-8 works with any locale, so we can fall back to
2767 * UTF-8.
2768 */
2769#ifdef WIN32
2771 printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2772 "The default database encoding will be set to \"%s\" instead.\n"),
2775#else
2776 pg_log_error("locale \"%s\" requires unsupported encoding \"%s\"",
2778 pg_log_error_detail("Encoding \"%s\" is not allowed as a server-side encoding.",
2780 pg_log_error_hint("Rerun %s with a different locale selection.",
2781 progname);
2782 exit(1);
2783#endif
2784 }
2785 else
2786 {
2788 printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2790 }
2791 }
2792 else
2794
2797 exit(1); /* check_locale_encoding printed the error */
2798
2800 {
2801 if ((strcmp(datlocale, "C.UTF-8") == 0 ||
2802 strcmp(datlocale, "PG_UNICODE_FAST") == 0) &&
2804 pg_fatal("builtin provider locale \"%s\" requires encoding \"%s\"",
2805 datlocale, "UTF-8");
2806 }
2807
2810 exit(1);
2811}
static bool check_icu_locale_encoding(int user_enc)
Definition initdb.c:2323
static int get_encoding_id(const char *encoding_name)
Definition initdb.c:860
static bool check_locale_encoding(const char *locale, int user_enc)
Definition initdb.c:2288
static void setlocales(void)
Definition initdb.c:2447
#define pg_valid_server_encoding_id
Definition pg_wchar.h:632

References _, check_icu_locale_encoding(), check_locale_encoding(), datlocale, encoding, encodingid, fb(), 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 2634 of file initdb.c.

2635{
2636 char *pgdata_get_env;
2637
2638 if (!pg_data)
2639 {
2640 pgdata_get_env = getenv("PGDATA");
2642 {
2643 /* PGDATA found */
2645 }
2646 else
2647 {
2648 pg_log_error("no data directory specified");
2649 pg_log_error_hint("You must identify the directory where the data for this database system "
2650 "will reside. Do this with either the invocation option -D or the "
2651 "environment variable PGDATA.");
2652 exit(1);
2653 }
2654 }
2655
2658
2659 /*
2660 * we have to set PGDATA for postgres rather than pass it on the command
2661 * line to avoid dumb quoting problems on Windows, and we would especially
2662 * need quotes otherwise on Windows because paths there are most likely to
2663 * have embedded spaces.
2664 */
2665 if (setenv("PGDATA", pg_data, 1) != 0)
2666 pg_fatal("could not set environment");
2667}
#define setenv(x, y, z)
Definition win32_port.h:542

References canonicalize_path(), fb(), 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 1827 of file initdb.c.

1828{
1829 PG_CMD_PRINTF("UPDATE pg_class "
1830 " SET relacl = (SELECT array_agg(a.acl) FROM "
1831 " (SELECT E'=r/\"%s\"' as acl "
1832 " UNION SELECT unnest(pg_catalog.acldefault("
1833 " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
1834 " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
1835 " ) as a) "
1836 " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1839 " AND relacl IS NULL;\n\n",
1841 PG_CMD_PUTS("GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
1842 PG_CMD_PUTS("REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
1843 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1844 " (objoid, classoid, objsubid, initprivs, privtype)"
1845 " SELECT"
1846 " oid,"
1847 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1848 " 0,"
1849 " relacl,"
1850 " 'i'"
1851 " FROM"
1852 " pg_class"
1853 " WHERE"
1854 " relacl IS NOT NULL"
1855 " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1857 CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1858 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1859 " (objoid, classoid, objsubid, initprivs, privtype)"
1860 " SELECT"
1861 " pg_class.oid,"
1862 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1863 " pg_attribute.attnum,"
1864 " pg_attribute.attacl,"
1865 " 'i'"
1866 " FROM"
1867 " pg_class"
1868 " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1869 " WHERE"
1870 " pg_attribute.attacl IS NOT NULL"
1871 " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1873 CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1874 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1875 " (objoid, classoid, objsubid, initprivs, privtype)"
1876 " SELECT"
1877 " oid,"
1878 " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1879 " 0,"
1880 " proacl,"
1881 " 'i'"
1882 " FROM"
1883 " pg_proc"
1884 " WHERE"
1885 " proacl IS NOT NULL;\n\n");
1886 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1887 " (objoid, classoid, objsubid, initprivs, privtype)"
1888 " SELECT"
1889 " oid,"
1890 " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1891 " 0,"
1892 " typacl,"
1893 " 'i'"
1894 " FROM"
1895 " pg_type"
1896 " WHERE"
1897 " typacl IS NOT NULL;\n\n");
1898 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1899 " (objoid, classoid, objsubid, initprivs, privtype)"
1900 " SELECT"
1901 " oid,"
1902 " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1903 " 0,"
1904 " lanacl,"
1905 " 'i'"
1906 " FROM"
1907 " pg_language"
1908 " WHERE"
1909 " lanacl IS NOT NULL;\n\n");
1910 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1911 " (objoid, classoid, objsubid, initprivs, privtype)"
1912 " SELECT"
1913 " oid,"
1914 " (SELECT oid FROM pg_class WHERE "
1915 " relname = 'pg_largeobject_metadata'),"
1916 " 0,"
1917 " lomacl,"
1918 " 'i'"
1919 " FROM"
1920 " pg_largeobject_metadata"
1921 " WHERE"
1922 " lomacl IS NOT NULL;\n\n");
1923 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1924 " (objoid, classoid, objsubid, initprivs, privtype)"
1925 " SELECT"
1926 " oid,"
1927 " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1928 " 0,"
1929 " nspacl,"
1930 " 'i'"
1931 " FROM"
1932 " pg_namespace"
1933 " WHERE"
1934 " nspacl IS NOT NULL;\n\n");
1935 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1936 " (objoid, classoid, objsubid, initprivs, privtype)"
1937 " SELECT"
1938 " oid,"
1939 " (SELECT oid FROM pg_class WHERE "
1940 " relname = 'pg_foreign_data_wrapper'),"
1941 " 0,"
1942 " fdwacl,"
1943 " 'i'"
1944 " FROM"
1945 " pg_foreign_data_wrapper"
1946 " WHERE"
1947 " fdwacl IS NOT NULL;\n\n");
1948 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1949 " (objoid, classoid, objsubid, initprivs, privtype)"
1950 " SELECT"
1951 " oid,"
1952 " (SELECT oid FROM pg_class "
1953 " WHERE relname = 'pg_foreign_server'),"
1954 " 0,"
1955 " srvacl,"
1956 " 'i'"
1957 " FROM"
1958 " pg_foreign_server"
1959 " WHERE"
1960 " srvacl IS NOT NULL;\n\n");
1961}

References CppAsString2, escape_quotes(), fb(), 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 1752 of file initdb.c.

1753{
1754 char **lines;
1755
1756 lines = readfile(filename);
1757
1758 for (char **line = lines; *line != NULL; line++)
1759 {
1760 PG_CMD_PUTS(*line);
1761 free(*line);
1762 }
1763
1764 PG_CMD_PUTS("\n\n");
1765
1766 free(lines);
1767}

References fb(), 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 1995 of file initdb.c.

1996{
1998
1999 PG_CMD_PRINTF("UPDATE information_schema.sql_implementation_info "
2000 " SET character_value = '%s' "
2001 " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
2002 infoversion);
2003
2004 PG_CMD_PRINTF("COPY information_schema.sql_features "
2005 " (feature_id, feature_name, sub_feature_id, "
2006 " sub_feature_name, is_supported, comments) "
2007 " FROM E'%s';\n\n",
2009}

References escape_quotes(), fb(), 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 2895 of file initdb.c.

2896{
2899
2900 /* the following are not valid on Windows */
2901#ifndef WIN32
2904
2905 /* Ignore SIGPIPE when writing to backend, so we can clean up */
2907
2908 /* Prevent SIGSYS so we can probe for kernel calls that might not work */
2910#endif
2911}
static void trapsig(SIGNAL_ARGS)
Definition initdb.c:2121
#define pqsignal
Definition port.h:547
#define SIGHUP
Definition win32_port.h:158
#define SIGPIPE
Definition win32_port.h:163
#define SIGQUIT
Definition win32_port.h:159

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

Referenced by initialize_data_directory().

◆ setup_text_search()

void setup_text_search ( void  )

Definition at line 2861 of file initdb.c.

2862{
2864 {
2867 {
2868 pg_log_info("could not find suitable text search configuration for locale \"%s\"",
2869 lc_ctype);
2870 default_text_search_config = "simple";
2871 }
2872 }
2873 else
2874 {
2876
2877 if (checkmatch == NULL)
2878 {
2879 pg_log_warning("suitable text search configuration for locale \"%s\" is unknown",
2880 lc_ctype);
2881 }
2883 {
2884 pg_log_warning("specified text search configuration \"%s\" might not match locale \"%s\"",
2886 }
2887 }
2888
2889 printf(_("The default text search configuration will be set to \"%s\".\n"),
2891}
static const char * find_matching_ts_config(const char *lc_type)
Definition initdb.c:954

References _, default_text_search_config, fb(), 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 1134 of file initdb.c.

1135{
1136 /*
1137 * This macro defines the minimum shared_buffers we want for a given
1138 * max_connections value. The arrays show the settings to try.
1139 */
1140#define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
1141
1142 /*
1143 * This macro defines the default value of autovacuum_worker_slots we want
1144 * for a given max_connections value. Note that it has been carefully
1145 * crafted to provide specific values for the associated values in
1146 * trial_conns. We want it to return autovacuum_worker_slots's initial
1147 * default value (16) for the maximum value in trial_conns[] (100), while
1148 * it mustn't return less than the default value of autovacuum_max_workers
1149 * (3) for the minimum value in trial_conns[].
1150 */
1151#define AV_SLOTS_FOR_CONNS(nconns) ((nconns) / 6)
1152
1153 static const int trial_conns[] = {
1154 100, 50, 40, 30, 20
1155 };
1156 static const int trial_bufs[] = {
1157 16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
1158 1000, 900, 800, 700, 600, 500,
1159 400, 300, 200, 100, 50
1160 };
1161
1162 const int connslen = sizeof(trial_conns) / sizeof(int);
1163 const int bufslen = sizeof(trial_bufs) / sizeof(int);
1164 int i,
1165 test_conns,
1166 test_buffs,
1167 ok_buffers = 0;
1168
1169 /*
1170 * Need to determine working DSM implementation first so that subsequent
1171 * tests don't fail because DSM setting doesn't work.
1172 */
1173 printf(_("selecting dynamic shared memory implementation ... "));
1174 fflush(stdout);
1177
1178 /*
1179 * Probe for max_connections before shared_buffers, since it is subject to
1180 * more constraints than shared_buffers. We also choose the default
1181 * autovacuum_worker_slots here.
1182 */
1183 printf(_("selecting default \"max_connections\" ... "));
1184 fflush(stdout);
1185
1186 for (i = 0; i < connslen; i++)
1187 {
1191
1193 {
1195 break;
1196 }
1197 }
1198 if (i >= connslen)
1199 i = connslen - 1;
1201
1202 printf("%d\n", n_connections);
1203
1204 printf(_("selecting default \"shared_buffers\" ... "));
1205 fflush(stdout);
1206
1207 for (i = 0; i < bufslen; i++)
1208 {
1209 /* Use same amount of memory, independent of BLCKSZ */
1210 test_buffs = (trial_bufs[i] * 8192) / BLCKSZ;
1211 if (test_buffs <= ok_buffers)
1212 {
1214 break;
1215 }
1216
1218 break;
1219 }
1221
1222 if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1223 printf("%dMB\n", (n_buffers * (BLCKSZ / 1024)) / 1024);
1224 else
1225 printf("%dkB\n", n_buffers * (BLCKSZ / 1024));
1226
1227 printf(_("selecting default time zone ... "));
1228 fflush(stdout);
1230 printf("%s\n", default_timezone ? default_timezone : "GMT");
1231}
static bool test_specific_config_settings(int test_conns, int test_av_slots, int test_buffs)
Definition initdb.c:1237
#define MIN_BUFS_FOR_CONNS(nconns)
#define AV_SLOTS_FOR_CONNS(nconns)
static const char * choose_dsm_implementation(void)
Definition initdb.c:1092
const char * select_default_timezone(const char *share_path)

References _, AV_SLOTS_FOR_CONNS, choose_dsm_implementation(), default_timezone, dynamic_shared_memory_type, fb(), i, MIN_BUFS_FOR_CONNS, n_av_slots, n_buffers, n_connections, printf, select_default_timezone(), share_path, 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_av_slots,
int  test_buffs 
)
static

Definition at line 1237 of file initdb.c.

1238{
1239 PQExpBufferData cmd;
1241 *gvalues;
1242 int status;
1243
1244 initPQExpBuffer(&cmd);
1245
1246 /* Set up the test postmaster invocation */
1247 printfPQExpBuffer(&cmd,
1248 "\"%s\" --check %s %s "
1249 "-c max_connections=%d "
1250 "-c autovacuum_worker_slots=%d "
1251 "-c shared_buffers=%d "
1252 "-c dynamic_shared_memory_type=%s",
1256
1257 /* Add any user-given setting overrides */
1259 gnames != NULL; /* assume lists have the same length */
1261 {
1262 appendPQExpBuffer(&cmd, " -c %s=", gnames->str);
1263 appendShellString(&cmd, gvalues->str);
1264 }
1265
1266 appendPQExpBuffer(&cmd,
1267 " < \"%s\" > \"%s\" 2>&1",
1268 DEVNULL, DEVNULL);
1269
1270 fflush(NULL);
1271 status = system(cmd.data);
1272
1273 termPQExpBuffer(&cmd);
1274
1275 return (status == 0);
1276}

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

Referenced by test_config_settings().

◆ trapsig()

static void trapsig ( SIGNAL_ARGS  )
static

Definition at line 2121 of file initdb.c.

2122{
2123 /* handle systems that reset the handler, like Windows (grr) */
2125 caught_signal = true;
2126}

References caught_signal, fb(), pqsignal, and trapsig().

Referenced by setup_signals(), and trapsig().

◆ usage()

static void usage ( const char progname)
static

Definition at line 2540 of file initdb.c.

2541{
2542 printf(_("%s initializes a PostgreSQL database cluster.\n\n"), progname);
2543 printf(_("Usage:\n"));
2544 printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
2545 printf(_("\nOptions:\n"));
2546 printf(_(" -A, --auth=METHOD default authentication method for local connections\n"));
2547 printf(_(" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
2548 printf(_(" --auth-local=METHOD default authentication method for local-socket connections\n"));
2549 printf(_(" [-D, --pgdata=]DATADIR location for this database cluster\n"));
2550 printf(_(" -E, --encoding=ENCODING set default encoding for new databases\n"));
2551 printf(_(" -g, --allow-group-access allow group read/execute on data directory\n"));
2552 printf(_(" --icu-locale=LOCALE set ICU locale ID for new databases\n"));
2553 printf(_(" --icu-rules=RULES set additional ICU collation rules for new databases\n"));
2554 printf(_(" -k, --data-checksums use data page checksums\n"));
2555 printf(_(" --locale=LOCALE set default locale for new databases\n"));
2556 printf(_(" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
2557 " --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
2558 " set default locale in the respective category for\n"
2559 " new databases (default taken from environment)\n"));
2560 printf(_(" --no-locale equivalent to --locale=C\n"));
2561 printf(_(" --builtin-locale=LOCALE\n"
2562 " set builtin locale name for new databases\n"));
2563 printf(_(" --locale-provider={builtin|libc|icu}\n"
2564 " set default locale provider for new databases\n"));
2565 printf(_(" --no-data-checksums do not use data page checksums\n"));
2566 printf(_(" --pwfile=FILE read password for the new superuser from file\n"));
2567 printf(_(" -T, --text-search-config=CFG\n"
2568 " default text search configuration\n"));
2569 printf(_(" -U, --username=NAME database superuser name\n"));
2570 printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
2571 printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
2572 printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
2573 printf(_("\nLess commonly used options:\n"));
2574 printf(_(" -c, --set NAME=VALUE override default setting for server parameter\n"));
2575 printf(_(" -d, --debug generate lots of debugging output\n"));
2576 printf(_(" --discard-caches set debug_discard_caches=1\n"));
2577 printf(_(" -L DIRECTORY where to find the input files\n"));
2578 printf(_(" -n, --no-clean do not clean up after errors\n"));
2579 printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
2580 printf(_(" --no-sync-data-files do not sync files within database directories\n"));
2581 printf(_(" --no-instructions do not print instructions for next steps\n"));
2582 printf(_(" -s, --show show internal settings, then exit\n"));
2583 printf(_(" --sync-method=METHOD set method for syncing files to disk\n"));
2584 printf(_(" -S, --sync-only only sync database files to disk, then exit\n"));
2585 printf(_("\nOther options:\n"));
2586 printf(_(" -V, --version output version information, then exit\n"));
2587 printf(_(" -?, --help show this help, then exit\n"));
2588 printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"
2589 "is used.\n"));
2590 printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2591 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2592}

References _, fb(), printf, and progname.

◆ vacuum_db()

static void vacuum_db ( FILE cmdfd)
static

Definition at line 2024 of file initdb.c.

2025{
2026 /* Run analyze before VACUUM so the statistics are frozen. */
2027 PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
2028}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ warn_on_mount_point()

void warn_on_mount_point ( int  error)

Definition at line 3056 of file initdb.c.

3057{
3058 if (error == 2)
3059 pg_log_error_detail("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
3060 else if (error == 3)
3061 pg_log_error_detail("It contains a lost+found directory, perhaps due to it being a mount point.");
3062
3063 pg_log_error_hint("Using a mount point directly as the data directory is not recommended.\n"
3064 "Create a subdirectory under the mount point.");
3065}
static void error(void)

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

1041{
1043 char *path;
1044
1045 if (extrapath == NULL)
1046 path = psprintf("%s/PG_VERSION", pg_data);
1047 else
1048 path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
1049
1050 if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
1051 pg_fatal("could not open file \"%s\" for writing: %m", path);
1052 if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
1054 pg_fatal("could not write file \"%s\": %m", path);
1055 free(path);
1056}
static char version_file[MAXPGPATH]
Definition pg_ctl.c:99

References fb(), 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 737 of file initdb.c.

738{
739 FILE *out_file;
740 char **line;
741
742 if ((out_file = fopen(path, "w")) == NULL)
743 pg_fatal("could not open file \"%s\" for writing: %m", path);
744 for (line = lines; *line != NULL; line++)
745 {
746 if (fputs(*line, out_file) < 0)
747 pg_fatal("could not write file \"%s\": %m", path);
748 free(*line);
749 }
750 if (fclose(out_file))
751 pg_fatal("could not close file \"%s\": %m", path);
752 free(lines);
753}

References fb(), 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",
}

Definition at line 96 of file initdb.c.

96 {
97 "trust", "reject", "scram-sha-256", "md5", "password", "ident", "radius",
98#ifdef ENABLE_GSS
99 "gss",
100#endif
101#ifdef ENABLE_SSPI
102 "sspi",
103#endif
104#ifdef USE_PAM
105 "pam",
106#endif
107#ifdef USE_BSD_AUTH
108 "bsd",
109#endif
110#ifdef USE_LDAP
111 "ldap",
112#endif
113#ifdef USE_SSL
114 "cert",
115#endif
116 NULL
117};

Referenced by main().

◆ auth_methods_local

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

Definition at line 118 of file initdb.c.

118 {
119 "trust", "reject", "scram-sha-256", "md5", "password", "peer", "radius",
120#ifdef USE_PAM
121 "pam",
122#endif
123#ifdef USE_BSD_AUTH
124 "bsd",
125#endif
126#ifdef USE_LDAP
127 "ldap",
128#endif
129 NULL
130};

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 214 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 227 of file initdb.c.

Referenced by initialize_data_directory().

◆ bin_path

char bin_path[MAXPGPATH]
static

Definition at line 260 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 177 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 226 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 194 of file initdb.c.

Referenced by check_ok(), and trapsig().

◆ conf_file

char* conf_file
static

Definition at line 181 of file initdb.c.

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

◆ data_checksums

bool data_checksums = true
static

Definition at line 167 of file initdb.c.

Referenced by bootstrap_template1(), and main().

◆ datlocale

char* datlocale = NULL
static

Definition at line 149 of file initdb.c.

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

◆ 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 204 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ dictionary_file

char* dictionary_file
static

Definition at line 182 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 203 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 append_btree_pattern(), append_database_pattern(), append_heap_pattern(), append_relation_pattern(), append_relation_pattern_helper(), append_schema_pattern(), appendReloptionsArray(), appendStringLiteral(), ascii(), assign_client_encoding(), builtin_validate_locale(), cache_locale_time(), cache_single_string(), canonicalize_path_enc(), CATALOG(), check_client_encoding(), check_encoding_locale_matches(), chr(), createdb(), db_encoding_convert(), dequote_downcase_identifier(), dumpDatabase(), encoding_conflicts_ascii(), entry_alloc(), exec_command_encoding(), fmtIdEnc(), fmtQualifiedIdEnc(), get_encoding_name_for_icu(), get_json_format(), getJsonEncodingConst(), is_encoding_supported_by_icu(), iso8859_to_utf8(), latin2mic(), latin2mic_with_table(), LocalToUtf(), lookup_collation(), main(), makeJsonByteaToTextConversion(), makeJsonFormat(), makeJsonLexContextCstringLen(), makeJsonLexContextIncremental(), mbvalidate(), mic2latin(), mic2latin_with_table(), patternToSQLRegex(), pg_any_to_server(), pg_encoding_dsplen(), pg_encoding_max_length(), pg_encoding_max_length_sql(), pg_encoding_mb2wchar_with_len(), pg_encoding_mbcliplen(), pg_encoding_mblen(), pg_encoding_mblen_bounded(), pg_encoding_mblen_or_incomplete(), pg_encoding_set_invalid(), pg_encoding_to_char(), PG_encoding_to_char(), pg_encoding_verifymbchar(), pg_encoding_verifymbstr(), pg_encoding_wchar2mb_with_len(), pg_server_to_any(), pg_valid_server_encoding_id(), pg_verify_mbstr(), pg_verify_mbstr_len(), pg_wcsformat(), pg_wcssize(), pg_wcswidth(), PGLC_localeconv(), pgss_store(), PQdsplen(), PQenv2encoding(), PQescapeStringInternal(), PQmblen(), PQmblenBounded(), PQsetClientEncoding(), PrepareClientEncoding(), print_aligned_text(), print_aligned_vertical(), processEncodingEntry(), psql_scan_setup(), quote_if_needed(), report_invalid_encoding(), report_invalid_encoding_int(), reportErrorPosition(), SetClientEncoding(), SetDatabaseEncoding(), setFmtEncoding(), SetMessageEncoding(), setup_locale_encoding(), splitTableColumnsSpec(), strip_quotes(), strlen_max_width(), strtokx(), test_mblen_func(), test_text_to_wchars(), test_wchars_to_text(), utf8_to_iso8859(), utf8_to_win(), UtfToLocal(), win_to_utf8(), and xml_recv().

◆ encodingid

int encodingid
static

Definition at line 176 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 184 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 190 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 192 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_xlog_or_symlink().

◆ hba_file

char* hba_file
static

Definition at line 178 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

◆ hosts_file

char* hosts_file
static

Definition at line 180 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 179 of file initdb.c.

Referenced by setup_config(), and setup_data_file_paths().

◆ info_schema_file

char* info_schema_file
static

Definition at line 183 of file initdb.c.

Referenced by setup_data_file_paths(), and setup_schema().

◆ infoversion

char infoversion[100]
static

Definition at line 193 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

◆ lc_numeric

char* lc_numeric = NULL
static

◆ 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

char* locale = NULL
static

◆ 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 189 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 191 of file initdb.c.

Referenced by cleanup_directories_atexit(), and create_xlog_or_symlink().

◆ n_av_slots

int n_av_slots = 16
static

Definition at line 201 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ n_buffers

int n_buffers = 50
static

Definition at line 202 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ n_connections

int n_connections = 10
static

Definition at line 200 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 196 of file initdb.c.

Referenced by check_ok().

◆ output_failed

bool output_failed = false
static

Definition at line 195 of file initdb.c.

Referenced by check_ok().

◆ pg_data

◆ pgdata_native

char* pgdata_native
static

Definition at line 197 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

◆ 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 232 of file initdb.c.

232 {
233 "global",
234 "pg_wal/archive_status",
235 "pg_wal/summaries",
236 "pg_commit_ts",
237 "pg_dynshmem",
238 "pg_notify",
239 "pg_serial",
240 "pg_snapshots",
241 "pg_subtrans",
242 "pg_twophase",
243 "pg_multixact",
244 "pg_multixact/members",
245 "pg_multixact/offsets",
246 "base",
247 "base/1",
248 "pg_replslot",
249 "pg_tblspc",
250 "pg_stat",
251 "pg_stat_tmp",
252 "pg_xact",
253 "pg_logical",
254 "pg_logical/snapshots",
255 "pg_logical/mappings"
256};

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_data_files

bool sync_data_files = true
static

Definition at line 171 of file initdb.c.

Referenced by main().

◆ sync_method

◆ 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 185 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 186 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 187 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 883 of file initdb.c.

884{
885 {"arabic", "ar"},
886 {"arabic", "Arabic"},
887 {"armenian", "hy"},
888 {"armenian", "Armenian"},
889 {"basque", "eu"},
890 {"basque", "Basque"},
891 {"catalan", "ca"},
892 {"catalan", "Catalan"},
893 {"danish", "da"},
894 {"danish", "Danish"},
895 {"dutch", "nl"},
896 {"dutch", "Dutch"},
897 {"english", "C"},
898 {"english", "POSIX"},
899 {"english", "en"},
900 {"english", "English"},
901 {"estonian", "et"},
902 {"estonian", "Estonian"},
903 {"finnish", "fi"},
904 {"finnish", "Finnish"},
905 {"french", "fr"},
906 {"french", "French"},
907 {"german", "de"},
908 {"german", "German"},
909 {"greek", "el"},
910 {"greek", "Greek"},
911 {"hindi", "hi"},
912 {"hindi", "Hindi"},
913 {"hungarian", "hu"},
914 {"hungarian", "Hungarian"},
915 {"indonesian", "id"},
916 {"indonesian", "Indonesian"},
917 {"irish", "ga"},
918 {"irish", "Irish"},
919 {"italian", "it"},
920 {"italian", "Italian"},
921 {"lithuanian", "lt"},
922 {"lithuanian", "Lithuanian"},
923 {"nepali", "ne"},
924 {"nepali", "Nepali"},
925 {"norwegian", "no"},
926 {"norwegian", "Norwegian"},
927 {"polish", "pl"},
928 {"polish", "Polish"},
929 {"portuguese", "pt"},
930 {"portuguese", "Portuguese"},
931 {"romanian", "ro"},
932 {"russian", "ru"},
933 {"russian", "Russian"},
934 {"serbian", "sr"},
935 {"serbian", "Serbian"},
936 {"spanish", "es"},
937 {"spanish", "Spanish"},
938 {"swedish", "sv"},
939 {"swedish", "Swedish"},
940 {"tamil", "ta"},
941 {"tamil", "Tamil"},
942 {"turkish", "tr"},
943 {"turkish", "Turkish"},
944 {"yiddish", "yi"},
945 {"yiddish", "Yiddish"},
946 {NULL, NULL} /* end marker */
947};

Referenced by find_matching_ts_config().

◆ username

char* username = NULL
static

Definition at line 153 of file initdb.c.

Referenced by add_client_identification(), BackgroundWorkerInitializeConnection(), bootstrap_template1(), check_password(), dumpUserConfig(), get_id(), get_object_address_defacl(), get_object_address_usermapping(), get_user_name(), getObjectDescription(), getObjectIdentityParts(), has_any_column_privilege_name_id(), has_column_privilege_name_id_attnum(), has_column_privilege_name_id_name(), has_database_privilege_name_id(), has_database_privilege_name_name(), has_foreign_data_wrapper_privilege_name_id(), has_foreign_data_wrapper_privilege_name_name(), has_function_privilege_name_id(), has_function_privilege_name_name(), has_language_privilege_name_id(), has_language_privilege_name_name(), has_largeobject_privilege_name_id(), has_parameter_privilege_name_name(), has_schema_privilege_name_id(), has_schema_privilege_name_name(), has_sequence_privilege_name_id(), has_server_privilege_name_id(), has_server_privilege_name_name(), has_table_privilege_name_id(), has_tablespace_privilege_name_id(), has_tablespace_privilege_name_name(), has_type_privilege_name_id(), has_type_privilege_name_name(), InitPostgres(), log_status_format(), main(), mock_scram_secret(), passwordFromFile(), pg_fe_getusername(), pg_has_role_name_id(), pg_has_role_name_name(), PostgresMain(), PostgresSingleUserMain(), process_pgfdw_appname(), prompt_for_password(), scram_mock_salt(), scram_verify_plain_password(), setup_auth(), setup_data_file_paths(), and setup_privileges().

◆ 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().