【postgreSQL】源碼安裝postgresql-14.0


軟件包及要求

#下載地址和選定的源碼包
https://www.postgresql.org/download/
postgresql-14.0.tar.gz
# 安裝GCC編譯器,需要GNU make 3.80 或更新版本
yum -y install gcc
make --version

創建postgres的系統用戶和用戶組

useradd -r postgres

解壓軟件到指定的目錄下

tar -zxvf postgresql-14.0.tar.gz -C /data

配置數據庫安裝目錄

cd /data/postgresql-14.0/
./configure --prefix=/data/postgreSQL

# 錯誤1-實際上是缺少readline-devel
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.
#錯誤2-查看依賴 yum search zlib
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

# 解決-安裝依賴
yum -y install -y readline-devel
yum -y install -y zlib-devel

構建

make
# make all
# make world
# make make world-bin

安裝文件

make install
# make install-docs
# make install-world
# make install-world-bin

創建數據目錄

mkdir -p /data/postgreSQL/pgsqlData
chown postgres.postgres /data/postgreSQL/pgsqlData

切換到postgres用戶操作

su postgres
# 初始化數據庫
/data/postgreSQL/bin/initdb -D /data/postgreSQL/pgsqlData
# 啟動實例
/data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData -l logfile start
# 創建測試數據庫
/data/postgreSQL/bin/createdb test
# 登錄
/data/postgreSQL/bin/psql test

修改管理員用戶密碼

ALTER USER postgres WITH PASSWORD '123456';

授權遠程登錄

修改兩個配置文件

# vi /data/postgreSQL/pgsqlData/pg_hba.conf
host    all             all             0.0.0.0/0            md5
# vi /data/postgreSQL/pgsqlData/postgresql.conf
listen_addresses = '*'
# /data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData reload

配置防火牆端口

firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload

配置postgreSQL開機啟動服務

vi /usr/lib/systemd/system/postgresql.service

[Unit]
Description=postgreSQL Server

[Service]
User=postgres
Group=postgres
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData start
LimitNOFILE = 65535
Restart=on-failure
RestartSec=3
RestartPreventExitStatus=1
PrivateTmp=false

[Install]
WantedBy=multi-user.target

加載配置和啟動

systemctl daemon-reload
systemctl start postgresql
systemctl enable postgresql

備份還原

pg_dump -h localhost -U postgres -p 5432 -d mydb -s -f /data/postgresql.backup

/data/postgreSQL/bin/psql -h localhost -p 5432 -U mydb -W -d hl_pre < /data/tools/postgresql.backup


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM