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

209 : Configuring the system for local \"trust\" authentication\n" \
210"# allows any local user to connect as any PostgreSQL user, including\n" \
211"# the database superuser. If you do not trust all your local users,\n" \
212"# 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 328 of file initdb.c.

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

◆ PG_CMD_DECL

#define PG_CMD_DECL   FILE *cmdfd

Definition at line 319 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:745

Definition at line 321 of file initdb.c.

322 { \
323 cmdfd = popen_check(cmd, "w"); \
324 if (cmdfd == NULL) \
325 exit(1); /* message already printed by popen_check */ \
326} 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:194
static int output_errno
Definition initdb.c:195

Definition at line 340 of file initdb.c.

341 { \
342 if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
343 output_failed = true, output_errno = errno; \
344} 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 334 of file initdb.c.

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

Typedef Documentation

◆ _stringlist

◆ save_locale_t

Definition at line 349 of file initdb.c.

Function Documentation

◆ add_stringlist_item()

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

Definition at line 445 of file initdb.c.

446{
449
451 newentry->next = NULL;
452 if (*listhead == NULL)
454 else
455 {
456 for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
457 /* skip */ ;
458 oldentry->next = newentry;
459 }
460}
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 1544 of file initdb.c.

1545{
1547 PQExpBufferData cmd;
1548 char **line;
1549 char **bki_lines;
1550 char headerline[MAXPGPATH];
1551 char buf[64];
1552
1553 printf(_("running bootstrap script ... "));
1554 fflush(stdout);
1555
1557
1558 /* Check that bki file appears to be of the right version */
1559
1560 snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
1562
1563 if (strcmp(headerline, *bki_lines) != 0)
1564 {
1565 pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
1567 pg_log_error_hint("Specify the correct path using the option -L.");
1568 exit(1);
1569 }
1570
1571 /* Substitute for various symbols used in the BKI file */
1572
1573 sprintf(buf, "%d", NAMEDATALEN);
1574 bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
1575
1576 sprintf(buf, "%d", (int) sizeof(Pointer));
1577 bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
1578
1579 bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
1580 (sizeof(Pointer) == 4) ? "i" : "d");
1581
1582 bki_lines = replace_token(bki_lines, "POSTGRES",
1584
1585 bki_lines = replace_token(bki_lines, "ENCODING",
1587
1588 bki_lines = replace_token(bki_lines, "LC_COLLATE",
1590
1591 bki_lines = replace_token(bki_lines, "LC_CTYPE",
1593
1594 bki_lines = replace_token(bki_lines, "DATLOCALE",
1595 datlocale ? escape_quotes_bki(datlocale) : "_null_");
1596
1597 bki_lines = replace_token(bki_lines, "ICU_RULES",
1598 icu_rules ? escape_quotes_bki(icu_rules) : "_null_");
1599
1600 sprintf(buf, "%c", locale_provider);
1601 bki_lines = replace_token(bki_lines, "LOCALE_PROVIDER", buf);
1602
1603 /* Also ensure backend isn't confused by this environment var: */
1604 unsetenv("PGCLIENTENCODING");
1605
1606 initPQExpBuffer(&cmd);
1607
1608 printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options);
1609 appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024));
1610 if (data_checksums)
1611 appendPQExpBufferStr(&cmd, " -k");
1612 if (debug)
1613 appendPQExpBufferStr(&cmd, " -d 5");
1614
1615
1616 PG_CMD_OPEN(cmd.data);
1617
1618 for (line = bki_lines; *line != NULL; line++)
1619 {
1620 PG_CMD_PUTS(*line);
1621 free(*line);
1622 }
1623
1624 PG_CMD_CLOSE();
1625
1626 termPQExpBuffer(&cmd);
1627 free(bki_lines);
1628
1629 check_ok();
1630}
void * Pointer
Definition c.h:549
#define _(x)
Definition elog.c:95
static char * escape_quotes_bki(const char *src)
Definition initdb.c:422
static char * encodingid_to_string(int enc)
Definition initdb.c:834
#define PG_CMD_CLOSE()
Definition initdb.c:328
static char * datlocale
Definition initdb.c:149
static char * lc_collate
Definition initdb.c:141
#define PG_CMD_PUTS(line)
Definition initdb.c:334
static char * lc_ctype
Definition initdb.c:142
static char ** readfile(const char *path)
Definition initdb.c:676
static bool debug
Definition initdb.c:161
static char backend_exec[MAXPGPATH]
Definition initdb.c:260
static bool data_checksums
Definition initdb.c:167
#define PG_CMD_DECL
Definition initdb.c:319
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:473
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:2105
static char * extra_options
Definition initdb.c:229
static const char *const boot_options
Definition initdb.c:225
#define PG_CMD_OPEN(cmd)
Definition initdb.c:321
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 2568 of file initdb.c.

2569{
2570 if (*authmethod == NULL)
2571 {
2572 authwarning = true;
2573 *authmethod = "trust";
2574 }
2575}
static bool authwarning
Definition initdb.c:213

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

2579{
2580 const char *const *p;
2581
2582 for (p = valid_methods; *p; p++)
2583 {
2584 if (strcmp(authmethod, *p) == 0)
2585 return;
2586 }
2587
2588 pg_fatal("invalid authentication method \"%s\" for \"%s\" connections",
2589 authmethod, conntype);
2590}
#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 2296 of file initdb.c.

2297{
2299 {
2300 pg_log_error("encoding mismatch");
2301 pg_log_error_detail("The encoding you selected (%s) is not supported with the ICU provider.",
2303 pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2304 "or choose a matching combination.",
2305 progname);
2306 return false;
2307 }
2308 return true;
2309}
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 995 of file initdb.c.

996{
997 struct stat statbuf;
998
999 if (stat(path, &statbuf) != 0)
1000 {
1001 if (errno == ENOENT)
1002 {
1003 pg_log_error("file \"%s\" does not exist", path);
1004 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1005 }
1006 else
1007 {
1008 pg_log_error("could not access file \"%s\": %m", path);
1009 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1010 }
1011 exit(1);
1012 }
1013 if (!S_ISREG(statbuf.st_mode))
1014 {
1015 pg_log_error("file \"%s\" is not a regular file", path);
1016 pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1017 exit(1);
1018 }
1019}
#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 2261 of file initdb.c.

2262{
2263 int locale_enc;
2264
2266
2267 /* See notes in createdb() to understand these tests */
2268 if (!(locale_enc == user_enc ||
2270 locale_enc == -1 ||
2271#ifdef WIN32
2272 user_enc == PG_UTF8 ||
2273#endif
2275 {
2276 pg_log_error("encoding mismatch");
2277 pg_log_error_detail("The encoding you selected (%s) and the encoding that the "
2278 "selected locale uses (%s) do not match. This would lead to "
2279 "misbehavior in various character string processing functions.",
2282 pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
2283 "or choose a matching combination.",
2284 progname);
2285 return false;
2286 }
2287 return true;
2288}
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 2198 of file initdb.c.

2199{
2201 char *res;
2202
2203 /* Don't let Windows' non-ASCII locale names in. */
2204 if (locale && !pg_is_ascii(locale))
2205 pg_fatal("locale name \"%s\" contains non-ASCII characters", locale);
2206
2207 if (canonname)
2208 *canonname = NULL; /* in case of failure */
2209
2210 save = save_global_locale(category);
2211
2212 /* for setlocale() call */
2213 if (!locale)
2214 locale = "";
2215
2216 /* set the locale with setlocale, to see if it accepts it. */
2217 res = setlocale(category, locale);
2218
2219 /* save canonical name if requested. */
2220 if (res && canonname)
2221 *canonname = pg_strdup(res);
2222
2223 /* restore old value. */
2224 restore_global_locale(category, save);
2225
2226 /* complain if locale wasn't valid */
2227 if (res == NULL)
2228 {
2229 if (*locale)
2230 {
2231 pg_log_error("invalid locale name \"%s\"", locale);
2232 pg_log_error_hint("If the locale name is specific to ICU, use --icu-locale.");
2233 exit(1);
2234 }
2235 else
2236 {
2237 /*
2238 * If no relevant switch was given on command line, locale is an
2239 * empty string, which is not too helpful to report. Presumably
2240 * setlocale() found something it did not like in the environment.
2241 * Ideally we'd report the bad environment variable, but since
2242 * setlocale's behavior is implementation-specific, it's hard to
2243 * be sure what it didn't like. Print a safe generic message.
2244 */
2245 pg_fatal("invalid locale settings; check LANG and LC_* environment variables");
2246 }
2247 }
2248
2249 /* Don't let Windows' non-ASCII locale names out. */
2251 pg_fatal("locale name \"%s\" contains non-ASCII characters",
2252 *canonname);
2253}
static void restore_global_locale(int category, save_locale_t save)
Definition initdb.c:389
static save_locale_t save_global_locale(int category)
Definition initdb.c:365
char * save_locale_t
Definition initdb.c:349
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 2593 of file initdb.c.

2594{
2595 if ((strcmp(authmethodlocal, "md5") == 0 ||
2596 strcmp(authmethodlocal, "password") == 0 ||
2597 strcmp(authmethodlocal, "scram-sha-256") == 0) &&
2598 (strcmp(authmethodhost, "md5") == 0 ||
2599 strcmp(authmethodhost, "password") == 0 ||
2600 strcmp(authmethodhost, "scram-sha-256") == 0) &&
2601 !(pwprompt || pwfilename))
2602 pg_fatal("must specify a password for the superuser to enable password authentication");
2603}
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 2105 of file initdb.c.

2106{
2107 if (caught_signal)
2108 {
2109 printf(_("caught signal\n"));
2110 fflush(stdout);
2111 exit(1);
2112 }
2113 else if (output_failed)
2114 {
2115 printf(_("could not write to child process: %s\n"),
2117 fflush(stdout);
2118 exit(1);
2119 }
2120 else
2121 {
2122 /* all seems well */
2123 printf(_("ok\n"));
2124 fflush(stdout);
2125 }
2126}
static bool caught_signal
Definition initdb.c:193
#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 1078 of file initdb.c.

1079{
1080#if defined(HAVE_SHM_OPEN) && !defined(__sun__)
1081 int ntries = 10;
1083
1084 /* Initialize prng; this function is its only user in this program. */
1085 pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
1086
1087 while (ntries > 0)
1088 {
1089 uint32 handle;
1090 char name[64];
1091 int fd;
1092
1093 handle = pg_prng_uint32(&prng_state);
1094 snprintf(name, 64, "/PostgreSQL.%u", handle);
1095 if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
1096 {
1097 close(fd);
1099 return "posix";
1100 }
1101 if (errno != EEXIST)
1102 break;
1103 --ntries;
1104 }
1105#endif
1106
1107#ifdef WIN32
1108 return "windows";
1109#else
1110 return "sysv";
1111#endif
1112}
uint64_t uint64
Definition c.h:559
uint32_t uint32
Definition c.h:558
#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 762 of file initdb.c.

763{
764 if (success)
765 return;
766
767 if (!noclean)
768 {
769 if (made_new_pgdata)
770 {
771 pg_log_info("removing data directory \"%s\"", pg_data);
772 if (!rmtree(pg_data, true))
773 pg_log_error("failed to remove data directory");
774 }
775 else if (found_existing_pgdata)
776 {
777 pg_log_info("removing contents of data directory \"%s\"",
778 pg_data);
779 if (!rmtree(pg_data, false))
780 pg_log_error("failed to remove contents of data directory");
781 }
782
784 {
785 pg_log_info("removing WAL directory \"%s\"", xlog_dir);
786 if (!rmtree(xlog_dir, true))
787 pg_log_error("failed to remove WAL directory");
788 }
789 else if (found_existing_xlogdir)
790 {
791 pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
792 if (!rmtree(xlog_dir, false))
793 pg_log_error("failed to remove contents of WAL directory");
794 }
795 /* otherwise died during startup, do nothing! */
796 }
797 else
798 {
800 pg_log_info("data directory \"%s\" not removed at user's request",
801 pg_data);
802
804 pg_log_info("WAL directory \"%s\" not removed at user's request",
805 xlog_dir);
806 }
807}
static bool noclean
Definition initdb.c:162
static bool found_existing_pgdata
Definition initdb.c:189
static bool found_existing_xlogdir
Definition initdb.c:191
static char * xlog_dir
Definition initdb.c:168
static bool success
Definition initdb.c:187
static bool made_new_xlogdir
Definition initdb.c:190
static char * pg_data
Definition initdb.c:138
static bool made_new_pgdata
Definition initdb.c:188
#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 2886 of file initdb.c.

2887{
2888 int ret;
2889
2890 switch ((ret = pg_check_dir(pg_data)))
2891 {
2892 case 0:
2893 /* PGDATA not there, must create it */
2894 printf(_("creating directory %s ... "),
2895 pg_data);
2896 fflush(stdout);
2897
2899 pg_fatal("could not create directory \"%s\": %m", pg_data);
2900 else
2901 check_ok();
2902
2903 made_new_pgdata = true;
2904 break;
2905
2906 case 1:
2907 /* Present but empty, fix permissions and use it */
2908 printf(_("fixing permissions on existing directory %s ... "),
2909 pg_data);
2910 fflush(stdout);
2911
2912 if (chmod(pg_data, pg_dir_create_mode) != 0)
2913 pg_fatal("could not change permissions of directory \"%s\": %m",
2914 pg_data);
2915 else
2916 check_ok();
2917
2918 found_existing_pgdata = true;
2919 break;
2920
2921 case 2:
2922 case 3:
2923 case 4:
2924 /* Present and not empty */
2925 pg_log_error("directory \"%s\" exists but is not empty", pg_data);
2926 if (ret != 4)
2928 else
2929 pg_log_error_hint("If you want to create a new database system, either remove or empty "
2930 "the directory \"%s\" or run %s "
2931 "with an argument other than \"%s\".",
2933 exit(1); /* no further message needed */
2934
2935 default:
2936 /* Trouble accessing directory */
2937 pg_fatal("could not access directory \"%s\": %m", pg_data);
2938 }
2939}
int pg_dir_create_mode
Definition file_perm.c:18
void warn_on_mount_point(int error)
Definition initdb.c:3027
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 2944 of file initdb.c.

2945{
2946 char *subdirloc;
2947
2948 /* form name of the place for the subdirectory or symlink */
2949 subdirloc = psprintf("%s/pg_wal", pg_data);
2950
2951 if (xlog_dir)
2952 {
2953 int ret;
2954
2955 /* clean up xlog directory name, check it's absolute */
2958 pg_fatal("WAL directory location must be an absolute path");
2959
2960 /* check if the specified xlog directory exists/is empty */
2961 switch ((ret = pg_check_dir(xlog_dir)))
2962 {
2963 case 0:
2964 /* xlog directory not there, must create it */
2965 printf(_("creating directory %s ... "),
2966 xlog_dir);
2967 fflush(stdout);
2968
2970 pg_fatal("could not create directory \"%s\": %m",
2971 xlog_dir);
2972 else
2973 check_ok();
2974
2975 made_new_xlogdir = true;
2976 break;
2977
2978 case 1:
2979 /* Present but empty, fix permissions and use it */
2980 printf(_("fixing permissions on existing directory %s ... "),
2981 xlog_dir);
2982 fflush(stdout);
2983
2985 pg_fatal("could not change permissions of directory \"%s\": %m",
2986 xlog_dir);
2987 else
2988 check_ok();
2989
2991 break;
2992
2993 case 2:
2994 case 3:
2995 case 4:
2996 /* Present and not empty */
2997 pg_log_error("directory \"%s\" exists but is not empty", xlog_dir);
2998 if (ret != 4)
3000 else
3001 pg_log_error_hint("If you want to store the WAL there, either remove or empty the directory \"%s\".",
3002 xlog_dir);
3003 exit(1);
3004
3005 default:
3006 /* Trouble accessing directory */
3007 pg_fatal("could not access directory \"%s\": %m", xlog_dir);
3008 }
3009
3010 if (symlink(xlog_dir, subdirloc) != 0)
3011 pg_fatal("could not create symbolic link \"%s\": %m",
3012 subdirloc);
3013 }
3014 else
3015 {
3016 /* Without -X option, just make the subdirectory normally */
3018 pg_fatal("could not create directory \"%s\": %m",
3019 subdirloc);
3020 }
3021
3022 free(subdirloc);
3023}
#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 834 of file initdb.c.

835{
836 char result[20];
837
838 sprintf(result, "%d", enc);
839 return pg_strdup(result);
840}

References enc, pg_strdup(), and sprintf.

Referenced by bootstrap_template1().

◆ escape_quotes()

static char * escape_quotes ( const char src)
static

Definition at line 406 of file initdb.c.

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

423{
424 char *result;
425 char *data = escape_quotes(src);
426 char *resultp;
427 char *datap;
428
429 result = (char *) pg_malloc(strlen(data) + 3);
430 resultp = result;
431 *resultp++ = '\'';
432 for (datap = data; *datap; datap++)
433 *resultp++ = *datap;
434 *resultp++ = '\'';
435 *resultp = '\0';
436
437 free(data);
438 return result;
439}
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
static char * escape_quotes(const char *src)
Definition initdb.c:406
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 940 of file initdb.c.

941{
942 int i;
943 char *langname,
944 *ptr;
945
946 /*
947 * Convert lc_ctype to a language name by stripping everything after an
948 * underscore (usual case) or a hyphen (Windows "locale name"; see
949 * comments at IsoLocaleName()).
950 *
951 * XXX Should ' ' be a stop character? This would select "norwegian" for
952 * the Windows locale "Norwegian (Nynorsk)_Norway.1252". If we do so, we
953 * should also accept the "nn" and "nb" Unix locales.
954 *
955 * Just for paranoia, we also stop at '.' or '@'.
956 */
957 if (lc_type == NULL)
958 langname = pg_strdup("");
959 else
960 {
961 ptr = langname = pg_strdup(lc_type);
962 while (*ptr &&
963 *ptr != '_' && *ptr != '-' && *ptr != '.' && *ptr != '@')
964 ptr++;
965 *ptr = '\0';
966 }
967
969 {
970 if (pg_strcasecmp(tsearch_config_languages[i].langname, langname) == 0)
971 {
972 free(langname);
974 }
975 }
976
977 free(langname);
978 return NULL;
979}
static const struct tsearch_config_match tsearch_config_languages[]
Definition initdb.c:869
int i
Definition isn.c:77
int pg_strcasecmp(const char *s1, const char *s2)
const char * tsconfname
Definition initdb.c:865

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

847{
848 int enc;
849
851 {
853 return enc;
854 }
855 pg_fatal("\"%s\" is not a valid server encoding name",
856 encoding_name ? encoding_name : "(null)");
857}
#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 815 of file initdb.c.

816{
817 const char *username;
818
819#ifndef WIN32
820 if (geteuid() == 0) /* 0 is root's uid */
821 {
822 pg_log_error("cannot be run as root");
823 pg_log_error_hint("Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
824 exit(1);
825 }
826#endif
827
829
830 return pg_strdup(username);
831}
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 1653 of file initdb.c.

1654{
1655 char *pwd1;
1656
1657 if (pwprompt)
1658 {
1659 /*
1660 * Read password from terminal
1661 */
1662 char *pwd2;
1663
1664 printf("\n");
1665 fflush(stdout);
1666 pwd1 = simple_prompt("Enter new superuser password: ", false);
1667 pwd2 = simple_prompt("Enter it again: ", false);
1668 if (strcmp(pwd1, pwd2) != 0)
1669 {
1670 fprintf(stderr, _("Passwords didn't match.\n"));
1671 exit(1);
1672 }
1673 free(pwd2);
1674 }
1675 else
1676 {
1677 /*
1678 * Read password from file
1679 *
1680 * Ideally this should insist that the file not be world-readable.
1681 * However, this option is mainly intended for use on Windows where
1682 * file permissions may not exist at all, so we'll skip the paranoia
1683 * for now.
1684 */
1685 FILE *pwf = fopen(pwfilename, "r");
1686
1687 if (!pwf)
1688 pg_fatal("could not open file \"%s\" for reading: %m",
1689 pwfilename);
1691 if (!pwd1)
1692 {
1693 if (ferror(pwf))
1694 pg_fatal("could not read password from file \"%s\": %m",
1695 pwfilename);
1696 else
1697 pg_fatal("password file \"%s\" is empty",
1698 pwfilename);
1699 }
1700 fclose(pwf);
1701
1703 }
1704
1706}
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 644 of file initdb.c.

645{
646 /* Don't use <ctype.h> macros here, they might accept too much */
647#define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
648#define DIGITS "0123456789"
649
650 if (*guc_value == '\0')
651 return true; /* empty string must be quoted */
652 if (strchr(LETTERS, *guc_value))
653 {
655 return false; /* it's an identifier */
656 return true; /* nope */
657 }
658 if (strchr(DIGITS, *guc_value))
659 {
660 /* skip over digits */
662 /* there can be zero or more unit letters after the digits */
664 return false; /* it's a number, possibly with units */
665 return true; /* nope */
666 }
667 return true; /* all else must be quoted */
668}
#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 2316 of file initdb.c.

2317{
2318#ifdef USE_ICU
2319 UErrorCode status;
2320 char *langtag;
2321 size_t buflen = 32; /* arbitrary starting buffer size */
2322 const bool strict = true;
2323
2324 /*
2325 * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
2326 * RFC5646 section 4.4). Additionally, in older ICU versions,
2327 * uloc_toLanguageTag() doesn't always return the ultimate length on the
2328 * first call, necessitating a loop.
2329 */
2330 langtag = pg_malloc(buflen);
2331 while (true)
2332 {
2333 status = U_ZERO_ERROR;
2334 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
2335
2336 /* try again if the buffer is not large enough */
2337 if (status == U_BUFFER_OVERFLOW_ERROR ||
2339 {
2340 buflen = buflen * 2;
2341 langtag = pg_realloc(langtag, buflen);
2342 continue;
2343 }
2344
2345 break;
2346 }
2347
2348 if (U_FAILURE(status))
2349 {
2351
2352 pg_fatal("could not convert locale name \"%s\" to language tag: %s",
2353 loc_str, u_errorName(status));
2354 }
2355
2356 return langtag;
2357#else
2358 pg_fatal("ICU is not supported in this build");
2359 return NULL; /* keep compiler quiet */
2360#endif
2361}
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 2369 of file initdb.c.

2370{
2371#ifdef USE_ICU
2372 UErrorCode status;
2373 char lang[ULOC_LANG_CAPACITY];
2374 bool found = false;
2375
2376 /* validate that we can extract the language */
2377 status = U_ZERO_ERROR;
2379 if (U_FAILURE(status))
2380 {
2381 pg_fatal("could not get language from locale \"%s\": %s",
2382 loc_str, u_errorName(status));
2383 return;
2384 }
2385
2386 /* check for special language name */
2387 if (strcmp(lang, "") == 0 ||
2388 strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
2389 found = true;
2390
2391 /* search for matching language within ICU */
2392 for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
2393 {
2394 const char *otherloc = uloc_getAvailable(i);
2396
2397 status = U_ZERO_ERROR;
2399 if (U_FAILURE(status))
2400 continue;
2401
2402 if (strcmp(lang, otherlang) == 0)
2403 found = true;
2404 }
2405
2406 if (!found)
2407 pg_fatal("locale \"%s\" has unknown language \"%s\"",
2408 loc_str, lang);
2409#else
2410 pg_fatal("ICU is not supported in this build");
2411#endif
2412}

References fb(), i, and pg_fatal.

Referenced by setlocales().

◆ initialize_data_directory()

void initialize_data_directory ( void  )

Definition at line 3040 of file initdb.c.

3041{
3043 PQExpBufferData cmd;
3044 int i;
3045
3046 setup_signals();
3047
3048 /*
3049 * Set mask based on requested PGDATA permissions. pg_mode_mask, and
3050 * friends like pg_dir_create_mode, are set to owner-only by default and
3051 * then updated if -g is passed in by calling SetDataDirectoryCreatePerm()
3052 * when parsing our options (see above).
3053 */
3055
3057
3059
3060 /* Create required subdirectories (other than pg_wal) */
3061 printf(_("creating subdirectories ... "));
3062 fflush(stdout);
3063
3064 for (i = 0; i < lengthof(subdirs); i++)
3065 {
3066 char *path;
3067
3068 path = psprintf("%s/%s", pg_data, subdirs[i]);
3069
3070 /*
3071 * The parent directory already exists, so we only need mkdir() not
3072 * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
3073 */
3074 if (mkdir(path, pg_dir_create_mode) < 0)
3075 pg_fatal("could not create directory \"%s\": %m", path);
3076
3077 free(path);
3078 }
3079
3080 check_ok();
3081
3082 /* Top level PG_VERSION is checked by bootstrapper, so make it first */
3084
3085 /* Select suitable configuration settings */
3086 set_null_conf();
3088
3089 /* Now create all the text config files */
3090 setup_config();
3091
3092 /* Bootstrap template1 */
3094
3095 /*
3096 * Make the per-database PG_VERSION for template1 only after init'ing it
3097 */
3098 write_version_file("base/1");
3099
3100 /*
3101 * Create the stuff we don't need to use bootstrap mode for, using a
3102 * backend running in simple standalone mode.
3103 */
3104 fputs(_("performing post-bootstrap initialization ... "), stdout);
3105 fflush(stdout);
3106
3107 initPQExpBuffer(&cmd);
3108 printfPQExpBuffer(&cmd, "\"%s\" %s %s template1 >%s",
3110
3111 PG_CMD_OPEN(cmd.data);
3112
3114
3116
3118
3120
3121 /*
3122 * Note that no objects created after setup_depend() will be "pinned".
3123 * They are all droppable at the whim of the DBA.
3124 */
3125
3127
3129
3131
3133
3135
3137
3139
3141
3143
3145
3146 PG_CMD_CLOSE();
3147 termPQExpBuffer(&cmd);
3148
3149 check_ok();
3150}
#define lengthof(array)
Definition c.h:815
int pg_mode_mask
Definition file_perm.c:25
static void setup_depend(FILE *cmdfd)
Definition initdb.c:1712
static void setup_collation(FILE *cmdfd)
Definition initdb.c:1767
void create_data_directory(void)
Definition initdb.c:2886
static void bootstrap_template1(void)
Definition initdb.c:1544
static void setup_run_file(FILE *cmdfd, const char *filename)
Definition initdb.c:1725
static void setup_auth(FILE *cmdfd)
Definition initdb.c:1636
static void make_postgres(FILE *cmdfd)
Definition initdb.c:2061
static void test_config_settings(void)
Definition initdb.c:1120
static const char *const backend_options
Definition initdb.c:226
static void setup_config(void)
Definition initdb.c:1285
static void setup_privileges(FILE *cmdfd)
Definition initdb.c:1800
static void write_version_file(const char *extrapath)
Definition initdb.c:1026
void setup_signals(void)
Definition initdb.c:2866
static char * system_views_file
Definition initdb.c:186
static void setup_description(FILE *cmdfd)
Definition initdb.c:1746
static void vacuum_db(FILE *cmdfd)
Definition initdb.c:1997
static const char *const subdirs[]
Definition initdb.c:231
void create_xlog_or_symlink(void)
Definition initdb.c:2944
static char * system_functions_file
Definition initdb.c:185
static char * dictionary_file
Definition initdb.c:181
static void setup_schema(FILE *cmdfd)
Definition initdb.c:1968
static char * system_constraints_file
Definition initdb.c:184
static void set_null_conf(void)
Definition initdb.c:1049
static void make_template0(FILE *cmdfd)
Definition initdb.c:2007
static void load_plpgsql(FILE *cmdfd)
Definition initdb.c:1988
#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 1988 of file initdb.c.

1989{
1990 PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
1991}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ locale_date_order()

static int locale_date_order ( const char locale)
static

Definition at line 2139 of file initdb.c.

2140{
2141 struct tm testtime;
2142 char buf[128];
2143 char *posD;
2144 char *posM;
2145 char *posY;
2147 size_t res;
2148 int result;
2149
2150 result = DATEORDER_MDY; /* default */
2151
2153
2155
2156 memset(&testtime, 0, sizeof(testtime));
2157 testtime.tm_mday = 22;
2158 testtime.tm_mon = 10; /* November, should come out as "11" */
2159 testtime.tm_year = 133; /* 2033 */
2160
2161 res = my_strftime(buf, sizeof(buf), "%x", &testtime);
2162
2164
2165 if (res == 0)
2166 return result;
2167
2168 posM = strstr(buf, "11");
2169 posD = strstr(buf, "22");
2170 posY = strstr(buf, "33");
2171
2172 if (!posM || !posD || !posY)
2173 return result;
2174
2175 if (posY < posM && posM < posD)
2176 result = DATEORDER_YMD;
2177 else if (posD < posM)
2178 result = DATEORDER_DMY;
2179 else
2180 result = DATEORDER_MDY;
2181
2182 return result;
2183}
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
Definition initdb.c:2130
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 3154 of file initdb.c.

3155{
3156 static struct option long_options[] = {
3157 {"pgdata", required_argument, NULL, 'D'},
3158 {"encoding", required_argument, NULL, 'E'},
3159 {"locale", required_argument, NULL, 1},
3160 {"lc-collate", required_argument, NULL, 2},
3161 {"lc-ctype", required_argument, NULL, 3},
3162 {"lc-monetary", required_argument, NULL, 4},
3163 {"lc-numeric", required_argument, NULL, 5},
3164 {"lc-time", required_argument, NULL, 6},
3165 {"lc-messages", required_argument, NULL, 7},
3166 {"no-locale", no_argument, NULL, 8},
3167 {"text-search-config", required_argument, NULL, 'T'},
3168 {"auth", required_argument, NULL, 'A'},
3169 {"auth-local", required_argument, NULL, 10},
3170 {"auth-host", required_argument, NULL, 11},
3171 {"pwprompt", no_argument, NULL, 'W'},
3172 {"pwfile", required_argument, NULL, 9},
3173 {"username", required_argument, NULL, 'U'},
3174 {"help", no_argument, NULL, '?'},
3175 {"version", no_argument, NULL, 'V'},
3176 {"debug", no_argument, NULL, 'd'},
3177 {"show", no_argument, NULL, 's'},
3178 {"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
3179 {"no-clean", no_argument, NULL, 'n'},
3180 {"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
3181 {"no-sync", no_argument, NULL, 'N'},
3182 {"no-instructions", no_argument, NULL, 13},
3183 {"set", required_argument, NULL, 'c'},
3184 {"sync-only", no_argument, NULL, 'S'},
3185 {"waldir", required_argument, NULL, 'X'},
3186 {"wal-segsize", required_argument, NULL, 12},
3187 {"data-checksums", no_argument, NULL, 'k'},
3188 {"allow-group-access", no_argument, NULL, 'g'},
3189 {"discard-caches", no_argument, NULL, 14},
3190 {"locale-provider", required_argument, NULL, 15},
3191 {"builtin-locale", required_argument, NULL, 16},
3192 {"icu-locale", required_argument, NULL, 17},
3193 {"icu-rules", required_argument, NULL, 18},
3194 {"sync-method", required_argument, NULL, 19},
3195 {"no-data-checksums", no_argument, NULL, 20},
3196 {"no-sync-data-files", no_argument, NULL, 21},
3197 {NULL, 0, NULL, 0}
3198 };
3199
3200 /*
3201 * options with no short version return a low integer, the rest return
3202 * their short version value
3203 */
3204 int c;
3205 int option_index;
3206 char *effective_user;
3208 char pg_ctl_path[MAXPGPATH];
3209
3210 /*
3211 * Ensure that buffering behavior of stdout matches what it is in
3212 * interactive usage (at least on most platforms). This prevents
3213 * unexpected output ordering when, eg, output is redirected to a file.
3214 * POSIX says we must do this before any other usage of these files.
3215 */
3216 setvbuf(stdout, NULL, PG_IOLBF, 0);
3217
3218 pg_logging_init(argv[0]);
3219 progname = get_progname(argv[0]);
3220 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
3221
3222 if (argc > 1)
3223 {
3224 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
3225 {
3226 usage(progname);
3227 exit(0);
3228 }
3229 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
3230 {
3231 puts("initdb (PostgreSQL) " PG_VERSION);
3232 exit(0);
3233 }
3234 }
3235
3236 /* process command-line options */
3237
3238 while ((c = getopt_long(argc, argv, "A:c:dD:E:gkL:nNsST:U:WX:",
3239 long_options, &option_index)) != -1)
3240 {
3241 switch (c)
3242 {
3243 case 'A':
3245
3246 /*
3247 * When ident is specified, use peer for local connections.
3248 * Mirrored, when peer is specified, use ident for TCP/IP
3249 * connections.
3250 */
3251 if (strcmp(authmethodhost, "ident") == 0)
3252 authmethodlocal = "peer";
3253 else if (strcmp(authmethodlocal, "peer") == 0)
3254 authmethodhost = "ident";
3255 break;
3256 case 10:
3258 break;
3259 case 11:
3261 break;
3262 case 'c':
3263 {
3264 char *buf = pg_strdup(optarg);
3265 char *equals = strchr(buf, '=');
3266
3267 if (!equals)
3268 {
3269 pg_log_error("-c %s requires a value", buf);
3270 pg_log_error_hint("Try \"%s --help\" for more information.",
3271 progname);
3272 exit(1);
3273 }
3274 *equals++ = '\0'; /* terminate variable name */
3277 pfree(buf);
3278 }
3279 break;
3280 case 'D':
3282 break;
3283 case 'E':
3285 break;
3286 case 'W':
3287 pwprompt = true;
3288 break;
3289 case 'U':
3291 break;
3292 case 'd':
3293 debug = true;
3294 printf(_("Running in debug mode.\n"));
3295 break;
3296 case 'n':
3297 noclean = true;
3298 printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3299 break;
3300 case 'N':
3301 do_sync = false;
3302 break;
3303 case 'S':
3304 sync_only = true;
3305 break;
3306 case 'k':
3307 data_checksums = true;
3308 break;
3309 case 'L':
3311 break;
3312 case 1:
3314 break;
3315 case 2:
3317 break;
3318 case 3:
3320 break;
3321 case 4:
3323 break;
3324 case 5:
3326 break;
3327 case 6:
3329 break;
3330 case 7:
3332 break;
3333 case 8:
3334 locale = "C";
3335 break;
3336 case 9:
3338 break;
3339 case 's':
3340 show_setting = true;
3341 break;
3342 case 'T':
3344 break;
3345 case 'X':
3347 break;
3348 case 12:
3349 if (!option_parse_int(optarg, "--wal-segsize", 1, 1024, &wal_segment_size_mb))
3350 exit(1);
3351 break;
3352 case 13:
3353 noinstructions = true;
3354 break;
3355 case 'g':
3357 break;
3358 case 14:
3359 extra_options = psprintf("%s %s",
3361 "-c debug_discard_caches=1");
3362 break;
3363 case 15:
3364 if (strcmp(optarg, "builtin") == 0)
3366 else if (strcmp(optarg, "icu") == 0)
3368 else if (strcmp(optarg, "libc") == 0)
3370 else
3371 pg_fatal("unrecognized locale provider: %s", optarg);
3372 break;
3373 case 16:
3376 break;
3377 case 17:
3379 icu_locale_specified = true;
3380 break;
3381 case 18:
3383 break;
3384 case 19:
3386 exit(1);
3387 break;
3388 case 20:
3389 data_checksums = false;
3390 break;
3391 case 21:
3392 sync_data_files = false;
3393 break;
3394 default:
3395 /* getopt_long already emitted a complaint */
3396 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3397 exit(1);
3398 }
3399 }
3400
3401
3402 /*
3403 * Non-option argument specifies data directory as long as it wasn't
3404 * already specified with -D / --pgdata
3405 */
3406 if (optind < argc && !pg_data)
3407 {
3408 pg_data = pg_strdup(argv[optind]);
3409 optind++;
3410 }
3411
3412 if (optind < argc)
3413 {
3414 pg_log_error("too many command-line arguments (first is \"%s\")",
3415 argv[optind]);
3416 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
3417 exit(1);
3418 }
3419
3421 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3422 "--builtin-locale", "builtin");
3423
3425 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3426 "--icu-locale", "icu");
3427
3429 pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
3430 "--icu-rules", "icu");
3431
3433
3434 /* If we only need to sync, just do it and exit */
3435 if (sync_only)
3436 {
3437 setup_pgdata();
3438
3439 /* must check that directory is readable */
3440 if (pg_check_dir(pg_data) <= 0)
3441 pg_fatal("could not access directory \"%s\": %m", pg_data);
3442
3443 fputs(_("syncing data to disk ... "), stdout);
3444 fflush(stdout);
3446 check_ok();
3447 return 0;
3448 }
3449
3450 if (pwprompt && pwfilename)
3451 pg_fatal("password prompt and password file cannot be specified together");
3452
3455
3458
3460
3461 if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
3462 pg_fatal("argument of %s must be a power of two between 1 and 1024", "--wal-segsize");
3463
3465
3466 setup_pgdata();
3467
3468 setup_bin_paths(argv[0]);
3469
3471 if (!username)
3473
3474 if (strncmp(username, "pg_", 3) == 0)
3475 pg_fatal("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
3476
3477 printf(_("The files belonging to this database system will be owned "
3478 "by user \"%s\".\n"
3479 "This user must also own the server process.\n\n"),
3481
3483
3485
3487
3489
3490 printf("\n");
3491
3492 if (data_checksums)
3493 printf(_("Data page checksums are enabled.\n"));
3494 else
3495 printf(_("Data page checksums are disabled.\n"));
3496
3497 if (pwprompt || pwfilename)
3498 get_su_pwd();
3499
3500 printf("\n");
3501
3503
3504 if (do_sync)
3505 {
3506 fputs(_("syncing data to disk ... "), stdout);
3507 fflush(stdout);
3509 check_ok();
3510 }
3511 else
3512 printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3513
3514 if (authwarning)
3515 {
3516 printf("\n");
3517 pg_log_warning("enabling \"trust\" authentication for local connections");
3518 pg_log_warning_hint("You can change this by editing pg_hba.conf or using the option -A, or "
3519 "--auth-local and --auth-host, the next time you run initdb.");
3520 }
3521
3522 if (!noinstructions)
3523 {
3524 /*
3525 * Build up a shell command to tell the user how to start the server
3526 */
3528
3529 /* Get directory specification used to start initdb ... */
3530 strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
3533 /* ... and tag on pg_ctl instead */
3535
3536 /* Convert the path to use native separators */
3538
3539 /* path to pg_ctl, properly quoted */
3541
3542 /* add -D switch, with properly quoted data directory */
3545
3546 /* add suggested -l switch and "start" command */
3547 /* translator: This is a placeholder in a shell command. */
3548 appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
3549
3550 printf(_("\nSuccess. You can now start the database server using:\n\n"
3551 " %s\n\n"),
3552 start_db_cmd->data);
3553
3555 }
3556
3557
3558 success = true;
3559 return 0;
3560}
#define PG_TEXTDOMAIN(domain)
Definition c.h:1231
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:815
static char * pgdata_native
Definition initdb.c:196
static void check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
Definition initdb.c:2578
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:3040
void setup_text_search(void)
Definition initdb.c:2832
static char * share_path
Definition initdb.c:135
void setup_bin_paths(const char *argv0)
Definition initdb.c:2644
static void check_authmethod_unspecified(const char **authmethod)
Definition initdb.c:2568
static const char *const auth_methods_host[]
Definition initdb.c:96
void setup_locale_encoding(void)
Definition initdb.c:2681
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:2593
static bool do_sync
Definition initdb.c:164
static void cleanup_directories_atexit(void)
Definition initdb.c:762
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:1941
void setup_data_file_paths(void)
Definition initdb.c:2788
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:445
static _stringlist * extra_guc_values
Definition initdb.c:160
static char * lc_numeric
Definition initdb.c:144
void setup_pgdata(void)
Definition initdb.c:2607
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:1653
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 2061 of file initdb.c.

2062{
2063 /*
2064 * Just as we did for template0, and for the same reasons, assign a fixed
2065 * OID to postgres and select the file_copy strategy.
2066 */
2067 PG_CMD_PUTS("CREATE DATABASE postgres OID = " CppAsString2(PostgresDbOid)
2068 " STRATEGY = file_copy;\n\n");
2069 PG_CMD_PUTS("COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
2070}
#define CppAsString2(x)
Definition c.h:440

References CppAsString2, fb(), and PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ make_template0()

static void make_template0 ( FILE cmdfd)
static

Definition at line 2007 of file initdb.c.

2008{
2009 /*
2010 * pg_upgrade tries to preserve database OIDs across upgrades. It's smart
2011 * enough to drop and recreate a conflicting database with the same name,
2012 * but if the same OID were used for one system-created database in the
2013 * old cluster and a different system-created database in the new cluster,
2014 * it would fail. To avoid that, assign a fixed OID to template0 rather
2015 * than letting the server choose one.
2016 *
2017 * (Note that, while the user could have dropped and recreated these
2018 * objects in the old cluster, the problem scenario only exists if the OID
2019 * that is in use in the old cluster is also used in the new cluster - and
2020 * the new cluster should be the result of a fresh initdb.)
2021 *
2022 * We use "STRATEGY = file_copy" here because checkpoints during initdb
2023 * are cheap. "STRATEGY = wal_log" would generate more WAL, which would be
2024 * a little bit slower and make the new cluster a little bit bigger.
2025 */
2026 PG_CMD_PUTS("CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
2027 " OID = " CppAsString2(Template0DbOid)
2028 " STRATEGY = file_copy;\n\n");
2029
2030 /*
2031 * template0 shouldn't have any collation-dependent objects, so unset the
2032 * collation version. This disables collation version checks when making
2033 * a new database from it.
2034 */
2035 PG_CMD_PUTS("UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
2036
2037 /*
2038 * While we are here, do set the collation version on template1.
2039 */
2040 PG_CMD_PUTS("UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
2041
2042 /*
2043 * Explicitly revoke public create-schema and create-temp-table privileges
2044 * in template1 and template0; else the latter would be on by default
2045 */
2046 PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
2047 PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
2048
2049 PG_CMD_PUTS("COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
2050
2051 /*
2052 * Finally vacuum to clean up dead rows in pg_database
2053 */
2054 PG_CMD_PUTS("VACUUM pg_database;\n\n");
2055}

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

2131{
2132 return strftime(s, max, fmt, tm);
2133}

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

746{
747 FILE *cmdfd;
748
749 fflush(NULL);
750 errno = 0;
751 cmdfd = popen(command, mode);
752 if (cmdfd == NULL)
753 pg_log_error("could not execute command \"%s\": %m", command);
754 return cmdfd;
755}
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 1268 of file initdb.c.

1269{
1271 char *result = pg_malloc(14);
1272
1273 if ((sz % 1024) == 0)
1274 snprintf(result, 14, "%dGB", sz / 1024);
1275 else
1276 snprintf(result, 14, "%dMB", sz);
1277
1278 return result;
1279}

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

677{
678 char **result;
679 FILE *infile;
680 StringInfoData line;
681 int maxlines;
682 int n;
683
684 if ((infile = fopen(path, "r")) == NULL)
685 pg_fatal("could not open file \"%s\" for reading: %m", path);
686
687 initStringInfo(&line);
688
689 maxlines = 1024;
690 result = pg_malloc_array(char *, maxlines);
691
692 n = 0;
693 while (pg_get_line_buf(infile, &line))
694 {
695 /* make sure there will be room for a trailing NULL pointer */
696 if (n >= maxlines - 1)
697 {
698 maxlines *= 2;
699 result = pg_realloc_array(result, char *, maxlines);
700 }
701
702 result[n++] = pg_strdup(line.data);
703 }
704 result[n] = NULL;
705
706 pfree(line.data);
707
708 fclose(infile);
709
710 return result;
711}
#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 528 of file initdb.c.

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

474{
475 int toklen,
476 replen,
477 diff;
478
480 replen = strlen(replacement);
481 diff = replen - toklen;
482
483 for (int i = 0; lines[i]; i++)
484 {
485 char *where;
486 char *newline;
487 int pre;
488
489 /* nothing to do if no change needed */
490 if ((where = strstr(lines[i], token)) == NULL)
491 continue;
492
493 /* if we get here a change is needed - set up new line */
494
495 newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
496
497 pre = where - lines[i];
498
499 memcpy(newline, lines[i], pre);
500
501 memcpy(newline + pre, replacement, replen);
502
503 strcpy(newline + pre + replen, lines[i] + pre + toklen);
504
505 free(lines[i]);
506 lines[i] = newline;
507 }
508
509 return lines;
510}

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

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

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

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

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

1942{
1943 char *letterversion;
1944 long major = 0,
1945 minor = 0,
1946 micro = 0;
1947 char *endptr;
1948 char *vstr = pg_strdup(PG_VERSION);
1949 char *ptr;
1950
1951 ptr = vstr + (strlen(vstr) - 1);
1952 while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
1953 ptr--;
1954 letterversion = ptr + 1;
1955 major = strtol(vstr, &endptr, 10);
1956 if (*endptr)
1957 minor = strtol(endptr + 1, &endptr, 10);
1958 if (*endptr)
1959 micro = strtol(endptr + 1, &endptr, 10);
1960 snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
1962}
static char infoversion[100]
Definition initdb.c:192

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

987{
988 *dest = psprintf("%s/%s", share_path, filename);
989}
static char * filename
Definition pg_dumpall.c:132

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

1050{
1051 FILE *conf_file;
1052 char *path;
1053
1054 path = psprintf("%s/postgresql.conf", pg_data);
1055 conf_file = fopen(path, PG_BINARY_W);
1056 if (conf_file == NULL)
1057 pg_fatal("could not open file \"%s\" for writing: %m", path);
1058 if (fclose(conf_file))
1059 pg_fatal("could not write file \"%s\": %m", path);
1060 free(path);
1061}
#define PG_BINARY_W
Definition c.h:1312
static char * conf_file
Definition initdb.c:180

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

2421{
2422 char *canonname;
2423
2424 /* set empty lc_* and datlocale values to locale config if set */
2425
2426 if (locale)
2427 {
2428 if (!lc_ctype)
2429 lc_ctype = locale;
2430 if (!lc_collate)
2432 if (!lc_numeric)
2434 if (!lc_time)
2435 lc_time = locale;
2436 if (!lc_monetary)
2438 if (!lc_messages)
2441 datlocale = locale;
2442 }
2443
2444 /*
2445 * canonicalize locale names, and obtain any missing values from our
2446 * current environment
2447 */
2458#if defined(LC_MESSAGES) && !defined(WIN32)
2461#else
2462 /* when LC_MESSAGES is not available, use the LC_CTYPE setting */
2465#endif
2466
2468 pg_fatal("locale must be specified if provider is %s",
2470
2472 {
2473 if (strcmp(datlocale, "C") == 0)
2474 canonname = "C";
2475 else if (strcmp(datlocale, "C.UTF-8") == 0 ||
2476 strcmp(datlocale, "C.UTF8") == 0)
2477 canonname = "C.UTF-8";
2478 else if (strcmp(datlocale, "PG_UNICODE_FAST") == 0)
2479 canonname = "PG_UNICODE_FAST";
2480 else
2481 pg_fatal("invalid locale name \"%s\" for builtin provider",
2482 datlocale);
2483
2485 }
2487 {
2488 char *langtag;
2489
2490 /* canonicalize to a language tag */
2492 printf(_("Using language tag \"%s\" for ICU locale \"%s\".\n"),
2496
2498
2499 /*
2500 * In supported builds, the ICU locale ID will be opened during
2501 * post-bootstrap initialization, which will perform extra checks.
2502 */
2503#ifndef USE_ICU
2504 pg_fatal("ICU is not supported in this build");
2505#endif
2506 }
2507}
static char * icu_language_tag(const char *loc_str)
Definition initdb.c:2316
static void check_locale_name(int category, const char *locale, char **canonname)
Definition initdb.c:2198
static void icu_validate_locale(const char *loc_str)
Definition initdb.c:2369

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

1637{
1638 /*
1639 * The authid table shouldn't be readable except through views, to ensure
1640 * passwords are not publicly visible.
1641 */
1642 PG_CMD_PUTS("REVOKE ALL ON pg_authid FROM public;\n\n");
1643
1645 PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1647}
#define PG_CMD_PRINTF(fmt,...)
Definition initdb.c:340

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

2645{
2646 int ret;
2647
2648 if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
2649 backend_exec)) < 0)
2650 {
2651 char full_path[MAXPGPATH];
2652
2653 if (find_my_exec(argv0, full_path) < 0)
2655
2656 if (ret == -1)
2657 pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
2658 "postgres", progname, full_path);
2659 else
2660 pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
2661 "postgres", full_path, progname);
2662 }
2663
2664 /* store binary directory */
2668
2669 if (!share_path)
2670 {
2673 }
2674 else if (!is_absolute_path(share_path))
2675 pg_fatal("input file location must be an absolute path");
2676
2678}
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:259
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 1767 of file initdb.c.

1768{
1769 /*
1770 * Set the collation version for collations defined in pg_collation.dat,
1771 * but not the ones where we know that the collation behavior will never
1772 * change.
1773 */
1774 PG_CMD_PUTS("UPDATE pg_collation SET collversion = pg_collation_actual_version(oid) WHERE collname = 'unicode';\n\n");
1775
1776 /* Import all collations we can find in the operating system */
1777 PG_CMD_PUTS("SELECT pg_import_system_collations('pg_catalog');\n\n");
1778}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_config()

static void setup_config ( void  )
static

Definition at line 1285 of file initdb.c.

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

2789{
2790 set_input(&bki_file, "postgres.bki");
2791 set_input(&hba_file, "pg_hba.conf.sample");
2792 set_input(&ident_file, "pg_ident.conf.sample");
2793 set_input(&conf_file, "postgresql.conf.sample");
2794 set_input(&dictionary_file, "snowball_create.sql");
2795 set_input(&info_schema_file, "information_schema.sql");
2796 set_input(&features_file, "sql_features.txt");
2797 set_input(&system_constraints_file, "system_constraints.sql");
2798 set_input(&system_functions_file, "system_functions.sql");
2799 set_input(&system_views_file, "system_views.sql");
2800
2801 if (show_setting || debug)
2802 {
2804 "VERSION=%s\n"
2805 "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2806 "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2807 "POSTGRESQL_CONF_SAMPLE=%s\n"
2808 "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2809 PG_VERSION,
2812 conf_file,
2814 if (show_setting)
2815 exit(0);
2816 }
2817
2828}
static char * features_file
Definition initdb.c:183
static void set_input(char **dest, const char *filename)
Definition initdb.c:986
static void check_input(char *path)
Definition initdb.c:995
static char * info_schema_file
Definition initdb.c:182

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

Referenced by main().

◆ setup_depend()

static void setup_depend ( FILE cmdfd)
static

Definition at line 1712 of file initdb.c.

1713{
1714 /*
1715 * Advance the OID counter so that subsequently-created objects aren't
1716 * pinned.
1717 */
1718 PG_CMD_PUTS("SELECT pg_stop_making_pinned_objects();\n\n");
1719}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_description()

static void setup_description ( FILE cmdfd)
static

Definition at line 1746 of file initdb.c.

1747{
1748 /* Create default descriptions for operator implementation functions */
1749 PG_CMD_PUTS("WITH funcdescs AS ( "
1750 "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
1751 "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1752 "INSERT INTO pg_description "
1753 " SELECT p_oid, 'pg_proc'::regclass, 0, "
1754 " 'implementation of ' || oprname || ' operator' "
1755 " FROM funcdescs "
1756 " WHERE NOT EXISTS (SELECT 1 FROM pg_description "
1757 " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
1758 " AND NOT EXISTS (SELECT 1 FROM pg_description "
1759 " WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
1760 " AND description LIKE 'deprecated%');\n\n");
1761}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ setup_locale_encoding()

void setup_locale_encoding ( void  )

Definition at line 2681 of file initdb.c.

2682{
2683 setlocales();
2684
2686 strcmp(lc_ctype, lc_collate) == 0 &&
2687 strcmp(lc_ctype, lc_time) == 0 &&
2688 strcmp(lc_ctype, lc_numeric) == 0 &&
2689 strcmp(lc_ctype, lc_monetary) == 0 &&
2690 strcmp(lc_ctype, lc_messages) == 0 &&
2691 (!datlocale || strcmp(lc_ctype, datlocale) == 0))
2692 printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
2693 else
2694 {
2695 printf(_("The database cluster will be initialized with this locale configuration:\n"));
2696 printf(_(" locale provider: %s\n"), collprovider_name(locale_provider));
2698 printf(_(" default collation: %s\n"), datlocale);
2699 printf(_(" LC_COLLATE: %s\n"
2700 " LC_CTYPE: %s\n"
2701 " LC_MESSAGES: %s\n"
2702 " LC_MONETARY: %s\n"
2703 " LC_NUMERIC: %s\n"
2704 " LC_TIME: %s\n"),
2705 lc_collate,
2706 lc_ctype,
2709 lc_numeric,
2710 lc_time);
2711 }
2712
2713 if (!encoding)
2714 {
2715 int ctype_enc;
2716
2718
2719 /*
2720 * If ctype_enc=SQL_ASCII, it's compatible with any encoding. ICU does
2721 * not support SQL_ASCII, so select UTF-8 instead.
2722 */
2725
2726 if (ctype_enc == -1)
2727 {
2728 /* Couldn't recognize the locale's codeset */
2729 pg_log_error("could not find suitable encoding for locale \"%s\"",
2730 lc_ctype);
2731 pg_log_error_hint("Rerun %s with the -E option.", progname);
2732 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2733 exit(1);
2734 }
2736 {
2737 /*
2738 * We recognized it, but it's not a legal server encoding. On
2739 * Windows, UTF-8 works with any locale, so we can fall back to
2740 * UTF-8.
2741 */
2742#ifdef WIN32
2744 printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2745 "The default database encoding will be set to \"%s\" instead.\n"),
2748#else
2749 pg_log_error("locale \"%s\" requires unsupported encoding \"%s\"",
2751 pg_log_error_detail("Encoding \"%s\" is not allowed as a server-side encoding.",
2753 pg_log_error_hint("Rerun %s with a different locale selection.",
2754 progname);
2755 exit(1);
2756#endif
2757 }
2758 else
2759 {
2761 printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2763 }
2764 }
2765 else
2767
2770 exit(1); /* check_locale_encoding printed the error */
2771
2773 {
2774 if ((strcmp(datlocale, "C.UTF-8") == 0 ||
2775 strcmp(datlocale, "PG_UNICODE_FAST") == 0) &&
2777 pg_fatal("builtin provider locale \"%s\" requires encoding \"%s\"",
2778 datlocale, "UTF-8");
2779 }
2780
2783 exit(1);
2784}
static bool check_icu_locale_encoding(int user_enc)
Definition initdb.c:2296
static int get_encoding_id(const char *encoding_name)
Definition initdb.c:846
static bool check_locale_encoding(const char *locale, int user_enc)
Definition initdb.c:2261
static void setlocales(void)
Definition initdb.c:2420
#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 2607 of file initdb.c.

2608{
2609 char *pgdata_get_env;
2610
2611 if (!pg_data)
2612 {
2613 pgdata_get_env = getenv("PGDATA");
2615 {
2616 /* PGDATA found */
2618 }
2619 else
2620 {
2621 pg_log_error("no data directory specified");
2622 pg_log_error_hint("You must identify the directory where the data for this database system "
2623 "will reside. Do this with either the invocation option -D or the "
2624 "environment variable PGDATA.");
2625 exit(1);
2626 }
2627 }
2628
2631
2632 /*
2633 * we have to set PGDATA for postgres rather than pass it on the command
2634 * line to avoid dumb quoting problems on Windows, and we would especially
2635 * need quotes otherwise on Windows because paths there are most likely to
2636 * have embedded spaces.
2637 */
2638 if (setenv("PGDATA", pg_data, 1) != 0)
2639 pg_fatal("could not set environment");
2640}
#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 1800 of file initdb.c.

1801{
1802 PG_CMD_PRINTF("UPDATE pg_class "
1803 " SET relacl = (SELECT array_agg(a.acl) FROM "
1804 " (SELECT E'=r/\"%s\"' as acl "
1805 " UNION SELECT unnest(pg_catalog.acldefault("
1806 " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
1807 " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
1808 " ) as a) "
1809 " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1812 " AND relacl IS NULL;\n\n",
1814 PG_CMD_PUTS("GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
1815 PG_CMD_PUTS("REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
1816 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1817 " (objoid, classoid, objsubid, initprivs, privtype)"
1818 " SELECT"
1819 " oid,"
1820 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1821 " 0,"
1822 " relacl,"
1823 " 'i'"
1824 " FROM"
1825 " pg_class"
1826 " WHERE"
1827 " relacl IS NOT NULL"
1828 " AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1830 CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1831 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1832 " (objoid, classoid, objsubid, initprivs, privtype)"
1833 " SELECT"
1834 " pg_class.oid,"
1835 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1836 " pg_attribute.attnum,"
1837 " pg_attribute.attacl,"
1838 " 'i'"
1839 " FROM"
1840 " pg_class"
1841 " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1842 " WHERE"
1843 " pg_attribute.attacl IS NOT NULL"
1844 " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
1846 CppAsString2(RELKIND_SEQUENCE) ");\n\n");
1847 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1848 " (objoid, classoid, objsubid, initprivs, privtype)"
1849 " SELECT"
1850 " oid,"
1851 " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1852 " 0,"
1853 " proacl,"
1854 " 'i'"
1855 " FROM"
1856 " pg_proc"
1857 " WHERE"
1858 " proacl IS NOT NULL;\n\n");
1859 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1860 " (objoid, classoid, objsubid, initprivs, privtype)"
1861 " SELECT"
1862 " oid,"
1863 " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1864 " 0,"
1865 " typacl,"
1866 " 'i'"
1867 " FROM"
1868 " pg_type"
1869 " WHERE"
1870 " typacl IS NOT NULL;\n\n");
1871 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1872 " (objoid, classoid, objsubid, initprivs, privtype)"
1873 " SELECT"
1874 " oid,"
1875 " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1876 " 0,"
1877 " lanacl,"
1878 " 'i'"
1879 " FROM"
1880 " pg_language"
1881 " WHERE"
1882 " lanacl IS NOT NULL;\n\n");
1883 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1884 " (objoid, classoid, objsubid, initprivs, privtype)"
1885 " SELECT"
1886 " oid,"
1887 " (SELECT oid FROM pg_class WHERE "
1888 " relname = 'pg_largeobject_metadata'),"
1889 " 0,"
1890 " lomacl,"
1891 " 'i'"
1892 " FROM"
1893 " pg_largeobject_metadata"
1894 " WHERE"
1895 " lomacl IS NOT NULL;\n\n");
1896 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1897 " (objoid, classoid, objsubid, initprivs, privtype)"
1898 " SELECT"
1899 " oid,"
1900 " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1901 " 0,"
1902 " nspacl,"
1903 " 'i'"
1904 " FROM"
1905 " pg_namespace"
1906 " WHERE"
1907 " nspacl IS NOT NULL;\n\n");
1908 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1909 " (objoid, classoid, objsubid, initprivs, privtype)"
1910 " SELECT"
1911 " oid,"
1912 " (SELECT oid FROM pg_class WHERE "
1913 " relname = 'pg_foreign_data_wrapper'),"
1914 " 0,"
1915 " fdwacl,"
1916 " 'i'"
1917 " FROM"
1918 " pg_foreign_data_wrapper"
1919 " WHERE"
1920 " fdwacl IS NOT NULL;\n\n");
1921 PG_CMD_PUTS("INSERT INTO pg_init_privs "
1922 " (objoid, classoid, objsubid, initprivs, privtype)"
1923 " SELECT"
1924 " oid,"
1925 " (SELECT oid FROM pg_class "
1926 " WHERE relname = 'pg_foreign_server'),"
1927 " 0,"
1928 " srvacl,"
1929 " 'i'"
1930 " FROM"
1931 " pg_foreign_server"
1932 " WHERE"
1933 " srvacl IS NOT NULL;\n\n");
1934}

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

1726{
1727 char **lines;
1728
1729 lines = readfile(filename);
1730
1731 for (char **line = lines; *line != NULL; line++)
1732 {
1733 PG_CMD_PUTS(*line);
1734 free(*line);
1735 }
1736
1737 PG_CMD_PUTS("\n\n");
1738
1739 free(lines);
1740}

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

1969{
1971
1972 PG_CMD_PRINTF("UPDATE information_schema.sql_implementation_info "
1973 " SET character_value = '%s' "
1974 " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
1975 infoversion);
1976
1977 PG_CMD_PRINTF("COPY information_schema.sql_features "
1978 " (feature_id, feature_name, sub_feature_id, "
1979 " sub_feature_name, is_supported, comments) "
1980 " FROM E'%s';\n\n",
1982}

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

2867{
2870
2871 /* the following are not valid on Windows */
2872#ifndef WIN32
2875
2876 /* Ignore SIGPIPE when writing to backend, so we can clean up */
2878
2879 /* Prevent SIGSYS so we can probe for kernel calls that might not work */
2881#endif
2882}
static void trapsig(SIGNAL_ARGS)
Definition initdb.c:2094
#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 2832 of file initdb.c.

2833{
2835 {
2838 {
2839 pg_log_info("could not find suitable text search configuration for locale \"%s\"",
2840 lc_ctype);
2841 default_text_search_config = "simple";
2842 }
2843 }
2844 else
2845 {
2847
2848 if (checkmatch == NULL)
2849 {
2850 pg_log_warning("suitable text search configuration for locale \"%s\" is unknown",
2851 lc_ctype);
2852 }
2854 {
2855 pg_log_warning("specified text search configuration \"%s\" might not match locale \"%s\"",
2857 }
2858 }
2859
2860 printf(_("The default text search configuration will be set to \"%s\".\n"),
2862}
static const char * find_matching_ts_config(const char *lc_type)
Definition initdb.c:940

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

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

1224{
1225 PQExpBufferData cmd;
1227 *gvalues;
1228 int status;
1229
1230 initPQExpBuffer(&cmd);
1231
1232 /* Set up the test postmaster invocation */
1233 printfPQExpBuffer(&cmd,
1234 "\"%s\" --check %s %s "
1235 "-c max_connections=%d "
1236 "-c autovacuum_worker_slots=%d "
1237 "-c shared_buffers=%d "
1238 "-c dynamic_shared_memory_type=%s",
1242
1243 /* Add any user-given setting overrides */
1245 gnames != NULL; /* assume lists have the same length */
1247 {
1248 appendPQExpBuffer(&cmd, " -c %s=", gnames->str);
1249 appendShellString(&cmd, gvalues->str);
1250 }
1251
1252 appendPQExpBuffer(&cmd,
1253 " < \"%s\" > \"%s\" 2>&1",
1254 DEVNULL, DEVNULL);
1255
1256 fflush(NULL);
1257 status = system(cmd.data);
1258
1259 termPQExpBuffer(&cmd);
1260
1261 return (status == 0);
1262}

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

2095{
2096 /* handle systems that reset the handler, like Windows (grr) */
2098 caught_signal = true;
2099}

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

Referenced by setup_signals(), and trapsig().

◆ usage()

static void usage ( const char progname)
static

Definition at line 2513 of file initdb.c.

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

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

◆ vacuum_db()

static void vacuum_db ( FILE cmdfd)
static

Definition at line 1997 of file initdb.c.

1998{
1999 /* Run analyze before VACUUM so the statistics are frozen. */
2000 PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
2001}

References PG_CMD_PUTS.

Referenced by initialize_data_directory().

◆ warn_on_mount_point()

void warn_on_mount_point ( int  error)

Definition at line 3027 of file initdb.c.

3028{
3029 if (error == 2)
3030 pg_log_error_detail("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
3031 else if (error == 3)
3032 pg_log_error_detail("It contains a lost+found directory, perhaps due to it being a mount point.");
3033
3034 pg_log_error_hint("Using a mount point directly as the data directory is not recommended.\n"
3035 "Create a subdirectory under the mount point.");
3036}
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 1026 of file initdb.c.

1027{
1029 char *path;
1030
1031 if (extrapath == NULL)
1032 path = psprintf("%s/PG_VERSION", pg_data);
1033 else
1034 path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
1035
1036 if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
1037 pg_fatal("could not open file \"%s\" for writing: %m", path);
1038 if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
1040 pg_fatal("could not write file \"%s\": %m", path);
1041 free(path);
1042}
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 723 of file initdb.c.

724{
725 FILE *out_file;
726 char **line;
727
728 if ((out_file = fopen(path, "w")) == NULL)
729 pg_fatal("could not open file \"%s\" for writing: %m", path);
730 for (line = lines; *line != NULL; line++)
731 {
732 if (fputs(*line, out_file) < 0)
733 pg_fatal("could not write file \"%s\": %m", path);
734 free(*line);
735 }
736 if (fclose(out_file))
737 pg_fatal("could not close file \"%s\": %m", path);
738 free(lines);
739}

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

Referenced by initialize_data_directory().

◆ bin_path

char bin_path[MAXPGPATH]
static

Definition at line 259 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 225 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 193 of file initdb.c.

Referenced by check_ok(), and trapsig().

◆ conf_file

char* conf_file
static

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

Referenced by setup_config(), and test_config_settings().

◆ dictionary_file

char* dictionary_file
static

Definition at line 181 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 202 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 183 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 189 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 191 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().

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

Referenced by setup_data_file_paths(), and setup_schema().

◆ infoversion

char infoversion[100]
static

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

Referenced by setup_config(), and test_config_settings().

◆ n_buffers

int n_buffers = 50
static

Definition at line 201 of file initdb.c.

Referenced by setup_config(), and test_config_settings().

◆ n_connections

int n_connections = 10
static

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

Referenced by check_ok().

◆ output_failed

bool output_failed = false
static

Definition at line 194 of file initdb.c.

Referenced by check_ok().

◆ pg_data

◆ pgdata_native

char* pgdata_native
static

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

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

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 184 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 185 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 186 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 869 of file initdb.c.

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

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