Linux安裝配置Postgresql12.1

環(huán)境介紹:Linux版本centos7、Postgresql版本12.1

安裝步驟

1、設(shè)置保存安裝包的目錄??

cd /home


2.到官網(wǎng)下載源包

到官網(wǎng)下載postgresql-12.1.tar.gz:https://www.postgresql.org/ftp/source/

下載完成通過(guò)FTP上傳至home目錄下

3.解壓源包

tar -zxvf postgresql-12.1.tar.gz


4.進(jìn)入解壓后目錄

cd /home/postgresql-12.1



5.下載依賴(lài)包

yum install -y bison

yum install -y flex

yum install -y readline-devel

yum install -y zlib-devel


6.配置生成Makefile到安裝目錄

./configure --prefix=/home/postgresql-12.1


7、編譯并安裝

?make

?make install

8.創(chuàng)建添加postgres用戶(hù)到postgres組

groupadd postgres

useradd -g postgres postgres

chown -R postgres:postgres /home

mkdir -p /home/postgresql-12.1/data

su postgres


9.初始化數(shù)據(jù)庫(kù)

/home/postgresql-12.1/bin/initdb -D /home/postgresql-12.1/data/


操作數(shù)據(jù)庫(kù)

?/home/postgresql-12.1/bin/pg_ctl -D /home/postgresql-12.1/data/ -l logfile start  --啟動(dòng)數(shù)據(jù)庫(kù)

?/home/postgresql-12.1/bin/pg_ctl -D /home/postgresql-12.1/data/ stop --停止數(shù)據(jù)庫(kù)

?/home/postgresql-12.1/bin/pg_ctl restart -D /home/postgresql-12.1/data/ -m fast --重啟數(shù)據(jù)庫(kù)


配置步驟

1、修改postgresql.conf

cd /home/postgresql-12.1/data/

vim postgresql.conf


原本Listen_addresses被注釋了,放開(kāi)并指定具體IP

2、修改postgresql.conf

vim pg_hba.conf

新增host? ? ? all? ? ? alll? ? ? 0.0.0.0/0? ? ? ? ? ? ? trust


3、添加環(huán)境變量

vim?/etc/profile

export PGHOME=/home/postgresql-12.1?

export PGDATA=/home/postgresql-12.1/data?

PATH=$PATH:$HOME/bin:$PGHOME/bin??

4、設(shè)置開(kāi)機(jī)自啟動(dòng)

cd /home/postgresql-12.1/contrib/start-scripts?


5.授權(quán)

chmod a+x linux


6.復(fù)制到啟動(dòng)文件中

cp linux /etc/init.d/postgresql (復(fù)制linux文件到/etc/init.d目錄下,并更名postgresql)

vim linux /etc/init.d/postgresql

7.添加到開(kāi)機(jī)啟動(dòng)

chkconfig --add postgresql (添加開(kāi)機(jī)啟動(dòng)項(xiàng)目)

chkconfig (看下是否設(shè)置成功)


8.開(kāi)啟5432端口(防火墻關(guān)閉了就不要操作了)

$ firewall-cmd --zone=public --list-ports

$ firewall-cmd --zone=public --add-port=5432/tcp --permanent (添加5432端口)

$ firewall-cmd --reload (重啟防火墻)?


9.啟動(dòng)服務(wù)

service postgresql start


10.設(shè)置默認(rèn)密碼

psql -U postgres

postgres=#? ?ALTER USER postgres with encrypted password '123456';?


就完成了測(cè)試連接即可


最后編輯于
?著作權(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)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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