computerの日記

Cisco,SHELL,C,Qt,C++,Linux,ネットワーク,Windows Scriptなどの発言です

Fedora29 -> Fedora30 アップグレードで、PostgreSQL が動かなくなったのを直した件

Fedora29 から、Fedora30 にアップグレード完了して、Web ページ(http://heavymetalhardrock.no-ip.info/)を開くと、以下のエラーになっていました。

ERROR: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

PostgreSQL が起動していないようです。

確認します。

# systemctl status postgresql
(表示)
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since xxxxxxxx
Process: 810 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=1/FAILURE)

May 10 01:15:07 xxxx systemd[1]: Starting PostgreSQL database server...
May 10 01:15:07 xxxx postgresql-check-db-dir[810]: An old version of the database format was found.
May 10 01:15:07 xxxx postgresql-check-db-dir[810]: Use 'postgresql-setup --upgrade' to upgrade to version '11'
May 10 01:15:07 xxxx postgresql-check-db-dir[810]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
May 10 01:15:07 xxxx systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
May 10 01:15:07 xxxx systemd[1]: postgresql.service: Failed with result 'exit-code'.
May 10 01:15:07 xxxx systemd[1]: Failed to start PostgreSQL database server.

 

どうやら、PostgreSQL のメジャーバージョンが、10 から 11 にアップグレードされたらしいです。
以下のコマンドを実行しました。

# postgresql-setup --upgrade
(表示)
* Upgrading database.
* Upgraded OK.
WARNING: The configuration files were replaced by default configuration.
WARNING: The previous configuration and data are stored in folder
WARNING: /var/lib/pgsql/data-old.
WARNING: If you've just upgraded your database from a previous major version of
Fedora or RHEL, please run reindexdb against your databases. Core library
collation data may have changed and this will invalidate database indexes. For
example, in Fedora 28 and RHEL 8 there have been extensive changes in glibc
collations to support ISO 14651:2016 (Unicode 9.0.0 data) and your indexes may
be affected: https://sourceware.org/ml/libc-announce/2018/msg00002.html
* See /var/lib/pgsql/upgrade_postgresql.log for details.

今までのデータベース領域は、/var/lib/psql/data-old に退避したということらしいです。
起動したか確認します。

# systemctl status postgresql
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since xxxxxxxx
Process: 1479 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 1481 (postmaster)
Tasks: 8 (limit: 1141)
Memory: 16.2M
CGroup: /system.slice/postgresql.service
├─1481 /usr/bin/postmaster -D /var/lib/pgsql/data
├─1482 postgres: logger
├─1484 postgres: checkpointer
├─1485 postgres: background writer
├─1486 postgres: walwriter
├─1487 postgres: autovacuum launcher
├─1488 postgres: stats collector
└─1489 postgres: logical replication launcher

May 10 01:21:47 xxxxxxxx systemd[1]: Starting PostgreSQL database server...
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.355 JST [1481] LOG: listening on IPv6 address "::1", port >
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.356 JST [1481] LOG: listening on IPv4 address "127.0.0.1",>
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.357 JST [1481] LOG: listening on Unix socket "/var/run/pos>
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.361 JST [1481] LOG: listening on Unix socket "/tmp/.s.PGSQ>
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.372 JST [1481] LOG: redirecting log output to logging coll>
May 10 01:21:47 xxxxxxxx postmaster[1481]: 2019-05-10 01:21:47.372 JST [1481] HINT: Future log output will appear in dire>
May 10 01:21:47 xxxxxxxx systemd[1]: Started PostgreSQL database server.

 

無事起動しているようです。

バージョンを確認しました。

# postmaster --version
postgres (PostgreSQL) 11.2

11.2 になっています。

Web ページをリロードすると、今度は、以下の表示が出ています。

ERROR: SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres"

退避した pg_hba.conf はどうなっていたかな。

# diff -ruNp data/pg_hba.conf data-old/pg_hba.conf
--- data/pg_hba.conf 2019-05-10 01:20:27.400566913 +0900
+++ data-old/pg_hba.conf 2018-05-22 09:11:24.777453980 +0900
@@ -77,11 +77,14 @@
# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
-local all all peer
+#local all all peer
+local all all trust
# IPv4 local connections:
-host all all 127.0.0.1/32 ident
+#host all all 127.0.0.1/32 ident
+host all all 127.0.0.1/32 trust
# IPv6 local connections:
-host all all ::1/128 ident
+#host all all ::1/128 ident
+host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer

最小限の修正で済ませたいな。

具体的には、/var/lib/pgslq/data/pg_hba.conf を開き、IPv6 の行の METHOD カラムを、
trust に修正して postgresql 再起動したらいけました。

このサーバでは、IPv6 が有効になっているため、優先的に IPv6 が使われるためのようですね。

お腹すいたァ。。