57 #include <unicode/ucol.h>
68 #include "catalog/pg_authid_d.h"
69 #include "catalog/pg_class_d.h"
70 #include "catalog/pg_collation_d.h"
71 #include "catalog/pg_database_d.h"
97 "trust",
"reject",
"scram-sha-256",
"md5",
"password",
"ident",
"radius",
119 "trust",
"reject",
"scram-sha-256",
"md5",
"password",
"peer",
"radius",
206 #define AUTHTRUST_WARNING \
207 "# CAUTION: Configuring the system for local \"trust\" authentication\n" \
208 "# allows any local user to connect as any PostgreSQL user, including\n" \
209 "# the database superuser. If you do not trust all your local users,\n" \
210 "# use another authentication method.\n"
224 static const char *
const backend_options =
"--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true -c log_checkpoints=false";
231 "pg_wal/archive_status",
241 "pg_multixact/members",
242 "pg_multixact/offsets",
251 "pg_logical/snapshots",
252 "pg_logical/mappings"
261 const char *
token,
const char *replacement);
263 const char *guc_name,
const char *guc_value,
264 bool mark_as_comment);
266 static char **
readfile(
const char *path);
267 static void writefile(
char *path,
char **lines);
269 static char *
get_id(
void);
316 #define PG_CMD_DECL FILE *cmdfd
318 #define PG_CMD_OPEN(cmd) \
320 cmdfd = popen_check(cmd, "w"); \
325 #define PG_CMD_CLOSE() \
327 if (pclose_check(cmdfd)) \
331 #define PG_CMD_PUTS(line) \
333 if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
334 output_failed = true, output_errno = errno; \
337 #define PG_CMD_PRINTF(fmt, ...) \
339 if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
340 output_failed = true, output_errno = errno; \
367 save = _wsetlocale(category, NULL);
389 if (!_wsetlocale(category, save))
390 pg_fatal(
"failed to restore old locale");
393 pg_fatal(
"failed to restore old locale \"%s\"", save);
429 for (datap =
data; *datap; datap++)
448 newentry->
next = NULL;
449 if (*listhead == NULL)
450 *listhead = newentry;
453 for (oldentry = *listhead; oldentry->
next; oldentry = oldentry->
next)
455 oldentry->
next = newentry;
476 toklen = strlen(
token);
477 replen = strlen(replacement);
478 diff = replen - toklen;
480 for (
int i = 0; lines[
i];
i++)
487 if ((where = strstr(lines[
i],
token)) == NULL)
494 pre = where - lines[
i];
498 memcpy(
newline + pre, replacement, replen);
500 strcpy(
newline + pre + replen, lines[
i] + pre + toklen);
526 bool mark_as_comment)
528 int namelen = strlen(guc_name);
541 for (
i = 0; lines[
i];
i++)
544 const char *namestart;
553 while (*where ==
'#' || isspace((
unsigned char) *where))
559 while (isspace((
unsigned char) *where))
565 memcpy(&
newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
568 where = strrchr(where,
'#');
579 for (ptr = lines[
i]; ptr < where; ptr++)
582 oldindent += 8 - (oldindent % 8);
589 oldindent =
Max(oldindent, newindent + 1);
590 while (newindent < oldindent)
592 int newindent_if_tab = newindent + 8 - (newindent % 8);
594 if (newindent_if_tab <= oldindent)
597 newindent = newindent_if_tab;
618 if (lines[
i] == NULL)
644 #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
645 #define DIGITS "0123456789"
647 if (*guc_value ==
'\0')
649 if (strchr(
LETTERS, *guc_value))
655 if (strchr(
DIGITS, *guc_value))
658 guc_value += strspn(guc_value,
DIGITS);
660 if (strspn(guc_value,
LETTERS) == strlen(guc_value))
681 if ((
infile = fopen(path,
"r")) == NULL)
682 pg_fatal(
"could not open file \"%s\" for reading: %m", path);
687 result = (
char **)
pg_malloc(maxlines *
sizeof(
char *));
693 if (n >= maxlines - 1)
696 result = (
char **)
pg_realloc(result, maxlines *
sizeof(
char *));
725 if ((out_file = fopen(path,
"w")) == NULL)
726 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
727 for (line = lines; *line != NULL; line++)
729 if (fputs(*line, out_file) < 0)
730 pg_fatal(
"could not write file \"%s\": %m", path);
733 if (fclose(out_file))
734 pg_fatal(
"could not close file \"%s\": %m", path);
748 cmdfd = popen(command,
mode);
750 pg_log_error(
"could not execute command \"%s\": %m", command);
774 pg_log_info(
"removing contents of data directory \"%s\"",
777 pg_log_error(
"failed to remove contents of data directory");
790 pg_log_error(
"failed to remove contents of WAL directory");
797 pg_log_info(
"data directory \"%s\" not removed at user's request",
801 pg_log_info(
"WAL directory \"%s\" not removed at user's request",
820 pg_log_error_hint(
"Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
847 if (encoding_name && *encoding_name)
852 pg_fatal(
"\"%s\" is not a valid server encoding name",
853 encoding_name ? encoding_name :
"(null)");
869 {
"arabic",
"Arabic"},
871 {
"armenian",
"Armenian"},
873 {
"basque",
"Basque"},
875 {
"catalan",
"Catalan"},
877 {
"danish",
"Danish"},
881 {
"english",
"POSIX"},
883 {
"english",
"English"},
885 {
"finnish",
"Finnish"},
887 {
"french",
"French"},
889 {
"german",
"German"},
895 {
"hungarian",
"Hungarian"},
896 {
"indonesian",
"id"},
897 {
"indonesian",
"Indonesian"},
901 {
"italian",
"Italian"},
902 {
"lithuanian",
"lt"},
903 {
"lithuanian",
"Lithuanian"},
905 {
"nepali",
"Nepali"},
907 {
"norwegian",
"Norwegian"},
908 {
"portuguese",
"pt"},
909 {
"portuguese",
"Portuguese"},
912 {
"russian",
"Russian"},
914 {
"serbian",
"Serbian"},
916 {
"spanish",
"Spanish"},
918 {
"swedish",
"Swedish"},
922 {
"turkish",
"Turkish"},
924 {
"yiddish",
"Yiddish"},
956 *ptr !=
'_' && *ptr !=
'-' && *ptr !=
'.' && *ptr !=
'@')
992 if (
stat(path, &statbuf) != 0)
997 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1001 pg_log_error(
"could not access file \"%s\": %m", path);
1002 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1008 pg_log_error(
"file \"%s\" is not a regular file", path);
1009 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
1024 if (extrapath == NULL)
1030 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
1033 pg_fatal(
"could not write file \"%s\": %m", path);
1050 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
1052 pg_fatal(
"could not write file \"%s\": %m", path);
1073 #if defined(HAVE_SHM_OPEN) && !defined(__sun__)
1088 if ((
fd = shm_open(
name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
1094 if (errno != EEXIST)
1119 #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
1121 static const int trial_conns[] = {
1124 static const int trial_bufs[] = {
1125 16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
1126 1000, 900, 800, 700, 600, 500,
1127 400, 300, 200, 100, 50
1130 const int connslen =
sizeof(trial_conns) /
sizeof(
int);
1131 const int bufslen =
sizeof(trial_bufs) /
sizeof(
int);
1141 printf(
_(
"selecting dynamic shared memory implementation ... "));
1150 printf(
_(
"selecting default \"max_connections\" ... "));
1153 for (
i = 0;
i < connslen;
i++)
1155 test_conns = trial_conns[
i];
1160 ok_buffers = test_buffs;
1170 printf(
_(
"selecting default \"shared_buffers\" ... "));
1173 for (
i = 0;
i < bufslen;
i++)
1176 test_buffs = (trial_bufs[
i] * 8192) / BLCKSZ;
1177 if (test_buffs <= ok_buffers)
1179 test_buffs = ok_buffers;
1188 if ((
n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1193 printf(
_(
"selecting default time zone ... "));
1214 "\"%s\" --check %s %s "
1215 "-c max_connections=%d "
1216 "-c shared_buffers=%d "
1217 "-c dynamic_shared_memory_type=%s",
1219 test_conns, test_buffs,
1225 gnames = gnames->
next, gvalues = gvalues->
next)
1232 " < \"%s\" > \"%s\" 2>&1",
1236 status = system(cmd.
data);
1240 return (status == 0);
1252 if ((sz % 1024) == 0)
1253 snprintf(result, 14,
"%dGB", sz / 1024);
1272 fputs(
_(
"creating configuration files ... "),
stdout);
1283 if ((
n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1284 snprintf(repltok,
sizeof(repltok),
"%dMB",
1287 snprintf(repltok,
sizeof(repltok),
"%dkB",
1307 strcpy(repltok,
"iso, ymd");
1310 strcpy(repltok,
"iso, dmy");
1314 strcpy(repltok,
"iso, mdy");
1320 snprintf(repltok,
sizeof(repltok),
"pg_catalog.%s",
1351 DEF_PGPORT_STR,
true);
1353 #if DEFAULT_BACKEND_FLUSH_AFTER > 0
1354 snprintf(repltok,
sizeof(repltok),
"%dkB",
1360 #if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1361 snprintf(repltok,
sizeof(repltok),
"%dkB",
1367 #if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1368 snprintf(repltok,
sizeof(repltok),
"%dkB",
1374 #ifndef USE_PREFETCH
1414 gnames = gnames->
next, gvalues = gvalues->
next)
1417 gvalues->
str,
false);
1425 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1431 conflines[0] =
pg_strdup(
"# Do not edit this file manually!\n");
1432 conflines[1] =
pg_strdup(
"# It will be overwritten by the ALTER SYSTEM command.\n");
1433 conflines[2] = NULL;
1439 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1446 conflines =
replace_token(conflines,
"@remove-line-for-nolocal@",
"");
1457 struct addrinfo *gai_result;
1458 struct addrinfo hints;
1465 err = WSAStartup(MAKEWORD(2, 2), &wsaData);
1469 hints.ai_flags = AI_NUMERICHOST;
1470 hints.ai_family = AF_UNSPEC;
1471 hints.ai_socktype = 0;
1472 hints.ai_protocol = 0;
1473 hints.ai_addrlen = 0;
1474 hints.ai_canonname = NULL;
1475 hints.ai_addr = NULL;
1476 hints.ai_next = NULL;
1479 getaddrinfo(
"::1", NULL, &hints, &gai_result) != 0)
1483 "#host all all ::1");
1485 "host replication all ::1",
1486 "#host replication all ::1");
1495 "@authmethodlocal@",
1506 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1517 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1536 printf(
_(
"running bootstrap script ... "));
1543 snprintf(headerline,
sizeof(headerline),
"# PostgreSQL %s\n",
1546 if (strcmp(headerline, *bki_lines) != 0)
1548 pg_log_error(
"input file \"%s\" does not belong to PostgreSQL %s",
1563 (
sizeof(
Pointer) == 4) ?
"i" :
"d");
1604 for (line = bki_lines; *line != NULL; line++)
1628 PG_CMD_PUTS(
"REVOKE ALL ON pg_authid FROM public;\n\n");
1652 pwd1 =
simple_prompt(
"Enter new superuser password: ",
false);
1654 if (strcmp(pwd1, pwd2) != 0)
1656 fprintf(stderr,
_(
"Passwords didn't match.\n"));
1674 pg_fatal(
"could not open file \"%s\" for reading: %m",
1680 pg_fatal(
"could not read password from file \"%s\": %m",
1683 pg_fatal(
"password file \"%s\" is empty",
1704 PG_CMD_PUTS(
"SELECT pg_stop_making_pinned_objects();\n\n");
1717 for (
char **line = lines; *line != NULL; line++)
1736 "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
1737 "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1738 "INSERT INTO pg_description "
1739 " SELECT p_oid, 'pg_proc'::regclass, 0, "
1740 " 'implementation of ' || oprname || ' operator' "
1742 " WHERE NOT EXISTS (SELECT 1 FROM pg_description "
1743 " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
1744 " AND NOT EXISTS (SELECT 1 FROM pg_description "
1745 " WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
1746 " AND description LIKE 'deprecated%');\n\n");
1760 PG_CMD_PUTS(
"UPDATE pg_collation SET collversion = pg_collation_actual_version(oid) WHERE collname = 'unicode';\n\n");
1763 PG_CMD_PUTS(
"SELECT pg_import_system_collations('pg_catalog');\n\n");
1789 " SET relacl = (SELECT array_agg(a.acl) FROM "
1790 " (SELECT E'=r/\"%s\"' as acl "
1791 " UNION SELECT unnest(pg_catalog.acldefault("
1792 " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE)
" THEN 's' "
1793 " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID)
"::oid))"
1795 " WHERE relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1798 " AND relacl IS NULL;\n\n",
1800 PG_CMD_PUTS(
"GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
1801 PG_CMD_PUTS(
"REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
1803 " (objoid, classoid, objsubid, initprivs, privtype)"
1806 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1813 " relacl IS NOT NULL"
1814 " AND relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1818 " (objoid, classoid, objsubid, initprivs, privtype)"
1821 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1822 " pg_attribute.attnum,"
1823 " pg_attribute.attacl,"
1827 " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1829 " pg_attribute.attacl IS NOT NULL"
1830 " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1834 " (objoid, classoid, objsubid, initprivs, privtype)"
1837 " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1844 " proacl IS NOT NULL;\n\n");
1846 " (objoid, classoid, objsubid, initprivs, privtype)"
1849 " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1856 " typacl IS NOT NULL;\n\n");
1858 " (objoid, classoid, objsubid, initprivs, privtype)"
1861 " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1868 " lanacl IS NOT NULL;\n\n");
1870 " (objoid, classoid, objsubid, initprivs, privtype)"
1873 " (SELECT oid FROM pg_class WHERE "
1874 " relname = 'pg_largeobject_metadata'),"
1879 " pg_largeobject_metadata"
1881 " lomacl IS NOT NULL;\n\n");
1883 " (objoid, classoid, objsubid, initprivs, privtype)"
1886 " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1893 " nspacl IS NOT NULL;\n\n");
1895 " (objoid, classoid, objsubid, initprivs, privtype)"
1898 " (SELECT oid FROM pg_class WHERE "
1899 " relname = 'pg_foreign_data_wrapper'),"
1904 " pg_foreign_data_wrapper"
1906 " fdwacl IS NOT NULL;\n\n");
1908 " (objoid, classoid, objsubid, initprivs, privtype)"
1911 " (SELECT oid FROM pg_class "
1912 " WHERE relname = 'pg_foreign_server'),"
1917 " pg_foreign_server"
1919 " srvacl IS NOT NULL;\n\n");
1929 char *letterversion;
1937 ptr = vstr + (strlen(vstr) - 1);
1938 while (ptr != vstr && (*ptr < '0' || *ptr >
'9'))
1940 letterversion = ptr + 1;
1941 major = strtol(vstr, &endptr, 10);
1943 minor = strtol(endptr + 1, &endptr, 10);
1945 micro = strtol(endptr + 1, &endptr, 10);
1947 major, minor, micro, letterversion);
1958 PG_CMD_PRINTF(
"UPDATE information_schema.sql_implementation_info "
1959 " SET character_value = '%s' "
1960 " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
1964 " (feature_id, feature_name, sub_feature_id, "
1965 " sub_feature_name, is_supported, comments) "
2012 PG_CMD_PUTS(
"CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
2014 " STRATEGY = file_copy;\n\n");
2021 PG_CMD_PUTS(
"UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
2026 PG_CMD_PUTS(
"UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
2032 PG_CMD_PUTS(
"REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
2033 PG_CMD_PUTS(
"REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
2035 PG_CMD_PUTS(
"COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
2054 " STRATEGY = file_copy;\n\n");
2055 PG_CMD_PUTS(
"COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
2101 printf(
_(
"could not write to child process: %s\n"),
2115 static inline size_t
2118 return strftime(s, max,
fmt,
tm);
2142 memset(&testtime, 0,
sizeof(testtime));
2143 testtime.tm_mday = 22;
2144 testtime.tm_mon = 10;
2145 testtime.tm_year = 133;
2154 posM = strstr(
buf,
"11");
2155 posD = strstr(
buf,
"22");
2156 posY = strstr(
buf,
"33");
2158 if (!posM || !posD || !posY)
2161 if (posY < posM && posM < posD)
2163 else if (posD < posM)
2191 pg_fatal(
"locale name \"%s\" contains non-ASCII characters",
locale);
2206 if (
res && canonname)
2231 pg_fatal(
"invalid locale settings; check LANG and LC_* environment variables");
2237 pg_fatal(
"locale name \"%s\" contains non-ASCII characters",
2254 if (!(locale_enc == user_enc ||
2264 "selected locale uses (%s) do not match. This would lead to "
2265 "misbehavior in various character string processing functions.",
2269 "or choose a matching combination.",
2287 pg_log_error_detail(
"The encoding you selected (%s) is not supported with the ICU provider.",
2290 "or choose a matching combination.",
2308 const bool strict =
true;
2319 status = U_ZERO_ERROR;
2320 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
2323 if (status == U_BUFFER_OVERFLOW_ERROR ||
2324 status == U_STRING_NOT_TERMINATED_WARNING)
2326 buflen = buflen * 2;
2334 if (U_FAILURE(status))
2338 pg_fatal(
"could not convert locale name \"%s\" to language tag: %s",
2339 loc_str, u_errorName(status));
2344 pg_fatal(
"ICU is not supported in this build");
2359 char lang[ULOC_LANG_CAPACITY];
2363 status = U_ZERO_ERROR;
2364 uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
2365 if (U_FAILURE(status))
2367 pg_fatal(
"could not get language from locale \"%s\": %s",
2368 loc_str, u_errorName(status));
2373 if (strcmp(lang,
"") == 0 ||
2374 strcmp(lang,
"root") == 0 || strcmp(lang,
"und") == 0)
2378 for (int32_t
i = 0; !found &&
i < uloc_countAvailable();
i++)
2380 const char *otherloc = uloc_getAvailable(
i);
2381 char otherlang[ULOC_LANG_CAPACITY];
2383 status = U_ZERO_ERROR;
2384 uloc_getLanguage(otherloc, otherlang, ULOC_LANG_CAPACITY, &status);
2385 if (U_FAILURE(status))
2388 if (strcmp(lang, otherlang) == 0)
2393 pg_fatal(
"locale \"%s\" has unknown language \"%s\"",
2396 pg_fatal(
"ICU is not supported in this build");
2444 #if defined(LC_MESSAGES) && !defined(WIN32)
2454 pg_fatal(
"locale must be specified if provider is %s",
2461 else if (strcmp(
datlocale,
"C.UTF-8") == 0 ||
2463 canonname =
"C.UTF-8";
2465 pg_fatal(
"invalid locale name \"%s\" for builtin provider",
2476 printf(
_(
"Using language tag \"%s\" for ICU locale \"%s\".\n"),
2488 pg_fatal(
"ICU is not supported in this build");
2499 printf(
_(
"%s initializes a PostgreSQL database cluster.\n\n"),
progname);
2503 printf(
_(
" -A, --auth=METHOD default authentication method for local connections\n"));
2504 printf(
_(
" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
2505 printf(
_(
" --auth-local=METHOD default authentication method for local-socket connections\n"));
2506 printf(
_(
" [-D, --pgdata=]DATADIR location for this database cluster\n"));
2507 printf(
_(
" -E, --encoding=ENCODING set default encoding for new databases\n"));
2508 printf(
_(
" -g, --allow-group-access allow group read/execute on data directory\n"));
2509 printf(
_(
" --icu-locale=LOCALE set ICU locale ID for new databases\n"));
2510 printf(
_(
" --icu-rules=RULES set additional ICU collation rules for new databases\n"));
2511 printf(
_(
" -k, --data-checksums use data page checksums\n"));
2512 printf(
_(
" --locale=LOCALE set default locale for new databases\n"));
2513 printf(
_(
" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
2514 " --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
2515 " set default locale in the respective category for\n"
2516 " new databases (default taken from environment)\n"));
2517 printf(
_(
" --no-locale equivalent to --locale=C\n"));
2518 printf(
_(
" --builtin-locale=LOCALE\n"
2519 " set builtin locale name for new databases\n"));
2520 printf(
_(
" --locale-provider={builtin|libc|icu}\n"
2521 " set default locale provider for new databases\n"));
2522 printf(
_(
" --no-data-checksums do not use data page checksums\n"));
2523 printf(
_(
" --pwfile=FILE read password for the new superuser from file\n"));
2524 printf(
_(
" -T, --text-search-config=CFG\n"
2525 " default text search configuration\n"));
2526 printf(
_(
" -U, --username=NAME database superuser name\n"));
2527 printf(
_(
" -W, --pwprompt prompt for a password for the new superuser\n"));
2528 printf(
_(
" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
2529 printf(
_(
" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
2530 printf(
_(
"\nLess commonly used options:\n"));
2531 printf(
_(
" -c, --set NAME=VALUE override default setting for server parameter\n"));
2532 printf(
_(
" -d, --debug generate lots of debugging output\n"));
2533 printf(
_(
" --discard-caches set debug_discard_caches=1\n"));
2534 printf(
_(
" -L DIRECTORY where to find the input files\n"));
2535 printf(
_(
" -n, --no-clean do not clean up after errors\n"));
2536 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
2537 printf(
_(
" --no-instructions do not print instructions for next steps\n"));
2538 printf(
_(
" -s, --show show internal settings, then exit\n"));
2539 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
2540 printf(
_(
" -S, --sync-only only sync database files to disk, then exit\n"));
2541 printf(
_(
"\nOther options:\n"));
2542 printf(
_(
" -V, --version output version information, then exit\n"));
2543 printf(
_(
" -?, --help show this help, then exit\n"));
2544 printf(
_(
"\nIf the data directory is not specified, the environment variable PGDATA\n"
2546 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2547 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2553 if (*authmethod == NULL)
2556 *authmethod =
"trust";
2563 const char *
const *p;
2565 for (p = valid_methods; *p; p++)
2567 if (strcmp(authmethod, *p) == 0)
2571 pg_fatal(
"invalid authentication method \"%s\" for \"%s\" connections",
2572 authmethod, conntype);
2585 pg_fatal(
"must specify a password for the superuser to enable password authentication");
2592 char *pgdata_get_env;
2596 pgdata_get_env = getenv(
"PGDATA");
2597 if (pgdata_get_env && strlen(pgdata_get_env))
2605 pg_log_error_hint(
"You must identify the directory where the data for this database system "
2606 "will reside. Do this with either the invocation option -D or the "
2607 "environment variable PGDATA.");
2622 pg_fatal(
"could not set environment");
2640 pg_fatal(
"program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
2643 pg_fatal(
"program \"%s\" was found by \"%s\" but was not the same version as %s",
2658 pg_fatal(
"input file location must be an absolute path");
2675 printf(
_(
"The database cluster will be initialized with locale \"%s\".\n"),
lc_ctype);
2678 printf(
_(
"The database cluster will be initialized with this locale configuration:\n"));
2684 " LC_MESSAGES: %s\n"
2685 " LC_MONETARY: %s\n"
2709 if (ctype_enc == -1)
2712 pg_log_error(
"could not find suitable encoding for locale \"%s\"",
2727 printf(
_(
"Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2728 "The default database encoding will be set to \"%s\" instead.\n"),
2732 pg_log_error(
"locale \"%s\" requires unsupported encoding \"%s\"",
2744 printf(
_(
"The default database encoding has accordingly been set to \"%s\".\n"),
2758 pg_fatal(
"builtin provider locale \"%s\" requires encoding \"%s\"",
2786 "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2787 "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2788 "POSTGRESQL_CONF_SAMPLE=%s\n"
2789 "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2820 pg_log_info(
"could not find suitable text search configuration for locale \"%s\"",
2829 if (checkmatch == NULL)
2831 pg_log_warning(
"suitable text search configuration for locale \"%s\" is unknown",
2836 pg_log_warning(
"specified text search configuration \"%s\" might not match locale \"%s\"",
2841 printf(
_(
"The default text search configuration will be set to \"%s\".\n"),
2884 printf(
_(
"creating directory %s ... "),
2898 printf(
_(
"fixing permissions on existing directory %s ... "),
2903 pg_fatal(
"could not change permissions of directory \"%s\": %m",
2919 pg_log_error_hint(
"If you want to create a new database system, either remove or empty "
2920 "the directory \"%s\" or run %s "
2921 "with an argument other than \"%s\".",
2948 pg_fatal(
"WAL directory location must be an absolute path");
2955 printf(
_(
"creating directory %s ... "),
2960 pg_fatal(
"could not create directory \"%s\": %m",
2970 printf(
_(
"fixing permissions on existing directory %s ... "),
2975 pg_fatal(
"could not change permissions of directory \"%s\": %m",
2991 pg_log_error_hint(
"If you want to store the WAL there, either remove or empty the directory \"%s\".",
3001 pg_fatal(
"could not create symbolic link \"%s\": %m",
3008 pg_fatal(
"could not create directory \"%s\": %m",
3020 pg_log_error_detail(
"It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
3021 else if (
error == 3)
3022 pg_log_error_detail(
"It contains a lost+found directory, perhaps due to it being a mount point.");
3024 pg_log_error_hint(
"Using a mount point directly as the data directory is not recommended.\n"
3025 "Create a subdirectory under the mount point.");
3051 printf(
_(
"creating subdirectories ... "));
3065 pg_fatal(
"could not create directory \"%s\": %m", path);
3094 fputs(
_(
"performing post-bootstrap initialization ... "),
stdout);
3146 static struct option long_options[] = {
3195 char *effective_user;
3213 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
3218 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
3220 puts(
"initdb (PostgreSQL) " PG_VERSION);
3227 while ((
c =
getopt_long(argc, argv,
"A:c:dD:E:gkL:nNsST:U:WX:",
3228 long_options, &option_index)) != -1)
3254 char *equals = strchr(
buf,
'=');
3283 printf(
_(
"Running in debug mode.\n"));
3287 printf(
_(
"Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3350 "-c debug_discard_caches=1");
3353 if (strcmp(
optarg,
"builtin") == 0)
3355 else if (strcmp(
optarg,
"icu") == 0)
3357 else if (strcmp(
optarg,
"libc") == 0)
3400 pg_log_error(
"too many command-line arguments (first is \"%s\")",
3407 pg_fatal(
"%s cannot be specified unless locale provider \"%s\" is chosen",
3408 "--builtin-locale",
"builtin");
3411 pg_fatal(
"%s cannot be specified unless locale provider \"%s\" is chosen",
3412 "--icu-locale",
"icu");
3415 pg_fatal(
"%s cannot be specified unless locale provider \"%s\" is chosen",
3416 "--icu-rules",
"icu");
3429 fputs(
_(
"syncing data to disk ... "),
stdout);
3437 pg_fatal(
"password prompt and password file cannot be specified together");
3448 pg_fatal(
"argument of %s must be a power of two between 1 and 1024",
"--wal-segsize");
3456 effective_user =
get_id();
3460 if (strncmp(
username,
"pg_", 3) == 0)
3461 pg_fatal(
"superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"",
username);
3463 printf(
_(
"The files belonging to this database system will be owned "
3465 "This user must also own the server process.\n\n"),
3479 printf(
_(
"Data page checksums are enabled.\n"));
3481 printf(
_(
"Data page checksums are disabled.\n"));
3492 fputs(
_(
"syncing data to disk ... "),
stdout);
3498 printf(
_(
"\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3503 pg_log_warning(
"enabling \"trust\" authentication for local connections");
3504 pg_log_warning_hint(
"You can change this by editing pg_hba.conf or using the option -A, or "
3505 "--auth-local and --auth-host, the next time you run initdb.");
3536 printf(
_(
"\nSuccess. You can now start the database server using:\n\n"
3538 start_db_cmd->
data);
#define PG_TEXTDOMAIN(domain)
int find_my_exec(const char *argv0, char *retpath)
void set_pglocale_pgservice(const char *argv0, const char *app)
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
static void PGresult * res
bool is_encoding_supported_by_icu(int encoding)
void err(int eval, const char *fmt,...)
void * pg_realloc(void *ptr, size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
#define pg_realloc_array(pointer, type, count)
#define pg_malloc_array(type, count)
void SetDataDirectoryCreatePerm(int dataDirMode)
#define PG_DIR_MODE_GROUP
@ DATA_DIR_SYNC_METHOD_FSYNC
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static char * escape_quotes_bki(const char *src)
static void usage(const char *progname)
static const char * default_timezone
static char * superuser_password
int main(int argc, char *argv[])
static char * get_id(void)
void warn_on_mount_point(int error)
static void setup_depend(FILE *cmdfd)
static bool found_existing_pgdata
static bool found_existing_xlogdir
static char * pgdata_native
#define PG_CMD_PUTS(line)
static void check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
static char ** readfile(const char *path)
static bool icu_locale_specified
static bool noinstructions
void initialize_data_directory(void)
static void setup_collation(FILE *cmdfd)
static bool check_icu_locale_encoding(int user_enc)
static char backend_exec[MAXPGPATH]
static void restore_global_locale(int category, save_locale_t save)
static bool data_checksums
void setup_text_search(void)
static int get_encoding_id(const char *encoding_name)
static char infoversion[100]
static FILE * popen_check(const char *command, const char *mode)
static const char * authmethodhost
void create_data_directory(void)
static bool guc_value_requires_quotes(const char *guc_value)
static char * features_file
struct _stringlist _stringlist
void setup_bin_paths(const char *argv0)
static bool check_locale_encoding(const char *locale, int user_enc)
static void check_authmethod_unspecified(const char **authmethod)
static char locale_provider
static const char *const auth_methods_host[]
static int wal_segment_size_mb
static void bootstrap_template1(void)
const char * select_default_timezone(const char *share_path)
void setup_locale_encoding(void)
static void setup_run_file(FILE *cmdfd, const char *filename)
static char * icu_language_tag(const char *loc_str)
static const char *const auth_methods_local[]
static char ** replace_token(char **lines, const char *token, const char *replacement)
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
static void setlocales(void)
static save_locale_t save_global_locale(int category)
static bool made_new_xlogdir
static void setup_auth(FILE *cmdfd)
static void check_need_password(const char *authmethodlocal, const char *authmethodhost)
static int locale_date_order(const char *locale)
static void make_postgres(FILE *cmdfd)
static void test_config_settings(void)
static void cleanup_directories_atexit(void)
static const char *const backend_options
static void setup_config(void)
static char * lc_messages
static void setup_privileges(FILE *cmdfd)
static void write_version_file(const char *extrapath)
static void trapsig(SIGNAL_ARGS)
static bool output_failed
static char * system_views_file
static void setup_description(FILE *cmdfd)
static char * escape_quotes(const char *src)
#define PG_CMD_PRINTF(fmt,...)
static bool builtin_locale_specified
static void vacuum_db(FILE *cmdfd)
static const char *const subdirs[]
static void set_info_version(void)
static const struct tsearch_config_match tsearch_config_languages[]
static const char * choose_dsm_implementation(void)
void setup_data_file_paths(void)
static void set_input(char **dest, const char *filename)
static bool made_new_pgdata
static char ** replace_guc_value(char **lines, const char *guc_name, const char *guc_value, bool mark_as_comment)
#define MIN_BUFS_FOR_CONNS(nconns)
static DataDirSyncMethod sync_method
static char bin_path[MAXPGPATH]
void create_xlog_or_symlink(void)
static char * system_functions_file
static _stringlist * extra_guc_names
static const char * dynamic_shared_memory_type
static void check_input(char *path)
static char * encodingid_to_string(int enc)
static void add_stringlist_item(_stringlist **listhead, const char *str)
static bool caught_signal
static const char * progname
static _stringlist * extra_guc_values
static bool test_specific_config_settings(int test_conns, int test_buffs)
#define AUTHTRUST_WARNING
static char * dictionary_file
static void writefile(char *path, char **lines)
static void setup_schema(FILE *cmdfd)
static void check_ok(void)
static char * system_constraints_file
static void set_null_conf(void)
static char * extra_options
static const char * find_matching_ts_config(const char *lc_type)
static const char * authmethodlocal
static const char *const boot_options
static void make_template0(FILE *cmdfd)
static char * info_schema_file
static void load_plpgsql(FILE *cmdfd)
static const char * default_text_search_config
static char * pretty_wal_size(int segment_count)
static void check_locale_name(int category, const char *locale, char **canonname)
static char * lc_monetary
static void icu_validate_locale(const char *loc_str)
static void get_su_pwd(void)
static void const char * fmt
static void const char fflush(stdout)
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_warning_hint(...)
#define pg_log_error_detail(...)
void pfree(void *pointer)
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 PgChecksumMode mode
#define DEFAULT_PGSOCKET_DIR
#define DEFAULT_XLOG_SEG_SIZE
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
#define DEFAULT_BGWRITER_FLUSH_AFTER
static char * pg_ctl_path
static char version_file[MAXPGPATH]
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
PGDLLIMPORT char * optarg
uint32 pg_prng_uint32(pg_prng_state *state)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
#define pg_encoding_to_char
#define pg_valid_server_encoding_id
#define pg_valid_server_encoding
#define pg_log_warning(...)
void get_share_path(const char *my_exec_path, char *ret_path)
void join_path_components(char *ret_path, const char *head, const char *tail)
char * last_dir_separator(const char *filename)
int pg_mkdir_p(char *path, int omode)
#define is_absolute_path(filename)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
void get_parent_directory(char *path)
int pg_check_dir(const char *dir)
const char * get_progname(const char *argv0)
pqsigfunc pqsignal(int signo, pqsigfunc func)
void make_native_path(char *filename)
#define PG_BACKEND_VERSIONSTR
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
size_t strlcpy(char *dst, const char *src, size_t siz)
char * escape_single_quotes_ascii(const char *src)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
static int fd(const char *x, int i)
static pg_prng_state prng_state
char * psprintf(const char *fmt,...)
void get_restricted_token(void)
bool rmtree(const char *path, bool rmtopdir)
char * simple_prompt(const char *prompt, bool echo)
int pg_strip_crlf(char *str)
bool pg_is_ascii(const char *str)
void appendShellString(PQExpBuffer buf, const char *str)
void initStringInfo(StringInfo str)
struct _stringlist * next
const char * get_user_name_or_exit(const char *progname)
#define symlink(oldpath, newpath)
#define IsValidWalSegSize(size)
#define DEFAULT_MAX_WAL_SEGS
#define DEFAULT_MIN_WAL_SEGS
static void infile(const char *name)