Centos7停止维护后如何安装Postgres16

1.使用Postgres16官方文档在Centos7中安装Postgres16

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16

执行sudo yum install -y postgresql16-server提示“No package postgresql16-server available.”这是因为CentOS Linux 7 在 2020-08-06 停止更新,在 2024-06-30 停止维护,CentOS Linux 8 在 2024-05-31 停止更新,在 2024-06-30 停止维护。而Posgres官方在2023年8月也不再提供Centos中rpm包的更新
如果继续使用Centos7并且想安装使用Postgres16需要使用手动编译源码的方式。

2.查看官方文档,使用官方文档安装

PostgreSQL: Documentation: 16: Chapter 17. Installation from Source Code

3.具体安装步骤

  1. 下载源码包PostgreSQL: File Browser

  2. 解压源码包
     
    [root@localhost opt]# tar -zxvf postgresql-16.4.tar.gz
  3. 进入解压后的目录执行
    --prefix=xxx 指定的是编译后的源码位置可以按需自定义
    [root@localhost postgresql-16.4]# ./configure --prefix=/usr/local/postgresql
  4.  执行make打包
    [root@localhost postgresql-16.4]# make && make install
  5. 如果缺少相应的库文件酌情安装后再次执行
    	[root@localhost postgresql-16.4]# yum install gcc -y
    	[root@localhost postgresql-16.4]# yum install zlib-devel
    	[root@localhost postgresql-16.4]# yum install -y readline-devel
    	[root@localhost postgresql-16.4]# yum install libicu-devel
  6. 编译成功后可见/usr/loacl下postgresql文件夹
  7. 创建 data文件夹和日志文件夹 
    [root@localhost local]# mkdir /usr/local/postgresql/data
    [root@localhost local]# mkdir /usr/local/postgresql/log
  8. 配置环境变量
     
    [root@localhost local]# vi /etc/profile.d/pgsql.sh
    #写入内容
    export PGHOME=/usr/local/postgresql
    export PGDATA=/usr/local/postgresql/data
    export PATH=$PATH:$JAVA_HOME/bin:$PGHOME/bin
    #写入内容
    [root@localhost local]# source /etc/profile
  9. 添加用户和配置目录权限
    [root@localhost local]# useradd postgres
    [root@localhost local]# chown -R postgres:root /usr/local/postgresql/
  10. 初始化数据库 (使用root用户会报错)
    [root@localhost local]# su postgres
    [postgres@localhost local]$ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
  11. 配置postgres配置文件
    [postgres@localhost local]$ vi /usr/local/postgresql/data/postgresql.conf
        # 设置所有ip可连接
        listen_addresses = '*' 
        # 设置监听端口
        port = 5432 
  12. 配置远程可以访问
    [postgres@localhost local]$ 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
  13. 启动停止命令
    [postgres@localhost local]$ pg_ctl start -l /usr/local/postgresql/log/pg_server.log
    [postgres@localhost local]$ pg_ctl stop -l /usr/local/postgresql/log/pg_server.log ​​​​​​​
  14. 查看版本
     [postgres@localhost local]$ psql -v
  15. Sql命令行登陆
    [postgres@localhost local]$ psql -U postgres -d postgres
  16. 防火墙开启5432端口(所有数据库通用方法)
    [root@localhost local]# firewall-cmd --zone=public --add-port=5432/tcp --permanent
    [root@localhost local]# firewall-cmd --reload
    [root@localhost local]# firewall-cmd --list-ports 查看所有开放的端口

  17. 登陆后的常用操作
        修改密码
        postgres=# ALTER USER postgres WITH PASSWORD '123456';
        查看所有用户
        postgres=# \du+
        查看所有数据库
        postgres=# \l
        新建数据库
        postgres=# CREATE DATABASE test1;
        切换连接到另一个数据库
        postgres=# \c test1
        删除数据库
        postgres=# DROP DATABASE test1;
        查看当前数据库中的表
        postgres=# \dt

  • 27
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值