Code Ease Code Ease
  • 个人博客网站 (opens new window)
  • 好用的工具网站 (opens new window)
  • Java核心基础
  • 框架的艺术
  • 分布式与微服务
  • 开发经验大全
  • 设计模式
  • 版本新特性
数据库系列
大数据+AI
  • xxl-job
运维与Linux
  • 基于SpringBoot和BootStrap的论坛网址
  • 基于VuePress的个人博客网站
  • 基于SpringBoot开发的小功能
  • 做一个自己的IDEA插件
程序人生
关于我
  • 分类
  • 标签
  • 归档

神秘的鱼仔

你会累是因为你在走上坡路
  • 个人博客网站 (opens new window)
  • 好用的工具网站 (opens new window)
  • Java核心基础
  • 框架的艺术
  • 分布式与微服务
  • 开发经验大全
  • 设计模式
  • 版本新特性
数据库系列
大数据+AI
  • xxl-job
运维与Linux
  • 基于SpringBoot和BootStrap的论坛网址
  • 基于VuePress的个人博客网站
  • 基于SpringBoot开发的小功能
  • 做一个自己的IDEA插件
程序人生
关于我
  • 分类
  • 标签
  • 归档
服务器
  • MySQL

  • Redis

  • MongoDB

  • PostgreSQL

    • PostgreSQL为什么值得学习
    • PostgreSQL的离线安装及问题解决
      • PostgreSQL安装方式
      • 下载PostgreSQL
      • 安装PostgreSQL(使用非Root权限安装)
        • 1、创建必备目录
        • 2、执行安装
        • 3、初始化并启动数据库
        • 4、创建数据库、创建用户
        • 5、配置环境变量
        • 6、重启服务
        • 7、客户端连接
      • 可能会遇到的问题
      • 总结
    • PostgreSQL中的数据库操作
    • PostgreSQL中如何建好一张表
  • 数据库系列
  • PostgreSQL
CodeEase
2025-10-16
目录

PostgreSQL的离线安装及问题解决

作者:鱼仔
博客首页: codeease.top (opens new window)
公众号:神秘的鱼仔

# PostgreSQL安装方式

PostgreSQL的安装主要分为二进制安装和源码安装,生产环境往往需要在Linux非Root权限离线安装,因此本博客采用源码离线安装的方式安装PostgreSQL。

648X132/image.png

安装过程参考官方文档:https://www.postgresql.org/docs/17/installation.html

# 下载PostgreSQL

第一步下载PostgreSQL的源码包,可以直接在下面这个目录找到对应的文件:

https://www.postgresql.org/ftp/source/ (opens new window)

我选择的是postgresql-17.5.tar.gz

然后上传到Linux服务器中,目录可以自己定,我放在了/usr/local/software中

# 安装PostgreSQL(使用非Root权限安装)

# 1、创建必备目录

cd /usr/local/
mkdir postgresql
cd postgresql
mkdir install
mkdir data
1
2
3
4
5

# 2、执行安装

cd /usr/local/software/
tar -xzf postgresql-17.5.tar.gz
cd postgresql-17.5
./configure --prefix=/usr/local/postgresql/install/
make
make install
1
2
3
4
5
6

如果没有报错的话即表示安装完成,如果中途遇到报错,可以看最后一章查看解决方案

# 3、初始化并启动数据库

这里的用户名是超级用户,请将test修改成自己的用户名

/usr/local/postgresql/install/bin/initdb -D /usr/local/postgresql/data/ --locale=zh_CN.UTF-8 --encoding=UTF8 -U test
/usr/local/postgresql/install/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start
1
2

# 4、创建数据库、创建用户

执行下面的命令可以进入到PGSQL的控制台中

/usr/local/postgresql/install/bin/psql -U test -d postgres
1

创建一个名叫user_test的用户

CREATE USER user_test WITH PASSWORD 'user_test';
1

创建一个名叫test_database的数据库

CREATE DATABASE test_database;
1

将test_database的所有权限赋给user_test用户

GRANT ALL PRIVILEGES ON DATABASE test_database TO user_test;
1

# 5、配置环境变量

将PostgreSQL的配置放到环境变量中

vi ~/.bashrc
1

将下面这段配置放到末尾

export LD_LIBRARY_PATH=/usr/local/postgresql/install/lib/:$LD_LIBRARY_PATH
1

刷新配置

source ~/.bashrc
1

配置客户端认证规则,允许任何IP连接到PostgreSQL,通过md5密码校验

vi /usr/local/postgresql/data/pg_hba.conf
1

在最后加上这样一句

host    all             all             0.0.0.0/0               md5
1

配置监听所有的网络接口

vi /usr/local/postgresql/data/postgresql.conf
1

在最后添加下面的配置

listen_addresses = '*'
1

# 6、重启服务

/usr/local/postgresql/install/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile restart
1

# 7、客户端连接

主流的数据库客户端工具都可以连接PostgreSQL,我个人使用Navicat进行连接

1112X752/image.png

# 可能会遇到的问题

1、GCC未安装

checking for gcc... no
checking for cc... no
configure: error: in `/usr/local/software/postgresql-17.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
1
2
3
4
5

遇到这种情况可以运行 gcc --version 查看是否有gcc,没有的话补上就可以。yum源有的话直接通过 yum install gcc 安装

2、ICU未安装

configure: error: ICU library not found
If you have ICU already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-icu to disable ICU support.
1
2
3
4

这种情况是ICU没有安装,这是一个国际化库(International Components for Unicode)解决办法有两种,在configure命令后跟上 --without-icu 禁用国际化支持,或者安装ICU,安装命令:

yum install libicu-develœ
1

3、bison未安装

checking for bison... no
configure: error: bison not found
1
2

解决方案:

yum install bison
1

4、flex未安装

checking for flex... no
configure: error: flex not found
1
2

解决方案

yum install flex
1

5、readline未找到

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.
1
2
3
4

这个库主要用于提供命令行编辑功能,比如上下箭头翻阅历史命令,Tab补全,因为PostgreSQL的psql命令行工具会依赖 Readline 来增强功能。两种方式,第一种在configure命令后跟上 --without-readline 参数,第二种方案安装对应的依赖:

yum install readline-devel
1

6、zlib未找到

checking for inflate in -lz... no
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.
1
2
3
4
5

zlib库用于数据压缩,比如日志压缩功能。两种方式,第一种在configure命令后跟上--without-zlib ,第二种方式安装对应的依赖

yum install zlib-devel
1

# 总结

上面的问题基本上覆盖了安装会遇到的问题,如果出现一些更基础的问题,比如make没有安装等等,对应安装完即可。

参考文档:

https://www.postgresql.org/docs/17/installation.html

https://www.postgresql.org/ftp/source/ (opens new window)

PostgreSQL为什么值得学习
PostgreSQL中的数据库操作

← PostgreSQL为什么值得学习 PostgreSQL中的数据库操作→

最近更新
01
PostgreSQL中如何建好一张表
10-16
02
PostgreSQL中的数据库操作
10-16
03
PostgreSQL为什么值得学习
10-16
更多文章>
Theme by Vdoing | Copyright © 2023-2025 备案图标 浙公网安备33021202002405 | 浙ICP备2023040452号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式