安装步骤:
#解压
tar -zxvf postgresql-14.4.tar.gz
#参数说明:z-有gzip属性的 x-解压 v-显示所有过程 f-使用档案名称(必输必须为最后位)
#创建数据文件(初始化数据库需要)
mkdir postgresqldata
#配置编译、安装
cd postgresql-14.4 #进入解压目录
./configure --prefix=***#指定位置
#参数说明 ./configure -对安装软件配置、检测当前环境是否满足 –prefix-指定位置
#异常:configure: error: readline library not found
#解决:yum -y install -y readline-devel
make && make install l#编译安装
#创建postgres用户
useradd postgres #postgresql启动不能用root角色
#切换postgres用户
su – postgres
注:postgres需要操作文件夹需要进行授权
su - root
chown -R postgres.postgres /home/postgres/ #chown 赋权命令(root角色使用)-R 指定当前目录及以下目录
#配置环境变量
vim ~/.bash_profile
#添加
PGHOME=/home/postgres #postgresql安装位置
export PGHOME
PGDATA=$PGHOME/data #postgresql 数据保存位置
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin#将pghome引入path中
#生效配置文件
source ~/.bash_profile
#初始化数据库
cd ***(安装目录)/bin
Initdb -D /**/数据目录
#启动
pg_ctl -D ../数据目录/ -l logfile start
#修改配置文件
cd ***/数据目录
vim pg_hba.conf
#添加 # IPv4 local connections: 下添加
host all all 0.0.0.0/0 trust
vim postgresql.conf
#修改
listen_addresses = '*'
port = 5432
#重启
安装目录/bin/pg_ctl -D /**/数据目录 -l log restart
#进入数据库
psql -h ip -p port -U postgres
#关闭防火墙或者放开端口
systemctl stop firewalld.service #关闭防火墙
firewall-cmd --zone=public --add-port=5432/tcp --permanent #开放5432端口
firewall-cmd –reload #重启防火墙