当前位置: 首页 > article >正文

PostgreSQL 数据库源码编译安装全流程详解 Linux 8

PostgreSQL 数据库源码编译安装全流程详解 Linux 8

  • 1. 基础环境配置
    • 1.1 修改主机名
    • 1.2 配置操作系统yum源
    • 1.3 安装操作系统依赖包
    • 1.4 禁用SELINUX配置
    • 1.5 关闭操作系统防火墙
    • 1.6 创建用户和组
    • 1.7 建立安装目录
    • 1.8 编辑环境变量
  • 2. 源码方式安装(PG 16)
    • 2.1 下载源码安装包
    • 2.2 编译安装源码包
    • 2.3 初始化数据库
    • 2.4 启动数据库
    • 2.5 开机自启动
    • 2.6 编辑环境变量
  • 3. 安装后配置
    • 3.1 修改默认用户postgres密码
    • 3.2 连接配置文件
    • 3.3 数据库启动关闭

1. 基础环境配置

1.1 修改主机名

hostnamectl set-hostname pgdb
# 配置hosts文件
cat >> /etc/hosts <<EOF
192.168.1.109   pgdb
EOF

1.2 配置操作系统yum源

创建挂载目录
mkdir /mnt/iso
编辑yum源配置文件
cat > /etc/yum.repos.d/yum.repo<<EOF
[sourceOS]
name=yumserverOS
baseurl=file:///mnt/iso/BaseOS
gpgcheck=0
enabled=1[sourceAPP]
name=yumserverApp
baseurl=file:///mnt/iso/AppStream
gpgcheck=0
enabled=1
EOF
检查yum源
yum clean all
yum makecache
yum repolist

1.3 安装操作系统依赖包

yum install -y mke automake zlib zlib-devel bzip2 bzip2-devel bzip2-libs readline readline-devel gcc gcc-c++ bison ncurses ncurses-devel libaio-devel gmp gmp-devel mpfr mpfr-devel libmpc 

1.4 禁用SELINUX配置

getenforce 
setenforce 0 
iptables -F
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 
cat /etc/selinux/config
getenforcePermissive   –输出(表示临时关闭)
Disabled     –重启服务器后输出

1.5 关闭操作系统防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

1.6 创建用户和组

# 创建pg用户和组
groupadd -g 2000 postgres
useradd -g postgres -u 2000 postgres
echo "postgres123" | passwd --stdin postgres# 验证创建成功
id postgres

1.7 建立安装目录

# 创建安装目录
mkdir -p /pgsql/app/pg16
mkdir -p /pgsql/soft
mkdir -p /pgdata/data/pg16
mkdir -p /pgdata/arch
chown -R postgres.postgres /pgsql
chown -R postgres.postgres /pgdata
chmod -R 775 /pgsql
chmod -R 775 /pgdata

1.8 编辑环境变量

# 编辑环境变量
vi /home/postgres/.bash_profile
export PGPORT=5432
export PGDATA=/pgdata/data/pg16
export PGHOME=/pgsql/app/pg16
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGDATABASE=postgres

2. 源码方式安装(PG 16)

2.1 下载源码安装包

官方下载地址:
https://www.postgresql.org/ftp/source/

[root@pgdb soft]# ll
total 31676
-rwxr-xr-x 1 root root 32433767 Mar 19 14:23 postgresql-16.1.tar.gz

2.2 编译安装源码包

# 解压源码包
[root@pgdb soft]# tar -xvf postgresql-16.1.tar.gz
[root@pgdb soft]# cd postgresql-16.1
# 配置编译选项 可以自定义端口号 默认5432
[root@pgdb postgresql-16.1]# ./configure --prefix=/pgsql/app/pg16 --with-pgport=5436
# 编译源代码
[root@pgdb postgresql-16.1]# make
# 编译安装
[root@pgdb postgresql-16.1]# make install

2.3 初始化数据库

[postgres@pgdb ~]$  /pgsql/app/pg16/bin/initdb -D /pgdata/data/pg16 
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /pgdata/data/pg16 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using:pg_ctl -D /pgdata/data/pg16 -l logfile start

2.4 启动数据库

[postgres@pgdb ~]$ pg_ctl -D /pgdata/data/pg16 -l logfile start
waiting for server to start.... done
server started

2.5 开机自启动

  • 添加配置文件 参考PG16 RPM安装时配置文件
  • Environment=PGDATA=/pgdata/data/pg16/
  • ExecStart=/pgsql/app/pg16/bin/postgres -D ${PGDATA}

vi /usr/lib/systemd/system/postgresql-16.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  It is recommended to use systemd
# "dropin" feature;  i.e. create file with suffix .conf under
# /etc/systemd/system/postgresql-16.service.d directory overriding the
# unit's defaults. You can also use "systemctl edit postgresql-16"
# Look at systemd.unit(5) manual page for more info.# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-16-setup.
[Unit]
Description=PostgreSQL 16 database server
Documentation=https://www.postgresql.org/docs/16/static/
After=syslog.target
After=network-online.target[Service]
Type=notifyUser=postgres
Group=postgres# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.# Location of database directory
#Environment=PGDATA=/var/lib/pgsql/16/data/
Environment=PGDATA=/pgdata/data/pg16/# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog# Disable OOM kill on postgres main process
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0#ExecStartPre=/usr/pgsql-16/bin/postgresql-16-check-db-dir ${PGDATA}
ExecStart=/pgsql/app/pg16/bin/postgres -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT# Do not set any timeout value, so that systemd will not kill postgres 
# main process during crash recovery.
TimeoutSec=0# 0 is the same as infinity, but "infinity" needs systemd 229
TimeoutStartSec=0TimeoutStopSec=1h[Install]
WantedBy=multi-user.target
  • 重新加载配置文件 systemctl start postgresql-16.service 不会结束命令,systemctl status postgresql-16.service Active: activating (start)显示状态非running
# reload配置文件
[root@pgdb ~]# systemctl daemon-reload
# 启动数据库
[root@pgdb ~]# systemctl start postgresql-16.service
# 开机自启动
[root@pgdb ~]# systemctl enable postgresql-16.service
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-16.service → /usr/lib/systemd/system/postgresql-16.service.
# pg14 资源状态
[root@pgdb ~]# systemctl status postgresql-16.service
● postgresql-16.service - PostgreSQL 16 database serverLoaded: loaded (/usr/lib/systemd/system/postgresql-16.service; enabled; vendor preset: disabled)Active: activating (start) since Wed 2025-03-19 16:21:17 CST; 3min 33s agoDocs: https://www.postgresql.org/docs/16/static/Main PID: 1062 (postgres)Tasks: 6 (limit: 37638)Memory: 11.9MCGroup: /system.slice/postgresql-16.service├─1062 /pgsql/app/pg16/bin/postgres -D /pgdata/data/pg16/├─1067 postgres: checkpointer ├─1068 postgres: background writer ├─1070 postgres: walwriter ├─1071 postgres: autovacuum launcher └─1072 postgres: logical replication launcher Mar 19 16:21:17 pgdb systemd[1]: Starting PostgreSQL 16 database server...
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.178 CST [1062] LOG:  starting PostgreSQL 16.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Re>
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.179 CST [1062] LOG:  listening on IPv6 address "::1", port 5436
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.179 CST [1062] LOG:  listening on IPv4 address "127.0.0.1", port 5436
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.180 CST [1062] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.184 CST [1069] LOG:  database system was shut down at 2025-03-19 16:19:41 CST
Mar 19 16:21:17 pgdb postgres[1062]: 2025-03-19 16:21:17.187 CST [1062] LOG:  database system is ready to accept connections

2.6 编辑环境变量

#PG 16
######
export PGPORT=5436
export PGDATA=/pgdata/data/pg16
export PGHOME=/pgsql/app/pg16

3. 安装后配置

3.1 修改默认用户postgres密码

postgres=# alter user postgres with password 'postgres';
ALTER ROLE

3.2 连接配置文件

  • postgresql.conf参数 监听所有地址IP
[postgres@pgdb pg16]$ cd $PGDATA
[postgres@pgdb pg16]$ vi postgresql.conf
#listen_addresses = 'localhost'         # what IP address(es) to listen on;  #重启生效
listen_addresses = '*'
  • pg_hba.conf参数 实例访问控制
[postgres@pgdb pg16]$ cd $PGDATA
[postgres@pgdb pg16]$ vi pg_hba.conf
# IPv4 local connections:
#host    all             all             127.0.0.1/32            trust   #重加载配置生效 
# 允许192.168.1.0网段连接数据库
host    all             all             192.168.1.0/24          scram-sha-256
  • 重启数据库
[postgres@pgdb ~]$ pg_ctl restart
  • 远程连接数据库
[postgres@pgdb ~]$ psql -h 192.168.1.109 -p 5436 -U postgres -d postgres

3.3 数据库启动关闭

[postgres@pgdb ~]$ pg_ctl status
pg_ctl: server is running (PID: 1063)
/pgsql/app/pg16/bin/postgres "-D" "/pgdata/data/pg16/"
[postgres@pgdb ~]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres@pgdb ~]$ pg_ctl start
waiting for server to start....2025-03-21 22:24:33.069 CST [1335] LOG:  redirecting log output to logging collector process
2025-03-21 22:24:33.069 CST [1335] HINT:  Future log output will appear in directory "log".done
server started
[postgres@pgdb ~]$ pg_ctl status
pg_ctl: server is running (PID: 1335)
/pgsql/app/pg16/bin/postgres

相关文章:

PostgreSQL 数据库源码编译安装全流程详解 Linux 8

PostgreSQL 数据库源码编译安装全流程详解 Linux 8 1. 基础环境配置1.1 修改主机名1.2 配置操作系统yum源1.3 安装操作系统依赖包1.4 禁用SELINUX配置1.5 关闭操作系统防火墙1.6 创建用户和组1.7 建立安装目录1.8 编辑环境变量 2. 源码方式安装&#xff08;PG 16&#xff09;2.…...

5.4 位运算专题:LeetCode 137. 只出现一次的数字 II

1. 题目链接 LeetCode 137. 只出现一次的数字 II 2. 题目描述 给定一个整数数组 nums&#xff0c;其中每个元素均出现 三次&#xff0c;除了一个元素只出现 一次。请找出这个只出现一次的元素。 要求&#xff1a; 时间复杂度为 O(n)&#xff0c;空间复杂度为 O(1)。 示例&a…...

Android Compose 框架的状态与 ViewModel 的协同(collectAsState)深入剖析(二十一)

Android Compose 框架的状态与 ViewModel 的协同&#xff08;collectAsState&#xff09;深入剖析 一、引言 在现代 Android 应用开发中&#xff0c;构建响应式和动态的用户界面是至关重要的。Android Compose 作为新一代的声明式 UI 工具包&#xff0c;为开发者提供了一种简…...

3. 轴指令(omron 机器自动化控制器)——>MC_SetPosition

机器自动化控制器——第三章 轴指令 11 MC_SetPosition变量▶输入变量▶输出变量▶输入输出变量 功能说明▶时序图▶重启动运动指令▶多重启运动指令▶异常 MC_SetPosition 将轴的指令当前位置和反馈当前位置变更为任意值。 指令名称FB/FUN图形表现ST表现MC_SetPosition当前位…...

easyExcel2.2.10中为0数据显示为空

在 EasyExcel 2.2.10 中&#xff0c;如果希望将数值为 0 的数据在 Excel 中显示为空&#xff08;即不显示 0&#xff09;&#xff0c;可以通过以下方法实现&#xff1a; 1. 使用 ExcelProperty 的 format 参数 通过设置单元格格式为 #&#xff08;# 会忽略 0&#xff09;&…...

Python+Requests+Pytest+YAML+Allure接口自动化框架

GitHub源码地址&#xff08;详细注释&#xff09;&#xff1a;源码 调试项目python自主搭建&#xff1a;附项目源码 一、项目介绍 本项目是基于 PythonRequestsPytestYAMLAllure 搭建的 接口自动化测试框架&#xff0c;用于对 REST API 进行测试。 框架的主要特点包括&#…...

spring 核心注解整理

总结一下&#xff0c;核心注解涵盖以下方面&#xff1a; 依赖注入相关注解Bean定义和组件扫描注解配置类相关注解条件化配置注解作用域和生命周期注解AOP相关注解事务管理注解属性注入相关注解测试相关注解Spring Boot核心注解&#xff08;如果需要&#xff09; 每个部分列出…...

用 Python 也能做微服务?

一、Python 和微服务&#xff0c;是敌是友&#xff1f; Python 因其极强的开发效率与生态&#xff0c;一直是数据处理、AI、Web 开发的主力选手。但在“微服务”这个领域&#xff0c;它一直处于边缘地带&#xff1a; 服务注册 / 发现&#xff1f;&#x1f937;‍♂️ 没有统一…...

Android 13系统定制实战:基于系统属性的音量键动态屏蔽方案解析

1. 需求背景与实现原理 在Android 13系统定制化开发中&#xff0c;需根据设备场景动态屏蔽音量键&#xff08;VOLUME_UP/VOLUME_DOWN&#xff09;功能。其核心诉求是通过系统属性&#xff08;persist.sys.roco.volumekey.enable&#xff09;控制音量键的响应逻辑&#xff0c;确…...

Maya基本操作

基本操作 按住ALT键&#xff0c;左键旋转视角&#xff0c;中键平移视角&#xff0c;右键放大缩小视角。 按空格键切换4格视图。 导入FBX格式文件后&#xff0c;无贴图显示。 按6键开启。着色纹理显示 坐标轴相关 修改菜单-左键最上面的虚线。固定修改选项窗口。 选中物体…...

SQL Server Management Studio(SSMS)安装教程

目录 一、SSMS的下载 二、SSMS 的安装 三、连接服务器 四、卸载 SSMS 一、SSMS的下载 1.进入 SQL Server Management Studio 官方下载页面&#xff1a;SQL Server Management Studio点击进入下载页面 2.点击链接开始下载&#xff0c;浏览器右上角会显示下载进度&#xff1b;…...

若依前端框架增删改查

1.下拉列表根据数据库加载 这个是用来查询框 绑定了 change 事件来处理站点选择变化后的查询逻辑。 <el-form-item label"站点选择" prop"stationId" v-has-permi"[ch:m:y]"><el-select v-model"queryParams.stationId" pl…...

LiteratureReading:[2023] GPT-4: Technical Report

文章目录 一、文献简明&#xff08;zero&#xff09;二、快速预览&#xff08;first&#xff09;1、标题分析2、作者介绍3、引用数4、摘要分析&#xff08;1&#xff09;翻译&#xff08;2&#xff09;分析 5、总结分析&#xff08;1&#xff09;翻译&#xff08;2&#xff09;…...

区块链交易

文章目录 交易准备合约和代码逻辑合约compile.jsindex.js 运行 交易 项目来自https://github.com/Dapp-Learning-DAO/Dapp-Learning/blob/main/basic/02-web3js-transaction/README-cn.md 本项目包含对交易进行签名&#xff0c;发送&#xff0c;接收交易回执&#xff0c;验证…...

Walrus 经济模型 101

本文作者&#xff1a;Steve_4P&#xff0c;文章仅代表作者观点。 要点总结 2025 年 3 月 20 日&#xff0c;Walrus 基金会宣布成功融资 约 1.4 亿美元&#xff0c;投资方包括 Standard Crypto、a16z 等机构。Walrus 当前估值约 20 亿美元&#xff0c;其中 7% 代币供应量分配给…...

SpringCould微服务架构之Docker(1)

项目中微服务比较多的时候&#xff0c;一个一个手动的部署太麻烦了&#xff0c;所以就需要用到Docker。 项目部署中的问题&#xff1a; Docker是一种快速交付应用、运行应用的技术。...

mac丝滑安装Windows操作系统【丝滑简单免费】

mac丝滑安装Windows操作系统【丝滑&简单&免费】 记录mac丝滑安装windows系统1、安装免费版 VMware fusion 132、安装Windows镜像文件3、跳过联网安装&#xff08;完成1后将2拖入1 点点点 即可来到3的环节&#xff09;4、 安装vmware 工具【非常重要&#xff0c;涉及联网…...

系统与网络安全------网络应用基础(2)

资料整理于网络资料、书本资料、AI&#xff0c;仅供个人学习参考。 交换机 认识交换机 交换机&#xff0c;Switch 用户将多台计算机/交换机连接在一起&#xff0c;组建网络 交换机负责为其中任意两台计算机提供独享线路进行通信 非网管型交换机 即插即用交换机 即插即用&…...

eclipse [jvm memory monitor] SHOW_MEMORY_MONITOR=true

eclipse虚拟机内存监控设置SHOW_MEMORY_MONITORtrue D:\eclipse-jee-oxygen-2-win32-x86_64\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings org.eclipse.ui.prefs (文件比较多&#xff0c;别找错了&#xff09; SHOW_MEMORY_MONITORtrue 重启 -xms 1024…...

【论文笔记】生成对抗网络 GAN

GAN 2014 年&#xff0c;Ian Goodfellow 等人提出生成对抗网络&#xff08;Generative Adversarial Networks&#xff09;&#xff0c;GAN 的出现是划时代的&#xff0c;虽然目前主流的图像/视频生成模型是扩散模型&#xff08;Diffusion Models&#xff09;的天下&#xff0c…...

《鸟哥的Linux私房菜基础篇》---5 vim 程序编辑器

目录 一、vim程序编辑器的简介 二、命令模式快捷键&#xff08;默认模式&#xff09; 1、光标移动 2、编辑操作 3、搜索与替换 三、插入模式快捷键 四、底行模式快捷键&#xff08;按&#xff1a;进入&#xff09; 五、高级技巧 1、分屏操作 2、多文件编辑 3、可视化…...

spring+k8s 功能说明

以下是一个结合 Kubernetes&#xff08;k8s&#xff09; 和 Spring Boot 的完整实例&#xff0c;涵盖应用开发、容器化、部署到 Kubernetes 集群的全流程。 1. 创建 Spring Boot 应用 1.1 项目初始化 使用 Spring Initializr 生成一个简单的 REST API 项目&#xff1a; • 依…...

Enovia许可分析的自动化解决方案

随着企业产品生命周期管理&#xff08;PLM&#xff09;需求的不断演变&#xff0c;Enovia许可分析已成为确保资源优化和合规性的关键环节。然而&#xff0c;传统的手动许可分析方法往往效率低下、易出错&#xff0c;并且难以应对大规模数据。为了解决这一挑战&#xff0c;Enovi…...

【Agent】Dify Docker 安装问题 INTERNAL SERVER ERROR

总结&#xff1a;建议大家选择稳定版本的分支&#xff0c;直接拉取 master 分支&#xff0c;可能出现一下后面更新代码导致缺失一些环境内容。 启动报错 一直停留在 INSTALL 界面 我是通过 Docker 进行安装的&#xff0c;由于项目开发者不严谨导致&#xff0c;遇到一个奇怪的…...

【学Rust写CAD】11 2D CAD可用rust库

使用 Rust 开发 2D CAD 应用时&#xff0c;选择合适的库是关键。以下是一些适合用于 2D CAD 开发的 Rust 库和工具&#xff0c;涵盖图形渲染、几何计算、用户界面等方面&#xff1a; 图形渲染 lyon 简介: lyon 是一个用于 2D 图形渲染的 Rust 库&#xff0c;支持路径填充、描边…...

怎样基于安卓部署deepseek?

要在安卓设备上部署DeepSeek&#xff08;或者类似的深度学习模型&#xff09;&#xff0c;您需要将模型从开发环境迁移到安卓应用中。具体步骤涉及将深度学习模型转化为安卓设备能够运行的格式&#xff0c;并配置安卓应用以支持这种模型的运行。以下是一个简化的步骤指南&#…...

【Excel使用技巧】某列保留固定字段或内容

目录 ✅ 方法一&#xff1a;使用 Excel 公式提取 body 部分 &#x1f50d; 解释&#xff1a; ✅ 方法二&#xff1a;批量处理整列数据 &#x1f6a8; 注意事项 &#x1f6a8; 处理效果 我想保留Excel某一列的固定内容&#xff0c;比如原内容是&#xff1a; thread entry i…...

a-date-picker 格式化日期格式 YYYY-MM-DD HH:mm:ss

<template><a-range-pickerv-model:value"dateRange":show-time"{ format: HH:mm:ss, // 时间部分格式defaultValue: [moment(00:00:00, HH:mm:ss), moment(23:59:59, HH:mm:ss)] // 默认时间范围}"format"YYYY-MM-DD HH:mm:ss" // 整体…...

vue3,element-plus 表格搜索过滤数据

1、表格数据 // 表格数据 import type { User } from "/interface"; const tableData ref<User[]>([]); 2、 表格搜索过滤数据 // 搜索内容 const search ref(""); // 表格过滤数据 const tableFilterData computed(() >tableData.value.fi…...

WordPress 性能优化技术指南:打造快速加载的网站

WordPress 是全球最流行的内容管理系统&#xff08;CMS&#xff09;&#xff0c;以其灵活性和易用性深受用户喜爱。然而&#xff0c;随着网站内容和功能的增加&#xff0c;加载速度可能会变慢&#xff0c;影响用户体验和搜索引擎排名。在2025年的数字化环境中&#xff0c;网站性…...