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"
96 "trust",
"reject",
"scram-sha-256",
"md5",
"password",
"ident",
"radius",
118 "trust",
"reject",
"scram-sha-256",
"md5",
"password",
"peer",
"radius",
207 #define AUTHTRUST_WARNING \
208 "# CAUTION: Configuring the system for local \"trust\" authentication\n" \
209 "# allows any local user to connect as any PostgreSQL user, including\n" \
210 "# the database superuser. If you do not trust all your local users,\n" \
211 "# use another authentication method.\n"
225 static const char *
backend_options =
"--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true -c log_checkpoints=false";
232 "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 char cmd[MAXPGPATH]; FILE *cmdfd
318 #define PG_CMD_OPEN \
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; \
374 for (datap =
data; *datap; datap++)
393 newentry->
next = NULL;
394 if (*listhead == NULL)
395 *listhead = newentry;
398 for (oldentry = *listhead; oldentry->
next; oldentry = oldentry->
next)
400 oldentry->
next = newentry;
421 toklen = strlen(
token);
422 replen = strlen(replacement);
423 diff = replen - toklen;
425 for (
int i = 0; lines[
i];
i++)
432 if ((where = strstr(lines[
i],
token)) == NULL)
439 pre = where - lines[
i];
443 memcpy(
newline + pre, replacement, replen);
445 strcpy(
newline + pre + replen, lines[
i] + pre + toklen);
471 bool mark_as_comment)
473 int namelen = strlen(guc_name);
486 for (
i = 0; lines[
i];
i++)
497 while (*where ==
'#' || isspace((
unsigned char) *where))
499 if (strncmp(where, guc_name, namelen) != 0)
502 while (isspace((
unsigned char) *where))
508 where = strrchr(where,
'#');
519 for (ptr = lines[
i]; ptr < where; ptr++)
522 oldindent += 8 - (oldindent % 8);
529 oldindent =
Max(oldindent, newindent + 1);
530 while (newindent < oldindent)
532 int newindent_if_tab = newindent + 8 - (newindent % 8);
534 if (newindent_if_tab <= oldindent)
537 newindent = newindent_if_tab;
558 if (lines[
i] == NULL)
584 #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
585 #define DIGITS "0123456789"
587 if (*guc_value ==
'\0')
589 if (strchr(
LETTERS, *guc_value))
595 if (strchr(
DIGITS, *guc_value))
598 guc_value += strspn(guc_value,
DIGITS);
600 if (strspn(guc_value,
LETTERS) == strlen(guc_value))
621 if ((
infile = fopen(path,
"r")) == NULL)
622 pg_fatal(
"could not open file \"%s\" for reading: %m", path);
627 result = (
char **)
pg_malloc(maxlines *
sizeof(
char *));
633 if (n >= maxlines - 1)
636 result = (
char **)
pg_realloc(result, maxlines *
sizeof(
char *));
665 if ((out_file = fopen(path,
"w")) == NULL)
666 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
667 for (line = lines; *line != NULL; line++)
669 if (fputs(*line, out_file) < 0)
670 pg_fatal(
"could not write file \"%s\": %m", path);
673 if (fclose(out_file))
674 pg_fatal(
"could not close file \"%s\": %m", path);
688 cmdfd = popen(command,
mode);
690 pg_log_error(
"could not execute command \"%s\": %m", command);
714 pg_log_info(
"removing contents of data directory \"%s\"",
717 pg_log_error(
"failed to remove contents of data directory");
730 pg_log_error(
"failed to remove contents of WAL directory");
737 pg_log_info(
"data directory \"%s\" not removed at user's request",
741 pg_log_info(
"WAL directory \"%s\" not removed at user's request",
760 pg_log_error_hint(
"Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
787 if (encoding_name && *encoding_name)
792 pg_fatal(
"\"%s\" is not a valid server encoding name",
793 encoding_name ? encoding_name :
"(null)");
809 {
"arabic",
"Arabic"},
811 {
"armenian",
"Armenian"},
813 {
"basque",
"Basque"},
815 {
"catalan",
"Catalan"},
817 {
"danish",
"Danish"},
821 {
"english",
"POSIX"},
823 {
"english",
"English"},
825 {
"finnish",
"Finnish"},
827 {
"french",
"French"},
829 {
"german",
"German"},
835 {
"hungarian",
"Hungarian"},
836 {
"indonesian",
"id"},
837 {
"indonesian",
"Indonesian"},
841 {
"italian",
"Italian"},
842 {
"lithuanian",
"lt"},
843 {
"lithuanian",
"Lithuanian"},
845 {
"nepali",
"Nepali"},
847 {
"norwegian",
"Norwegian"},
848 {
"portuguese",
"pt"},
849 {
"portuguese",
"Portuguese"},
852 {
"russian",
"Russian"},
854 {
"serbian",
"Serbian"},
856 {
"spanish",
"Spanish"},
858 {
"swedish",
"Swedish"},
862 {
"turkish",
"Turkish"},
864 {
"yiddish",
"Yiddish"},
896 *ptr !=
'_' && *ptr !=
'-' && *ptr !=
'.' && *ptr !=
'@')
932 if (
stat(path, &statbuf) != 0)
937 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
942 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
948 pg_log_error(
"file \"%s\" is not a regular file", path);
949 pg_log_error_hint(
"This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
964 if (extrapath == NULL)
970 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
973 pg_fatal(
"could not write file \"%s\": %m", path);
990 pg_fatal(
"could not open file \"%s\" for writing: %m", path);
992 pg_fatal(
"could not write file \"%s\": %m", path);
1013 #if defined(HAVE_SHM_OPEN) && !defined(__sun__)
1018 pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
1028 if ((
fd = shm_open(
name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
1034 if (errno != EEXIST)
1059 #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
1061 static const int trial_conns[] = {
1064 static const int trial_bufs[] = {
1065 16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
1066 1000, 900, 800, 700, 600, 500,
1067 400, 300, 200, 100, 50
1070 const int connslen =
sizeof(trial_conns) /
sizeof(
int);
1071 const int bufslen =
sizeof(trial_bufs) /
sizeof(
int);
1081 printf(
_(
"selecting dynamic shared memory implementation ... "));
1090 printf(
_(
"selecting default max_connections ... "));
1093 for (
i = 0;
i < connslen;
i++)
1095 test_conns = trial_conns[
i];
1100 ok_buffers = test_buffs;
1110 printf(
_(
"selecting default shared_buffers ... "));
1113 for (
i = 0;
i < bufslen;
i++)
1116 test_buffs = (trial_bufs[
i] * 8192) / BLCKSZ;
1117 if (test_buffs <= ok_buffers)
1119 test_buffs = ok_buffers;
1128 if ((
n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1133 printf(
_(
"selecting default time zone ... "));
1152 "\"%s\" --check %s %s "
1153 "-c max_connections=%d "
1154 "-c shared_buffers=%d "
1155 "-c dynamic_shared_memory_type=%s",
1157 test_conns, test_buffs,
1163 gnames = gnames->
next, gvalues = gvalues->
next)
1170 " < \"%s\" > \"%s\" 2>&1",
1190 if ((sz % 1024) == 0)
1191 snprintf(result, 14,
"%dGB", sz / 1024);
1210 fputs(
_(
"creating configuration files ... "),
stdout);
1221 if ((
n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
1222 snprintf(repltok,
sizeof(repltok),
"%dMB",
1225 snprintf(repltok,
sizeof(repltok),
"%dkB",
1246 if (strcmp(
lc_time,
"C") != 0)
1253 strcpy(repltok,
"iso, ymd");
1256 strcpy(repltok,
"iso, dmy");
1260 strcpy(repltok,
"iso, mdy");
1266 snprintf(repltok,
sizeof(repltok),
"pg_catalog.%s",
1297 DEF_PGPORT_STR,
true);
1299 #if DEFAULT_BACKEND_FLUSH_AFTER > 0
1300 snprintf(repltok,
sizeof(repltok),
"%dkB",
1306 #if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1307 snprintf(repltok,
sizeof(repltok),
"%dkB",
1313 #if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1314 snprintf(repltok,
sizeof(repltok),
"%dkB",
1320 #ifndef USE_PREFETCH
1360 gnames = gnames->
next, gvalues = gvalues->
next)
1363 gvalues->
str,
false);
1371 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1377 conflines[0] =
pg_strdup(
"# Do not edit this file manually!\n");
1378 conflines[1] =
pg_strdup(
"# It will be overwritten by the ALTER SYSTEM command.\n");
1379 conflines[2] = NULL;
1385 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1392 conflines =
replace_token(conflines,
"@remove-line-for-nolocal@",
"");
1403 struct addrinfo *gai_result;
1404 struct addrinfo hints;
1411 err = WSAStartup(MAKEWORD(2, 2), &wsaData);
1415 hints.ai_flags = AI_NUMERICHOST;
1416 hints.ai_family = AF_UNSPEC;
1417 hints.ai_socktype = 0;
1418 hints.ai_protocol = 0;
1419 hints.ai_addrlen = 0;
1420 hints.ai_canonname = NULL;
1421 hints.ai_addr = NULL;
1422 hints.ai_next = NULL;
1425 getaddrinfo(
"::1", NULL, &hints, &gai_result) != 0)
1429 "#host all all ::1");
1431 "host replication all ::1",
1432 "#host replication all ::1");
1441 "@authmethodlocal@",
1452 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1463 pg_fatal(
"could not change permissions of \"%s\": %m", path);
1481 printf(
_(
"running bootstrap script ... "));
1488 snprintf(headerline,
sizeof(headerline),
"# PostgreSQL %s\n",
1491 if (strcmp(headerline, *bki_lines) != 0)
1493 pg_log_error(
"input file \"%s\" does not belong to PostgreSQL %s",
1508 (
sizeof(
Pointer) == 4) ?
"i" :
"d");
1538 "\"%s\" --boot -X %d %s %s %s %s",
1543 debug ?
"-d 5" :
"");
1548 for (line = bki_lines; *line != NULL; line++)
1571 PG_CMD_PUTS(
"REVOKE ALL ON pg_authid FROM public;\n\n");
1595 pwd1 =
simple_prompt(
"Enter new superuser password: ",
false);
1597 if (strcmp(pwd1, pwd2) != 0)
1599 fprintf(stderr,
_(
"Passwords didn't match.\n"));
1617 pg_fatal(
"could not open file \"%s\" for reading: %m",
1623 pg_fatal(
"could not read password from file \"%s\": %m",
1626 pg_fatal(
"password file \"%s\" is empty",
1647 PG_CMD_PUTS(
"SELECT pg_stop_making_pinned_objects();\n\n");
1660 for (
char **line = lines; *line != NULL; line++)
1679 "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
1680 "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
1681 "INSERT INTO pg_description "
1682 " SELECT p_oid, 'pg_proc'::regclass, 0, "
1683 " 'implementation of ' || oprname || ' operator' "
1685 " WHERE NOT EXISTS (SELECT 1 FROM pg_description "
1686 " WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
1687 " AND NOT EXISTS (SELECT 1 FROM pg_description "
1688 " WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
1689 " AND description LIKE 'deprecated%');\n\n");
1703 PG_CMD_PRINTF(
"INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, colliculocale)"
1704 "VALUES (pg_nextoid('pg_catalog.pg_collation', 'oid', 'pg_catalog.pg_collation_oid_index'), 'unicode', 'pg_catalog'::regnamespace, %u, '%c', true, -1, 'und');\n\n",
1705 BOOTSTRAP_SUPERUSERID, COLLPROVIDER_ICU);
1707 PG_CMD_PRINTF(
"INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype)"
1708 "VALUES (pg_nextoid('pg_catalog.pg_collation', 'oid', 'pg_catalog.pg_collation_oid_index'), 'ucs_basic', 'pg_catalog'::regnamespace, %u, '%c', true, %d, 'C', 'C');\n\n",
1709 BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC,
PG_UTF8);
1712 PG_CMD_PUTS(
"SELECT pg_import_system_collations('pg_catalog');\n\n");
1738 " SET relacl = (SELECT array_agg(a.acl) FROM "
1739 " (SELECT E'=r/\"%s\"' as acl "
1740 " UNION SELECT unnest(pg_catalog.acldefault("
1741 " CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE)
" THEN 's' "
1742 " ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID)
"::oid))"
1744 " WHERE relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1747 " AND relacl IS NULL;\n\n",
1749 PG_CMD_PUTS(
"GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
1750 PG_CMD_PUTS(
"REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
1752 " (objoid, classoid, objsubid, initprivs, privtype)"
1755 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1762 " relacl IS NOT NULL"
1763 " AND relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1767 " (objoid, classoid, objsubid, initprivs, privtype)"
1770 " (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
1771 " pg_attribute.attnum,"
1772 " pg_attribute.attacl,"
1776 " JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
1778 " pg_attribute.attacl IS NOT NULL"
1779 " AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION)
", "
1783 " (objoid, classoid, objsubid, initprivs, privtype)"
1786 " (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
1793 " proacl IS NOT NULL;\n\n");
1795 " (objoid, classoid, objsubid, initprivs, privtype)"
1798 " (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
1805 " typacl IS NOT NULL;\n\n");
1807 " (objoid, classoid, objsubid, initprivs, privtype)"
1810 " (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
1817 " lanacl IS NOT NULL;\n\n");
1819 " (objoid, classoid, objsubid, initprivs, privtype)"
1822 " (SELECT oid FROM pg_class WHERE "
1823 " relname = 'pg_largeobject_metadata'),"
1828 " pg_largeobject_metadata"
1830 " lomacl IS NOT NULL;\n\n");
1832 " (objoid, classoid, objsubid, initprivs, privtype)"
1835 " (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
1842 " nspacl IS NOT NULL;\n\n");
1844 " (objoid, classoid, objsubid, initprivs, privtype)"
1847 " (SELECT oid FROM pg_class WHERE "
1848 " relname = 'pg_foreign_data_wrapper'),"
1853 " pg_foreign_data_wrapper"
1855 " fdwacl IS NOT NULL;\n\n");
1857 " (objoid, classoid, objsubid, initprivs, privtype)"
1860 " (SELECT oid FROM pg_class "
1861 " WHERE relname = 'pg_foreign_server'),"
1866 " pg_foreign_server"
1868 " srvacl IS NOT NULL;\n\n");
1878 char *letterversion;
1886 ptr = vstr + (strlen(vstr) - 1);
1887 while (ptr != vstr && (*ptr < '0' || *ptr >
'9'))
1889 letterversion = ptr + 1;
1890 major = strtol(vstr, &endptr, 10);
1892 minor = strtol(endptr + 1, &endptr, 10);
1894 micro = strtol(endptr + 1, &endptr, 10);
1896 major, minor, micro, letterversion);
1907 PG_CMD_PRINTF(
"UPDATE information_schema.sql_implementation_info "
1908 " SET character_value = '%s' "
1909 " WHERE implementation_info_name = 'DBMS VERSION';\n\n",
1913 " (feature_id, feature_name, sub_feature_id, "
1914 " sub_feature_name, is_supported, comments) "
1961 PG_CMD_PUTS(
"CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
1963 " STRATEGY = file_copy;\n\n");
1970 PG_CMD_PUTS(
"UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
1975 PG_CMD_PUTS(
"UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
1982 PG_CMD_PUTS(
"REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
1983 PG_CMD_PUTS(
"REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
1985 PG_CMD_PUTS(
"COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
2004 " STRATEGY = file_copy;\n\n");
2005 PG_CMD_PUTS(
"COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
2051 printf(
_(
"could not write to child process: %s\n"),
2065 static inline size_t
2068 return strftime(s, max,
fmt,
tm);
2095 memset(&testtime, 0,
sizeof(testtime));
2096 testtime.tm_mday = 22;
2097 testtime.tm_mon = 10;
2098 testtime.tm_year = 133;
2108 posM = strstr(
buf,
"11");
2109 posD = strstr(
buf,
"22");
2110 posY = strstr(
buf,
"33");
2112 if (!posM || !posD || !posY)
2115 if (posY < posM && posM < posD)
2117 else if (posD < posM)
2161 if (
res && canonname)
2166 pg_fatal(
"failed to restore old locale \"%s\"", save);
2184 pg_fatal(
"invalid locale settings; check LANG and LC_* environment variables");
2202 if (!(locale_enc == user_enc ||
2212 "selected locale uses (%s) do not match. This would lead to "
2213 "misbehavior in various character string processing functions.",
2217 "or choose a matching combination.",
2235 pg_log_error_detail(
"The encoding you selected (%s) is not supported with the ICU provider.",
2238 "or choose a matching combination.",
2253 UCollator *collator;
2261 pg_fatal(
"could not open collator for locale \"%s\": %s",
2264 pg_fatal(
"could not open collator for default locale: %s",
2274 default_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
2278 ucol_close(collator);
2279 pg_fatal(
"could not determine default ICU locale");
2285 ucol_close(collator);
2331 #if defined(LC_MESSAGES) && !defined(WIN32)
2349 pg_fatal(
"ICU is not supported in this build");
2360 printf(
_(
"%s initializes a PostgreSQL database cluster.\n\n"),
progname);
2364 printf(
_(
" -A, --auth=METHOD default authentication method for local connections\n"));
2365 printf(
_(
" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
2366 printf(
_(
" --auth-local=METHOD default authentication method for local-socket connections\n"));
2367 printf(
_(
" [-D, --pgdata=]DATADIR location for this database cluster\n"));
2368 printf(
_(
" -E, --encoding=ENCODING set default encoding for new databases\n"));
2369 printf(
_(
" -g, --allow-group-access allow group read/execute on data directory\n"));
2370 printf(
_(
" --icu-locale=LOCALE set ICU locale ID for new databases\n"));
2371 printf(
_(
" --icu-rules=RULES set additional ICU collation rules for new databases\n"));
2372 printf(
_(
" -k, --data-checksums use data page checksums\n"));
2373 printf(
_(
" --locale=LOCALE set default locale for new databases\n"));
2374 printf(
_(
" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
2375 " --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
2376 " set default locale in the respective category for\n"
2377 " new databases (default taken from environment)\n"));
2378 printf(
_(
" --no-locale equivalent to --locale=C\n"));
2379 printf(
_(
" --locale-provider={libc|icu}\n"
2380 " set default locale provider for new databases\n"));
2381 printf(
_(
" --pwfile=FILE read password for the new superuser from file\n"));
2382 printf(
_(
" -T, --text-search-config=CFG\n"
2383 " default text search configuration\n"));
2384 printf(
_(
" -U, --username=NAME database superuser name\n"));
2385 printf(
_(
" -W, --pwprompt prompt for a password for the new superuser\n"));
2386 printf(
_(
" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
2387 printf(
_(
" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
2388 printf(
_(
"\nLess commonly used options:\n"));
2389 printf(
_(
" -c, --set NAME=VALUE override default setting for server parameter\n"));
2390 printf(
_(
" -d, --debug generate lots of debugging output\n"));
2391 printf(
_(
" --discard-caches set debug_discard_caches=1\n"));
2392 printf(
_(
" -L DIRECTORY where to find the input files\n"));
2393 printf(
_(
" -n, --no-clean do not clean up after errors\n"));
2394 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
2395 printf(
_(
" --no-instructions do not print instructions for next steps\n"));
2396 printf(
_(
" -s, --show show internal settings\n"));
2397 printf(
_(
" -S, --sync-only only sync database files to disk, then exit\n"));
2398 printf(
_(
"\nOther options:\n"));
2399 printf(
_(
" -V, --version output version information, then exit\n"));
2400 printf(
_(
" -?, --help show this help, then exit\n"));
2401 printf(
_(
"\nIf the data directory is not specified, the environment variable PGDATA\n"
2403 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2404 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2410 if (*authmethod == NULL)
2413 *authmethod =
"trust";
2420 const char *
const *p;
2422 for (p = valid_methods; *p; p++)
2424 if (strcmp(authmethod, *p) == 0)
2427 if (strchr(authmethod,
' '))
2428 if (strncmp(authmethod, *p, (authmethod - strchr(authmethod,
' '))) == 0)
2432 pg_fatal(
"invalid authentication method \"%s\" for \"%s\" connections",
2433 authmethod, conntype);
2446 pg_fatal(
"must specify a password for the superuser to enable password authentication");
2453 char *pgdata_get_env;
2457 pgdata_get_env = getenv(
"PGDATA");
2458 if (pgdata_get_env && strlen(pgdata_get_env))
2466 pg_log_error_hint(
"You must identify the directory where the data for this database system "
2467 "will reside. Do this with either the invocation option -D or the "
2468 "environment variable PGDATA.");
2483 pg_fatal(
"could not set environment");
2501 pg_fatal(
"program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
2504 pg_fatal(
"program \"%s\" was found by \"%s\" but was not the same version as %s",
2519 pg_fatal(
"input file location must be an absolute path");
2536 printf(
_(
"The database cluster will be initialized with locale \"%s\".\n"),
lc_ctype);
2539 printf(
_(
"The database cluster will be initialized with this locale configuration:\n"));
2545 " LC_MESSAGES: %s\n"
2546 " LC_MONETARY: %s\n"
2570 if (ctype_enc == -1)
2573 pg_log_error(
"could not find suitable encoding for locale \"%s\"",
2588 printf(
_(
"Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2589 "The default database encoding will be set to \"%s\" instead.\n"),
2593 pg_log_error(
"locale \"%s\" requires unsupported encoding \"%s\"",
2605 printf(
_(
"The default database encoding has accordingly been set to \"%s\".\n"),
2640 "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
2641 "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2642 "POSTGRESQL_CONF_SAMPLE=%s\n"
2643 "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
2674 pg_log_info(
"could not find suitable text search configuration for locale \"%s\"",
2683 if (checkmatch == NULL)
2685 pg_log_warning(
"suitable text search configuration for locale \"%s\" is unknown",
2690 pg_log_warning(
"specified text search configuration \"%s\" might not match locale \"%s\"",
2695 printf(
_(
"The default text search configuration will be set to \"%s\".\n"),
2738 printf(
_(
"creating directory %s ... "),
2752 printf(
_(
"fixing permissions on existing directory %s ... "),
2757 pg_fatal(
"could not change permissions of directory \"%s\": %m",
2773 pg_log_error_hint(
"If you want to create a new database system, either remove or empty "
2774 "the directory \"%s\" or run %s "
2775 "with an argument other than \"%s\".",
2802 pg_fatal(
"WAL directory location must be an absolute path");
2809 printf(
_(
"creating directory %s ... "),
2814 pg_fatal(
"could not create directory \"%s\": %m",
2824 printf(
_(
"fixing permissions on existing directory %s ... "),
2829 pg_fatal(
"could not change permissions of directory \"%s\": %m",
2845 pg_log_error_hint(
"If you want to store the WAL there, either remove or empty the directory \"%s\".",
2855 pg_fatal(
"could not create symbolic link \"%s\": %m",
2862 pg_fatal(
"could not create directory \"%s\": %m",
2874 pg_log_error_detail(
"It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
2875 else if (
error == 3)
2876 pg_log_error_detail(
"It contains a lost+found directory, perhaps due to it being a mount point.");
2878 pg_log_error_hint(
"Using a mount point directly as the data directory is not recommended.\n"
2879 "Create a subdirectory under the mount point.");
2904 printf(
_(
"creating subdirectories ... "));
2918 pg_fatal(
"could not create directory \"%s\": %m", path);
2947 fputs(
_(
"performing post-bootstrap initialization ... "),
stdout);
2951 "\"%s\" %s %s template1 >%s",
2999 static struct option long_options[] = {
3045 char *effective_user;
3063 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
3068 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
3070 puts(
"initdb (PostgreSQL) " PG_VERSION);
3077 while ((
c =
getopt_long(argc, argv,
"A:c:dD:E:gkL:nNsST:U:WX:",
3078 long_options, &option_index)) != -1)
3104 char *equals = strchr(
buf,
'=');
3133 printf(
_(
"Running in debug mode.\n"));
3137 printf(
_(
"Running in no-clean mode. Mistakes will not be cleaned up.\n"));
3199 "-c debug_discard_caches=1");
3202 if (strcmp(
optarg,
"icu") == 0)
3204 else if (strcmp(
optarg,
"libc") == 0)
3235 pg_log_error(
"too many command-line arguments (first is \"%s\")",
3242 pg_fatal(
"%s cannot be specified unless locale provider \"%s\" is chosen",
3243 "--icu-locale",
"icu");
3246 pg_fatal(
"%s cannot be specified unless locale provider \"%s\" is chosen",
3247 "--icu-rules",
"icu");
3260 fputs(
_(
"syncing data to disk ... "),
stdout);
3262 fsync_pgdata(
pg_data, PG_VERSION_NUM);
3268 pg_fatal(
"password prompt and password file cannot be specified together");
3290 pg_fatal(
"argument of --wal-segsize must be a number");
3292 pg_fatal(
"argument of --wal-segsize must be a power of 2 between 1 and 1024");
3301 effective_user =
get_id();
3305 if (strncmp(
username,
"pg_", 3) == 0)
3306 pg_fatal(
"superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"",
username);
3308 printf(
_(
"The files belonging to this database system will be owned "
3310 "This user must also own the server process.\n\n"),
3324 printf(
_(
"Data page checksums are enabled.\n"));
3326 printf(
_(
"Data page checksums are disabled.\n"));
3337 fputs(
_(
"syncing data to disk ... "),
stdout);
3339 fsync_pgdata(
pg_data, PG_VERSION_NUM);
3343 printf(
_(
"\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
3348 pg_log_warning(
"enabling \"trust\" authentication for local connections");
3349 pg_log_warning_hint(
"You can change this by editing pg_hba.conf or using the option -A, or "
3350 "--auth-local and --auth-host, the next time you run initdb.");
3361 strlcpy(pg_ctl_path, argv[0],
sizeof(pg_ctl_path));
3381 printf(
_(
"\nSuccess. You can now start the database server using:\n\n"
3383 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
int pg_valid_server_encoding_id(int encoding)
int pg_valid_server_encoding(const char *name)
bool is_encoding_supported_by_icu(int encoding)
const char * pg_encoding_to_char(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
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 void check_icu_locale(void)
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 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 char * str_wal_segment_size_mb
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 const char *const auth_methods_local[]
static char ** replace_token(char **lines, const char *token, const char *replacement)
static const char * backend_options
static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
static void setlocales(void)
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 void setup_config(void)
static char * lc_messages
static void setup_privileges(FILE *cmdfd)
static void write_version_file(const char *extrapath)
static const char * boot_options
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 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 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 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 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)
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 version_file[MAXPGPATH]
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
PGDLLIMPORT char * optarg
struct pg_locale_struct default_locale
uint32 pg_prng_uint32(pg_prng_state *state)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
static void static void status(const char *fmt,...) pg_attribute_printf(1
#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)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
static int fd(const char *x, int i)
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)
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)