yum 安裝postgresql9.6遇到的坑及問題解決


 yum 安裝了 PostgreSQL            
             安裝           

yum install  https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-redhat-repo-42.0-11.noarch.rpm
yum install postgresql96

 

  • 初始化數據庫 
cd pgsql-9.6/
/usr/pgsql-9.6/bin/postgresql96-setup initdb

執行完畢顯示:

Initializing database ... OK
創建用戶組和用戶:

  • 創建用戶組:
sudo groupadd postgresql
  • 創建用戶:
sudo useradd -gpostgresql postgresql

實現開機自啓服務

systemctl enable postgresql-9.6

Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.

啓動數據庫服務

systemctl start  postgresql-9.6

報錯情況下:

在這裏插入圖片描述

Job for postgresql-9.6.service failed because the control process exited with error code. See "systemctl status postgresql-9.6.service" and "journalctl -xe" for details.

解決方案1:
查看啓動狀態:systemctl status postgresql-9.6 有如下報錯:

在這裏插入圖片描述

● postgresql-9.6.service - PostgreSQL 9.6 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-9.6.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2020-06-10 13:26:43 CST; 26s ago
     Docs: https://www.postgresql.org/docs/9.6/static/
  Process: 24750 ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
  Process: 24743 ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 24750 (code=exited, status=1/FAILURE)

Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 systemd[1]: Starting PostgreSQL 9.6 database server...
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 postmaster[24750]: < 2020-06-10 13:26:43.566 CST > LOG:  redirecting log output to logging collector process
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 postmaster[24750]: < 2020-06-10 13:26:43.566 CST > HINT:  Future log output will appear in directory "pg_log".
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 systemd[1]: postgresql-9.6.service: main process exited, code=exited, status=1/FAILURE
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 systemd[1]: Failed to start PostgreSQL 9.6 database server.
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 systemd[1]: Unit postgresql-9.6.service entered failed state.
Jun 10 13:26:43 hecs-x-xlarge-2-linux-20200604174817 systemd[1]: postgresql-9.6.service failed.

 

權限的問題,授權一下:
chmod 700 /var/lib/pgsql/9.6/data
再次啓動:正常了。

解決方案2:很有可能是以前安裝過PostgreSQL     ,那就是需要刪除/var/lib/pgsql

rm -rf   /var/lib/pgsql

再次啓動:正常了。

  • 查看是否安裝成功
[root@hecs-x-xlarge-2-linux-20200604174817 data]# netstat -tlun | grep 5432  #postgres是佔用5432端口
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN     
tcp6       0      0 :::5432                 :::*                    LISTEN     


 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章