在CentOS 7 / RHEL 7安裝PostgreSQL 10

CentOS 到了7.x版本, PostgreSQL也來(lái)到了10.x版本. 前些天MySQL都直接跨到了8.0版本.


本文是一篇在CentOS 7.4上安裝安裝PostgreSQL 10.3 的教程. 本文發(fā)布于2018-04-28.

1. 切換到root用戶:
# su -
2. 把最新的rpm包添加到系統(tǒng)庫(kù):

PostgreSQL會(huì)為所有的Linux平臺(tái)發(fā)布rpm包, 而且會(huì)比其他的的庫(kù)更新的更快.
可以試試在瀏覽器輸入 https://download.postgresql.org/pub 看會(huì)發(fā)現(xiàn)什么.

### CentOS 7 ###

# rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

### RHEL 7 ###

# rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
3. 用 yum 安裝PostgreSQL:
# yum install -y postgresql10-server postgresql10
4. 安裝完成后, 初次使用前先進(jìn)行初始化:
# /usr/pgsql-10/bin/postgresql-10-setup initdb

PostgreSQL文件默認(rèn)放在路徑: /var/lib/pgsql/10/data/

5. 啟動(dòng)PostgreSQL:
# systemctl start postgresql-10
6. 設(shè)置PostgreSQL自啟動(dòng):
# systemctl enable postgresql-10
7. 查詢PostgreSQL運(yùn)行狀態(tài):
# systemctl status postgresql-10

會(huì)輸出類似的信息:

● postgresql-10.service - PostgreSQL 10 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-10.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-04-27 18:03:08 CST; 21h ago
     Docs: https://www.postgresql.org/docs/10/static/
 Main PID: 14916 (postmaster)
   CGroup: /system.slice/postgresql-10.service
           ├─14916 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
           ├─14920 postgres: logger process
           ├─14922 postgres: checkpointer process
           ├─14923 postgres: writer process
           ├─14924 postgres: wal writer process
           ├─14925 postgres: autovacuum launcher process
           ├─14926 postgres: stats collector process
           └─14927 postgres: bgworker: logical replication launcher

Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ systemd[1]: Starting PostgreSQL 10 database server...
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.762 CST [14916] LOG:  listening on IPv4 address "127.0.0.1...t 5432
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.762 CST [14916] LOG:  could not bind IPv6 address "::1": C...ddress
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.762 CST [14916] HINT:  Is another postmaster already runni...retry.
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.764 CST [14916] LOG:  listening on Unix socket "/var/run/p....5432"
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.767 CST [14916] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.777 CST [14916] LOG:  redirecting log output to logging co...rocess
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ postmaster[14916]: 2018-04-27 18:03:08.777 CST [14916] HINT:  Future log output will appear in di..."log".
Apr 27 18:03:08 iZbp144wg7yw6hrfyu76anZ systemd[1]: Started PostgreSQL 10 database server.
Hint: Some lines were ellipsized, use -l to show in full.
8. 再確認(rèn)看看PostgreSQL是否運(yùn)行在5432端口:
# netstat -antup | grep 5432

會(huì)有類似輸出:

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      14916/postmaster
9. 連接PostgreSQL服務(wù)器:

PostgreSQL會(huì)自動(dòng)創(chuàng)建postgres用戶, 創(chuàng)建數(shù)據(jù)庫(kù)之前, 要用postgres用戶或root用戶登錄并重置postgres用戶密碼.

# su -l postgres
10. 連接數(shù)據(jù)庫(kù), psql命令會(huì)激活PostgreSQL數(shù)據(jù)庫(kù)終端:
$ psql

會(huì)輸出下列說(shuō)明連接進(jìn)入了PostgreSQL數(shù)據(jù)庫(kù):

psql (10.3)
Type "help" for help.

postgres=# 
11. 重置postgres用戶密碼:
postgres=# \password

文章來(lái)源并整理自IT's Ggeek By Raj.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容