简体   繁体   中英

PostgreSQL 10 reads postgresql.conf from /etc but data directory specified in /var

I am confused about the configuration of my PostgreSQL 10 installation on Ubuntu on WSL2.

I initialized the db to use trust authentication (not my requirement, insecure I know) and specified the data directory like:

/usr/lib/postgresql/10/bin/initdb -Atrust 
-D /var/lib/postgresql/10/main/

I checked /var/lib/postgresql/10/main/pg_hba.conf and it correctly shows trust authentication for all hosts. However, when I start the server with either of these methods:

$ sudo service postgresql start
$ sudo su postgres -c 'pg_ctlcluster 10 main start'

I could not log in without a password, eg the authentication method was not trust.

After running ps -ef | grep postgresql ps -ef | grep postgresql I see this:

/usr/lib/postgresql/10/bin/postgres 
-D /var/lib/postgresql/10/main 
-c config_file=/etc/postgresql/10/main/postgresql.conf

It is using the correct data directory but reading the config file from the /etc location. The /etc/postgresql/10/main/postgresql.conf says to use /etc/postgresql/10/main/pg_hba.conf which was not modified by initdb so has the default of md5 password authentication.

I am confused as to why the startup scripts use the correct data dir in /var but get their config from another location at /etc .

This is the only way I can get the server to start with the correct config in /var , and it is very wordy so I would rather use the system command:

sudo su postgres -c '/usr/lib/postgresql/10/bin/pg_ctl start 
-D  /var/lib/postgresql/10/main 
-l /var/log/postgresql/postgresql-10-main.log'

Any help would be greatly appreciated, thanks in advance.

I am using PostgreSQL 10 on Ubuntu on WSL2 on Windows 10. Here are my installation details: Linux and Ubuntu:

$ uname -a
Linux ISC20-0521-WD 4.4.0-17763-Microsoft #864-Microsoft Thu Nov 07 15:22:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

pg version:

$ psql --version
psql (PostgreSQL) 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)

Here is the output of pgconfig:

$ pg_config
BINDIR = /usr/lib/postgresql/10/bin
DOCDIR = /usr/share/doc/postgresql-doc-10
HTMLDIR = /usr/share/doc/postgresql-doc-10
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/10/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/10/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/10/man
SHAREDIR = /usr/share/postgresql/10
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/10/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-tclconfig=/usr/lib/x86_64-linux-gnu/tcl8.6' '--with-includes=/usr/include/tcl8.6' 'PYTHON=/usr/bin/python' '--mandir=/usr/share/postgresql/10/man' '--docdir=/usr/share/doc/postgresql-doc-10' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/10' '--bindir=/usr/lib/postgresql/10/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 10.10-0ubuntu0.18.04.1)' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-systemd' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' '--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' '--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' '--with-selinux' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/x86_64-linux-gnu/mit-krb5 -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm

and pg_lsclusters:

$ pg_lsclusters -s
Ver Cluster Port Status      Owner    Data directory              Log file
10  main    5432 online,auto postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log

The Debian/Ubuntu packages made the choice to place the configuration files in /etc rather than in the data directory, which is an unusual, but valid choice.

You are best served by using the pg_createcluster script provided by the Ubunto packages to create a cluster. That will place the configuration files in /etc , and things should work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM