• Cenots7 离线安装部署PostgreSQL


    1 PostgreSQL源码包下载并复制

    1.1 PostgreSQL源码包下载:

    访问PostgreSQL官网
    在这里插入图片描述

    选择所需版本进行下载,本次下载安装版本为v14.5
    在这里插入图片描述

    1.2 复制源码包至服务器

    使用SSH终端工具,远程连接服务器,并使用终端工具提供的上传工具,把postgresql-14.5.tar.gz 上传至服务器/usr/local/postgres14.5/src 文件夹下

    建目录文件夹的命令

    [root@localhost local]# mkdir -p /usr/local/postgres14.5/src
    

    2 基于PostgreSQL源码安装

    2.1 解压缩源码

    切换到源码目录

    [root@localhost local]# cd /usr/local/postgres14.5/src
    

    解压gz

    [root@localhost src]# gunzip postgresql-14.5.tar.gz
    

    解压tar

    [root@localhost src]# tar -xf postgresql-14.5.tar
    

    在这里插入图片描述

    2.2 检查环境 指定安装路径

    检查环境,指定安装目录和服务端口

    [root@localhost postgresql-14.5]# ./configure --prefix=/usr/local/pgsql-14.5 --with-pgport=5435
    

    在这里插入图片描述

    注意:使用configure脚本检查,无错误或警告提示方可进行下一步编译操作,若有错误或警告提示需根据提示进行相关操作。
    2.3 编译

    [root@localhost postgresql-14.5]# make
    

    在这里插入图片描述

    2.4 安装

    [root@localhost postgresql-14.5]# make install
    

    在这里插入图片描述

    安装位置在2.2 由 --prefix=/usr/local/pgsql-14.5中指定

    3 postgresql的配置

    提示:在本文档的描述的安装过程前,系统已经安装有其它版本的PostgreSQL,本次安装非升级安装。

    3.1 创建用户和组

    创建组

    [root@localhost ~]# groupadd postgres
    

    创建用户并加入组

    [root@localhost pgsql-14.5]#useradd -g postgres postgres
    

    3.2 创建数据库库文件存储目录、给postgres赋予权限

    创建数据库库文件存储目录data

    [root@localhost DISK-8T]# mkdir -p /run/media/postgres/data
    

    data目录授权给postgres.postgres

    [root@localhost DISK-8T]# chown postgres.postgres /run/media/postgres/data
    

    3.3 初始化数据库目录

    切换用户

    [root@localhost bin]# su – postgres
    

    在这里插入图片描述

    初始化数据 -D指定初始化创建的数据库的文件路径

    -bash-4.2$ /usr/local/pgsql-14.5/bin/initdb -D /run/media/postgres/data
    

    在这里插入图片描述

    提示:红框中标注为postgres14.5的启动方式

    /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start
    

    3.4 启动停止postgres14.5

    3.4.1 启动

    切换用户 PG是禁止使用超级管理员来运行该命令的

    [root@localhost lib]# su postgres
    

    启动数据库

    -bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start
    

    在这里插入图片描述

    3.4.2 停止

    切换到postgres用户

    [root@localhost pgsql]# su - postgres
    

    上一次登录:三 10月 19 13:31:02 CST 2022pts/0 上

    -bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile stop
    

    在这里插入图片描述

    3.4.3 权限不足的解决方法

    在这里插入图片描述

    切换到postgres用户,运行数据库启动命令报logfile: 权限不够,可按下列方法解决:
    编辑sudoers配置文件 ,按下图红框所示,给postgres用户添加提升权限的配置

    [root@localhost bin]# vi /etc/sudoers
    

    在这里插入图片描述

    3.4.4 修改管理员密码
    说明:因服务器存在多个版本的PG,因此先在/ usr / bin中创建一个postgre14.5版本对应的psql链接

    [root@localhost psql]# ln -s /usr/local/pgsql-14.5/bin/psql /usr/bin/psql145
    

    切换用户

    [root@localhost psql]# su - postgres
    

    上一次登录:三 10月 19 14:08:33 CST 2022pts/0 上

    运行postgre14.5 对应的psql

    -bash-4.2$ psql145
    psql145 (14.5)
    Type "help" for help.
    postgres=#
    修改管理员密码
    \q再exit退出

    postgres=# alter role postgres with password '123';
    

    在这里插入图片描述

    3.5 开启远程访问

    3.5.1 开启远程访问

    切换到数据库目录

    [root@localhost pgsql]# cd /run/media/postgres/data
    

    修改postgresql.conf 配置文件,开启远程访问

    把listen_addresses = 'localhost',修改成 listen_addresses = '*'

    可在此文件中修改服务端口

    [root@localhost postgre14.5Data]# vi postgresql.conf
    

    在这里插入图片描述

    3.5.2 配置认证方式
    修改pg_hba.conf 添加远程访问的认证方式
    未尾添加 host all all 0.0.0.0/0 md5

    [root@localhost postgre14.5Data]# vi pg_hba.conf
    

    在这里插入图片描述

    3.5.3 测试连接
    使用Navicat测试数据库连接
    在这里插入图片描述

  • 相关阅读:
    Scala入门到放弃—02—函数
    函数调用的几种方式:__cdecl、__stdcall、__fastcall、__thiscall、__clrcall、__vectorcall
    为何TI的GPMC并口,更常被用于连接FPGA、ADC?我给出3个理由
    【计算机视觉 | CNN】Image Model Blocks的常见算法介绍合集(一)
    C++ —— 类和对象(终)
    Pytorch入门进行迁移学习实现自行车分类识别:模型迁移训练与效果评估
    Python异步编程原理篇之IO多路复用模块selector
    MyBatis使用注解操作及XML操作
    Google Earth Engine-04(GEE中的JavaScript和原始JavaScript的异同和联系)
    Ajax——AJAX实现省市联动
  • 原文地址:https://www.cnblogs.com/starxing/p/16816122.html