微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐