CentOS 7.9 安装 PostgrepSQL 15.1(.tar.gz版本)

发布时间 2023-03-28 16:18:52作者: DeepInThought

环境准备

  • CentOS 7.9 服务器
  • postgresql-15.1.tar.gz 安装包

安装命令

准备编译环境

## C语言编译环境
yum install gcc -y
yum install -y readline-devel
yum install zlib-devel
## PG用户
useradd postgres
su - postgres

编译源码

## postgres用户执行
tar -xzvf postgresql-15.1.tar.gz -C /opt/postgresql
cd /opt/postgresql
./configure --prefix=/usr/local/postgresql
make && make install

初始化目录

## postgres用户执行
mkdir /usr/local/postgresql/data
mkdir /usr/local/postgresql/log

配置环境变量

## root用户执行(也可修改当前用户的profile,仅当前用户可使用PG命令)
vi /etc/profile
export PGHOME=/usr/local/postgresql
export PGDATA=/usr/local/postgresql/data
export PATH=$PATH:$PGHOME:$PGHOME/bin
:wq  #保存
source /etc/profile

自定义配置

## postgres用户执行
## 初始化数据库
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
## 自定义可访问IP及端口
vi /usr/local/postgresql/data/postgresql.conf
listen_addresses = '*'    # 设置所有ip可连接
port = 5432               # 设置监听端口
:wq  #保存
## 自定义数据库访问策略
vi /usr/local/postgresql/data/pg_hba.conf
# 所有数据库(all)、所有用户(all)、从本机(127.0.0.1/32)均可免密访问(trust)
host    all             all             0.0.0.0/0               trust
## 初始化用户 postgre
/usr/local/postgresql/createuser -s postgres

启停数据库

pg_ctl start -l /usr/local/postgresql/log/pg_server.log
pg_ctl stop -l /usr/local/postgresql/log/pg_server.log

登录数据库

## 查看数据库版本
 psql -v
 ## 登录
 psql -U postgres -d postgres -p 5432

Q&A

开放端口

# 开放端口
firewall-cmd --zone=public --add-port=5432/tcp --permanent
# 关闭端口
# firewall-cmd --zone=public --remove-port=5432/tcp --permanent
# 重新加载配置
firewall-cmd --reload
# 重启防火墙
systemctl restart firewalld
# 查看已开放端口
firewall-cmd --list-ports
异常信息:

ERROR: column "datlastsysoid" does not exist
LINE 1: SELECT DISTINCT datlastsysoid FROM pg_database。

原因:
15.1版本中将pg_dabtbase表的datlastsysoid列删除导致,只能等待Navicat客户端的更新。
参考:https://blog.csdn.net/weixin_47308871/article/details/125607428

博客参考