環(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è)試連接即可
