2003-11-10 23:51:16 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* initdb --- initialize a PostgreSQL installation
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* initdb creates (initializes) a PostgreSQL database cluster (site,
|
|
|
|
* instance, installation, whatever). A database cluster is a
|
2006-06-18 17:38:37 +02:00
|
|
|
* collection of PostgreSQL databases all managed by the same server.
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* To create the database cluster, we create the directory that contains
|
|
|
|
* all its data, create the files that hold the global tables, create
|
2005-06-21 06:02:34 +02:00
|
|
|
* a few other control files for it, and create three databases: the
|
|
|
|
* template databases "template0" and "template1", and a default user
|
|
|
|
* database "postgres".
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* The template databases are ordinary PostgreSQL databases. template0
|
|
|
|
* is never supposed to change after initdb, whereas template1 can be
|
|
|
|
* changed to add site-local standard data. Either one can be copied
|
|
|
|
* to produce a new database.
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2005-06-21 06:02:34 +02:00
|
|
|
* For largely-historical reasons, the template1 database is the one built
|
|
|
|
* by the basic bootstrap process. After it is complete, template0 and
|
|
|
|
* the default database, postgres, are made just by copying template1.
|
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* To create template1, we run the postgres (backend) program in bootstrap
|
|
|
|
* mode and feed it data from the postgres.bki library file. After this
|
|
|
|
* initial bootstrap phase, some additional stuff is created by normal
|
|
|
|
* SQL commands fed to a standalone backend. Some of those commands are
|
|
|
|
* just embedded into this program (yeah, it's ugly), but larger chunks
|
|
|
|
* are taken from script files.
|
|
|
|
*
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* The program has some memory leakage - it isn't worth cleaning it up.
|
2003-11-14 00:46:31 +01:00
|
|
|
*
|
|
|
|
* This is a C implementation of the previous shell script for setting up a
|
|
|
|
* PostgreSQL cluster location, and should be highly compatible with it.
|
|
|
|
* author of C translation: Andrew Dunstan mailto:andrew@dunslane.net
|
|
|
|
*
|
|
|
|
* This code is released under the terms of the PostgreSQL License.
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2003-11-14 00:46:31 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/bin/initdb/initdb.c
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres_fe.h"
|
|
|
|
|
|
|
|
#include <dirent.h>
|
2012-07-13 23:16:58 +02:00
|
|
|
#include <fcntl.h>
|
2022-08-13 23:53:28 +02:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
2003-11-10 23:51:16 +01:00
|
|
|
#include <sys/stat.h>
|
2023-03-09 19:52:41 +01:00
|
|
|
#ifdef USE_ICU
|
|
|
|
#include <unicode/ucol.h>
|
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
2005-12-09 16:51:14 +01:00
|
|
|
#include <time.h>
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2013-10-11 01:38:56 +02:00
|
|
|
#ifdef HAVE_SHM_OPEN
|
|
|
|
#include "sys/mman.h"
|
|
|
|
#endif
|
|
|
|
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
#include "access/xlog_internal.h"
|
2018-04-08 19:59:52 +02:00
|
|
|
#include "catalog/pg_authid_d.h"
|
2018-04-09 20:39:58 +02:00
|
|
|
#include "catalog/pg_class_d.h" /* pgrminclude ignore */
|
2018-04-08 19:59:52 +02:00
|
|
|
#include "catalog/pg_collation_d.h"
|
Rethink method for assigning OIDs to the template0 and postgres DBs.
Commit aa0105141 assigned fixed OIDs to template0 and postgres
in a very ad-hoc way. Notably, instead of teaching Catalog.pm
about these OIDs, the unused_oids script was just hacked to
not show them as unused. That's problematic since, for example,
duplicate_oids wouldn't report any future conflict. Hence,
invent a macro DECLARE_OID_DEFINING_MACRO() that can be used to
define an OID that is known to Catalog.pm and will participate
in duplicate-detection as well as renumbering by renumber_oids.pl.
(We don't anticipate renumbering these particular OIDs, but we
might as well build out all the Catalog.pm infrastructure while
we're here.)
Another issue is that aa0105141 neglected to touch IsPinnedObject,
with the result that it now claimed template0 and postgres are
pinned. The right thing to do there seems to be to teach it that
no database is pinned, since in fact DROP DATABASE doesn't check
for pinned-ness (and at least for these cases, that is an
intentional choice). It's not clear whether this wrong answer
had any visible effect, but perhaps it could have resulted in
erroneous management of dependency entries.
In passing, rename the TemplateDbOid macro to Template1DbOid
to reduce confusion (likely we should have done that way back
when we invented template0, but we didn't), and rename the
OID macros for template0 and postgres to have a similar style.
There are no changes to postgres.bki here, so no need for a
catversion bump.
Discussion: https://postgr.es/m/2935358.1650479692@sss.pgh.pa.us
2022-04-21 22:23:12 +02:00
|
|
|
#include "catalog/pg_database_d.h" /* pgrminclude ignore */
|
2018-04-07 23:45:39 +02:00
|
|
|
#include "common/file_perm.h"
|
2016-09-29 18:00:00 +02:00
|
|
|
#include "common/file_utils.h"
|
2019-05-14 20:19:49 +02:00
|
|
|
#include "common/logging.h"
|
Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.
Standardize on xoroshiro128** as our basic PRNG algorithm, eliminating
a bunch of platform dependencies as well as fundamentally-obsolete PRNG
code. In addition, this API replacement will ease replacing the
algorithm again in future, should that become necessary.
xoroshiro128** is a few percent slower than the drand48 family,
but it can produce full-width 64-bit random values not only 48-bit,
and it should be much more trustworthy. It's likely to be noticeably
faster than the platform's random(), depending on which platform you
are thinking about; and we can have non-global state vectors easily,
unlike with random(). It is not cryptographically strong, but neither
are the functions it replaces.
Fabien Coelho, reviewed by Dean Rasheed, Aleksander Alekseev, and myself
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2105241211230.165418@pseudo
2021-11-29 03:32:36 +01:00
|
|
|
#include "common/pg_prng.h"
|
2015-03-30 23:07:52 +02:00
|
|
|
#include "common/restricted_token.h"
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
#include "common/string.h"
|
2014-01-11 00:03:28 +01:00
|
|
|
#include "common/username.h"
|
2016-11-26 00:36:10 +01:00
|
|
|
#include "fe_utils/string_utils.h"
|
2003-11-13 02:09:24 +01:00
|
|
|
#include "getopt_long.h"
|
2016-11-26 00:36:10 +01:00
|
|
|
#include "mb/pg_wchar.h"
|
2005-12-09 16:51:14 +01:00
|
|
|
#include "miscadmin.h"
|
2003-11-13 02:09:24 +01:00
|
|
|
|
2015-05-29 19:05:16 +02:00
|
|
|
|
2011-09-09 23:59:11 +02:00
|
|
|
/* Ideally this would be in a .h file, but it hardly seems worth the trouble */
|
|
|
|
extern const char *select_default_timezone(const char *share_path);
|
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
static const char *const auth_methods_host[] = {
|
2017-04-18 13:50:50 +02:00
|
|
|
"trust", "reject", "scram-sha-256", "md5", "password", "ident", "radius",
|
2012-02-01 20:18:55 +01:00
|
|
|
#ifdef ENABLE_GSS
|
|
|
|
"gss",
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SSPI
|
|
|
|
"sspi",
|
|
|
|
#endif
|
|
|
|
#ifdef USE_PAM
|
|
|
|
"pam", "pam ",
|
|
|
|
#endif
|
2016-04-08 19:51:54 +02:00
|
|
|
#ifdef USE_BSD_AUTH
|
|
|
|
"bsd",
|
|
|
|
#endif
|
2012-02-01 20:18:55 +01:00
|
|
|
#ifdef USE_LDAP
|
|
|
|
"ldap",
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SSL
|
|
|
|
"cert",
|
|
|
|
#endif
|
2015-12-18 01:38:21 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const char *const auth_methods_local[] = {
|
2017-04-18 13:50:50 +02:00
|
|
|
"trust", "reject", "scram-sha-256", "md5", "password", "peer", "radius",
|
2012-02-01 20:18:55 +01:00
|
|
|
#ifdef USE_PAM
|
|
|
|
"pam", "pam ",
|
|
|
|
#endif
|
2016-04-08 19:51:54 +02:00
|
|
|
#ifdef USE_BSD_AUTH
|
|
|
|
"bsd",
|
|
|
|
#endif
|
2012-02-01 20:18:55 +01:00
|
|
|
#ifdef USE_LDAP
|
|
|
|
"ldap",
|
|
|
|
#endif
|
2015-12-18 01:38:21 +01:00
|
|
|
NULL
|
|
|
|
};
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/*
|
|
|
|
* these values are passed in by makefile defines
|
|
|
|
*/
|
2005-03-11 16:36:27 +01:00
|
|
|
static char *share_path = NULL;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
/* values to be obtained from arguments */
|
2017-08-31 04:28:36 +02:00
|
|
|
static char *pg_data = NULL;
|
|
|
|
static char *encoding = NULL;
|
|
|
|
static char *locale = NULL;
|
|
|
|
static char *lc_collate = NULL;
|
|
|
|
static char *lc_ctype = NULL;
|
|
|
|
static char *lc_monetary = NULL;
|
|
|
|
static char *lc_numeric = NULL;
|
|
|
|
static char *lc_time = NULL;
|
|
|
|
static char *lc_messages = NULL;
|
2023-03-09 19:52:41 +01:00
|
|
|
#ifdef USE_ICU
|
|
|
|
static char locale_provider = COLLPROVIDER_ICU;
|
|
|
|
#else
|
2022-03-17 11:11:21 +01:00
|
|
|
static char locale_provider = COLLPROVIDER_LIBC;
|
2023-03-09 19:52:41 +01:00
|
|
|
#endif
|
2022-03-17 11:11:21 +01:00
|
|
|
static char *icu_locale = NULL;
|
2023-03-08 16:35:42 +01:00
|
|
|
static char *icu_rules = NULL;
|
2017-08-31 04:28:36 +02:00
|
|
|
static const char *default_text_search_config = NULL;
|
|
|
|
static char *username = NULL;
|
2005-03-11 16:36:27 +01:00
|
|
|
static bool pwprompt = false;
|
|
|
|
static char *pwfilename = NULL;
|
2016-08-30 21:25:01 +02:00
|
|
|
static char *superuser_password = NULL;
|
2017-08-31 04:28:36 +02:00
|
|
|
static const char *authmethodhost = NULL;
|
|
|
|
static const char *authmethodlocal = NULL;
|
2005-03-11 16:36:27 +01:00
|
|
|
static bool debug = false;
|
|
|
|
static bool noclean = false;
|
2021-01-17 14:28:17 +01:00
|
|
|
static bool noinstructions = false;
|
2012-07-13 23:16:58 +02:00
|
|
|
static bool do_sync = true;
|
2012-12-04 04:47:59 +01:00
|
|
|
static bool sync_only = false;
|
2005-03-11 16:36:27 +01:00
|
|
|
static bool show_setting = false;
|
2013-03-22 14:54:07 +01:00
|
|
|
static bool data_checksums = false;
|
2017-08-31 04:28:36 +02:00
|
|
|
static char *xlog_dir = NULL;
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
static char *str_wal_segment_size_mb = NULL;
|
|
|
|
static int wal_segment_size_mb;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* internal vars */
|
2005-03-11 16:36:27 +01:00
|
|
|
static const char *progname;
|
2017-08-31 04:28:36 +02:00
|
|
|
static int encodingid;
|
2005-03-11 16:36:27 +01:00
|
|
|
static char *bki_file;
|
|
|
|
static char *hba_file;
|
|
|
|
static char *ident_file;
|
|
|
|
static char *conf_file;
|
2007-08-21 03:11:32 +02:00
|
|
|
static char *dictionary_file;
|
2005-03-11 16:36:27 +01:00
|
|
|
static char *info_schema_file;
|
|
|
|
static char *features_file;
|
2021-01-30 19:14:31 +01:00
|
|
|
static char *system_constraints_file;
|
2021-04-17 00:20:42 +02:00
|
|
|
static char *system_functions_file;
|
2005-03-11 16:36:27 +01:00
|
|
|
static char *system_views_file;
|
2018-12-29 13:21:57 +01:00
|
|
|
static bool success = false;
|
2005-03-11 16:36:27 +01:00
|
|
|
static bool made_new_pgdata = false;
|
|
|
|
static bool found_existing_pgdata = false;
|
2007-01-06 20:40:00 +01:00
|
|
|
static bool made_new_xlogdir = false;
|
|
|
|
static bool found_existing_xlogdir = false;
|
2005-03-11 16:36:27 +01:00
|
|
|
static char infoversion[100];
|
|
|
|
static bool caught_signal = false;
|
|
|
|
static bool output_failed = false;
|
|
|
|
static int output_errno = 0;
|
2012-11-30 22:45:08 +01:00
|
|
|
static char *pgdata_native;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
/* defaults */
|
2005-03-11 16:36:27 +01:00
|
|
|
static int n_connections = 10;
|
|
|
|
static int n_buffers = 50;
|
2018-08-10 20:14:27 +02:00
|
|
|
static const char *dynamic_shared_memory_type = NULL;
|
Attempt to identify system timezone by reading /etc/localtime symlink.
On many modern platforms, /etc/localtime is a symlink to a file within the
IANA database. Reading the symlink lets us find out the name of the system
timezone directly, without going through the brute-force search embodied in
scan_available_timezones(). This shortens the runtime of initdb by some
tens of ms, which is helpful for the buildfarm, and it also allows us to
reliably select the same zone name the system was actually configured for,
rather than possibly choosing one of IANA's many zone aliases. (For
example, in a system configured for "Asia/Tokyo", the brute-force search
would not choose that name but its alias "Japan", on the grounds of the
latter string being shorter. More surprisingly, "Navajo" is preferred
to either "America/Denver" or "US/Mountain", as seen in an old complaint
from Josh Berkus.)
If /etc/localtime doesn't exist, or isn't a symlink, or we can't make
sense of its contents, or the contents match a zone we know but that
zone doesn't match the observed behavior of localtime(), fall back to
the brute-force search.
Also, tweak initdb so that it prints the zone name it selected.
In passing, replace the last few references to the "Olson" database in
code comments with "IANA", as that's been our preferred term since
commit b2cbced9e.
Patch by me, per a suggestion from Robert Haas; review by Michael Paquier
Discussion: https://postgr.es/m/7408.1525812528@sss.pgh.pa.us
2018-09-13 18:36:21 +02:00
|
|
|
static const char *default_timezone = NULL;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2004-08-01 07:59:13 +02:00
|
|
|
/*
|
|
|
|
* Warning messages for authentication methods
|
|
|
|
*/
|
2005-03-11 16:36:27 +01:00
|
|
|
#define AUTHTRUST_WARNING \
|
2010-01-26 07:58:39 +01:00
|
|
|
"# 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"
|
2019-07-22 19:28:25 +02:00
|
|
|
static bool authwarning = false;
|
2004-08-01 07:59:13 +02:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/*
|
|
|
|
* Centralized knowledge of switches to pass to backend
|
|
|
|
*
|
2012-07-13 23:16:58 +02:00
|
|
|
* Note: we run the backend with -F (fsync disabled) and then do a single
|
|
|
|
* pass of fsync'ing at the end. This is faster than fsync'ing each step.
|
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* Note: in the shell-script version, we also passed PGDATA as a -D switch,
|
|
|
|
* but here it is more convenient to pass it as an environment variable
|
|
|
|
* (no quoting to worry about).
|
|
|
|
*/
|
2021-12-13 15:48:04 +01:00
|
|
|
static const char *boot_options = "-F -c log_checkpoints=false";
|
|
|
|
static const char *backend_options = "--single -F -O -j -c search_path=pg_catalog -c exit_on_error=true -c log_checkpoints=false";
|
2003-11-14 00:46:31 +01:00
|
|
|
|
2021-07-01 19:33:05 +02:00
|
|
|
/* Additional switches to pass to backend (either boot or standalone) */
|
|
|
|
static char *extra_options = "";
|
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
static const char *const subdirs[] = {
|
2012-11-30 22:45:08 +01:00
|
|
|
"global",
|
2016-10-20 17:24:37 +02:00
|
|
|
"pg_wal/archive_status",
|
Keep track of transaction commit timestamps
Transactions can now set their commit timestamp directly as they commit,
or an external transaction commit timestamp can be fed from an outside
system using the new function TransactionTreeSetCommitTsData(). This
data is crash-safe, and truncated at Xid freeze point, same as pg_clog.
This module is disabled by default because it causes a performance hit,
but can be enabled in postgresql.conf requiring only a server restart.
A new test in src/test/modules is included.
Catalog version bumped due to the new subdirectory within PGDATA and a
couple of new SQL functions.
Authors: Álvaro Herrera and Petr Jelínek
Reviewed to varying degrees by Michael Paquier, Andres Freund, Robert
Haas, Amit Kapila, Fujii Masao, Jaime Casanova, Simon Riggs, Steven
Singer, Peter Eisentraut
2014-12-03 15:53:02 +01:00
|
|
|
"pg_commit_ts",
|
2013-10-10 03:05:02 +02:00
|
|
|
"pg_dynshmem",
|
2012-11-30 22:45:08 +01:00
|
|
|
"pg_notify",
|
|
|
|
"pg_serial",
|
|
|
|
"pg_snapshots",
|
|
|
|
"pg_subtrans",
|
|
|
|
"pg_twophase",
|
2016-01-07 21:22:01 +01:00
|
|
|
"pg_multixact",
|
2012-11-30 22:45:08 +01:00
|
|
|
"pg_multixact/members",
|
|
|
|
"pg_multixact/offsets",
|
|
|
|
"base",
|
|
|
|
"base/1",
|
2014-02-01 04:45:17 +01:00
|
|
|
"pg_replslot",
|
2012-11-30 22:45:08 +01:00
|
|
|
"pg_tblspc",
|
2013-02-18 21:56:08 +01:00
|
|
|
"pg_stat",
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
2014-03-03 22:32:18 +01:00
|
|
|
"pg_stat_tmp",
|
2017-03-17 14:46:58 +01:00
|
|
|
"pg_xact",
|
2014-07-02 21:07:47 +02:00
|
|
|
"pg_logical",
|
|
|
|
"pg_logical/snapshots",
|
|
|
|
"pg_logical/mappings"
|
2012-11-30 22:45:08 +01:00
|
|
|
};
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2004-05-11 23:57:15 +02:00
|
|
|
/* path to 'initdb' binary directory */
|
2005-03-11 16:36:27 +01:00
|
|
|
static char bin_path[MAXPGPATH];
|
|
|
|
static char backend_exec[MAXPGPATH];
|
2004-05-10 22:51:58 +02:00
|
|
|
|
2004-12-27 21:39:21 +01:00
|
|
|
static char **replace_token(char **lines,
|
|
|
|
const char *token, const char *replacement);
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2009-09-02 04:40:52 +02:00
|
|
|
static char **readfile(const char *path);
|
2004-05-10 22:51:58 +02:00
|
|
|
static void writefile(char *path, char **lines);
|
2004-11-29 04:05:03 +01:00
|
|
|
static FILE *popen_check(const char *command, const char *mode);
|
2003-11-10 23:51:16 +01:00
|
|
|
static char *get_id(void);
|
2017-10-31 15:34:31 +01:00
|
|
|
static int get_encoding_id(const char *encoding_name);
|
|
|
|
static void set_input(char **dest, const char *filename);
|
2003-11-10 23:51:16 +01:00
|
|
|
static void check_input(char *path);
|
2017-10-31 15:34:31 +01:00
|
|
|
static void write_version_file(const char *extrapath);
|
2003-11-10 23:51:16 +01:00
|
|
|
static void set_null_conf(void);
|
2006-01-01 00:50:59 +01:00
|
|
|
static void test_config_settings(void);
|
2003-11-10 23:51:16 +01:00
|
|
|
static void setup_config(void);
|
2010-01-07 00:23:51 +01:00
|
|
|
static void bootstrap_template1(void);
|
2015-12-18 01:38:21 +01:00
|
|
|
static void setup_auth(FILE *cmdfd);
|
2016-08-30 21:25:01 +02:00
|
|
|
static void get_su_pwd(void);
|
2015-12-18 01:38:21 +01:00
|
|
|
static void setup_depend(FILE *cmdfd);
|
2021-01-30 19:14:31 +01:00
|
|
|
static void setup_run_file(FILE *cmdfd, const char *filename);
|
2015-12-18 01:38:21 +01:00
|
|
|
static void setup_description(FILE *cmdfd);
|
|
|
|
static void setup_collation(FILE *cmdfd);
|
|
|
|
static void setup_privileges(FILE *cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
static void set_info_version(void);
|
2015-12-18 01:38:21 +01:00
|
|
|
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);
|
2022-09-14 20:44:45 +02:00
|
|
|
static void trapsig(SIGNAL_ARGS);
|
2003-11-10 23:51:16 +01:00
|
|
|
static void check_ok(void);
|
2004-10-07 20:57:26 +02:00
|
|
|
static char *escape_quotes(const char *src);
|
2018-04-18 01:53:50 +02:00
|
|
|
static char *escape_quotes_bki(const char *src);
|
2005-12-09 16:51:14 +01:00
|
|
|
static int locale_date_order(const char *locale);
|
2014-05-14 17:51:10 +02:00
|
|
|
static void check_locale_name(int category, const char *locale,
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
char **canonname);
|
2022-09-20 22:09:30 +02:00
|
|
|
static bool check_locale_encoding(const char *locale, int user_enc);
|
2004-05-10 22:51:58 +02:00
|
|
|
static void setlocales(void);
|
|
|
|
static void usage(const char *progname);
|
2012-11-30 22:45:08 +01:00
|
|
|
void setup_pgdata(void);
|
|
|
|
void setup_bin_paths(const char *argv0);
|
|
|
|
void setup_data_file_paths(void);
|
|
|
|
void setup_locale_encoding(void);
|
2012-12-04 05:22:56 +01:00
|
|
|
void setup_signals(void);
|
2012-11-30 22:45:08 +01:00
|
|
|
void setup_text_search(void);
|
2012-12-04 05:22:56 +01:00
|
|
|
void create_data_directory(void);
|
2016-01-08 00:20:57 +01:00
|
|
|
void create_xlog_or_symlink(void);
|
2013-02-17 00:52:50 +01:00
|
|
|
void warn_on_mount_point(int error);
|
2012-12-04 05:22:56 +01:00
|
|
|
void initialize_data_directory(void);
|
2012-11-30 22:45:08 +01:00
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* macros for running pipes to postgres
|
|
|
|
*/
|
2004-11-29 04:05:03 +01:00
|
|
|
#define PG_CMD_DECL char cmd[MAXPGPATH]; FILE *cmdfd
|
2003-11-10 23:52:10 +01:00
|
|
|
|
|
|
|
#define PG_CMD_OPEN \
|
|
|
|
do { \
|
2004-11-29 04:05:03 +01:00
|
|
|
cmdfd = popen_check(cmd, "w"); \
|
|
|
|
if (cmdfd == NULL) \
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1); /* message already printed by popen_check */ \
|
2003-11-10 23:52:10 +01:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define PG_CMD_CLOSE \
|
|
|
|
do { \
|
2004-11-29 04:05:03 +01:00
|
|
|
if (pclose_check(cmdfd)) \
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1); /* message already printed by pclose_check */ \
|
2003-11-10 23:52:10 +01:00
|
|
|
} while (0)
|
|
|
|
|
2004-11-29 04:05:03 +01:00
|
|
|
#define PG_CMD_PUTS(line) \
|
2003-11-10 23:52:10 +01:00
|
|
|
do { \
|
2004-11-29 04:05:03 +01:00
|
|
|
if (fputs(line, cmdfd) < 0 || fflush(cmdfd) < 0) \
|
|
|
|
output_failed = true, output_errno = errno; \
|
|
|
|
} while (0)
|
|
|
|
|
2019-08-08 08:47:55 +02:00
|
|
|
#define PG_CMD_PRINTF(fmt, ...) \
|
2004-11-29 04:05:03 +01:00
|
|
|
do { \
|
2019-08-08 08:47:55 +02:00
|
|
|
if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
|
2011-02-08 22:04:18 +01:00
|
|
|
output_failed = true, output_errno = errno; \
|
|
|
|
} while (0)
|
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
/*
|
|
|
|
* Escape single quotes and backslashes, suitably for insertions into
|
|
|
|
* configuration files or SQL E'' strings.
|
|
|
|
*/
|
2013-01-05 15:40:19 +01:00
|
|
|
static char *
|
|
|
|
escape_quotes(const char *src)
|
|
|
|
{
|
|
|
|
char *result = escape_single_quotes_ascii(src);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2013-01-05 15:40:19 +01:00
|
|
|
if (!result)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("out of memory");
|
2013-01-05 15:40:19 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
/*
|
|
|
|
* Escape a field value to be inserted into the BKI data.
|
2020-10-04 22:09:55 +02:00
|
|
|
* Run the value through escape_quotes (which will be inverted
|
|
|
|
* by the backend's DeescapeQuotedString() function), then wrap
|
|
|
|
* the value in single quotes, even if that isn't strictly necessary.
|
2018-04-18 01:53:50 +02:00
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
escape_quotes_bki(const char *src)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *data = escape_quotes(src);
|
|
|
|
char *resultp;
|
|
|
|
char *datap;
|
|
|
|
|
2020-10-04 22:09:55 +02:00
|
|
|
result = (char *) pg_malloc(strlen(data) + 3);
|
2018-04-18 01:53:50 +02:00
|
|
|
resultp = result;
|
2020-10-04 22:09:55 +02:00
|
|
|
*resultp++ = '\'';
|
2018-04-18 01:53:50 +02:00
|
|
|
for (datap = data; *datap; datap++)
|
2020-10-04 22:09:55 +02:00
|
|
|
*resultp++ = *datap;
|
|
|
|
*resultp++ = '\'';
|
2018-04-18 01:53:50 +02:00
|
|
|
*resultp = '\0';
|
|
|
|
|
|
|
|
free(data);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* make a copy of the array of lines, with token replaced by replacement
|
|
|
|
* the first time it occurs on each line.
|
2003-11-14 00:46:31 +01:00
|
|
|
*
|
2003-11-10 23:51:16 +01:00
|
|
|
* This does most of what sed was used for in the shell script, but
|
|
|
|
* doesn't need any regexp stuff.
|
|
|
|
*/
|
|
|
|
static char **
|
2004-12-27 21:39:21 +01:00
|
|
|
replace_token(char **lines, const char *token, const char *replacement)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
|
|
|
int numlines = 1;
|
|
|
|
int i;
|
|
|
|
char **result;
|
|
|
|
int toklen,
|
|
|
|
replen,
|
|
|
|
diff;
|
|
|
|
|
|
|
|
for (i = 0; lines[i]; i++)
|
|
|
|
numlines++;
|
|
|
|
|
2005-07-10 18:13:13 +02:00
|
|
|
result = (char **) pg_malloc(numlines * sizeof(char *));
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
toklen = strlen(token);
|
|
|
|
replen = strlen(replacement);
|
|
|
|
diff = replen - toklen;
|
|
|
|
|
|
|
|
for (i = 0; i < numlines; i++)
|
|
|
|
{
|
|
|
|
char *where;
|
|
|
|
char *newline;
|
|
|
|
int pre;
|
|
|
|
|
|
|
|
/* just copy pointer if NULL or no change needed */
|
|
|
|
if (lines[i] == NULL || (where = strstr(lines[i], token)) == NULL)
|
|
|
|
{
|
|
|
|
result[i] = lines[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we get here a change is needed - set up new line */
|
|
|
|
|
2005-07-10 18:13:13 +02:00
|
|
|
newline = (char *) pg_malloc(strlen(lines[i]) + diff + 1);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
pre = where - lines[i];
|
|
|
|
|
Replace a bunch more uses of strncpy() with safer coding.
strncpy() has a well-deserved reputation for being unsafe, so make an
effort to get rid of nearly all occurrences in HEAD.
A large fraction of the remaining uses were passing length less than or
equal to the known strlen() of the source, in which case no null-padding
can occur and the behavior is equivalent to memcpy(), though doubtless
slower and certainly harder to reason about. So just use memcpy() in
these cases.
In other cases, use either StrNCpy() or strlcpy() as appropriate (depending
on whether padding to the full length of the destination buffer seems
useful).
I left a few strncpy() calls alone in the src/timezone/ code, to keep it
in sync with upstream (the IANA tzcode distribution). There are also a
few such calls in ecpg that could possibly do with more analysis.
AFAICT, none of these changes are more than cosmetic, except for the four
occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength
source leads to a non-null-terminated destination buffer and ensuing
misbehavior. These don't seem like security issues, first because no stack
clobber is possible and second because if your values of sslcert etc are
coming from untrusted sources then you've got problems way worse than this.
Still, it's undesirable to have unpredictable behavior for overlength
inputs, so back-patch those four changes to all active branches.
2015-01-24 19:05:42 +01:00
|
|
|
memcpy(newline, lines[i], pre);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
Replace a bunch more uses of strncpy() with safer coding.
strncpy() has a well-deserved reputation for being unsafe, so make an
effort to get rid of nearly all occurrences in HEAD.
A large fraction of the remaining uses were passing length less than or
equal to the known strlen() of the source, in which case no null-padding
can occur and the behavior is equivalent to memcpy(), though doubtless
slower and certainly harder to reason about. So just use memcpy() in
these cases.
In other cases, use either StrNCpy() or strlcpy() as appropriate (depending
on whether padding to the full length of the destination buffer seems
useful).
I left a few strncpy() calls alone in the src/timezone/ code, to keep it
in sync with upstream (the IANA tzcode distribution). There are also a
few such calls in ecpg that could possibly do with more analysis.
AFAICT, none of these changes are more than cosmetic, except for the four
occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength
source leads to a non-null-terminated destination buffer and ensuing
misbehavior. These don't seem like security issues, first because no stack
clobber is possible and second because if your values of sslcert etc are
coming from untrusted sources then you've got problems way worse than this.
Still, it's undesirable to have unpredictable behavior for overlength
inputs, so back-patch those four changes to all active branches.
2015-01-24 19:05:42 +01:00
|
|
|
memcpy(newline + pre, replacement, replen);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
strcpy(newline + pre + replen, lines[i] + pre + toklen);
|
|
|
|
|
|
|
|
result[i] = newline;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the lines from a text file
|
|
|
|
*/
|
|
|
|
static char **
|
2009-09-02 04:40:52 +02:00
|
|
|
readfile(const char *path)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2020-09-05 22:20:04 +02:00
|
|
|
char **result;
|
2003-11-10 23:51:16 +01:00
|
|
|
FILE *infile;
|
2020-09-06 19:57:10 +02:00
|
|
|
StringInfoData line;
|
2020-09-05 22:20:04 +02:00
|
|
|
int maxlines;
|
2012-10-13 11:48:14 +02:00
|
|
|
int n;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-10 23:52:10 +01:00
|
|
|
if ((infile = fopen(path, "r")) == NULL)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not open file \"%s\" for reading: %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2020-09-06 19:57:10 +02:00
|
|
|
initStringInfo(&line);
|
|
|
|
|
2020-09-05 22:20:04 +02:00
|
|
|
maxlines = 1024;
|
|
|
|
result = (char **) pg_malloc(maxlines * sizeof(char *));
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2020-09-05 22:20:04 +02:00
|
|
|
n = 0;
|
2020-09-22 21:55:13 +02:00
|
|
|
while (pg_get_line_buf(infile, &line))
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2020-09-05 22:20:04 +02:00
|
|
|
/* make sure there will be room for a trailing NULL pointer */
|
|
|
|
if (n >= maxlines - 1)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2020-09-05 22:20:04 +02:00
|
|
|
maxlines *= 2;
|
|
|
|
result = (char **) pg_realloc(result, maxlines * sizeof(char *));
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2020-09-06 19:57:10 +02:00
|
|
|
result[n++] = pg_strdup(line.data);
|
2020-09-05 22:20:04 +02:00
|
|
|
}
|
|
|
|
result[n] = NULL;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2020-09-06 19:57:10 +02:00
|
|
|
pfree(line.data);
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
fclose(infile);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write an array of lines to a file
|
2004-10-24 17:55:29 +02:00
|
|
|
*
|
|
|
|
* This is only used to write text files. Use fopen "w" not PG_BINARY_W
|
|
|
|
* so that the resulting configuration files are nicely editable on Windows.
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
writefile(char *path, char **lines)
|
|
|
|
{
|
|
|
|
FILE *out_file;
|
|
|
|
char **line;
|
|
|
|
|
2004-10-24 17:55:29 +02:00
|
|
|
if ((out_file = fopen(path, "w")) == NULL)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not open file \"%s\" for writing: %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
for (line = lines; *line != NULL; line++)
|
|
|
|
{
|
|
|
|
if (fputs(*line, out_file) < 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not write file \"%s\": %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
free(*line);
|
|
|
|
}
|
|
|
|
if (fclose(out_file))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not close file \"%s\": %m", path);
|
2004-11-29 04:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a subcommand with suitable error messaging
|
|
|
|
*/
|
|
|
|
static FILE *
|
|
|
|
popen_check(const char *command, const char *mode)
|
|
|
|
{
|
|
|
|
FILE *cmdfd;
|
|
|
|
|
2022-08-29 19:55:38 +02:00
|
|
|
fflush(NULL);
|
2004-11-29 04:05:03 +01:00
|
|
|
errno = 0;
|
|
|
|
cmdfd = popen(command, mode);
|
|
|
|
if (cmdfd == NULL)
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("could not execute command \"%s\": %m", command);
|
2004-11-29 04:05:03 +01:00
|
|
|
return cmdfd;
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clean up any files we created on failure
|
|
|
|
* if we created the data directory remove it too
|
|
|
|
*/
|
|
|
|
static void
|
2018-12-29 13:21:57 +01:00
|
|
|
cleanup_directories_atexit(void)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2018-12-29 13:21:57 +01:00
|
|
|
if (success)
|
|
|
|
return;
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
if (!noclean)
|
|
|
|
{
|
|
|
|
if (made_new_pgdata)
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("removing data directory \"%s\"", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
if (!rmtree(pg_data, true))
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("failed to remove data directory");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2003-11-14 19:32:34 +01:00
|
|
|
else if (found_existing_pgdata)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("removing contents of data directory \"%s\"",
|
|
|
|
pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
if (!rmtree(pg_data, false))
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("failed to remove contents of data directory");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2007-01-06 20:40:00 +01:00
|
|
|
|
|
|
|
if (made_new_xlogdir)
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("removing WAL directory \"%s\"", xlog_dir);
|
2007-01-06 20:40:00 +01:00
|
|
|
if (!rmtree(xlog_dir, true))
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("failed to remove WAL directory");
|
2007-01-06 20:40:00 +01:00
|
|
|
}
|
|
|
|
else if (found_existing_xlogdir)
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
|
2007-01-06 20:40:00 +01:00
|
|
|
if (!rmtree(xlog_dir, false))
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("failed to remove contents of WAL directory");
|
2007-01-06 20:40:00 +01:00
|
|
|
}
|
2003-11-14 19:32:34 +01:00
|
|
|
/* otherwise died during startup, do nothing! */
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2003-11-14 00:46:31 +01:00
|
|
|
else
|
|
|
|
{
|
2003-11-14 19:32:34 +01:00
|
|
|
if (made_new_pgdata || found_existing_pgdata)
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("data directory \"%s\" not removed at user's request",
|
|
|
|
pg_data);
|
2007-01-06 20:40:00 +01:00
|
|
|
|
|
|
|
if (made_new_xlogdir || found_existing_xlogdir)
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_info("WAL directory \"%s\" not removed at user's request",
|
|
|
|
xlog_dir);
|
2003-11-14 00:46:31 +01:00
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-12-17 19:44:09 +01:00
|
|
|
* find the current user
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2013-12-18 18:16:16 +01:00
|
|
|
* on unix make sure it isn't root
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
get_id(void)
|
|
|
|
{
|
2013-12-18 18:16:16 +01:00
|
|
|
const char *username;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2013-12-18 18:16:16 +01:00
|
|
|
#ifndef WIN32
|
2005-01-08 23:51:15 +01:00
|
|
|
if (geteuid() == 0) /* 0 is root's uid */
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("cannot be run as root");
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
|
2003-11-10 23:51:16 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2013-12-18 18:16:16 +01:00
|
|
|
username = get_user_name_or_exit(progname);
|
|
|
|
|
|
|
|
return pg_strdup(username);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2004-07-14 19:55:10 +02:00
|
|
|
static char *
|
|
|
|
encodingid_to_string(int enc)
|
|
|
|
{
|
|
|
|
char result[20];
|
|
|
|
|
|
|
|
sprintf(result, "%d", enc);
|
2012-10-02 21:35:10 +02:00
|
|
|
return pg_strdup(result);
|
2004-07-14 19:55:10 +02:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* get the encoding id for a given encoding name
|
|
|
|
*/
|
2017-08-31 04:28:36 +02:00
|
|
|
static int
|
2017-10-31 15:34:31 +01:00
|
|
|
get_encoding_id(const char *encoding_name)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
|
|
|
int enc;
|
|
|
|
|
|
|
|
if (encoding_name && *encoding_name)
|
|
|
|
{
|
2007-03-30 00:46:42 +02:00
|
|
|
if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
|
2017-08-31 04:28:36 +02:00
|
|
|
return enc;
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("\"%s\" is not a valid server encoding name",
|
|
|
|
encoding_name ? encoding_name : "(null)");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2007-08-21 03:11:32 +02:00
|
|
|
/*
|
|
|
|
* Support for determining the best default text search configuration.
|
2007-10-25 22:22:53 +02:00
|
|
|
* We key this off the first part of LC_CTYPE (ie, the language name).
|
2007-08-21 03:11:32 +02:00
|
|
|
*/
|
|
|
|
struct tsearch_config_match
|
|
|
|
{
|
|
|
|
const char *tsconfname;
|
|
|
|
const char *langname;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tsearch_config_match tsearch_config_languages[] =
|
|
|
|
{
|
Sync our Snowball stemmer dictionaries with current upstream.
We haven't touched these since text search functionality landed in core
in 2007 :-(. While the upstream project isn't a beehive of activity,
they do make additions and bug fixes from time to time. Update our
copies of these files.
Also update our documentation about how to keep things in sync, since
they're not making distribution tarballs these days. Fortunately,
their source code turns out to be a breeze to build.
Notable changes:
* The non-UTF8 version of the hungarian stemmer now works in LATIN2
not LATIN1.
* New stemmers have appeared for arabic, indonesian, irish, lithuanian,
nepali, and tamil. These all work in UTF8, and the indonesian and
irish ones also work in LATIN1.
(There are some new stemmers that I did not incorporate, mainly because
their names don't match the underlying languages, suggesting that they're
not to be considered mainstream.)
Worth noting: the upstream Nepali dictionary was contributed by
Arthur Zakirov.
initdb forced because the contents of snowball_create.sql have
changed.
Still TODO: see about updating the stopword lists.
Arthur Zakirov, minor mods and doc work by me
Discussion: https://postgr.es/m/20180626122025.GA12647@zakirov.localdomain
Discussion: https://postgr.es/m/20180219140849.GA9050@zakirov.localdomain
2018-09-24 23:29:08 +02:00
|
|
|
{"arabic", "ar"},
|
|
|
|
{"arabic", "Arabic"},
|
2021-02-19 07:57:42 +01:00
|
|
|
{"armenian", "hy"},
|
|
|
|
{"armenian", "Armenian"},
|
2020-06-08 07:58:51 +02:00
|
|
|
{"basque", "eu"},
|
|
|
|
{"basque", "Basque"},
|
|
|
|
{"catalan", "ca"},
|
|
|
|
{"catalan", "Catalan"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"danish", "da"},
|
|
|
|
{"danish", "Danish"},
|
|
|
|
{"dutch", "nl"},
|
|
|
|
{"dutch", "Dutch"},
|
2007-08-21 03:11:32 +02:00
|
|
|
{"english", "C"},
|
|
|
|
{"english", "POSIX"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"english", "en"},
|
|
|
|
{"english", "English"},
|
|
|
|
{"finnish", "fi"},
|
|
|
|
{"finnish", "Finnish"},
|
|
|
|
{"french", "fr"},
|
|
|
|
{"french", "French"},
|
|
|
|
{"german", "de"},
|
|
|
|
{"german", "German"},
|
2019-07-04 13:10:41 +02:00
|
|
|
{"greek", "el"},
|
|
|
|
{"greek", "Greek"},
|
2020-06-08 07:58:51 +02:00
|
|
|
{"hindi", "hi"},
|
|
|
|
{"hindi", "Hindi"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"hungarian", "hu"},
|
|
|
|
{"hungarian", "Hungarian"},
|
Sync our Snowball stemmer dictionaries with current upstream.
We haven't touched these since text search functionality landed in core
in 2007 :-(. While the upstream project isn't a beehive of activity,
they do make additions and bug fixes from time to time. Update our
copies of these files.
Also update our documentation about how to keep things in sync, since
they're not making distribution tarballs these days. Fortunately,
their source code turns out to be a breeze to build.
Notable changes:
* The non-UTF8 version of the hungarian stemmer now works in LATIN2
not LATIN1.
* New stemmers have appeared for arabic, indonesian, irish, lithuanian,
nepali, and tamil. These all work in UTF8, and the indonesian and
irish ones also work in LATIN1.
(There are some new stemmers that I did not incorporate, mainly because
their names don't match the underlying languages, suggesting that they're
not to be considered mainstream.)
Worth noting: the upstream Nepali dictionary was contributed by
Arthur Zakirov.
initdb forced because the contents of snowball_create.sql have
changed.
Still TODO: see about updating the stopword lists.
Arthur Zakirov, minor mods and doc work by me
Discussion: https://postgr.es/m/20180626122025.GA12647@zakirov.localdomain
Discussion: https://postgr.es/m/20180219140849.GA9050@zakirov.localdomain
2018-09-24 23:29:08 +02:00
|
|
|
{"indonesian", "id"},
|
|
|
|
{"indonesian", "Indonesian"},
|
|
|
|
{"irish", "ga"},
|
|
|
|
{"irish", "Irish"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"italian", "it"},
|
|
|
|
{"italian", "Italian"},
|
Sync our Snowball stemmer dictionaries with current upstream.
We haven't touched these since text search functionality landed in core
in 2007 :-(. While the upstream project isn't a beehive of activity,
they do make additions and bug fixes from time to time. Update our
copies of these files.
Also update our documentation about how to keep things in sync, since
they're not making distribution tarballs these days. Fortunately,
their source code turns out to be a breeze to build.
Notable changes:
* The non-UTF8 version of the hungarian stemmer now works in LATIN2
not LATIN1.
* New stemmers have appeared for arabic, indonesian, irish, lithuanian,
nepali, and tamil. These all work in UTF8, and the indonesian and
irish ones also work in LATIN1.
(There are some new stemmers that I did not incorporate, mainly because
their names don't match the underlying languages, suggesting that they're
not to be considered mainstream.)
Worth noting: the upstream Nepali dictionary was contributed by
Arthur Zakirov.
initdb forced because the contents of snowball_create.sql have
changed.
Still TODO: see about updating the stopword lists.
Arthur Zakirov, minor mods and doc work by me
Discussion: https://postgr.es/m/20180626122025.GA12647@zakirov.localdomain
Discussion: https://postgr.es/m/20180219140849.GA9050@zakirov.localdomain
2018-09-24 23:29:08 +02:00
|
|
|
{"lithuanian", "lt"},
|
|
|
|
{"lithuanian", "Lithuanian"},
|
|
|
|
{"nepali", "ne"},
|
|
|
|
{"nepali", "Nepali"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"norwegian", "no"},
|
|
|
|
{"norwegian", "Norwegian"},
|
|
|
|
{"portuguese", "pt"},
|
|
|
|
{"portuguese", "Portuguese"},
|
|
|
|
{"romanian", "ro"},
|
|
|
|
{"russian", "ru"},
|
|
|
|
{"russian", "Russian"},
|
2021-02-19 07:57:42 +01:00
|
|
|
{"serbian", "sr"},
|
|
|
|
{"serbian", "Serbian"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"spanish", "es"},
|
|
|
|
{"spanish", "Spanish"},
|
|
|
|
{"swedish", "sv"},
|
|
|
|
{"swedish", "Swedish"},
|
Sync our Snowball stemmer dictionaries with current upstream.
We haven't touched these since text search functionality landed in core
in 2007 :-(. While the upstream project isn't a beehive of activity,
they do make additions and bug fixes from time to time. Update our
copies of these files.
Also update our documentation about how to keep things in sync, since
they're not making distribution tarballs these days. Fortunately,
their source code turns out to be a breeze to build.
Notable changes:
* The non-UTF8 version of the hungarian stemmer now works in LATIN2
not LATIN1.
* New stemmers have appeared for arabic, indonesian, irish, lithuanian,
nepali, and tamil. These all work in UTF8, and the indonesian and
irish ones also work in LATIN1.
(There are some new stemmers that I did not incorporate, mainly because
their names don't match the underlying languages, suggesting that they're
not to be considered mainstream.)
Worth noting: the upstream Nepali dictionary was contributed by
Arthur Zakirov.
initdb forced because the contents of snowball_create.sql have
changed.
Still TODO: see about updating the stopword lists.
Arthur Zakirov, minor mods and doc work by me
Discussion: https://postgr.es/m/20180626122025.GA12647@zakirov.localdomain
Discussion: https://postgr.es/m/20180219140849.GA9050@zakirov.localdomain
2018-09-24 23:29:08 +02:00
|
|
|
{"tamil", "ta"},
|
|
|
|
{"tamil", "Tamil"},
|
2007-10-25 22:22:53 +02:00
|
|
|
{"turkish", "tr"},
|
|
|
|
{"turkish", "Turkish"},
|
2021-02-19 07:57:42 +01:00
|
|
|
{"yiddish", "yi"},
|
|
|
|
{"yiddish", "Yiddish"},
|
2007-08-21 03:11:32 +02:00
|
|
|
{NULL, NULL} /* end marker */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a text search configuration matching lc_ctype, and return its
|
|
|
|
* name; return NULL if no match.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
find_matching_ts_config(const char *lc_type)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *langname,
|
|
|
|
*ptr;
|
|
|
|
|
|
|
|
/*
|
2007-10-25 22:22:53 +02:00
|
|
|
* Convert lc_ctype to a language name by stripping everything after an
|
2013-02-06 20:52:29 +01:00
|
|
|
* underscore (usual case) or a hyphen (Windows "locale name"; see
|
|
|
|
* comments at IsoLocaleName()).
|
|
|
|
*
|
|
|
|
* XXX Should ' ' be a stop character? This would select "norwegian" for
|
|
|
|
* the Windows locale "Norwegian (Nynorsk)_Norway.1252". If we do so, we
|
|
|
|
* should also accept the "nn" and "nb" Unix locales.
|
|
|
|
*
|
|
|
|
* Just for paranoia, we also stop at '.' or '@'.
|
2007-08-21 03:11:32 +02:00
|
|
|
*/
|
|
|
|
if (lc_type == NULL)
|
2012-10-02 21:35:10 +02:00
|
|
|
langname = pg_strdup("");
|
2007-08-21 03:11:32 +02:00
|
|
|
else
|
|
|
|
{
|
2012-10-02 21:35:10 +02:00
|
|
|
ptr = langname = pg_strdup(lc_type);
|
2013-02-06 20:52:29 +01:00
|
|
|
while (*ptr &&
|
|
|
|
*ptr != '_' && *ptr != '-' && *ptr != '.' && *ptr != '@')
|
2007-08-21 03:11:32 +02:00
|
|
|
ptr++;
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; tsearch_config_languages[i].tsconfname; i++)
|
|
|
|
{
|
|
|
|
if (pg_strcasecmp(tsearch_config_languages[i].langname, langname) == 0)
|
|
|
|
{
|
|
|
|
free(langname);
|
|
|
|
return tsearch_config_languages[i].tsconfname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(langname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* set name of given input file variable under data directory
|
|
|
|
*/
|
|
|
|
static void
|
2017-10-31 15:34:31 +01:00
|
|
|
set_input(char **dest, const char *filename)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2013-10-23 01:40:26 +02:00
|
|
|
*dest = psprintf("%s/%s", share_path, filename);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check that given input file exists
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_input(char *path)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
2007-01-31 19:52:49 +01:00
|
|
|
if (stat(path, &statbuf) != 0)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT)
|
2007-11-16 22:47:32 +01:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("file \"%s\" does not exist", path);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
|
2007-11-16 22:47:32 +01:00
|
|
|
}
|
2007-01-31 19:52:49 +01:00
|
|
|
else
|
2007-11-16 22:47:32 +01:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("could not access file \"%s\": %m", path);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
|
2007-11-16 22:47:32 +01:00
|
|
|
}
|
2007-01-31 19:52:49 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!S_ISREG(statbuf.st_mode))
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("file \"%s\" is not a regular file", path);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
|
2003-11-10 23:51:16 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write out the PG_VERSION file in the data dir, or its subdirectory
|
|
|
|
* if extrapath is not NULL
|
|
|
|
*/
|
|
|
|
static void
|
2017-10-31 15:34:31 +01:00
|
|
|
write_version_file(const char *extrapath)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
|
|
|
FILE *version_file;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (extrapath == NULL)
|
2013-10-23 01:40:26 +02:00
|
|
|
path = psprintf("%s/PG_VERSION", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
else
|
2013-10-23 01:40:26 +02:00
|
|
|
path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
|
2010-01-07 00:23:51 +01:00
|
|
|
|
|
|
|
if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not open file \"%s\" for writing: %m", path);
|
2010-01-07 00:23:51 +01:00
|
|
|
if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
|
2004-11-29 04:05:03 +01:00
|
|
|
fclose(version_file))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not write file \"%s\": %m", path);
|
2006-08-20 18:08:09 +02:00
|
|
|
free(path);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-01 00:50:59 +01:00
|
|
|
* set up an empty config file so we can check config settings by launching
|
|
|
|
* a test backend
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_null_conf(void)
|
|
|
|
{
|
|
|
|
FILE *conf_file;
|
|
|
|
char *path;
|
|
|
|
|
2013-10-23 01:40:26 +02:00
|
|
|
path = psprintf("%s/postgresql.conf", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
conf_file = fopen(path, PG_BINARY_W);
|
2004-11-29 04:05:03 +01:00
|
|
|
if (conf_file == NULL)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not open file \"%s\" for writing: %m", path);
|
2004-11-29 04:05:03 +01:00
|
|
|
if (fclose(conf_file))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not write file \"%s\": %m", path);
|
2006-08-20 18:08:09 +02:00
|
|
|
free(path);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2013-10-11 01:38:56 +02:00
|
|
|
/*
|
|
|
|
* Determine which dynamic shared memory implementation should be used on
|
|
|
|
* this platform. POSIX shared memory is preferable because the default
|
|
|
|
* allocation limits are much higher than the limits for System V on most
|
|
|
|
* systems that support both, but the fact that a platform has shm_open
|
|
|
|
* doesn't guarantee that that call will succeed when attempted. So, we
|
|
|
|
* attempt to reproduce what the postmaster will do when allocating a POSIX
|
|
|
|
* segment in dsm_impl.c; if it doesn't work, we assume it won't work for
|
|
|
|
* the postmaster either, and configure the cluster for System V shared
|
|
|
|
* memory instead.
|
2022-07-02 06:06:47 +02:00
|
|
|
*
|
|
|
|
* We avoid choosing Solaris's implementation of shm_open() by default. It
|
|
|
|
* can sleep and fail spuriously under contention.
|
2013-10-11 01:38:56 +02:00
|
|
|
*/
|
2018-08-10 20:14:27 +02:00
|
|
|
static const char *
|
2013-10-11 01:38:56 +02:00
|
|
|
choose_dsm_implementation(void)
|
|
|
|
{
|
2022-07-02 06:06:47 +02:00
|
|
|
#if defined(HAVE_SHM_OPEN) && !defined(__sun__)
|
2013-10-11 01:38:56 +02:00
|
|
|
int ntries = 10;
|
Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.
Standardize on xoroshiro128** as our basic PRNG algorithm, eliminating
a bunch of platform dependencies as well as fundamentally-obsolete PRNG
code. In addition, this API replacement will ease replacing the
algorithm again in future, should that become necessary.
xoroshiro128** is a few percent slower than the drand48 family,
but it can produce full-width 64-bit random values not only 48-bit,
and it should be much more trustworthy. It's likely to be noticeably
faster than the platform's random(), depending on which platform you
are thinking about; and we can have non-global state vectors easily,
unlike with random(). It is not cryptographically strong, but neither
are the functions it replaces.
Fabien Coelho, reviewed by Dean Rasheed, Aleksander Alekseev, and myself
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2105241211230.165418@pseudo
2021-11-29 03:32:36 +01:00
|
|
|
pg_prng_state prng_state;
|
2013-10-11 01:38:56 +02:00
|
|
|
|
Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.
Standardize on xoroshiro128** as our basic PRNG algorithm, eliminating
a bunch of platform dependencies as well as fundamentally-obsolete PRNG
code. In addition, this API replacement will ease replacing the
algorithm again in future, should that become necessary.
xoroshiro128** is a few percent slower than the drand48 family,
but it can produce full-width 64-bit random values not only 48-bit,
and it should be much more trustworthy. It's likely to be noticeably
faster than the platform's random(), depending on which platform you
are thinking about; and we can have non-global state vectors easily,
unlike with random(). It is not cryptographically strong, but neither
are the functions it replaces.
Fabien Coelho, reviewed by Dean Rasheed, Aleksander Alekseev, and myself
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2105241211230.165418@pseudo
2021-11-29 03:32:36 +01:00
|
|
|
/* Initialize prng; this function is its only user in this program. */
|
|
|
|
pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
|
2018-09-24 07:56:39 +02:00
|
|
|
|
2013-10-11 01:38:56 +02:00
|
|
|
while (ntries > 0)
|
|
|
|
{
|
|
|
|
uint32 handle;
|
|
|
|
char name[64];
|
|
|
|
int fd;
|
|
|
|
|
Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.
Standardize on xoroshiro128** as our basic PRNG algorithm, eliminating
a bunch of platform dependencies as well as fundamentally-obsolete PRNG
code. In addition, this API replacement will ease replacing the
algorithm again in future, should that become necessary.
xoroshiro128** is a few percent slower than the drand48 family,
but it can produce full-width 64-bit random values not only 48-bit,
and it should be much more trustworthy. It's likely to be noticeably
faster than the platform's random(), depending on which platform you
are thinking about; and we can have non-global state vectors easily,
unlike with random(). It is not cryptographically strong, but neither
are the functions it replaces.
Fabien Coelho, reviewed by Dean Rasheed, Aleksander Alekseev, and myself
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2105241211230.165418@pseudo
2021-11-29 03:32:36 +01:00
|
|
|
handle = pg_prng_uint32(&prng_state);
|
2013-10-11 01:38:56 +02:00
|
|
|
snprintf(name, 64, "/PostgreSQL.%u", handle);
|
|
|
|
if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
shm_unlink(name);
|
|
|
|
return "posix";
|
|
|
|
}
|
|
|
|
if (errno != EEXIST)
|
|
|
|
break;
|
|
|
|
--ntries;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
return "windows";
|
|
|
|
#else
|
|
|
|
return "sysv";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-12-28 00:54:01 +01:00
|
|
|
/*
|
2006-01-01 00:50:59 +01:00
|
|
|
* Determine platform-specific config settings
|
|
|
|
*
|
2018-08-10 20:14:27 +02:00
|
|
|
* Use reasonable values if kernel will let us, else scale back.
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2006-01-01 00:50:59 +01:00
|
|
|
test_config_settings(void)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2006-01-01 00:50:59 +01:00
|
|
|
/*
|
2008-09-30 12:52:14 +02:00
|
|
|
* This macro defines the minimum shared_buffers we want for a given
|
|
|
|
* max_connections value. The arrays show the settings to try.
|
2006-01-01 00:50:59 +01:00
|
|
|
*/
|
2006-10-04 20:58:08 +02:00
|
|
|
#define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
|
2006-01-01 00:50:59 +01:00
|
|
|
|
|
|
|
static const int trial_conns[] = {
|
2018-03-08 17:26:20 +01:00
|
|
|
100, 50, 40, 30, 20
|
2006-01-01 00:50:59 +01:00
|
|
|
};
|
|
|
|
static const int trial_bufs[] = {
|
2012-07-04 21:52:35 +02:00
|
|
|
16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,
|
2006-10-04 20:58:08 +02:00
|
|
|
1000, 900, 800, 700, 600, 500,
|
|
|
|
400, 300, 200, 100, 50
|
2006-01-01 00:50:59 +01:00
|
|
|
};
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
char cmd[MAXPGPATH];
|
2006-01-01 00:50:59 +01:00
|
|
|
const int connslen = sizeof(trial_conns) / sizeof(int);
|
|
|
|
const int bufslen = sizeof(trial_bufs) / sizeof(int);
|
2003-11-10 23:51:16 +01:00
|
|
|
int i,
|
2006-01-01 00:50:59 +01:00
|
|
|
status,
|
|
|
|
test_conns,
|
|
|
|
test_buffs,
|
2006-01-02 17:45:12 +01:00
|
|
|
ok_buffers = 0;
|
2006-10-04 02:30:14 +02:00
|
|
|
|
2018-07-10 17:37:42 +02:00
|
|
|
/*
|
|
|
|
* Need to determine working DSM implementation first so that subsequent
|
|
|
|
* tests don't fail because DSM setting doesn't work.
|
|
|
|
*/
|
|
|
|
printf(_("selecting dynamic shared memory implementation ... "));
|
|
|
|
fflush(stdout);
|
|
|
|
dynamic_shared_memory_type = choose_dsm_implementation();
|
|
|
|
printf("%s\n", dynamic_shared_memory_type);
|
|
|
|
|
2018-08-10 20:14:27 +02:00
|
|
|
/*
|
|
|
|
* Probe for max_connections before shared_buffers, since it is subject to
|
|
|
|
* more constraints than shared_buffers.
|
|
|
|
*/
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("selecting default max_connections ... "));
|
2003-11-13 02:36:00 +01:00
|
|
|
fflush(stdout);
|
|
|
|
|
2006-01-01 00:50:59 +01:00
|
|
|
for (i = 0; i < connslen; i++)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2006-01-01 00:50:59 +01:00
|
|
|
test_conns = trial_conns[i];
|
|
|
|
test_buffs = MIN_BUFS_FOR_CONNS(test_conns);
|
2005-12-28 00:54:01 +01:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(cmd, sizeof(cmd),
|
2021-08-05 21:17:31 +02:00
|
|
|
"\"%s\" --check %s %s "
|
2006-01-01 00:50:59 +01:00
|
|
|
"-c max_connections=%d "
|
2006-10-04 20:58:08 +02:00
|
|
|
"-c shared_buffers=%d "
|
2018-07-10 17:37:42 +02:00
|
|
|
"-c dynamic_shared_memory_type=%s "
|
Replace SYSTEMQUOTEs with Windows-specific wrapper functions.
It's easy to forget using SYSTEMQUOTEs when constructing command strings
for system() or popen(). Even if we fix all the places missing it now, it is
bound to be forgotten again in the future. Introduce wrapper functions that
do the the extra quoting for you, and get rid of SYSTEMQUOTEs in all the
callers.
We previosly used SYSTEMQUOTEs in all the hard-coded command strings, and
this doesn't change the behavior of those. But user-supplied commands, like
archive_command, restore_command, COPY TO/FROM PROGRAM calls, as well as
pgbench's \shell, will now gain an extra pair of quotes. That is desirable,
but if you have existing scripts or config files that include an extra
pair of quotes, those might need to be adjusted.
Reviewed by Amit Kapila and Tom Lane
2014-05-05 15:07:40 +02:00
|
|
|
"< \"%s\" > \"%s\" 2>&1",
|
2021-07-01 19:33:05 +02:00
|
|
|
backend_exec, boot_options, extra_options,
|
2008-09-30 12:52:14 +02:00
|
|
|
test_conns, test_buffs,
|
2018-07-10 17:37:42 +02:00
|
|
|
dynamic_shared_memory_type,
|
2008-06-26 03:35:45 +02:00
|
|
|
DEVNULL, DEVNULL);
|
2022-08-29 19:55:38 +02:00
|
|
|
fflush(NULL);
|
2003-11-10 23:51:16 +01:00
|
|
|
status = system(cmd);
|
|
|
|
if (status == 0)
|
2006-01-02 17:45:12 +01:00
|
|
|
{
|
|
|
|
ok_buffers = test_buffs;
|
2003-11-10 23:51:16 +01:00
|
|
|
break;
|
2006-01-02 17:45:12 +01:00
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2006-01-01 00:50:59 +01:00
|
|
|
if (i >= connslen)
|
|
|
|
i = connslen - 1;
|
|
|
|
n_connections = trial_conns[i];
|
2003-11-13 02:36:00 +01:00
|
|
|
|
|
|
|
printf("%d\n", n_connections);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2008-09-30 12:52:14 +02:00
|
|
|
printf(_("selecting default shared_buffers ... "));
|
2003-11-13 02:36:00 +01:00
|
|
|
fflush(stdout);
|
|
|
|
|
2006-01-01 00:50:59 +01:00
|
|
|
for (i = 0; i < bufslen; i++)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2007-02-21 00:49:38 +01:00
|
|
|
/* Use same amount of memory, independent of BLCKSZ */
|
|
|
|
test_buffs = (trial_bufs[i] * 8192) / BLCKSZ;
|
2006-01-02 17:45:12 +01:00
|
|
|
if (test_buffs <= ok_buffers)
|
|
|
|
{
|
|
|
|
test_buffs = ok_buffers;
|
|
|
|
break;
|
|
|
|
}
|
2005-12-28 00:54:01 +01:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(cmd, sizeof(cmd),
|
2021-08-05 21:17:31 +02:00
|
|
|
"\"%s\" --check %s %s "
|
2006-01-01 00:50:59 +01:00
|
|
|
"-c max_connections=%d "
|
2006-10-04 20:58:08 +02:00
|
|
|
"-c shared_buffers=%d "
|
2018-07-10 17:37:42 +02:00
|
|
|
"-c dynamic_shared_memory_type=%s "
|
Replace SYSTEMQUOTEs with Windows-specific wrapper functions.
It's easy to forget using SYSTEMQUOTEs when constructing command strings
for system() or popen(). Even if we fix all the places missing it now, it is
bound to be forgotten again in the future. Introduce wrapper functions that
do the the extra quoting for you, and get rid of SYSTEMQUOTEs in all the
callers.
We previosly used SYSTEMQUOTEs in all the hard-coded command strings, and
this doesn't change the behavior of those. But user-supplied commands, like
archive_command, restore_command, COPY TO/FROM PROGRAM calls, as well as
pgbench's \shell, will now gain an extra pair of quotes. That is desirable,
but if you have existing scripts or config files that include an extra
pair of quotes, those might need to be adjusted.
Reviewed by Amit Kapila and Tom Lane
2014-05-05 15:07:40 +02:00
|
|
|
"< \"%s\" > \"%s\" 2>&1",
|
2021-07-01 19:33:05 +02:00
|
|
|
backend_exec, boot_options, extra_options,
|
2008-09-30 12:52:14 +02:00
|
|
|
n_connections, test_buffs,
|
2018-07-10 17:37:42 +02:00
|
|
|
dynamic_shared_memory_type,
|
2008-06-26 03:35:45 +02:00
|
|
|
DEVNULL, DEVNULL);
|
2022-08-29 19:55:38 +02:00
|
|
|
fflush(NULL);
|
2003-11-10 23:51:16 +01:00
|
|
|
status = system(cmd);
|
|
|
|
if (status == 0)
|
|
|
|
break;
|
|
|
|
}
|
2006-01-02 17:45:12 +01:00
|
|
|
n_buffers = test_buffs;
|
2003-11-13 02:36:00 +01:00
|
|
|
|
2006-10-04 20:58:08 +02:00
|
|
|
if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
|
2008-09-30 12:52:14 +02:00
|
|
|
printf("%dMB\n", (n_buffers * (BLCKSZ / 1024)) / 1024);
|
2006-10-03 23:11:55 +02:00
|
|
|
else
|
2008-09-30 12:52:14 +02:00
|
|
|
printf("%dkB\n", n_buffers * (BLCKSZ / 1024));
|
Attempt to identify system timezone by reading /etc/localtime symlink.
On many modern platforms, /etc/localtime is a symlink to a file within the
IANA database. Reading the symlink lets us find out the name of the system
timezone directly, without going through the brute-force search embodied in
scan_available_timezones(). This shortens the runtime of initdb by some
tens of ms, which is helpful for the buildfarm, and it also allows us to
reliably select the same zone name the system was actually configured for,
rather than possibly choosing one of IANA's many zone aliases. (For
example, in a system configured for "Asia/Tokyo", the brute-force search
would not choose that name but its alias "Japan", on the grounds of the
latter string being shorter. More surprisingly, "Navajo" is preferred
to either "America/Denver" or "US/Mountain", as seen in an old complaint
from Josh Berkus.)
If /etc/localtime doesn't exist, or isn't a symlink, or we can't make
sense of its contents, or the contents match a zone we know but that
zone doesn't match the observed behavior of localtime(), fall back to
the brute-force search.
Also, tweak initdb so that it prints the zone name it selected.
In passing, replace the last few references to the "Olson" database in
code comments with "IANA", as that's been our preferred term since
commit b2cbced9e.
Patch by me, per a suggestion from Robert Haas; review by Michael Paquier
Discussion: https://postgr.es/m/7408.1525812528@sss.pgh.pa.us
2018-09-13 18:36:21 +02:00
|
|
|
|
2019-07-09 15:47:09 +02:00
|
|
|
printf(_("selecting default time zone ... "));
|
Attempt to identify system timezone by reading /etc/localtime symlink.
On many modern platforms, /etc/localtime is a symlink to a file within the
IANA database. Reading the symlink lets us find out the name of the system
timezone directly, without going through the brute-force search embodied in
scan_available_timezones(). This shortens the runtime of initdb by some
tens of ms, which is helpful for the buildfarm, and it also allows us to
reliably select the same zone name the system was actually configured for,
rather than possibly choosing one of IANA's many zone aliases. (For
example, in a system configured for "Asia/Tokyo", the brute-force search
would not choose that name but its alias "Japan", on the grounds of the
latter string being shorter. More surprisingly, "Navajo" is preferred
to either "America/Denver" or "US/Mountain", as seen in an old complaint
from Josh Berkus.)
If /etc/localtime doesn't exist, or isn't a symlink, or we can't make
sense of its contents, or the contents match a zone we know but that
zone doesn't match the observed behavior of localtime(), fall back to
the brute-force search.
Also, tweak initdb so that it prints the zone name it selected.
In passing, replace the last few references to the "Olson" database in
code comments with "IANA", as that's been our preferred term since
commit b2cbced9e.
Patch by me, per a suggestion from Robert Haas; review by Michael Paquier
Discussion: https://postgr.es/m/7408.1525812528@sss.pgh.pa.us
2018-09-13 18:36:21 +02:00
|
|
|
fflush(stdout);
|
|
|
|
default_timezone = select_default_timezone(share_path);
|
|
|
|
printf("%s\n", default_timezone ? default_timezone : "GMT");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
/*
|
|
|
|
* Calculate the default wal_size with a "pretty" unit.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
pretty_wal_size(int segment_count)
|
|
|
|
{
|
|
|
|
int sz = wal_segment_size_mb * segment_count;
|
2018-03-15 16:10:41 +01:00
|
|
|
char *result = pg_malloc(14);
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
|
|
|
|
if ((sz % 1024) == 0)
|
2018-03-15 16:10:41 +01:00
|
|
|
snprintf(result, 14, "%dGB", sz / 1024);
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
else
|
2018-03-15 16:10:41 +01:00
|
|
|
snprintf(result, 14, "%dMB", sz);
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* set up all the config files
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
setup_config(void)
|
|
|
|
{
|
|
|
|
char **conflines;
|
2012-08-10 23:26:44 +02:00
|
|
|
char repltok[MAXPGPATH];
|
2003-11-10 23:51:16 +01:00
|
|
|
char path[MAXPGPATH];
|
2013-12-18 15:42:44 +01:00
|
|
|
char *autoconflines[3];
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-23 22:41:30 +01:00
|
|
|
fputs(_("creating configuration files ... "), stdout);
|
2003-11-13 02:36:00 +01:00
|
|
|
fflush(stdout);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
/* postgresql.conf */
|
|
|
|
|
|
|
|
conflines = readfile(conf_file);
|
|
|
|
|
|
|
|
snprintf(repltok, sizeof(repltok), "max_connections = %d", n_connections);
|
|
|
|
conflines = replace_token(conflines, "#max_connections = 100", repltok);
|
|
|
|
|
2006-10-04 20:58:08 +02:00
|
|
|
if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)
|
|
|
|
snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB",
|
|
|
|
(n_buffers * (BLCKSZ / 1024)) / 1024);
|
2006-10-03 23:11:55 +02:00
|
|
|
else
|
2006-10-04 20:58:08 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB",
|
|
|
|
n_buffers * (BLCKSZ / 1024));
|
2021-08-23 18:33:38 +02:00
|
|
|
conflines = replace_token(conflines, "#shared_buffers = 128MB", repltok);
|
2003-11-10 23:52:10 +01:00
|
|
|
|
2012-08-10 23:26:44 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
|
|
|
|
DEFAULT_PGSOCKET_DIR);
|
|
|
|
conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
|
|
|
|
repltok);
|
|
|
|
|
2004-12-27 21:39:21 +01:00
|
|
|
#if DEF_PGPORT != 5432
|
|
|
|
snprintf(repltok, sizeof(repltok), "#port = %d", DEF_PGPORT);
|
|
|
|
conflines = replace_token(conflines, "#port = 5432", repltok);
|
|
|
|
#endif
|
|
|
|
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
/* set default max_wal_size and min_wal_size */
|
|
|
|
snprintf(repltok, sizeof(repltok), "min_wal_size = %s",
|
|
|
|
pretty_wal_size(DEFAULT_MIN_WAL_SEGS));
|
|
|
|
conflines = replace_token(conflines, "#min_wal_size = 80MB", repltok);
|
|
|
|
|
|
|
|
snprintf(repltok, sizeof(repltok), "max_wal_size = %s",
|
|
|
|
pretty_wal_size(DEFAULT_MAX_WAL_SEGS));
|
|
|
|
conflines = replace_token(conflines, "#max_wal_size = 1GB", repltok);
|
|
|
|
|
2006-05-27 20:07:06 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "lc_messages = '%s'",
|
|
|
|
escape_quotes(lc_messages));
|
2003-11-10 23:51:16 +01:00
|
|
|
conflines = replace_token(conflines, "#lc_messages = 'C'", repltok);
|
|
|
|
|
2006-05-27 20:07:06 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'",
|
|
|
|
escape_quotes(lc_monetary));
|
2003-11-10 23:51:16 +01:00
|
|
|
conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok);
|
|
|
|
|
2006-05-27 20:07:06 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'",
|
|
|
|
escape_quotes(lc_numeric));
|
2003-11-10 23:51:16 +01:00
|
|
|
conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok);
|
|
|
|
|
2006-05-27 20:07:06 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "lc_time = '%s'",
|
|
|
|
escape_quotes(lc_time));
|
2003-11-10 23:51:16 +01:00
|
|
|
conflines = replace_token(conflines, "#lc_time = 'C'", repltok);
|
|
|
|
|
2005-12-09 16:51:14 +01:00
|
|
|
switch (locale_date_order(lc_time))
|
|
|
|
{
|
|
|
|
case DATEORDER_YMD:
|
|
|
|
strcpy(repltok, "datestyle = 'iso, ymd'");
|
|
|
|
break;
|
|
|
|
case DATEORDER_DMY:
|
|
|
|
strcpy(repltok, "datestyle = 'iso, dmy'");
|
|
|
|
break;
|
|
|
|
case DATEORDER_MDY:
|
|
|
|
default:
|
|
|
|
strcpy(repltok, "datestyle = 'iso, mdy'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
conflines = replace_token(conflines, "#datestyle = 'iso, mdy'", repltok);
|
|
|
|
|
2007-08-21 03:11:32 +02:00
|
|
|
snprintf(repltok, sizeof(repltok),
|
|
|
|
"default_text_search_config = 'pg_catalog.%s'",
|
|
|
|
escape_quotes(default_text_search_config));
|
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"#default_text_search_config = 'pg_catalog.simple'",
|
|
|
|
repltok);
|
|
|
|
|
2011-09-09 23:59:11 +02:00
|
|
|
if (default_timezone)
|
|
|
|
{
|
|
|
|
snprintf(repltok, sizeof(repltok), "timezone = '%s'",
|
|
|
|
escape_quotes(default_timezone));
|
|
|
|
conflines = replace_token(conflines, "#timezone = 'GMT'", repltok);
|
|
|
|
snprintf(repltok, sizeof(repltok), "log_timezone = '%s'",
|
|
|
|
escape_quotes(default_timezone));
|
|
|
|
conflines = replace_token(conflines, "#log_timezone = 'GMT'", repltok);
|
|
|
|
}
|
|
|
|
|
2013-10-11 01:38:56 +02:00
|
|
|
snprintf(repltok, sizeof(repltok), "dynamic_shared_memory_type = %s",
|
|
|
|
dynamic_shared_memory_type);
|
|
|
|
conflines = replace_token(conflines, "#dynamic_shared_memory_type = posix",
|
|
|
|
repltok);
|
|
|
|
|
2016-11-26 00:36:10 +01:00
|
|
|
#if DEFAULT_BACKEND_FLUSH_AFTER > 0
|
|
|
|
snprintf(repltok, sizeof(repltok), "#backend_flush_after = %dkB",
|
|
|
|
DEFAULT_BACKEND_FLUSH_AFTER * (BLCKSZ / 1024));
|
|
|
|
conflines = replace_token(conflines, "#backend_flush_after = 0",
|
|
|
|
repltok);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEFAULT_BGWRITER_FLUSH_AFTER > 0
|
|
|
|
snprintf(repltok, sizeof(repltok), "#bgwriter_flush_after = %dkB",
|
|
|
|
DEFAULT_BGWRITER_FLUSH_AFTER * (BLCKSZ / 1024));
|
|
|
|
conflines = replace_token(conflines, "#bgwriter_flush_after = 0",
|
|
|
|
repltok);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
|
|
|
|
snprintf(repltok, sizeof(repltok), "#checkpoint_flush_after = %dkB",
|
|
|
|
DEFAULT_CHECKPOINT_FLUSH_AFTER * (BLCKSZ / 1024));
|
|
|
|
conflines = replace_token(conflines, "#checkpoint_flush_after = 0",
|
|
|
|
repltok);
|
|
|
|
#endif
|
|
|
|
|
2014-10-19 06:45:40 +02:00
|
|
|
#ifndef USE_PREFETCH
|
2014-10-19 03:35:46 +02:00
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"#effective_io_concurrency = 1",
|
|
|
|
"#effective_io_concurrency = 0");
|
|
|
|
#endif
|
|
|
|
|
2016-08-17 10:39:22 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"#update_process_title = on",
|
|
|
|
"#update_process_title = off");
|
|
|
|
#endif
|
|
|
|
|
2020-06-10 16:16:37 +02:00
|
|
|
/*
|
|
|
|
* Change password_encryption setting to md5 if md5 was chosen as an
|
|
|
|
* authentication method, unless scram-sha-256 was also chosen.
|
|
|
|
*/
|
|
|
|
if ((strcmp(authmethodlocal, "md5") == 0 &&
|
|
|
|
strcmp(authmethodhost, "scram-sha-256") != 0) ||
|
|
|
|
(strcmp(authmethodhost, "md5") == 0 &&
|
|
|
|
strcmp(authmethodlocal, "scram-sha-256") != 0))
|
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
|
|
|
{
|
|
|
|
conflines = replace_token(conflines,
|
2020-06-10 16:16:37 +02:00
|
|
|
"#password_encryption = scram-sha-256",
|
|
|
|
"password_encryption = md5");
|
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
|
|
|
}
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
/*
|
|
|
|
* If group access has been enabled for the cluster then it makes sense to
|
|
|
|
* ensure that the log files also allow group access. Otherwise a backup
|
|
|
|
* from a user in the group would fail if the log files were not
|
|
|
|
* relocated.
|
|
|
|
*/
|
|
|
|
if (pg_dir_create_mode == PG_DIR_MODE_GROUP)
|
|
|
|
{
|
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"#log_file_mode = 0600",
|
|
|
|
"log_file_mode = 0640");
|
|
|
|
}
|
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
writefile(path, conflines);
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(path, pg_file_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of \"%s\": %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2013-12-18 15:42:44 +01:00
|
|
|
/*
|
|
|
|
* create the automatic configuration file to store the configuration
|
|
|
|
* parameters set by ALTER SYSTEM command. The parameters present in this
|
|
|
|
* file will override the value of parameters that exists before parse of
|
|
|
|
* this file.
|
|
|
|
*/
|
2014-01-27 04:23:20 +01:00
|
|
|
autoconflines[0] = pg_strdup("# Do not edit this file manually!\n");
|
|
|
|
autoconflines[1] = pg_strdup("# It will be overwritten by the ALTER SYSTEM command.\n");
|
2013-12-18 15:42:44 +01:00
|
|
|
autoconflines[2] = NULL;
|
|
|
|
|
2014-12-04 01:54:01 +01:00
|
|
|
sprintf(path, "%s/postgresql.auto.conf", pg_data);
|
2013-12-18 15:42:44 +01:00
|
|
|
|
|
|
|
writefile(path, autoconflines);
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(path, pg_file_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of \"%s\": %m", path);
|
2013-12-18 15:42:44 +01:00
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
free(conflines);
|
|
|
|
|
|
|
|
|
|
|
|
/* pg_hba.conf */
|
|
|
|
|
|
|
|
conflines = readfile(hba_file);
|
|
|
|
|
2004-10-06 11:13:10 +02:00
|
|
|
conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
|
2004-10-06 11:01:18 +02:00
|
|
|
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2005-08-22 18:27:36 +02:00
|
|
|
/*
|
|
|
|
* Probe to see if there is really any platform support for IPv6, and
|
|
|
|
* comment out the relevant pg_hba line if not. This avoids runtime
|
|
|
|
* warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
|
|
|
|
* useful on Windows, where executables built on a machine with IPv6 may
|
|
|
|
* have to run on a machine without.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct addrinfo *gai_result;
|
|
|
|
struct addrinfo hints;
|
2005-08-27 20:44:03 +02:00
|
|
|
int err = 0;
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2005-08-27 20:44:03 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
/* need to call WSAStartup before calling getaddrinfo */
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
err = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
|
|
|
#endif
|
2005-08-22 18:27:36 +02:00
|
|
|
|
2019-08-05 05:14:58 +02:00
|
|
|
/* for best results, this code should match parse_hba_line() */
|
2005-08-22 18:27:36 +02:00
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
2014-04-16 19:20:54 +02:00
|
|
|
hints.ai_family = AF_UNSPEC;
|
2005-08-22 18:27:36 +02:00
|
|
|
hints.ai_socktype = 0;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
hints.ai_addrlen = 0;
|
|
|
|
hints.ai_canonname = NULL;
|
|
|
|
hints.ai_addr = NULL;
|
|
|
|
hints.ai_next = NULL;
|
|
|
|
|
2005-08-27 20:44:03 +02:00
|
|
|
if (err != 0 ||
|
|
|
|
getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
|
2017-03-10 18:17:56 +01:00
|
|
|
{
|
2005-08-22 18:27:36 +02:00
|
|
|
conflines = replace_token(conflines,
|
2010-01-26 17:18:12 +01:00
|
|
|
"host all all ::1",
|
|
|
|
"#host all all ::1");
|
2017-03-10 18:17:56 +01:00
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"host replication all ::1",
|
|
|
|
"#host replication all ::1");
|
|
|
|
}
|
2005-08-22 18:27:36 +02:00
|
|
|
}
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-08-01 07:59:13 +02:00
|
|
|
/* Replace default authentication methods */
|
|
|
|
conflines = replace_token(conflines,
|
2012-02-01 20:18:55 +01:00
|
|
|
"@authmethodhost@",
|
|
|
|
authmethodhost);
|
2011-03-19 18:44:35 +01:00
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"@authmethodlocal@",
|
|
|
|
authmethodlocal);
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-08-01 07:59:13 +02:00
|
|
|
conflines = replace_token(conflines,
|
|
|
|
"@authcomment@",
|
2012-02-01 20:18:55 +01:00
|
|
|
(strcmp(authmethodlocal, "trust") == 0 || strcmp(authmethodhost, "trust") == 0) ? AUTHTRUST_WARNING : "");
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
writefile(path, conflines);
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(path, pg_file_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of \"%s\": %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
free(conflines);
|
|
|
|
|
|
|
|
/* pg_ident.conf */
|
|
|
|
|
|
|
|
conflines = readfile(ident_file);
|
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
writefile(path, conflines);
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(path, pg_file_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of \"%s\": %m", path);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
free(conflines);
|
|
|
|
|
|
|
|
check_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2003-11-14 00:46:31 +01:00
|
|
|
* run the BKI script in bootstrap mode to create template1
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2010-01-07 00:23:51 +01:00
|
|
|
bootstrap_template1(void)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2004-11-29 04:05:03 +01:00
|
|
|
PG_CMD_DECL;
|
|
|
|
char **line;
|
2003-11-10 23:51:16 +01:00
|
|
|
char **bki_lines;
|
|
|
|
char headerline[MAXPGPATH];
|
2008-07-19 06:01:29 +02:00
|
|
|
char buf[64];
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
printf(_("running bootstrap script ... "));
|
2003-11-13 02:36:00 +01:00
|
|
|
fflush(stdout);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
bki_lines = readfile(bki_file);
|
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/* Check that bki file appears to be of the right version */
|
|
|
|
|
|
|
|
snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
|
2010-01-07 00:23:51 +01:00
|
|
|
PG_MAJORVERSION);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
if (strcmp(headerline, *bki_lines) != 0)
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
|
|
|
|
bki_file, PG_VERSION);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Specify the correct path using the option -L.");
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2008-07-19 06:01:29 +02:00
|
|
|
/* Substitute for various symbols used in the BKI file */
|
|
|
|
|
|
|
|
sprintf(buf, "%d", NAMEDATALEN);
|
|
|
|
bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
|
|
|
|
|
2008-11-14 03:09:52 +01:00
|
|
|
sprintf(buf, "%d", (int) sizeof(Pointer));
|
|
|
|
bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
|
|
|
|
|
|
|
|
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
|
|
|
|
(sizeof(Pointer) == 4) ? "i" : "d");
|
|
|
|
|
2008-07-19 06:01:29 +02:00
|
|
|
bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
|
|
|
|
FLOAT8PASSBYVAL ? "true" : "false");
|
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
bki_lines = replace_token(bki_lines, "POSTGRES",
|
|
|
|
escape_quotes_bki(username));
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
bki_lines = replace_token(bki_lines, "ENCODING",
|
|
|
|
encodingid_to_string(encodingid));
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
bki_lines = replace_token(bki_lines, "LC_COLLATE",
|
|
|
|
escape_quotes_bki(lc_collate));
|
2009-06-11 16:49:15 +02:00
|
|
|
|
2018-04-18 01:53:50 +02:00
|
|
|
bki_lines = replace_token(bki_lines, "LC_CTYPE",
|
|
|
|
escape_quotes_bki(lc_ctype));
|
2009-06-11 16:49:15 +02:00
|
|
|
|
2022-03-17 11:11:21 +01:00
|
|
|
bki_lines = replace_token(bki_lines, "ICU_LOCALE",
|
2023-03-08 16:35:42 +01:00
|
|
|
icu_locale ? escape_quotes_bki(icu_locale) : "_null_");
|
|
|
|
|
|
|
|
bki_lines = replace_token(bki_lines, "ICU_RULES",
|
|
|
|
icu_rules ? escape_quotes_bki(icu_rules) : "_null_");
|
2022-03-17 11:11:21 +01:00
|
|
|
|
|
|
|
sprintf(buf, "%c", locale_provider);
|
|
|
|
bki_lines = replace_token(bki_lines, "LOCALE_PROVIDER", buf);
|
|
|
|
|
2004-05-05 18:09:31 +02:00
|
|
|
/* Also ensure backend isn't confused by this environment var: */
|
2004-05-05 23:18:29 +02:00
|
|
|
unsetenv("PGCLIENTENCODING");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
snprintf(cmd, sizeof(cmd),
|
2021-11-03 07:34:28 +01:00
|
|
|
"\"%s\" --boot -X %d %s %s %s %s",
|
2013-03-22 14:54:07 +01:00
|
|
|
backend_exec,
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
wal_segment_size_mb * (1024 * 1024),
|
2013-03-22 14:54:07 +01:00
|
|
|
data_checksums ? "-k" : "",
|
2021-07-01 19:33:05 +02:00
|
|
|
boot_options, extra_options,
|
2020-12-28 03:37:42 +01:00
|
|
|
debug ? "-d 5" : "");
|
2017-08-31 04:28:36 +02:00
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
PG_CMD_OPEN;
|
|
|
|
|
|
|
|
for (line = bki_lines; *line != NULL; line++)
|
|
|
|
{
|
2004-11-29 04:05:03 +01:00
|
|
|
PG_CMD_PUTS(*line);
|
2003-11-10 23:51:16 +01:00
|
|
|
free(*line);
|
|
|
|
}
|
|
|
|
|
|
|
|
PG_CMD_CLOSE;
|
|
|
|
|
|
|
|
free(bki_lines);
|
|
|
|
|
|
|
|
check_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up the shadow password table
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_auth(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* The authid table shouldn't be readable except through views, to
|
|
|
|
* ensure passwords are not publicly visible.
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("REVOKE ALL ON pg_authid FROM public;\n\n");
|
2016-08-30 21:25:01 +02:00
|
|
|
|
|
|
|
if (superuser_password)
|
2019-08-08 08:47:55 +02:00
|
|
|
PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
|
2016-08-30 21:25:01 +02:00
|
|
|
username, escape_quotes(superuser_password));
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-08-30 21:25:01 +02:00
|
|
|
* get the superuser password if required
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2016-08-30 21:25:01 +02:00
|
|
|
get_su_pwd(void)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
char *pwd1;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2004-06-24 21:26:59 +02:00
|
|
|
if (pwprompt)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2004-06-24 21:26:59 +02:00
|
|
|
/*
|
|
|
|
* Read password from terminal
|
|
|
|
*/
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
char *pwd2;
|
|
|
|
|
2016-08-30 21:25:01 +02:00
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
pwd1 = simple_prompt("Enter new superuser password: ", false);
|
|
|
|
pwd2 = simple_prompt("Enter it again: ", false);
|
2004-06-24 21:26:59 +02:00
|
|
|
if (strcmp(pwd1, pwd2) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, _("Passwords didn't match.\n"));
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1);
|
2004-06-24 21:26:59 +02:00
|
|
|
}
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
free(pwd2);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2004-06-24 21:26:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Read password from file
|
|
|
|
*
|
|
|
|
* Ideally this should insist that the file not be world-readable.
|
|
|
|
* However, this option is mainly intended for use on Windows where
|
|
|
|
* file permissions may not exist at all, so we'll skip the paranoia
|
|
|
|
* for now.
|
|
|
|
*/
|
|
|
|
FILE *pwf = fopen(pwfilename, "r");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2004-06-24 21:26:59 +02:00
|
|
|
if (!pwf)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not open file \"%s\" for reading: %m",
|
|
|
|
pwfilename);
|
2021-11-18 01:09:54 +01:00
|
|
|
pwd1 = pg_get_line(pwf, NULL);
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
if (!pwd1)
|
2004-06-24 21:26:59 +02:00
|
|
|
{
|
2014-12-05 13:27:56 +01:00
|
|
|
if (ferror(pwf))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not read password from file \"%s\": %m",
|
|
|
|
pwfilename);
|
2014-12-05 13:27:56 +01:00
|
|
|
else
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("password file \"%s\" is empty",
|
|
|
|
pwfilename);
|
2004-06-24 21:26:59 +02:00
|
|
|
}
|
|
|
|
fclose(pwf);
|
|
|
|
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
(void) pg_strip_crlf(pwd1);
|
2004-06-24 21:26:59 +02:00
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
|
Remove arbitrary restrictions on password length.
This patch started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.
recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it. (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)
Likewise remove the arbitrary error condition in pg_saslprep().
The remaining limits are mostly in client-side code that prompts
for passwords. To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary. Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line. (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another patch.)
I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.
This patch is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor patch. Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.
Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
2020-09-04 02:09:18 +02:00
|
|
|
superuser_password = pwd1;
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up pg_depend
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_depend(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* Advance the OID counter so that subsequently-created objects aren't
|
|
|
|
* pinned.
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("SELECT pg_stop_making_pinned_objects();\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-01-30 19:14:31 +01:00
|
|
|
* Run external file
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2021-01-30 19:14:31 +01:00
|
|
|
setup_run_file(FILE *cmdfd, const char *filename)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2021-01-30 19:14:31 +01:00
|
|
|
char **lines;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
lines = readfile(filename);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
for (char **line = lines; *line != NULL; line++)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2004-11-29 04:05:03 +01:00
|
|
|
PG_CMD_PUTS(*line);
|
2003-11-10 23:51:16 +01:00
|
|
|
free(*line);
|
|
|
|
}
|
|
|
|
|
2018-05-08 21:59:01 +02:00
|
|
|
PG_CMD_PUTS("\n\n");
|
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
free(lines);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-01-19 12:54:58 +01:00
|
|
|
* fill in extra description data
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_description(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2011-03-03 21:55:47 +01:00
|
|
|
/* Create default descriptions for operator implementation functions */
|
|
|
|
PG_CMD_PUTS("WITH funcdescs AS ( "
|
2018-05-08 21:59:01 +02:00
|
|
|
"SELECT p.oid as p_oid, o.oid as o_oid, oprname "
|
2011-03-03 21:55:47 +01:00
|
|
|
"FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
|
|
|
|
"INSERT INTO pg_description "
|
|
|
|
" SELECT p_oid, 'pg_proc'::regclass, 0, "
|
|
|
|
" 'implementation of ' || oprname || ' operator' "
|
|
|
|
" FROM funcdescs "
|
2018-05-08 21:59:01 +02:00
|
|
|
" WHERE NOT EXISTS (SELECT 1 FROM pg_description "
|
|
|
|
" WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) "
|
|
|
|
" AND NOT EXISTS (SELECT 1 FROM pg_description "
|
|
|
|
" WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
|
|
|
|
" AND description LIKE 'deprecated%');\n\n");
|
2006-02-12 04:22:21 +01:00
|
|
|
}
|
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
/*
|
|
|
|
* populate pg_collation
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_collation(FILE *cmdfd)
|
2011-02-08 22:04:18 +01:00
|
|
|
{
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
/*
|
2023-03-10 13:35:00 +01:00
|
|
|
* Add SQL-standard names. We don't want to pin these, so they don't go
|
|
|
|
* in pg_collation.dat. But add them before reading system collations, so
|
|
|
|
* that they win if libc defines a locale with the same name.
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
*/
|
2023-03-10 13:35:00 +01:00
|
|
|
PG_CMD_PRINTF("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, colliculocale)"
|
|
|
|
"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",
|
|
|
|
BOOTSTRAP_SUPERUSERID, COLLPROVIDER_ICU);
|
|
|
|
|
2019-08-08 08:47:55 +02:00
|
|
|
PG_CMD_PRINTF("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype)"
|
2019-03-22 12:09:32 +01:00
|
|
|
"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",
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC, PG_UTF8);
|
2011-02-08 22:04:18 +01:00
|
|
|
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
/* Now import all collations we can find in the operating system */
|
|
|
|
PG_CMD_PUTS("SELECT pg_import_system_collations('pg_catalog');\n\n");
|
2011-02-08 22:04:18 +01:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
2003-11-14 00:46:31 +01:00
|
|
|
* Set up privileges
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
2005-04-12 21:29:24 +02:00
|
|
|
* We mark most system catalogs as world-readable. We don't currently have
|
|
|
|
* to touch functions, languages, or databases, because their default
|
|
|
|
* permissions are OK.
|
|
|
|
*
|
2003-11-14 00:46:31 +01:00
|
|
|
* Some objects may require different permissions by default, so we
|
|
|
|
* make sure we don't overwrite privilege sets that have already been
|
|
|
|
* set (NOT NULL).
|
2016-04-07 03:45:32 +02:00
|
|
|
*
|
|
|
|
* Also populate pg_init_privs to save what the privileges are at init
|
|
|
|
* time. This is used by pg_dump to allow users to change privileges
|
|
|
|
* on catalog objects and to have those privilege changes preserved
|
|
|
|
* across dump/reload and pg_upgrade.
|
2016-07-17 15:04:46 +02:00
|
|
|
*
|
|
|
|
* Note that pg_init_privs is only for per-database objects and therefore
|
|
|
|
* we don't include databases or tablespaces.
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_privileges(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2022-12-05 23:28:59 +01:00
|
|
|
PG_CMD_PRINTF("UPDATE pg_class "
|
|
|
|
" SET relacl = (SELECT array_agg(a.acl) FROM "
|
|
|
|
" (SELECT E'=r/\"%s\"' as acl "
|
|
|
|
" UNION SELECT unnest(pg_catalog.acldefault("
|
|
|
|
" CASE WHEN relkind = " CppAsString2(RELKIND_SEQUENCE) " THEN 's' "
|
|
|
|
" ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
|
|
|
|
" ) as a) "
|
|
|
|
" WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
|
|
|
|
CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
|
|
|
|
CppAsString2(RELKIND_SEQUENCE) ")"
|
|
|
|
" AND relacl IS NULL;\n\n",
|
|
|
|
escape_quotes(username));
|
|
|
|
PG_CMD_PUTS("GRANT USAGE ON SCHEMA pg_catalog, public TO PUBLIC;\n\n");
|
|
|
|
PG_CMD_PUTS("REVOKE ALL ON pg_largeobject FROM PUBLIC;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
|
|
|
|
" 0,"
|
|
|
|
" relacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_class"
|
|
|
|
" WHERE"
|
|
|
|
" relacl IS NOT NULL"
|
|
|
|
" AND relkind IN (" CppAsString2(RELKIND_RELATION) ", "
|
|
|
|
CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
|
|
|
|
CppAsString2(RELKIND_SEQUENCE) ");\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" pg_class.oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_class'),"
|
|
|
|
" pg_attribute.attnum,"
|
|
|
|
" pg_attribute.attacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_class"
|
|
|
|
" JOIN pg_attribute ON (pg_class.oid = pg_attribute.attrelid)"
|
|
|
|
" WHERE"
|
|
|
|
" pg_attribute.attacl IS NOT NULL"
|
|
|
|
" AND pg_class.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
|
|
|
|
CppAsString2(RELKIND_VIEW) ", " CppAsString2(RELKIND_MATVIEW) ", "
|
|
|
|
CppAsString2(RELKIND_SEQUENCE) ");\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_proc'),"
|
|
|
|
" 0,"
|
|
|
|
" proacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_proc"
|
|
|
|
" WHERE"
|
|
|
|
" proacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_type'),"
|
|
|
|
" 0,"
|
|
|
|
" typacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_type"
|
|
|
|
" WHERE"
|
|
|
|
" typacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_language'),"
|
|
|
|
" 0,"
|
|
|
|
" lanacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_language"
|
|
|
|
" WHERE"
|
|
|
|
" lanacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE "
|
|
|
|
" relname = 'pg_largeobject_metadata'),"
|
|
|
|
" 0,"
|
|
|
|
" lomacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_largeobject_metadata"
|
|
|
|
" WHERE"
|
|
|
|
" lomacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE relname = 'pg_namespace'),"
|
|
|
|
" 0,"
|
|
|
|
" nspacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_namespace"
|
|
|
|
" WHERE"
|
|
|
|
" nspacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class WHERE "
|
|
|
|
" relname = 'pg_foreign_data_wrapper'),"
|
|
|
|
" 0,"
|
|
|
|
" fdwacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_foreign_data_wrapper"
|
|
|
|
" WHERE"
|
|
|
|
" fdwacl IS NOT NULL;\n\n");
|
|
|
|
PG_CMD_PUTS("INSERT INTO pg_init_privs "
|
|
|
|
" (objoid, classoid, objsubid, initprivs, privtype)"
|
|
|
|
" SELECT"
|
|
|
|
" oid,"
|
|
|
|
" (SELECT oid FROM pg_class "
|
|
|
|
" WHERE relname = 'pg_foreign_server'),"
|
|
|
|
" 0,"
|
|
|
|
" srvacl,"
|
|
|
|
" 'i'"
|
|
|
|
" FROM"
|
|
|
|
" pg_foreign_server"
|
|
|
|
" WHERE"
|
|
|
|
" srvacl IS NOT NULL;\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-11-14 00:46:31 +01:00
|
|
|
* extract the strange version of version required for information schema
|
|
|
|
* (09.08.0007abc)
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_info_version(void)
|
|
|
|
{
|
|
|
|
char *letterversion;
|
|
|
|
long major = 0,
|
|
|
|
minor = 0,
|
|
|
|
micro = 0;
|
|
|
|
char *endptr;
|
2012-10-02 21:35:10 +02:00
|
|
|
char *vstr = pg_strdup(PG_VERSION);
|
2003-11-10 23:51:16 +01:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = vstr + (strlen(vstr) - 1);
|
|
|
|
while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
|
|
|
|
ptr--;
|
|
|
|
letterversion = ptr + 1;
|
|
|
|
major = strtol(vstr, &endptr, 10);
|
|
|
|
if (*endptr)
|
|
|
|
minor = strtol(endptr + 1, &endptr, 10);
|
|
|
|
if (*endptr)
|
|
|
|
micro = strtol(endptr + 1, &endptr, 10);
|
|
|
|
snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
|
|
|
|
major, minor, micro, letterversion);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load info schema and populate from features file
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_schema(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2021-01-30 19:14:31 +01:00
|
|
|
setup_run_file(cmdfd, info_schema_file);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2019-08-08 08:47:55 +02:00
|
|
|
PG_CMD_PRINTF("UPDATE information_schema.sql_implementation_info "
|
2003-11-10 23:51:16 +01:00
|
|
|
" SET character_value = '%s' "
|
2015-12-18 01:38:21 +01:00
|
|
|
" WHERE implementation_info_name = 'DBMS VERSION';\n\n",
|
2003-11-10 23:51:16 +01:00
|
|
|
infoversion);
|
|
|
|
|
2019-08-08 08:47:55 +02:00
|
|
|
PG_CMD_PRINTF("COPY information_schema.sql_features "
|
2003-11-14 00:46:31 +01:00
|
|
|
" (feature_id, feature_name, sub_feature_id, "
|
|
|
|
" sub_feature_name, is_supported, comments) "
|
2015-12-18 01:38:21 +01:00
|
|
|
" FROM E'%s';\n\n",
|
2006-05-27 20:07:06 +02:00
|
|
|
escape_quotes(features_file));
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2009-12-18 22:28:42 +01:00
|
|
|
/*
|
2017-04-05 06:38:25 +02:00
|
|
|
* load PL/pgSQL server-side language
|
2009-12-18 22:28:42 +01:00
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
load_plpgsql(FILE *cmdfd)
|
2009-12-18 22:28:42 +01:00
|
|
|
{
|
2015-12-18 01:38:21 +01:00
|
|
|
PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
|
2009-12-18 22:28:42 +01:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* clean everything up in template1
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
vacuum_db(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2015-03-31 17:51:39 +02:00
|
|
|
/* Run analyze before VACUUM so the statistics are frozen. */
|
2015-12-18 01:38:21 +01:00
|
|
|
PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy template1 to template0
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
make_template0(FILE *cmdfd)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
pg_upgrade: Preserve database OIDs.
Commit 9a974cbcba005256a19991203583a94b4f9a21a9 arranged to preserve
relfilenodes and tablespace OIDs. For similar reasons, also arrange
to preserve database OIDs.
One problem is that, up until now, the OIDs assigned to the template0
and postgres databases have not been fixed. This could be a problem
when upgrading, because pg_upgrade might try to migrate a database
from the old cluster to the new cluster while keeping the OID and find
a different database with that OID, resulting in a failure. If it finds
a database with the same name and the same OID that's OK: it will be
dropped and recreated. But the same OID and a different name is a
problem.
To prevent that, fix the OIDs for postgres and template0 to specific
values less than 16384. To avoid running afoul of this rule, these
values should not be changed in future releases. It's not a problem
that these OIDs aren't fixed in existing releases, because the OIDs
that we're assigning here weren't used for either of these databases
in any previous release. Thus, there's no chance that an upgrade of
a cluster from any previous release will collide with the OIDs we're
assigning here. And going forward, the OIDs will always be fixed, so
the only potential collision is with a system database having the
same name and the same OID, which is OK.
This patch lets users assign a specific OID to a database as well,
provided however that it can't be less than 16384. I (rhaas) thought
it might be better not to expose this capability to users, but the
consensus was otherwise, so the syntax is documented. Letting users
assign OIDs below 16384 would not be OK, though, because a
user-created database with a low-numbered OID might collide with a
system-created database in a future release. We therefore prohibit
that.
Shruthi KC, based on an earlier patch from Antonin Houska, reviewed
and with some adjustments by me.
Discussion: http://postgr.es/m/CA+TgmoYgTwYcUmB=e8+hRHOFA0kkS6Kde85+UNdon6q7bt1niQ@mail.gmail.com
Discussion: http://postgr.es/m/CAASxf_Mnwm1Dh2vd5FAhVX6S1nwNSZUB1z12VddYtM++H2+p7w@mail.gmail.com
2022-01-24 20:23:15 +01:00
|
|
|
/*
|
|
|
|
* pg_upgrade tries to preserve database OIDs across upgrades. It's smart
|
|
|
|
* enough to drop and recreate a conflicting database with the same name,
|
|
|
|
* but if the same OID were used for one system-created database in the
|
|
|
|
* old cluster and a different system-created database in the new cluster,
|
|
|
|
* it would fail. To avoid that, assign a fixed OID to template0 rather
|
|
|
|
* than letting the server choose one.
|
|
|
|
*
|
|
|
|
* (Note that, while the user could have dropped and recreated these
|
|
|
|
* objects in the old cluster, the problem scenario only exists if the OID
|
|
|
|
* that is in use in the old cluster is also used in the new cluster - and
|
|
|
|
* the new cluster should be the result of a fresh initdb.)
|
2022-03-31 21:15:11 +02:00
|
|
|
*
|
|
|
|
* We use "STRATEGY = file_copy" here because checkpoints during initdb
|
|
|
|
* are cheap. "STRATEGY = wal_log" would generate more WAL, which would be
|
|
|
|
* a little bit slower and make the new cluster a little bit bigger.
|
pg_upgrade: Preserve database OIDs.
Commit 9a974cbcba005256a19991203583a94b4f9a21a9 arranged to preserve
relfilenodes and tablespace OIDs. For similar reasons, also arrange
to preserve database OIDs.
One problem is that, up until now, the OIDs assigned to the template0
and postgres databases have not been fixed. This could be a problem
when upgrading, because pg_upgrade might try to migrate a database
from the old cluster to the new cluster while keeping the OID and find
a different database with that OID, resulting in a failure. If it finds
a database with the same name and the same OID that's OK: it will be
dropped and recreated. But the same OID and a different name is a
problem.
To prevent that, fix the OIDs for postgres and template0 to specific
values less than 16384. To avoid running afoul of this rule, these
values should not be changed in future releases. It's not a problem
that these OIDs aren't fixed in existing releases, because the OIDs
that we're assigning here weren't used for either of these databases
in any previous release. Thus, there's no chance that an upgrade of
a cluster from any previous release will collide with the OIDs we're
assigning here. And going forward, the OIDs will always be fixed, so
the only potential collision is with a system database having the
same name and the same OID, which is OK.
This patch lets users assign a specific OID to a database as well,
provided however that it can't be less than 16384. I (rhaas) thought
it might be better not to expose this capability to users, but the
consensus was otherwise, so the syntax is documented. Letting users
assign OIDs below 16384 would not be OK, though, because a
user-created database with a low-numbered OID might collide with a
system-created database in a future release. We therefore prohibit
that.
Shruthi KC, based on an earlier patch from Antonin Houska, reviewed
and with some adjustments by me.
Discussion: http://postgr.es/m/CA+TgmoYgTwYcUmB=e8+hRHOFA0kkS6Kde85+UNdon6q7bt1niQ@mail.gmail.com
Discussion: http://postgr.es/m/CAASxf_Mnwm1Dh2vd5FAhVX6S1nwNSZUB1z12VddYtM++H2+p7w@mail.gmail.com
2022-01-24 20:23:15 +01:00
|
|
|
*/
|
2022-12-05 23:28:59 +01:00
|
|
|
PG_CMD_PUTS("CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false"
|
|
|
|
" OID = " CppAsString2(Template0DbOid)
|
|
|
|
" STRATEGY = file_copy;\n\n");
|
2022-02-14 08:09:04 +01:00
|
|
|
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* template0 shouldn't have any collation-dependent objects, so unset
|
|
|
|
* the collation version. This disables collation version checks when
|
|
|
|
* making a new database from it.
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("UPDATE pg_database SET datcollversion = NULL WHERE datname = 'template0';\n\n");
|
2022-02-14 08:09:04 +01:00
|
|
|
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* While we are here, do set the collation version on template1.
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("UPDATE pg_database SET datcollversion = pg_database_collation_actual_version(oid) WHERE datname = 'template1';\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* Explicitly revoke public create-schema and create-temp-table
|
|
|
|
* privileges in template1 and template0; else the latter would be on
|
|
|
|
* by default
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n\n");
|
|
|
|
PG_CMD_PUTS("REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n\n");
|
2011-03-15 16:26:20 +01:00
|
|
|
|
2022-12-05 23:28:59 +01:00
|
|
|
PG_CMD_PUTS("COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2022-12-05 23:28:59 +01:00
|
|
|
/*
|
|
|
|
* Finally vacuum to clean up dead rows in pg_database
|
|
|
|
*/
|
|
|
|
PG_CMD_PUTS("VACUUM pg_database;\n\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2005-06-21 06:02:34 +02:00
|
|
|
/*
|
|
|
|
* copy template1 to postgres
|
|
|
|
*/
|
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
make_postgres(FILE *cmdfd)
|
2005-06-21 06:02:34 +02:00
|
|
|
{
|
2022-03-31 21:15:11 +02:00
|
|
|
/*
|
|
|
|
* Just as we did for template0, and for the same reasons, assign a fixed
|
|
|
|
* OID to postgres and select the file_copy strategy.
|
|
|
|
*/
|
2022-12-05 23:28:59 +01:00
|
|
|
PG_CMD_PUTS("CREATE DATABASE postgres OID = " CppAsString2(PostgresDbOid)
|
|
|
|
" STRATEGY = file_copy;\n\n");
|
|
|
|
PG_CMD_PUTS("COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n");
|
2005-06-21 06:02:34 +02:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* signal handler in case we are interrupted.
|
|
|
|
*
|
|
|
|
* The Windows runtime docs at
|
2020-02-19 05:20:33 +01:00
|
|
|
* https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal
|
2003-11-10 23:51:16 +01:00
|
|
|
* specifically forbid a number of things being done from a signal handler,
|
|
|
|
* including IO, memory allocation and system calls, and only allow jmpbuf
|
|
|
|
* if you are handling SIGFPE.
|
|
|
|
*
|
|
|
|
* I avoided doing the forbidden things by setting a flag instead of calling
|
2018-12-29 13:21:57 +01:00
|
|
|
* exit() directly.
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
|
|
|
* Also note the behaviour of Windows with SIGINT, which says this:
|
2020-02-19 05:20:33 +01:00
|
|
|
* SIGINT is not supported for any Win32 application. When a CTRL+C interrupt
|
|
|
|
* occurs, Win32 operating systems generate a new thread to specifically
|
|
|
|
* handle that interrupt. This can cause a single-thread application, such as
|
|
|
|
* one in UNIX, to become multithreaded and cause unexpected behavior.
|
2003-11-10 23:51:16 +01:00
|
|
|
*
|
|
|
|
* I have no idea how to handle this. (Strange they call UNIX an application!)
|
|
|
|
* So this will need some testing on Windows.
|
|
|
|
*/
|
|
|
|
static void
|
2022-09-14 20:44:45 +02:00
|
|
|
trapsig(SIGNAL_ARGS)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
|
|
|
/* handle systems that reset the handler, like Windows (grr) */
|
2022-09-14 20:44:45 +02:00
|
|
|
pqsignal(postgres_signal_arg, trapsig);
|
2003-11-14 19:32:34 +01:00
|
|
|
caught_signal = true;
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-12-29 13:21:57 +01:00
|
|
|
* call exit() if we got a signal, or else output "ok".
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
2004-10-11 01:37:45 +02:00
|
|
|
check_ok(void)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2003-11-14 19:32:34 +01:00
|
|
|
if (caught_signal)
|
|
|
|
{
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("caught signal\n"));
|
2004-11-29 04:05:03 +01:00
|
|
|
fflush(stdout);
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1);
|
2003-11-14 19:32:34 +01:00
|
|
|
}
|
|
|
|
else if (output_failed)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2004-11-29 04:05:03 +01:00
|
|
|
printf(_("could not write to child process: %s\n"),
|
|
|
|
strerror(output_errno));
|
|
|
|
fflush(stdout);
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-14 19:32:34 +01:00
|
|
|
/* all seems well */
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("ok\n"));
|
2004-11-29 04:05:03 +01:00
|
|
|
fflush(stdout);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-12 01:15:38 +02:00
|
|
|
/* Hack to suppress a warning about %x from some versions of gcc */
|
|
|
|
static inline size_t
|
|
|
|
my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
|
|
|
|
{
|
|
|
|
return strftime(s, max, fmt, tm);
|
|
|
|
}
|
|
|
|
|
2005-12-09 16:51:14 +01:00
|
|
|
/*
|
|
|
|
* Determine likely date order from locale
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
locale_date_order(const char *locale)
|
|
|
|
{
|
|
|
|
struct tm testtime;
|
|
|
|
char buf[128];
|
|
|
|
char *posD;
|
|
|
|
char *posM;
|
|
|
|
char *posY;
|
|
|
|
char *save;
|
|
|
|
size_t res;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = DATEORDER_MDY; /* default */
|
|
|
|
|
|
|
|
save = setlocale(LC_TIME, NULL);
|
|
|
|
if (!save)
|
|
|
|
return result;
|
2012-10-02 21:35:10 +02:00
|
|
|
save = pg_strdup(save);
|
2005-12-09 16:51:14 +01:00
|
|
|
|
|
|
|
setlocale(LC_TIME, locale);
|
|
|
|
|
|
|
|
memset(&testtime, 0, sizeof(testtime));
|
|
|
|
testtime.tm_mday = 22;
|
|
|
|
testtime.tm_mon = 10; /* November, should come out as "11" */
|
|
|
|
testtime.tm_year = 133; /* 2033 */
|
|
|
|
|
2007-07-12 01:15:38 +02:00
|
|
|
res = my_strftime(buf, sizeof(buf), "%x", &testtime);
|
2005-12-09 16:51:14 +01:00
|
|
|
|
|
|
|
setlocale(LC_TIME, save);
|
|
|
|
free(save);
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
posM = strstr(buf, "11");
|
|
|
|
posD = strstr(buf, "22");
|
|
|
|
posY = strstr(buf, "33");
|
|
|
|
|
|
|
|
if (!posM || !posD || !posY)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (posY < posM && posM < posD)
|
|
|
|
result = DATEORDER_YMD;
|
|
|
|
else if (posD < posM)
|
|
|
|
result = DATEORDER_DMY;
|
|
|
|
else
|
|
|
|
result = DATEORDER_MDY;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
2014-05-14 17:51:10 +02:00
|
|
|
* Verify that locale name is valid for the locale category.
|
2008-09-23 11:20:39 +02:00
|
|
|
*
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
* If successful, and canonname isn't NULL, a malloc'd copy of the locale's
|
|
|
|
* canonical name is stored there. This is especially useful for figuring out
|
|
|
|
* what locale name "" means (ie, the environment value). (Actually,
|
|
|
|
* it seems that on most implementations that's the only thing it's good for;
|
|
|
|
* we could wish that setlocale gave back a canonically spelled version of
|
|
|
|
* the locale name, but typically it doesn't.)
|
|
|
|
*
|
|
|
|
* this should match the backend's check_locale() function
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
2014-05-14 17:51:10 +02:00
|
|
|
static void
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
check_locale_name(int category, const char *locale, char **canonname)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
|
|
|
char *save;
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
char *res;
|
|
|
|
|
|
|
|
if (canonname)
|
|
|
|
*canonname = NULL; /* in case of failure */
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
save = setlocale(category, NULL);
|
|
|
|
if (!save)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("setlocale() failed");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
/* save may be pointing at a modifiable scratch variable, so copy it. */
|
2012-10-02 21:35:10 +02:00
|
|
|
save = pg_strdup(save);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2017-08-31 04:28:36 +02:00
|
|
|
/* for setlocale() call */
|
|
|
|
if (!locale)
|
|
|
|
locale = "";
|
|
|
|
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
/* set the locale with setlocale, to see if it accepts it. */
|
|
|
|
res = setlocale(category, locale);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
/* save canonical name if requested. */
|
|
|
|
if (res && canonname)
|
2012-10-02 21:35:10 +02:00
|
|
|
*canonname = pg_strdup(res);
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
|
|
|
|
/* restore old value. */
|
|
|
|
if (!setlocale(category, save))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("failed to restore old locale \"%s\"", save);
|
2003-11-10 23:51:16 +01:00
|
|
|
free(save);
|
|
|
|
|
2014-05-14 17:51:10 +02:00
|
|
|
/* complain if locale wasn't valid */
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
if (res == NULL)
|
2014-05-14 17:51:10 +02:00
|
|
|
{
|
|
|
|
if (*locale)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("invalid locale name \"%s\"", locale);
|
2014-05-14 17:51:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If no relevant switch was given on command line, locale is an
|
|
|
|
* empty string, which is not too helpful to report. Presumably
|
|
|
|
* setlocale() found something it did not like in the environment.
|
|
|
|
* Ideally we'd report the bad environment variable, but since
|
|
|
|
* setlocale's behavior is implementation-specific, it's hard to
|
|
|
|
* be sure what it didn't like. Print a safe generic message.
|
|
|
|
*/
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("invalid locale settings; check LANG and LC_* environment variables");
|
2014-05-14 17:51:10 +02:00
|
|
|
}
|
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2008-09-23 12:58:03 +02:00
|
|
|
/*
|
|
|
|
* check if the chosen encoding matches the encoding required by the locale
|
|
|
|
*
|
|
|
|
* this should match the similar check in the backend createdb() function
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
check_locale_encoding(const char *locale, int user_enc)
|
|
|
|
{
|
|
|
|
int locale_enc;
|
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
locale_enc = pg_get_encoding_from_locale(locale, true);
|
2008-09-23 12:58:03 +02:00
|
|
|
|
2009-11-12 03:46:16 +01:00
|
|
|
/* See notes in createdb() to understand these tests */
|
2008-09-23 12:58:03 +02:00
|
|
|
if (!(locale_enc == user_enc ||
|
|
|
|
locale_enc == PG_SQL_ASCII ||
|
2009-11-12 03:46:16 +01:00
|
|
|
locale_enc == -1 ||
|
2008-09-23 12:58:03 +02:00
|
|
|
#ifdef WIN32
|
2009-11-12 03:46:16 +01:00
|
|
|
user_enc == PG_UTF8 ||
|
2008-09-23 12:58:03 +02:00
|
|
|
#endif
|
2009-11-12 03:46:16 +01:00
|
|
|
user_enc == PG_SQL_ASCII))
|
2008-09-23 12:58:03 +02:00
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("encoding mismatch");
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_detail("The encoding you selected (%s) and the encoding that the "
|
|
|
|
"selected locale uses (%s) do not match. This would lead to "
|
|
|
|
"misbehavior in various character string processing functions.",
|
|
|
|
pg_encoding_to_char(user_enc),
|
|
|
|
pg_encoding_to_char(locale_enc));
|
|
|
|
pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
|
|
|
|
"or choose a matching combination.",
|
|
|
|
progname);
|
2008-09-23 12:58:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-16 09:37:54 +02:00
|
|
|
/*
|
|
|
|
* check if the chosen encoding matches is supported by ICU
|
|
|
|
*
|
|
|
|
* this should match the similar check in the backend createdb() function
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
check_icu_locale_encoding(int user_enc)
|
|
|
|
{
|
|
|
|
if (!(is_encoding_supported_by_icu(user_enc)))
|
|
|
|
{
|
|
|
|
pg_log_error("encoding mismatch");
|
|
|
|
pg_log_error_detail("The encoding you selected (%s) is not supported with the ICU provider.",
|
|
|
|
pg_encoding_to_char(user_enc));
|
|
|
|
pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
|
|
|
|
"or choose a matching combination.",
|
|
|
|
progname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-09 19:52:41 +01:00
|
|
|
/*
|
|
|
|
* Check that ICU accepts the locale name; or if not specified, retrieve the
|
|
|
|
* default ICU locale.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_icu_locale(void)
|
|
|
|
{
|
|
|
|
#ifdef USE_ICU
|
|
|
|
UCollator *collator;
|
|
|
|
UErrorCode status;
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
collator = ucol_open(icu_locale, &status);
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
if (icu_locale)
|
|
|
|
pg_fatal("could not open collator for locale \"%s\": %s",
|
|
|
|
icu_locale, u_errorName(status));
|
|
|
|
else
|
|
|
|
pg_fatal("could not open collator for default locale: %s",
|
|
|
|
u_errorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if not specified, get locale from default collator */
|
|
|
|
if (icu_locale == NULL)
|
|
|
|
{
|
|
|
|
const char *default_locale;
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
default_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
|
|
|
|
&status);
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
ucol_close(collator);
|
|
|
|
pg_fatal("could not determine default ICU locale");
|
|
|
|
}
|
|
|
|
|
|
|
|
icu_locale = pg_strdup(default_locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
ucol_close(collator);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* set up the locale variables
|
|
|
|
*
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
* assumes we have called setlocale(LC_ALL, "") -- see set_pglocale_pgservice
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
setlocales(void)
|
|
|
|
{
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
char *canonname;
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/* set empty lc_* values to locale config if set */
|
|
|
|
|
2017-08-31 04:28:36 +02:00
|
|
|
if (locale)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_ctype)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_ctype = locale;
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_collate)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_collate = locale;
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_numeric)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_numeric = locale;
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_time)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_time = locale;
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_monetary)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_monetary = locale;
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!lc_messages)
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_messages = locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-05-14 17:51:10 +02:00
|
|
|
* canonicalize locale names, and obtain any missing values from our
|
|
|
|
* current environment
|
2003-11-10 23:51:16 +01:00
|
|
|
*/
|
2014-05-14 17:51:10 +02:00
|
|
|
check_locale_name(LC_CTYPE, lc_ctype, &canonname);
|
|
|
|
lc_ctype = canonname;
|
|
|
|
check_locale_name(LC_COLLATE, lc_collate, &canonname);
|
|
|
|
lc_collate = canonname;
|
|
|
|
check_locale_name(LC_NUMERIC, lc_numeric, &canonname);
|
|
|
|
lc_numeric = canonname;
|
|
|
|
check_locale_name(LC_TIME, lc_time, &canonname);
|
|
|
|
lc_time = canonname;
|
|
|
|
check_locale_name(LC_MONETARY, lc_monetary, &canonname);
|
|
|
|
lc_monetary = canonname;
|
2004-10-23 00:30:57 +02:00
|
|
|
#if defined(LC_MESSAGES) && !defined(WIN32)
|
2014-05-14 17:51:10 +02:00
|
|
|
check_locale_name(LC_MESSAGES, lc_messages, &canonname);
|
|
|
|
lc_messages = canonname;
|
2003-11-10 23:51:16 +01:00
|
|
|
#else
|
Replace empty locale name with implied value in CREATE DATABASE and initdb.
setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.
Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().
For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.
Per report from Jeff Davis, though this is not his proposed patch.
2012-03-26 03:47:22 +02:00
|
|
|
/* when LC_MESSAGES is not available, use the LC_CTYPE setting */
|
2014-05-14 17:51:10 +02:00
|
|
|
check_locale_name(LC_CTYPE, lc_messages, &canonname);
|
|
|
|
lc_messages = canonname;
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2022-03-17 11:11:21 +01:00
|
|
|
|
|
|
|
if (locale_provider == COLLPROVIDER_ICU)
|
|
|
|
{
|
2023-03-09 19:52:41 +01:00
|
|
|
check_icu_locale();
|
2022-03-17 11:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2022-03-20 10:21:45 +01:00
|
|
|
* In supported builds, the ICU locale ID will be checked by the
|
2022-04-08 20:55:14 +02:00
|
|
|
* backend during post-bootstrap initialization.
|
2022-03-17 11:11:21 +01:00
|
|
|
*/
|
2022-03-20 10:21:45 +01:00
|
|
|
#ifndef USE_ICU
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("ICU is not supported in this build");
|
2022-03-17 11:11:21 +01:00
|
|
|
#endif
|
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print help text
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-23 22:41:30 +01:00
|
|
|
usage(const char *progname)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("%s initializes a PostgreSQL database cluster.\n\n"), progname);
|
|
|
|
printf(_("Usage:\n"));
|
|
|
|
printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
|
|
|
|
printf(_("\nOptions:\n"));
|
2009-02-25 14:03:07 +01:00
|
|
|
printf(_(" -A, --auth=METHOD default authentication method for local connections\n"));
|
2012-02-01 20:18:55 +01:00
|
|
|
printf(_(" --auth-host=METHOD default authentication method for local TCP/IP connections\n"));
|
|
|
|
printf(_(" --auth-local=METHOD default authentication method for local-socket connections\n"));
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_(" [-D, --pgdata=]DATADIR location for this database cluster\n"));
|
|
|
|
printf(_(" -E, --encoding=ENCODING set default encoding for new databases\n"));
|
2018-04-07 23:45:39 +02:00
|
|
|
printf(_(" -g, --allow-group-access allow group read/execute on data directory\n"));
|
2022-03-17 11:11:21 +01:00
|
|
|
printf(_(" --icu-locale=LOCALE set ICU locale ID for new databases\n"));
|
2023-03-08 16:35:42 +01:00
|
|
|
printf(_(" --icu-rules=RULES set additional ICU collation rules for new databases\n"));
|
2021-01-06 02:52:26 +01:00
|
|
|
printf(_(" -k, --data-checksums use data page checksums\n"));
|
2009-02-25 14:03:07 +01:00
|
|
|
printf(_(" --locale=LOCALE set default locale for new databases\n"));
|
|
|
|
printf(_(" --lc-collate=, --lc-ctype=, --lc-messages=LOCALE\n"
|
|
|
|
" --lc-monetary=, --lc-numeric=, --lc-time=LOCALE\n"
|
|
|
|
" set default locale in the respective category for\n"
|
|
|
|
" new databases (default taken from environment)\n"));
|
|
|
|
printf(_(" --no-locale equivalent to --locale=C\n"));
|
2022-03-17 11:11:21 +01:00
|
|
|
printf(_(" --locale-provider={libc|icu}\n"
|
|
|
|
" set default locale provider for new databases\n"));
|
2020-12-28 03:37:42 +01:00
|
|
|
printf(_(" --pwfile=FILE read password for the new superuser from file\n"));
|
2007-09-25 18:29:34 +02:00
|
|
|
printf(_(" -T, --text-search-config=CFG\n"
|
|
|
|
" default text search configuration\n"));
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_(" -U, --username=NAME database superuser name\n"));
|
2020-12-28 03:37:42 +01:00
|
|
|
printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
|
2017-02-09 22:42:51 +01:00
|
|
|
printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
|
2018-03-24 20:40:21 +01:00
|
|
|
printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
|
2003-11-23 23:17:59 +01:00
|
|
|
printf(_("\nLess commonly used options:\n"));
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_(" -d, --debug generate lots of debugging output\n"));
|
2021-07-13 21:01:01 +02:00
|
|
|
printf(_(" --discard-caches set debug_discard_caches=1\n"));
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_(" -L DIRECTORY where to find the input files\n"));
|
2016-10-19 18:00:00 +02:00
|
|
|
printf(_(" -n, --no-clean do not clean up after errors\n"));
|
|
|
|
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
|
2021-01-17 14:28:17 +01:00
|
|
|
printf(_(" --no-instructions do not print instructions for next steps\n"));
|
2009-02-25 14:03:07 +01:00
|
|
|
printf(_(" -s, --show show internal settings\n"));
|
2021-08-16 13:38:01 +02:00
|
|
|
printf(_(" -S, --sync-only only sync database files to disk, then exit\n"));
|
2009-02-25 14:03:07 +01:00
|
|
|
printf(_("\nOther options:\n"));
|
|
|
|
printf(_(" -V, --version output version information, then exit\n"));
|
2012-06-18 01:44:00 +02:00
|
|
|
printf(_(" -?, --help show this help, then exit\n"));
|
2003-11-23 23:17:59 +01:00
|
|
|
printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"
|
|
|
|
"is used.\n"));
|
2020-02-28 08:54:49 +01:00
|
|
|
printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
|
2020-02-28 08:54:49 +01:00
|
|
|
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
|
2003-11-23 22:41:30 +01:00
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2019-07-22 19:28:25 +02:00
|
|
|
static void
|
|
|
|
check_authmethod_unspecified(const char **authmethod)
|
|
|
|
{
|
|
|
|
if (*authmethod == NULL)
|
|
|
|
{
|
|
|
|
authwarning = true;
|
|
|
|
*authmethod = "trust";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 20:18:55 +01:00
|
|
|
static void
|
2015-12-18 01:38:21 +01:00
|
|
|
check_authmethod_valid(const char *authmethod, const char *const *valid_methods, const char *conntype)
|
2012-02-01 20:18:55 +01:00
|
|
|
{
|
2015-12-18 01:38:21 +01:00
|
|
|
const char *const *p;
|
2012-02-01 20:18:55 +01:00
|
|
|
|
|
|
|
for (p = valid_methods; *p; p++)
|
|
|
|
{
|
|
|
|
if (strcmp(authmethod, *p) == 0)
|
|
|
|
return;
|
|
|
|
/* with space = param */
|
|
|
|
if (strchr(authmethod, ' '))
|
|
|
|
if (strncmp(authmethod, *p, (authmethod - strchr(authmethod, ' '))) == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("invalid authentication method \"%s\" for \"%s\" connections",
|
|
|
|
authmethod, conntype);
|
2012-02-01 20:18:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-30 14:39:16 +02:00
|
|
|
check_need_password(const char *authmethodlocal, const char *authmethodhost)
|
2012-02-01 20:18:55 +01:00
|
|
|
{
|
2012-06-30 14:39:16 +02:00
|
|
|
if ((strcmp(authmethodlocal, "md5") == 0 ||
|
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
|
|
|
strcmp(authmethodlocal, "password") == 0 ||
|
2017-04-18 13:50:50 +02:00
|
|
|
strcmp(authmethodlocal, "scram-sha-256") == 0) &&
|
2012-06-30 14:39:16 +02:00
|
|
|
(strcmp(authmethodhost, "md5") == 0 ||
|
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
|
|
|
strcmp(authmethodhost, "password") == 0 ||
|
2017-04-18 13:50:50 +02:00
|
|
|
strcmp(authmethodhost, "scram-sha-256") == 0) &&
|
2012-02-01 20:18:55 +01:00
|
|
|
!(pwprompt || pwfilename))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("must specify a password for the superuser to enable password authentication");
|
2012-02-01 20:18:55 +01:00
|
|
|
}
|
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
setup_pgdata(void)
|
|
|
|
{
|
Use setenv() in preference to putenv().
Since at least 2001 we've used putenv() and avoided setenv(), on the
grounds that the latter was unportable and not in POSIX. However,
POSIX added it that same year, and by now the situation has reversed:
setenv() is probably more portable than putenv(), since POSIX now
treats the latter as not being a core function. And setenv() has
cleaner semantics too. So, let's reverse that old policy.
This commit adds a simple src/port/ implementation of setenv() for
any stragglers (we have one in the buildfarm, but I'd not be surprised
if that code is never used in the field). More importantly, extend
win32env.c to also support setenv(). Then, replace usages of putenv()
with setenv(), and get rid of some ad-hoc implementations of setenv()
wannabees.
Also, adjust our src/port/ implementation of unsetenv() to follow the
POSIX spec that it returns an error indicator, rather than returning
void as per the ancient BSD convention. I don't feel a need to make
all the call sites check for errors, but the portability stub ought
to match real-world practice.
Discussion: https://postgr.es/m/2065122.1609212051@sss.pgh.pa.us
2020-12-30 18:55:59 +01:00
|
|
|
char *pgdata_get_env;
|
2012-11-30 22:45:08 +01:00
|
|
|
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!pg_data)
|
2012-11-30 22:45:08 +01:00
|
|
|
{
|
|
|
|
pgdata_get_env = getenv("PGDATA");
|
|
|
|
if (pgdata_get_env && strlen(pgdata_get_env))
|
|
|
|
{
|
|
|
|
/* PGDATA found */
|
|
|
|
pg_data = pg_strdup(pgdata_get_env);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("no data directory specified");
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("You must identify the directory where the data for this database system "
|
|
|
|
"will reside. Do this with either the invocation option -D or the "
|
|
|
|
"environment variable PGDATA.");
|
2012-11-30 22:45:08 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pgdata_native = pg_strdup(pg_data);
|
|
|
|
canonicalize_path(pg_data);
|
2006-02-10 23:05:42 +01:00
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
/*
|
|
|
|
* we have to set PGDATA for postgres rather than pass it on the command
|
2004-08-12 01:28:54 +02:00
|
|
|
* line to avoid dumb quoting problems on Windows, and we would especially
|
|
|
|
* need quotes otherwise on Windows because paths there are most likely to
|
2003-11-10 23:51:16 +01:00
|
|
|
* have embedded spaces.
|
|
|
|
*/
|
Use setenv() in preference to putenv().
Since at least 2001 we've used putenv() and avoided setenv(), on the
grounds that the latter was unportable and not in POSIX. However,
POSIX added it that same year, and by now the situation has reversed:
setenv() is probably more portable than putenv(), since POSIX now
treats the latter as not being a core function. And setenv() has
cleaner semantics too. So, let's reverse that old policy.
This commit adds a simple src/port/ implementation of setenv() for
any stragglers (we have one in the buildfarm, but I'd not be surprised
if that code is never used in the field). More importantly, extend
win32env.c to also support setenv(). Then, replace usages of putenv()
with setenv(), and get rid of some ad-hoc implementations of setenv()
wannabees.
Also, adjust our src/port/ implementation of unsetenv() to follow the
POSIX spec that it returns an error indicator, rather than returning
void as per the ancient BSD convention. I don't feel a need to make
all the call sites check for errors, but the portability stub ought
to match real-world practice.
Discussion: https://postgr.es/m/2065122.1609212051@sss.pgh.pa.us
2020-12-30 18:55:59 +01:00
|
|
|
if (setenv("PGDATA", pg_data, 1) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not set environment");
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_bin_paths(const char *argv0)
|
|
|
|
{
|
|
|
|
int ret;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
|
2004-05-17 15:17:29 +02:00
|
|
|
backend_exec)) < 0)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2004-10-15 06:32:28 +02:00
|
|
|
char full_path[MAXPGPATH];
|
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
if (find_my_exec(argv0, full_path) < 0)
|
2007-02-10 15:58:55 +01:00
|
|
|
strlcpy(full_path, progname, sizeof(full_path));
|
2004-10-15 06:32:28 +02:00
|
|
|
|
2004-05-11 23:57:15 +02:00
|
|
|
if (ret == -1)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
|
|
|
|
"postgres", progname, full_path);
|
2004-05-11 23:57:15 +02:00
|
|
|
else
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
|
|
|
|
"postgres", full_path, progname);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2004-05-11 23:57:15 +02:00
|
|
|
/* store binary directory */
|
2004-05-17 16:35:34 +02:00
|
|
|
strcpy(bin_path, backend_exec);
|
2004-06-11 00:26:24 +02:00
|
|
|
*last_dir_separator(bin_path) = '\0';
|
2004-08-09 22:20:47 +02:00
|
|
|
canonicalize_path(bin_path);
|
2004-05-17 16:35:34 +02:00
|
|
|
|
|
|
|
if (!share_path)
|
|
|
|
{
|
2005-07-10 18:13:13 +02:00
|
|
|
share_path = pg_malloc(MAXPGPATH);
|
2004-05-17 16:35:34 +02:00
|
|
|
get_share_path(backend_exec, share_path);
|
|
|
|
}
|
2004-08-16 17:44:03 +02:00
|
|
|
else if (!is_absolute_path(share_path))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("input file location must be an absolute path");
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-05-18 05:36:45 +02:00
|
|
|
canonicalize_path(share_path);
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
2004-05-18 05:36:45 +02:00
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
void
|
|
|
|
setup_locale_encoding(void)
|
|
|
|
{
|
2004-07-14 19:55:10 +02:00
|
|
|
setlocales();
|
|
|
|
|
2022-03-17 11:11:21 +01:00
|
|
|
if (locale_provider == COLLPROVIDER_LIBC &&
|
|
|
|
strcmp(lc_ctype, lc_collate) == 0 &&
|
2003-11-10 23:51:16 +01:00
|
|
|
strcmp(lc_ctype, lc_time) == 0 &&
|
|
|
|
strcmp(lc_ctype, lc_numeric) == 0 &&
|
|
|
|
strcmp(lc_ctype, lc_monetary) == 0 &&
|
2022-03-17 11:11:21 +01:00
|
|
|
strcmp(lc_ctype, lc_messages) == 0 &&
|
|
|
|
(!icu_locale || strcmp(lc_ctype, icu_locale) == 0))
|
2012-04-13 19:37:07 +02:00
|
|
|
printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);
|
2003-11-10 23:51:16 +01:00
|
|
|
else
|
|
|
|
{
|
2022-03-17 11:11:21 +01:00
|
|
|
printf(_("The database cluster will be initialized with this locale configuration:\n"));
|
|
|
|
printf(_(" provider: %s\n"), collprovider_name(locale_provider));
|
|
|
|
if (icu_locale)
|
|
|
|
printf(_(" ICU locale: %s\n"), icu_locale);
|
|
|
|
printf(_(" LC_COLLATE: %s\n"
|
|
|
|
" LC_CTYPE: %s\n"
|
|
|
|
" LC_MESSAGES: %s\n"
|
|
|
|
" LC_MONETARY: %s\n"
|
|
|
|
" LC_NUMERIC: %s\n"
|
|
|
|
" LC_TIME: %s\n"),
|
2003-11-10 23:51:16 +01:00
|
|
|
lc_collate,
|
|
|
|
lc_ctype,
|
|
|
|
lc_messages,
|
|
|
|
lc_monetary,
|
|
|
|
lc_numeric,
|
|
|
|
lc_time);
|
|
|
|
}
|
|
|
|
|
2022-03-17 11:11:21 +01:00
|
|
|
if (!encoding && locale_provider == COLLPROVIDER_ICU)
|
2022-09-16 09:37:54 +02:00
|
|
|
{
|
2022-03-17 11:11:21 +01:00
|
|
|
encodingid = PG_UTF8;
|
2022-09-16 09:37:54 +02:00
|
|
|
printf(_("The default database encoding has been set to \"%s\".\n"),
|
|
|
|
pg_encoding_to_char(encodingid));
|
|
|
|
}
|
2022-03-17 11:11:21 +01:00
|
|
|
else if (!encoding)
|
2004-07-14 19:55:10 +02:00
|
|
|
{
|
2007-09-29 00:25:49 +02:00
|
|
|
int ctype_enc;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
ctype_enc = pg_get_encoding_from_locale(lc_ctype, true);
|
2007-09-29 00:25:49 +02:00
|
|
|
|
2009-11-12 03:46:16 +01:00
|
|
|
if (ctype_enc == -1)
|
2007-09-29 00:25:49 +02:00
|
|
|
{
|
2009-11-12 03:46:16 +01:00
|
|
|
/* Couldn't recognize the locale's codeset */
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("could not find suitable encoding for locale \"%s\"",
|
|
|
|
lc_ctype);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Rerun %s with the -E option.", progname);
|
|
|
|
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
|
2007-09-29 00:25:49 +02:00
|
|
|
exit(1);
|
2004-07-14 19:55:10 +02:00
|
|
|
}
|
2007-10-13 22:18:42 +02:00
|
|
|
else if (!pg_valid_server_encoding_id(ctype_enc))
|
2007-09-29 02:14:40 +02:00
|
|
|
{
|
2011-04-15 19:44:13 +02:00
|
|
|
/*
|
|
|
|
* We recognized it, but it's not a legal server encoding. On
|
|
|
|
* Windows, UTF-8 works with any locale, so we can fall back to
|
|
|
|
* UTF-8.
|
|
|
|
*/
|
|
|
|
#ifdef WIN32
|
2017-08-31 04:28:36 +02:00
|
|
|
encodingid = PG_UTF8;
|
2012-04-13 19:37:07 +02:00
|
|
|
printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
|
|
|
|
"The default database encoding will be set to \"%s\" instead.\n"),
|
2011-04-15 19:44:13 +02:00
|
|
|
pg_encoding_to_char(ctype_enc),
|
2017-08-31 04:28:36 +02:00
|
|
|
pg_encoding_to_char(encodingid));
|
2011-04-15 19:44:13 +02:00
|
|
|
#else
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("locale \"%s\" requires unsupported encoding \"%s\"",
|
|
|
|
lc_ctype, pg_encoding_to_char(ctype_enc));
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_detail("Encoding \"%s\" is not allowed as a server-side encoding.",
|
|
|
|
pg_encoding_to_char(ctype_enc));
|
|
|
|
pg_log_error_hint("Rerun %s with a different locale selection.",
|
|
|
|
progname);
|
2007-09-29 02:14:40 +02:00
|
|
|
exit(1);
|
2011-04-15 19:44:13 +02:00
|
|
|
#endif
|
2007-09-29 02:14:40 +02:00
|
|
|
}
|
2004-07-14 19:55:10 +02:00
|
|
|
else
|
2007-09-29 00:25:49 +02:00
|
|
|
{
|
2017-08-31 04:28:36 +02:00
|
|
|
encodingid = ctype_enc;
|
2012-04-13 19:37:07 +02:00
|
|
|
printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
|
2017-08-31 04:28:36 +02:00
|
|
|
pg_encoding_to_char(encodingid));
|
2007-09-29 00:25:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
encodingid = get_encoding_id(encoding);
|
|
|
|
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!check_locale_encoding(lc_ctype, encodingid) ||
|
|
|
|
!check_locale_encoding(lc_collate, encodingid))
|
2008-09-23 12:58:03 +02:00
|
|
|
exit(1); /* check_locale_encoding printed the error */
|
2022-09-16 09:37:54 +02:00
|
|
|
|
|
|
|
if (locale_provider == COLLPROVIDER_ICU &&
|
|
|
|
!check_icu_locale_encoding(encodingid))
|
|
|
|
exit(1);
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_data_file_paths(void)
|
|
|
|
{
|
|
|
|
set_input(&bki_file, "postgres.bki");
|
|
|
|
set_input(&hba_file, "pg_hba.conf.sample");
|
|
|
|
set_input(&ident_file, "pg_ident.conf.sample");
|
|
|
|
set_input(&conf_file, "postgresql.conf.sample");
|
|
|
|
set_input(&dictionary_file, "snowball_create.sql");
|
|
|
|
set_input(&info_schema_file, "information_schema.sql");
|
|
|
|
set_input(&features_file, "sql_features.txt");
|
2021-01-30 19:14:31 +01:00
|
|
|
set_input(&system_constraints_file, "system_constraints.sql");
|
2021-04-17 00:20:42 +02:00
|
|
|
set_input(&system_functions_file, "system_functions.sql");
|
2012-11-30 22:45:08 +01:00
|
|
|
set_input(&system_views_file, "system_views.sql");
|
|
|
|
|
|
|
|
if (show_setting || debug)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"VERSION=%s\n"
|
|
|
|
"PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
|
|
|
|
"POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
|
|
|
|
"POSTGRESQL_CONF_SAMPLE=%s\n"
|
|
|
|
"PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
|
|
|
|
PG_VERSION,
|
|
|
|
pg_data, share_path, bin_path,
|
|
|
|
username, bki_file,
|
|
|
|
conf_file,
|
|
|
|
hba_file, ident_file);
|
|
|
|
if (show_setting)
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
check_input(bki_file);
|
|
|
|
check_input(hba_file);
|
|
|
|
check_input(ident_file);
|
|
|
|
check_input(conf_file);
|
|
|
|
check_input(dictionary_file);
|
|
|
|
check_input(info_schema_file);
|
|
|
|
check_input(features_file);
|
2021-04-17 00:20:42 +02:00
|
|
|
check_input(system_constraints_file);
|
|
|
|
check_input(system_functions_file);
|
2012-11-30 22:45:08 +01:00
|
|
|
check_input(system_views_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_text_search(void)
|
|
|
|
{
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!default_text_search_config)
|
2007-08-21 03:11:32 +02:00
|
|
|
{
|
|
|
|
default_text_search_config = find_matching_ts_config(lc_ctype);
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!default_text_search_config)
|
2007-08-21 03:11:32 +02:00
|
|
|
{
|
2019-07-01 13:34:31 +02:00
|
|
|
pg_log_info("could not find suitable text search configuration for locale \"%s\"",
|
|
|
|
lc_ctype);
|
2007-08-21 03:11:32 +02:00
|
|
|
default_text_search_config = "simple";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *checkmatch = find_matching_ts_config(lc_ctype);
|
|
|
|
|
|
|
|
if (checkmatch == NULL)
|
|
|
|
{
|
2019-07-01 13:34:31 +02:00
|
|
|
pg_log_warning("suitable text search configuration for locale \"%s\" is unknown",
|
|
|
|
lc_ctype);
|
2007-08-21 03:11:32 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(checkmatch, default_text_search_config) != 0)
|
|
|
|
{
|
2019-07-01 13:34:31 +02:00
|
|
|
pg_log_warning("specified text search configuration \"%s\" might not match locale \"%s\"",
|
|
|
|
default_text_search_config, lc_ctype);
|
2007-08-21 03:11:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(_("The default text search configuration will be set to \"%s\".\n"),
|
|
|
|
default_text_search_config);
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
2003-11-10 23:51:16 +01:00
|
|
|
|
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
void
|
2012-12-04 05:22:56 +01:00
|
|
|
setup_signals(void)
|
2012-11-30 22:45:08 +01:00
|
|
|
{
|
2003-11-10 23:51:16 +01:00
|
|
|
/* some of these are not valid on Windows */
|
|
|
|
#ifdef SIGHUP
|
|
|
|
pqsignal(SIGHUP, trapsig);
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
#ifdef SIGINT
|
|
|
|
pqsignal(SIGINT, trapsig);
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
#ifdef SIGQUIT
|
|
|
|
pqsignal(SIGQUIT, trapsig);
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
#ifdef SIGTERM
|
|
|
|
pqsignal(SIGTERM, trapsig);
|
2003-11-10 23:52:10 +01:00
|
|
|
#endif
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 19:32:34 +01:00
|
|
|
/* Ignore SIGPIPE when writing to backend, so we can clean up */
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
pqsignal(SIGPIPE, SIG_IGN);
|
|
|
|
#endif
|
2013-10-25 03:51:00 +02:00
|
|
|
|
|
|
|
/* Prevent SIGSYS so we can probe for kernel calls that might not work */
|
|
|
|
#ifdef SIGSYS
|
|
|
|
pqsignal(SIGSYS, SIG_IGN);
|
|
|
|
#endif
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-12-04 05:22:56 +01:00
|
|
|
create_data_directory(void)
|
2012-11-30 22:45:08 +01:00
|
|
|
{
|
2013-02-17 00:52:50 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch ((ret = pg_check_dir(pg_data)))
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2003-11-14 18:19:35 +01:00
|
|
|
case 0:
|
|
|
|
/* PGDATA not there, must create it */
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("creating directory %s ... "),
|
2003-11-14 18:19:35 +01:00
|
|
|
pg_data);
|
|
|
|
fflush(stdout);
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
if (pg_mkdir_p(pg_data, pg_dir_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not create directory \"%s\": %m", pg_data);
|
2003-11-14 18:19:35 +01:00
|
|
|
else
|
|
|
|
check_ok();
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 18:19:35 +01:00
|
|
|
made_new_pgdata = true;
|
|
|
|
break;
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 18:19:35 +01:00
|
|
|
case 1:
|
|
|
|
/* Present but empty, fix permissions and use it */
|
2003-11-23 22:41:30 +01:00
|
|
|
printf(_("fixing permissions on existing directory %s ... "),
|
2003-11-14 18:19:35 +01:00
|
|
|
pg_data);
|
|
|
|
fflush(stdout);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(pg_data, pg_dir_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of directory \"%s\": %m",
|
|
|
|
pg_data);
|
2003-11-14 18:19:35 +01:00
|
|
|
else
|
|
|
|
check_ok();
|
2003-11-14 19:32:34 +01:00
|
|
|
|
|
|
|
found_existing_pgdata = true;
|
2003-11-14 18:19:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2013-02-17 00:52:50 +01:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2003-11-14 18:19:35 +01:00
|
|
|
/* Present and not empty */
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("directory \"%s\" exists but is not empty", pg_data);
|
2013-02-17 00:52:50 +01:00
|
|
|
if (ret != 4)
|
|
|
|
warn_on_mount_point(ret);
|
|
|
|
else
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("If you want to create a new database system, either remove or empty "
|
|
|
|
"the directory \"%s\" or run %s "
|
|
|
|
"with an argument other than \"%s\".",
|
|
|
|
pg_data, progname, pg_data);
|
2003-11-14 19:32:34 +01:00
|
|
|
exit(1); /* no further message needed */
|
2003-11-14 18:19:35 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Trouble accessing directory */
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not access directory \"%s\": %m", pg_data);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
2012-12-04 05:22:56 +01:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2017-05-12 17:49:56 +02:00
|
|
|
/* Create WAL directory, and symlink if required */
|
2012-12-04 05:22:56 +01:00
|
|
|
void
|
2016-01-08 00:20:57 +01:00
|
|
|
create_xlog_or_symlink(void)
|
2012-12-04 05:22:56 +01:00
|
|
|
{
|
2016-01-08 00:20:57 +01:00
|
|
|
char *subdirloc;
|
|
|
|
|
|
|
|
/* form name of the place for the subdirectory or symlink */
|
2016-10-20 17:24:37 +02:00
|
|
|
subdirloc = psprintf("%s/pg_wal", pg_data);
|
2016-01-08 00:20:57 +01:00
|
|
|
|
2017-08-31 04:28:36 +02:00
|
|
|
if (xlog_dir)
|
2007-01-06 20:40:00 +01:00
|
|
|
{
|
2013-02-17 00:52:50 +01:00
|
|
|
int ret;
|
2007-01-06 20:40:00 +01:00
|
|
|
|
2008-06-02 05:48:00 +02:00
|
|
|
/* clean up xlog directory name, check it's absolute */
|
|
|
|
canonicalize_path(xlog_dir);
|
|
|
|
if (!is_absolute_path(xlog_dir))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("WAL directory location must be an absolute path");
|
2007-01-06 20:40:00 +01:00
|
|
|
|
2010-12-11 01:42:44 +01:00
|
|
|
/* check if the specified xlog directory exists/is empty */
|
2013-02-17 00:52:50 +01:00
|
|
|
switch ((ret = pg_check_dir(xlog_dir)))
|
2007-01-06 20:40:00 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* xlog directory not there, must create it */
|
|
|
|
printf(_("creating directory %s ... "),
|
|
|
|
xlog_dir);
|
|
|
|
fflush(stdout);
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
if (pg_mkdir_p(xlog_dir, pg_dir_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not create directory \"%s\": %m",
|
|
|
|
xlog_dir);
|
2007-01-06 20:40:00 +01:00
|
|
|
else
|
|
|
|
check_ok();
|
|
|
|
|
|
|
|
made_new_xlogdir = true;
|
|
|
|
break;
|
2010-12-11 01:42:44 +01:00
|
|
|
|
2007-01-06 20:40:00 +01:00
|
|
|
case 1:
|
|
|
|
/* Present but empty, fix permissions and use it */
|
|
|
|
printf(_("fixing permissions on existing directory %s ... "),
|
|
|
|
xlog_dir);
|
|
|
|
fflush(stdout);
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
if (chmod(xlog_dir, pg_dir_create_mode) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not change permissions of directory \"%s\": %m",
|
|
|
|
xlog_dir);
|
2007-01-06 20:40:00 +01:00
|
|
|
else
|
|
|
|
check_ok();
|
|
|
|
|
|
|
|
found_existing_xlogdir = true;
|
|
|
|
break;
|
2010-12-11 01:42:44 +01:00
|
|
|
|
2007-01-06 20:40:00 +01:00
|
|
|
case 2:
|
2013-02-17 00:52:50 +01:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2007-01-06 20:40:00 +01:00
|
|
|
/* Present and not empty */
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("directory \"%s\" exists but is not empty", xlog_dir);
|
2013-02-17 00:52:50 +01:00
|
|
|
if (ret != 4)
|
|
|
|
warn_on_mount_point(ret);
|
|
|
|
else
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("If you want to store the WAL there, either remove or empty the directory \"%s\".",
|
|
|
|
xlog_dir);
|
2018-12-29 13:21:57 +01:00
|
|
|
exit(1);
|
2007-01-06 20:40:00 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Trouble accessing directory */
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not access directory \"%s\": %m", xlog_dir);
|
2007-01-06 20:40:00 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 00:20:57 +01:00
|
|
|
if (symlink(xlog_dir, subdirloc) != 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not create symbolic link \"%s\": %m",
|
|
|
|
subdirloc);
|
2007-01-06 20:40:00 +01:00
|
|
|
}
|
2016-01-08 00:20:57 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Without -X option, just make the subdirectory normally */
|
2018-04-07 23:45:39 +02:00
|
|
|
if (mkdir(subdirloc, pg_dir_create_mode) < 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not create directory \"%s\": %m",
|
|
|
|
subdirloc);
|
2016-01-08 00:20:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
free(subdirloc);
|
2012-12-04 05:22:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-17 00:52:50 +01:00
|
|
|
void
|
|
|
|
warn_on_mount_point(int error)
|
|
|
|
{
|
|
|
|
if (error == 2)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_detail("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
|
2013-02-17 00:52:50 +01:00
|
|
|
else if (error == 3)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_detail("It contains a lost+found directory, perhaps due to it being a mount point.");
|
2013-02-17 00:52:50 +01:00
|
|
|
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Using a mount point directly as the data directory is not recommended.\n"
|
|
|
|
"Create a subdirectory under the mount point.");
|
2013-02-17 00:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-04 05:22:56 +01:00
|
|
|
void
|
|
|
|
initialize_data_directory(void)
|
|
|
|
{
|
2015-12-18 01:38:21 +01:00
|
|
|
PG_CMD_DECL;
|
2012-12-04 05:22:56 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
setup_signals();
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
/*
|
|
|
|
* Set mask based on requested PGDATA permissions. pg_mode_mask, and
|
|
|
|
* friends like pg_dir_create_mode, are set to owner-only by default and
|
|
|
|
* then updated if -g is passed in by calling SetDataDirectoryCreatePerm()
|
|
|
|
* when parsing our options (see above).
|
|
|
|
*/
|
|
|
|
umask(pg_mode_mask);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-12-04 05:22:56 +01:00
|
|
|
create_data_directory();
|
|
|
|
|
2016-01-08 00:20:57 +01:00
|
|
|
create_xlog_or_symlink();
|
2007-01-06 20:40:00 +01:00
|
|
|
|
2016-10-20 17:24:37 +02:00
|
|
|
/* Create required subdirectories (other than pg_wal) */
|
2006-01-27 20:01:15 +01:00
|
|
|
printf(_("creating subdirectories ... "));
|
|
|
|
fflush(stdout);
|
2003-11-14 00:46:31 +01:00
|
|
|
|
2016-01-07 21:22:01 +01:00
|
|
|
for (i = 0; i < lengthof(subdirs); i++)
|
2003-11-10 23:51:16 +01:00
|
|
|
{
|
2016-01-07 21:22:01 +01:00
|
|
|
char *path;
|
|
|
|
|
|
|
|
path = psprintf("%s/%s", pg_data, subdirs[i]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The parent directory already exists, so we only need mkdir() not
|
|
|
|
* pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
|
|
|
|
*/
|
2018-04-07 23:45:39 +02:00
|
|
|
if (mkdir(path, pg_dir_create_mode) < 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not create directory \"%s\": %m", path);
|
2016-01-07 21:22:01 +01:00
|
|
|
|
|
|
|
free(path);
|
2003-11-10 23:51:16 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 20:01:15 +01:00
|
|
|
check_ok();
|
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/* Top level PG_VERSION is checked by bootstrapper, so make it first */
|
2010-01-07 00:23:51 +01:00
|
|
|
write_version_file(NULL);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2006-01-01 00:50:59 +01:00
|
|
|
/* Select suitable configuration settings */
|
2003-11-10 23:51:16 +01:00
|
|
|
set_null_conf();
|
2006-01-01 00:50:59 +01:00
|
|
|
test_config_settings();
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/* Now create all the text config files */
|
2003-11-10 23:51:16 +01:00
|
|
|
setup_config();
|
|
|
|
|
2003-11-14 00:46:31 +01:00
|
|
|
/* Bootstrap template1 */
|
2010-01-07 00:23:51 +01:00
|
|
|
bootstrap_template1();
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
/*
|
|
|
|
* Make the per-database PG_VERSION for template1 only after init'ing it
|
|
|
|
*/
|
2010-01-07 00:23:51 +01:00
|
|
|
write_version_file("base/1");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
/*
|
|
|
|
* Create the stuff we don't need to use bootstrap mode for, using a
|
|
|
|
* backend running in simple standalone mode.
|
|
|
|
*/
|
|
|
|
fputs(_("performing post-bootstrap initialization ... "), stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
snprintf(cmd, sizeof(cmd),
|
2021-07-01 19:33:05 +02:00
|
|
|
"\"%s\" %s %s template1 >%s",
|
|
|
|
backend_exec, backend_options, extra_options,
|
2015-12-18 01:38:21 +01:00
|
|
|
DEVNULL);
|
|
|
|
|
|
|
|
PG_CMD_OPEN;
|
2003-11-14 00:46:31 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_auth(cmdfd);
|
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
setup_run_file(cmdfd, system_constraints_file);
|
|
|
|
|
2021-04-17 00:20:42 +02:00
|
|
|
setup_run_file(cmdfd, system_functions_file);
|
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_depend(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
Add testing to detect errors of omission in "pin" dependency creation.
It's essential that initdb.c's setup_depend() scan each system catalog
that could contain objects that need to have "p" (pin) entries in pg_depend
or pg_shdepend. Forgetting to add that, either when a catalog is first
invented or when it first acquires DATA() entries, is an obvious bug
hazard. We can detect such omissions at reasonable cost by probing every
OID-containing system catalog to see whether the lowest-numbered OID in it
is pinned. If so, the catalog must have been properly accounted for in
setup_depend(). If the lowest OID is above FirstNormalObjectId then the
catalog must have been empty at the end of initdb, so it doesn't matter.
There are a small number of catalogs whose first entry is made later in
initdb than setup_depend(), resulting in nonempty expected output of the
test, but these can be manually inspected to see that they are OK. Any
future mistake of this ilk will manifest as a new entry in the test's
output.
Since pg_conversion is already in the test's output, add it to the set of
catalogs scanned by setup_depend(). That has no effect today (hence, no
catversion bump here) but it will protect us if we ever do add pin-worthy
conversions.
This test is very much like the catalog sanity checks embodied in
opr_sanity.sql and type_sanity.sql, but testing pg_depend doesn't seem to
fit naturally into either of those scripts' charters. Hence, invent a new
test script misc_sanity.sql, which can be a home for this as well as tests
on any other catalogs we might want in future.
Discussion: https://postgr.es/m/8068.1498155068@sss.pgh.pa.us
2017-06-23 17:03:04 +02:00
|
|
|
/*
|
|
|
|
* Note that no objects created after setup_depend() will be "pinned".
|
|
|
|
* They are all droppable at the whim of the DBA.
|
|
|
|
*/
|
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
setup_run_file(cmdfd, system_views_file);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_description(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_collation(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
setup_run_file(cmdfd, dictionary_file);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_privileges(cmdfd);
|
2007-08-21 03:11:32 +02:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
setup_schema(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
load_plpgsql(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
vacuum_db(cmdfd);
|
2009-12-18 22:28:42 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
make_template0(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
make_postgres(cmdfd);
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2015-12-18 01:38:21 +01:00
|
|
|
PG_CMD_CLOSE;
|
|
|
|
|
|
|
|
check_ok();
|
2012-11-30 22:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"pgdata", required_argument, NULL, 'D'},
|
|
|
|
{"encoding", required_argument, NULL, 'E'},
|
|
|
|
{"locale", required_argument, NULL, 1},
|
|
|
|
{"lc-collate", required_argument, NULL, 2},
|
|
|
|
{"lc-ctype", required_argument, NULL, 3},
|
|
|
|
{"lc-monetary", required_argument, NULL, 4},
|
|
|
|
{"lc-numeric", required_argument, NULL, 5},
|
|
|
|
{"lc-time", required_argument, NULL, 6},
|
|
|
|
{"lc-messages", required_argument, NULL, 7},
|
|
|
|
{"no-locale", no_argument, NULL, 8},
|
|
|
|
{"text-search-config", required_argument, NULL, 'T'},
|
|
|
|
{"auth", required_argument, NULL, 'A'},
|
|
|
|
{"auth-local", required_argument, NULL, 10},
|
|
|
|
{"auth-host", required_argument, NULL, 11},
|
|
|
|
{"pwprompt", no_argument, NULL, 'W'},
|
|
|
|
{"pwfile", required_argument, NULL, 9},
|
|
|
|
{"username", required_argument, NULL, 'U'},
|
|
|
|
{"help", no_argument, NULL, '?'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{"debug", no_argument, NULL, 'd'},
|
|
|
|
{"show", no_argument, NULL, 's'},
|
2016-10-19 18:00:00 +02:00
|
|
|
{"noclean", no_argument, NULL, 'n'}, /* for backwards compatibility */
|
|
|
|
{"no-clean", no_argument, NULL, 'n'},
|
|
|
|
{"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
|
|
|
|
{"no-sync", no_argument, NULL, 'N'},
|
2021-01-17 14:28:17 +01:00
|
|
|
{"no-instructions", no_argument, NULL, 13},
|
2012-12-04 04:47:59 +01:00
|
|
|
{"sync-only", no_argument, NULL, 'S'},
|
2017-02-09 22:42:51 +01:00
|
|
|
{"waldir", required_argument, NULL, 'X'},
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
{"wal-segsize", required_argument, NULL, 12},
|
2013-03-22 14:54:07 +01:00
|
|
|
{"data-checksums", no_argument, NULL, 'k'},
|
2018-04-07 23:45:39 +02:00
|
|
|
{"allow-group-access", no_argument, NULL, 'g'},
|
2021-07-13 21:01:01 +02:00
|
|
|
{"discard-caches", no_argument, NULL, 14},
|
2022-03-17 11:11:21 +01:00
|
|
|
{"locale-provider", required_argument, NULL, 15},
|
|
|
|
{"icu-locale", required_argument, NULL, 16},
|
2023-03-08 16:35:42 +01:00
|
|
|
{"icu-rules", required_argument, NULL, 17},
|
2012-11-30 22:45:08 +01:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* options with no short version return a low integer, the rest return
|
|
|
|
* their short version value
|
|
|
|
*/
|
|
|
|
int c;
|
|
|
|
int option_index;
|
|
|
|
char *effective_user;
|
2016-08-20 21:05:25 +02:00
|
|
|
PQExpBuffer start_db_cmd;
|
|
|
|
char pg_ctl_path[MAXPGPATH];
|
2012-11-30 22:45:08 +01:00
|
|
|
|
2014-05-15 03:13:54 +02:00
|
|
|
/*
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
* Ensure that buffering behavior of stdout matches what it is in
|
2014-05-15 03:13:54 +02:00
|
|
|
* interactive usage (at least on most platforms). This prevents
|
|
|
|
* unexpected output ordering when, eg, output is redirected to a file.
|
|
|
|
* POSIX says we must do this before any other usage of these files.
|
|
|
|
*/
|
2014-05-15 21:57:54 +02:00
|
|
|
setvbuf(stdout, NULL, PG_IOLBF, 0);
|
2014-05-15 03:13:54 +02:00
|
|
|
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_logging_init(argv[0]);
|
2012-11-30 22:45:08 +01:00
|
|
|
progname = get_progname(argv[0]);
|
|
|
|
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
{
|
|
|
|
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
|
|
|
{
|
|
|
|
usage(progname);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
|
|
|
{
|
|
|
|
puts("initdb (PostgreSQL) " PG_VERSION);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process command-line options */
|
|
|
|
|
2020-12-28 03:37:42 +01:00
|
|
|
while ((c = getopt_long(argc, argv, "A:dD:E:gkL:nNsST:U:WX:", long_options, &option_index)) != -1)
|
2012-11-30 22:45:08 +01:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
authmethodlocal = authmethodhost = pg_strdup(optarg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When ident is specified, use peer for local connections.
|
|
|
|
* Mirrored, when peer is specified, use ident for TCP/IP
|
|
|
|
* connections.
|
|
|
|
*/
|
|
|
|
if (strcmp(authmethodhost, "ident") == 0)
|
|
|
|
authmethodlocal = "peer";
|
|
|
|
else if (strcmp(authmethodlocal, "peer") == 0)
|
|
|
|
authmethodhost = "ident";
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
authmethodlocal = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
authmethodhost = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
pg_data = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
encoding = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
pwprompt = true;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
username = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug = true;
|
|
|
|
printf(_("Running in debug mode.\n"));
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
noclean = true;
|
2016-10-19 18:00:00 +02:00
|
|
|
printf(_("Running in no-clean mode. Mistakes will not be cleaned up.\n"));
|
2012-11-30 22:45:08 +01:00
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
do_sync = false;
|
|
|
|
break;
|
2012-12-04 04:47:59 +01:00
|
|
|
case 'S':
|
|
|
|
sync_only = true;
|
|
|
|
break;
|
2013-03-22 14:54:07 +01:00
|
|
|
case 'k':
|
|
|
|
data_checksums = true;
|
|
|
|
break;
|
2012-11-30 22:45:08 +01:00
|
|
|
case 'L':
|
|
|
|
share_path = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
locale = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
lc_collate = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
lc_ctype = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
lc_monetary = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
lc_numeric = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
lc_time = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
lc_messages = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
locale = "C";
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
pwfilename = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
show_setting = true;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
default_text_search_config = pg_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
xlog_dir = pg_strdup(optarg);
|
|
|
|
break;
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
case 12:
|
|
|
|
str_wal_segment_size_mb = pg_strdup(optarg);
|
|
|
|
break;
|
2021-01-17 14:28:17 +01:00
|
|
|
case 13:
|
|
|
|
noinstructions = true;
|
|
|
|
break;
|
2018-04-07 23:45:39 +02:00
|
|
|
case 'g':
|
|
|
|
SetDataDirectoryCreatePerm(PG_DIR_MODE_GROUP);
|
|
|
|
break;
|
2021-07-01 19:33:05 +02:00
|
|
|
case 14:
|
|
|
|
extra_options = psprintf("%s %s",
|
|
|
|
extra_options,
|
2021-07-13 21:01:01 +02:00
|
|
|
"-c debug_discard_caches=1");
|
2021-07-01 19:33:05 +02:00
|
|
|
break;
|
2022-03-17 11:11:21 +01:00
|
|
|
case 15:
|
|
|
|
if (strcmp(optarg, "icu") == 0)
|
|
|
|
locale_provider = COLLPROVIDER_ICU;
|
|
|
|
else if (strcmp(optarg, "libc") == 0)
|
|
|
|
locale_provider = COLLPROVIDER_LIBC;
|
|
|
|
else
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("unrecognized locale provider: %s", optarg);
|
2022-03-17 11:11:21 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
icu_locale = pg_strdup(optarg);
|
|
|
|
break;
|
2023-03-08 16:35:42 +01:00
|
|
|
case 17:
|
|
|
|
icu_rules = pg_strdup(optarg);
|
|
|
|
break;
|
2012-11-30 22:45:08 +01:00
|
|
|
default:
|
|
|
|
/* getopt_long already emitted a complaint */
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
|
2012-11-30 22:45:08 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Non-option argument specifies data directory as long as it wasn't
|
|
|
|
* already specified with -D / --pgdata
|
|
|
|
*/
|
2017-08-31 04:28:36 +02:00
|
|
|
if (optind < argc && !pg_data)
|
2012-11-30 22:45:08 +01:00
|
|
|
{
|
|
|
|
pg_data = pg_strdup(argv[optind]);
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
pg_log_error("too many command-line arguments (first is \"%s\")",
|
|
|
|
argv[optind]);
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
|
2012-11-30 22:45:08 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-03-17 11:11:21 +01:00
|
|
|
if (icu_locale && locale_provider != COLLPROVIDER_ICU)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
|
|
|
|
"--icu-locale", "icu");
|
2022-03-17 11:11:21 +01:00
|
|
|
|
2023-03-08 16:35:42 +01:00
|
|
|
if (icu_rules && locale_provider != COLLPROVIDER_ICU)
|
|
|
|
pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
|
|
|
|
"--icu-rules", "icu");
|
|
|
|
|
2018-12-29 13:21:57 +01:00
|
|
|
atexit(cleanup_directories_atexit);
|
|
|
|
|
2015-05-29 23:02:58 +02:00
|
|
|
/* If we only need to fsync, just do it and exit */
|
2012-12-04 04:47:59 +01:00
|
|
|
if (sync_only)
|
|
|
|
{
|
|
|
|
setup_pgdata();
|
2015-05-29 23:02:58 +02:00
|
|
|
|
|
|
|
/* must check that directory is readable */
|
|
|
|
if (pg_check_dir(pg_data) <= 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("could not access directory \"%s\": %m", pg_data);
|
2015-05-29 23:02:58 +02:00
|
|
|
|
2016-09-29 18:00:00 +02:00
|
|
|
fputs(_("syncing data to disk ... "), stdout);
|
|
|
|
fflush(stdout);
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
fsync_pgdata(pg_data, PG_VERSION_NUM);
|
2016-09-29 18:00:00 +02:00
|
|
|
check_ok();
|
2012-12-04 04:47:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
if (pwprompt && pwfilename)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("password prompt and password file cannot be specified together");
|
2012-11-30 22:45:08 +01:00
|
|
|
|
2019-07-22 19:28:25 +02:00
|
|
|
check_authmethod_unspecified(&authmethodlocal);
|
|
|
|
check_authmethod_unspecified(&authmethodhost);
|
2012-11-30 22:45:08 +01:00
|
|
|
|
|
|
|
check_authmethod_valid(authmethodlocal, auth_methods_local, "local");
|
|
|
|
check_authmethod_valid(authmethodhost, auth_methods_host, "host");
|
|
|
|
|
|
|
|
check_need_password(authmethodlocal, authmethodhost);
|
|
|
|
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
/* set wal segment size */
|
|
|
|
if (str_wal_segment_size_mb == NULL)
|
|
|
|
wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
/* check that the argument is a number */
|
|
|
|
wal_segment_size_mb = strtol(str_wal_segment_size_mb, &endptr, 10);
|
|
|
|
|
|
|
|
/* verify that wal segment size is valid */
|
2018-03-25 15:17:07 +02:00
|
|
|
if (endptr == str_wal_segment_size_mb || *endptr != '\0')
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("argument of --wal-segsize must be a number");
|
2018-03-24 20:40:21 +01:00
|
|
|
if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("argument of --wal-segsize must be a power of 2 between 1 and 1024");
|
Make WAL segment size configurable at initdb time.
For performance reasons a larger segment size than the default 16MB
can be useful. A larger segment size has two main benefits: Firstly,
in setups using archiving, it makes it easier to write scripts that
can keep up with higher amounts of WAL, secondly, the WAL has to be
written and synced to disk less frequently.
But at the same time large segment size are disadvantageous for
smaller databases. So far the segment size had to be configured at
compile time, often making it unrealistic to choose one fitting to a
particularly load. Therefore change it to a initdb time setting.
This includes a breaking changes to the xlogreader.h API, which now
requires the current segment size to be configured. For that and
similar reasons a number of binaries had to be taught how to recognize
the current segment size.
Author: Beena Emerson, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Kuntal Ghosh, Michael
Paquier, Peter Eisentraut, Robert Hass, Tushar Ahuja
Discussion: https://postgr.es/m/CAOG9ApEAcQ--1ieKbhFzXSQPw_YLmepaa4hNdnY5+ZULpt81Mw@mail.gmail.com
2017-09-20 07:03:48 +02:00
|
|
|
}
|
|
|
|
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
get_restricted_token();
|
2012-11-30 22:45:08 +01:00
|
|
|
|
|
|
|
setup_pgdata();
|
|
|
|
|
|
|
|
setup_bin_paths(argv[0]);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
effective_user = get_id();
|
2017-08-31 04:28:36 +02:00
|
|
|
if (!username)
|
2012-11-30 22:45:08 +01:00
|
|
|
username = effective_user;
|
|
|
|
|
2016-05-08 17:55:44 +02:00
|
|
|
if (strncmp(username, "pg_", 3) == 0)
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_fatal("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
|
2016-05-08 17:55:44 +02:00
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
printf(_("The files belonging to this database system will be owned "
|
|
|
|
"by user \"%s\".\n"
|
|
|
|
"This user must also own the server process.\n\n"),
|
|
|
|
effective_user);
|
|
|
|
|
|
|
|
set_info_version();
|
|
|
|
|
|
|
|
setup_data_file_paths();
|
|
|
|
|
|
|
|
setup_locale_encoding();
|
|
|
|
|
|
|
|
setup_text_search();
|
2013-03-22 14:54:07 +01:00
|
|
|
|
2013-06-19 03:56:13 +02:00
|
|
|
printf("\n");
|
|
|
|
|
2013-03-22 14:54:07 +01:00
|
|
|
if (data_checksums)
|
|
|
|
printf(_("Data page checksums are enabled.\n"));
|
|
|
|
else
|
|
|
|
printf(_("Data page checksums are disabled.\n"));
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2016-08-30 21:25:01 +02:00
|
|
|
if (pwprompt || pwfilename)
|
|
|
|
get_su_pwd();
|
|
|
|
|
2012-11-30 22:45:08 +01:00
|
|
|
printf("\n");
|
2003-11-10 23:51:16 +01:00
|
|
|
|
2012-12-04 05:22:56 +01:00
|
|
|
initialize_data_directory();
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-12-04 15:52:00 +01:00
|
|
|
if (do_sync)
|
2016-09-29 18:00:00 +02:00
|
|
|
{
|
|
|
|
fputs(_("syncing data to disk ... "), stdout);
|
|
|
|
fflush(stdout);
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
fsync_pgdata(pg_data, PG_VERSION_NUM);
|
2016-09-29 18:00:00 +02:00
|
|
|
check_ok();
|
|
|
|
}
|
2012-12-04 15:52:00 +01:00
|
|
|
else
|
|
|
|
printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
|
|
|
|
|
2019-07-22 19:28:25 +02:00
|
|
|
if (authwarning)
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
pg_log_warning("enabling \"trust\" authentication for local connections");
|
2022-04-08 20:55:14 +02:00
|
|
|
pg_log_warning_hint("You can change this by editing pg_hba.conf or using the option -A, or "
|
|
|
|
"--auth-local and --auth-host, the next time you run initdb.");
|
2019-07-22 19:28:25 +02:00
|
|
|
}
|
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
if (!noinstructions)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Build up a shell command to tell the user how to start the server
|
|
|
|
*/
|
|
|
|
start_db_cmd = createPQExpBuffer();
|
|
|
|
|
|
|
|
/* Get directory specification used to start initdb ... */
|
|
|
|
strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
|
|
|
|
canonicalize_path(pg_ctl_path);
|
|
|
|
get_parent_directory(pg_ctl_path);
|
|
|
|
/* ... and tag on pg_ctl instead */
|
|
|
|
join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl");
|
2016-08-20 21:05:25 +02:00
|
|
|
|
2021-03-02 19:39:34 +01:00
|
|
|
/* Convert the path to use native separators */
|
|
|
|
make_native_path(pg_ctl_path);
|
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
/* path to pg_ctl, properly quoted */
|
|
|
|
appendShellString(start_db_cmd, pg_ctl_path);
|
2016-08-20 21:05:25 +02:00
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
/* add -D switch, with properly quoted data directory */
|
|
|
|
appendPQExpBufferStr(start_db_cmd, " -D ");
|
|
|
|
appendShellString(start_db_cmd, pgdata_native);
|
2016-08-20 21:05:25 +02:00
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
/* add suggested -l switch and "start" command */
|
|
|
|
/* translator: This is a placeholder in a shell command. */
|
|
|
|
appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
|
2016-08-20 21:05:25 +02:00
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
printf(_("\nSuccess. You can now start the database server using:\n\n"
|
|
|
|
" %s\n\n"),
|
|
|
|
start_db_cmd->data);
|
2012-12-04 05:22:56 +01:00
|
|
|
|
2021-01-17 14:28:17 +01:00
|
|
|
destroyPQExpBuffer(start_db_cmd);
|
|
|
|
}
|
2016-08-20 21:05:25 +02:00
|
|
|
|
2012-12-04 05:22:56 +01:00
|
|
|
|
2018-12-29 13:21:57 +01:00
|
|
|
success = true;
|
2003-11-10 23:51:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|