@narunblog

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Centos7でpostgresqlを起動できない

発生している問題・エラー

こちらの記事を参考にpostgresqlをインストールしました。
最後に起動しようとしたらエラーで起動できませんでした。

出ているエラーメッセージを入力

(base) [root@ik1-301-10597 ~]# systemctl start postgresql-13.service
Job for postgresql-13.service failed because the control process exited with error code.
See "systemctl status postgresql-13.service" and "journalctl -xe" for details.
(base) [root@ik1-301-10597 ~]# 
(base) [root@ik1-301-10597 ~]# 
(base) [root@ik1-301-10597 ~]# 
(base) [root@ik1-301-10597 ~]# journalctl -xe
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
-- 
-- Unit postgresql-13.service has failed.
-- 
-- The result is failed.
Aug 15 10:24:40 ik1-301-10597.vs.sakura.ne.jp sshd[156137]: Failed password for invalid user teamspeak3 from 165.227.196.43 port 43662 ssh2
Aug 15 10:24:40 ik1-301-10597.vs.sakura.ne.jp sshd[156137]: Received disconnect from 165.227.196.43 port 43662:11: Bye Bye [preauth]
Aug 15 10:24:40 ik1-301-10597.vs.sakura.ne.jp sshd[156137]: Disconnected from invalid user teamspeak3 165.227.196.43 port 43662 [preauth]
Aug 15 10:24:53 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: Invalid user git from 121.4.71.154 port 58846
Aug 15 10:24:53 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: pam_unix(sshd:auth): check pass; user unknown
Aug 15 10:24:53 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=121.4.71.154
Aug 15 10:24:56 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: Failed password for invalid user git from 121.4.71.154 port 58846 ssh2
Aug 15 10:24:56 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: Received disconnect from 121.4.71.154 port 58846:11: Bye Bye [preauth]
Aug 15 10:24:56 ik1-301-10597.vs.sakura.ne.jp sshd[156152]: Disconnected from invalid user git 121.4.71.154 port 58846 [preauth]
Aug 15 10:24:58 ik1-301-10597.vs.sakura.ne.jp sshd[156154]: Invalid user web from 68.183.66.107 port 48706
Aug 15 10:24:58 ik1-301-10597.vs.sakura.ne.jp sshd[156154]: pam_unix(sshd:auth): check pass; user unknown
Aug 15 10:24:58 ik1-301-10597.vs.sakura.ne.jp sshd[156154]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=68.183.66.107

(base) [root@ik1-301-10597 ~]# 
(base) [root@ik1-301-10597 ~]# systemctl status postgresql-13.service
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2021-08-15 10:24:39 JST; 5h 20min ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 156146 ExecStart=/usr/pgsql-13/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
  Process: 156141 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 156146 (code=exited, status=1/FAILURE)

Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp systemd[1]: Starting PostgreSQL 13 database server...
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp postmaster[156146]: 2021-08-15 10:24:39.427 JST [156146] LOG:  redirecting log output to logging collector process
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp postmaster[156146]: 2021-08-15 10:24:39.427 JST [156146] HINT:  Future log output will appear in directory "log".
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp systemd[1]: postgresql-13.service: Main process exited, code=exited, status=1/FAILURE
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp systemd[1]: postgresql-13.service: Killing process 156148 (postmaster) with signal SIGKILL.
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp systemd[1]: postgresql-13.service: Failed with result 'exit-code'.
Aug 15 10:24:39 ik1-301-10597.vs.sakura.ne.jp systemd[1]: Failed to start PostgreSQL 13 database server.
(base) [root@ik1-301-10597 ~]# 
2021-08-15 09:40:07.395 JST [154544] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 09:40:07.395 JST [154544] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 09:40:07.395 JST [154544] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:40:07.395 JST [154544] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 09:40:07.395 JST [154544] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:40:07.395 JST [154544] WARNING:  could not create listen socket for "localhost"
2021-08-15 09:40:07.395 JST [154544] FATAL:  could not create any TCP/IP sockets
2021-08-15 09:40:07.397 JST [154544] LOG:  database system is shut down
2021-08-15 09:51:48.633 JST [154919] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 09:51:48.633 JST [154919] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 09:51:48.633 JST [154919] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:51:48.633 JST [154919] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 09:51:48.633 JST [154919] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:51:48.633 JST [154919] WARNING:  could not create listen socket for "localhost"
2021-08-15 09:51:48.633 JST [154919] FATAL:  could not create any TCP/IP sockets
2021-08-15 09:51:48.635 JST [154919] LOG:  database system is shut down
2021-08-15 09:53:15.087 JST [155014] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 09:53:15.088 JST [155014] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 09:53:15.088 JST [155014] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:53:15.088 JST [155014] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 09:53:15.088 JST [155014] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:53:15.088 JST [155014] WARNING:  could not create listen socket for "localhost"
2021-08-15 09:53:15.088 JST [155014] FATAL:  could not create any TCP/IP sockets
2021-08-15 09:53:15.089 JST [155014] LOG:  database system is shut down
2021-08-15 09:53:37.095 JST [155039] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 09:53:37.095 JST [155039] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 09:53:37.095 JST [155039] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:53:37.095 JST [155039] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 09:53:37.095 JST [155039] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:53:37.095 JST [155039] WARNING:  could not create listen socket for "localhost"
2021-08-15 09:53:37.095 JST [155039] FATAL:  could not create any TCP/IP sockets
2021-08-15 09:53:37.097 JST [155039] LOG:  database system is shut down
2021-08-15 09:57:44.074 JST [155181] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 09:57:44.075 JST [155181] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 09:57:44.075 JST [155181] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:57:44.075 JST [155181] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 09:57:44.075 JST [155181] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 09:57:44.075 JST [155181] WARNING:  could not create listen socket for "localhost"
2021-08-15 09:57:44.075 JST [155181] FATAL:  could not create any TCP/IP sockets
2021-08-15 09:57:44.076 JST [155181] LOG:  database system is shut down
2021-08-15 10:02:41.998 JST [155423] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 10:02:41.998 JST [155423] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 10:02:41.998 JST [155423] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:02:41.998 JST [155423] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 10:02:41.998 JST [155423] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:02:41.998 JST [155423] WARNING:  could not create listen socket for "localhost"
2021-08-15 10:02:41.998 JST [155423] FATAL:  could not create any TCP/IP sockets
2021-08-15 10:02:41.999 JST [155423] LOG:  database system is shut down
2021-08-15 10:13:10.455 JST [155736] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 10:13:10.456 JST [155736] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 10:13:10.456 JST [155736] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:13:10.456 JST [155736] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 10:13:10.456 JST [155736] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:13:10.456 JST [155736] WARNING:  could not create listen socket for "localhost"
2021-08-15 10:13:10.456 JST [155736] FATAL:  could not create any TCP/IP sockets
2021-08-15 10:13:10.457 JST [155736] LOG:  database system is shut down
2021-08-15 10:17:58.420 JST [155902] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 10:17:58.420 JST [155902] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 10:17:58.420 JST [155902] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:17:58.420 JST [155902] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 10:17:58.420 JST [155902] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:17:58.420 JST [155902] WARNING:  could not create listen socket for "localhost"
2021-08-15 10:17:58.420 JST [155902] FATAL:  could not create any TCP/IP sockets
2021-08-15 10:17:58.422 JST [155902] LOG:  database system is shut down
2021-08-15 10:18:04.794 JST [155916] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 10:18:04.795 JST [155916] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 10:18:04.795 JST [155916] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:18:04.795 JST [155916] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 10:18:04.795 JST [155916] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:18:04.795 JST [155916] WARNING:  could not create listen socket for "localhost"
2021-08-15 10:18:04.795 JST [155916] FATAL:  could not create any TCP/IP sockets
2021-08-15 10:18:04.796 JST [155916] LOG:  database system is shut down
2021-08-15 10:24:39.427 JST [156146] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
2021-08-15 10:24:39.427 JST [156146] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2021-08-15 10:24:39.427 JST [156146] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:24:39.427 JST [156146] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2021-08-15 10:24:39.427 JST [156146] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-08-15 10:24:39.427 JST [156146] WARNING:  could not create listen socket for "localhost"
2021-08-15 10:24:39.427 JST [156146] FATAL:  could not create any TCP/IP sockets
2021-08-15 10:24:39.428 JST [156146] LOG:  database system is shut down
(base) [root@ik1-301-10597 ~]# 

自分で試したこと

エラーを確認

設定ができていないのか、それ以前の問題なのか分からないため、
教えて欲しいです。

原因

前postgresqlを起動したときのプロセスが生きてた。
5432ポートを重複して使おうとしていた。

解決策

5432ポートのプロセスを強制終了して、postgresqlを起動する

以下コードを順番に実行

sudo lsof -i:5432 #5432ポートで動いているプロセスの確認
kill -9 153727 #確認したプロセスのpidを強制終了

systemctl start postgresql-13.service #再度postgresqlを起動

ついでにステータス確認

systemctl status postgresql-13.service

● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-08-15 16:58:00 JST; 41s ago
     Docs: https://www.postgresql.org/docs/13/static/
 Main PID: 166312 (postmaster)
    Tasks: 8 (limit: 12532)
   Memory: 18.1M
   CGroup: /system.slice/postgresql-13.service
           ├─166312 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─166314 postgres: logger 
           ├─166316 postgres: checkpointer 
           ├─166317 postgres: background writer 
           ├─166318 postgres: walwriter 
           ├─166319 postgres: autovacuum launcher 
           ├─166320 postgres: stats collector 
           └─166321 postgres: logical replication launcher 

Aug 15 16:58:00 ik1-301-10597.vs.sakura.ne.jp systemd[1]: Starting PostgreSQL 13 database server...

(base) [root@ik1-301-10597 ~]# kill -9 153727

Activeになってれば大丈夫そう。

1 likes

No Answers yet.

Your answer might help someone💌