【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
posted @ 2021-11-07 22:53  巫安生  阅读(2166)  评论(0编辑  收藏  举报