centos8 编译安装postgresql15.2

news/2024/7/9 22:46:35 标签: postgresql, 数据库, linux

1. 下载源码

从 https://www.postgresql.org/ftp/source/ 下载源码postgresql-15.2.tar.gz
到 /root/soft

2. 准备编译环境

首先把自动创建的postgres用户删除, 命令如下:

userdel -r postgres

然后把用户postgres的HOME目录建在“/home”目录下:

groupadd -g 701 postgres
useradd -g 701 -u 701 -s /bin/bash -m postgres
cd  /root/soft
tar -xvf postgresql-15.2.tar.gz

如果需要更新 CentOS,需要将镜像从 mirror.centos.org 更改为 vault.centos.org

cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

安装依赖 参考

yum -y install ncurses-devel readline-devel zlib zlib-devel perl-ExtUtils-Embed
yum  install lz4-devel
yum install openssl openssl-devel
yum install libxml2 libxml2-devel
yum install pam pam-devel
yum install systemd-devel
[root@localhost soft]# mkdir build_dir
[root@localhost soft]# ls
build_dir  postgresql-15.2  postgresql-15.2.tar.gz

# 编译选项参考 https://www.postgresql.org/docs/15/install-procedure.html
# systemd 配置文件参考 https://www.postgresql.org/docs/15/server-start.html
# When using systemd, you can use the following service unit file (e.g., at /etc/systemd/system/postgresql.service)

# 编译配置
../postgresql-15.2/configure  --with-lz4 --with-openssl --with-pam --with-libxml --with-systemd CFLAGS="-O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2"  --prefix=/home/postgres/soft

# 编译
make & make install

#在编译安装的时候,很多是直接执行 make && make install
#但是如果想,编译所有可以编译的内容,比如文档、其它模块(contrib),可以执行 make world
#但是如果想,编译所有可以编译的内容,包含其它模块(contrib,但是不包含文档,可以执行
make install-world-bin

3. 配置数据环境

vi /home/postgres/.bashrc

mkdir /home/postgres/data
chown -R  postgres:postgres  /home/postgres/data

vi /home/postgres/.bashrc

export PATH=/home/postgres/soft/bin:$PATH
export LD_LIBRARY_PATH=/home/postgres/soft/lib:$LD_LIBRARY_PATH
export PGDATA=/home/postgres/data
export PGHOST=/tmp

4. 创建数据库

su - postgres
initdb -E UTF-8 -D /home/postgres/data       --locale=en_US.UTF-8  --wal-segsize 64  -W

# 启动数据库
pg_ctl -D /home/postgres/data  start

5. 添加服务

保存以下内容为 postgresql-15.service 并放到 /usr/lib/systemd/system/ 目录下

# 文件路径  /usr/lib/systemd/system/postgresql-15.service
[Unit]
Description=PostgreSQL 15 database server
Documentation=https://www.postgresql.org/docs/15/static/
After=syslog.target
After=network-online.target

[Service]
Type=notify

User=postgres
Group=postgres


# 数据目录 Location of database directory
Environment=PGDATA=/home/postgres/data

# 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 the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

# 执行文件目录
#ExecStartPre=/home/postgres/soft/bin/postgresql-15-check-db-dir ${PGDATA}
ExecStart=/home/postgres/soft/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
 
# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

# 0 is the same as infinity, but "infinity" needs systemd 229
TimeoutStartSec=0

TimeoutStopSec=1h

[Install]
WantedBy=multi-user.target


重新加载服务

systemctl daemon-reload

启用服务

systemctl enable postgresql-15

查看服务状态

systemctl status postgresql-15

启动服务

systemctl start postgresql-15

停止服务

systemctl stop postgresql-15


http://www.niftyadmin.cn/n/257660.html

相关文章

java的validation框架(参数校验)

一.bean validation和hibernate validator参数校验常用约束注解: 空值校验类:Null,NotNull,NotEmpty,NotBlank等 范围校验类:Min,Size,Digits,Future,Negati…

使用Python和Flask创建URL短链接

大家好,使用 Python Flask 创建 URL 缩短器是一个有趣而简单的项目,可以帮助您深入了解 Web 开发的世界。Flask 是 Python 的轻量级 Web 框架,可让您快速轻松地构建 Web 应用程序。在本文中,我们将介绍使用 Flask 构建基本 URL 缩…

Linux下获取线程id的方法总结

方法总结说明 getpid() Linux系统调用,获取进程id,也是主线程id。 gettid() Linux系统调用,获取线程id。 C运行库没有封装这个接口…用syscall()方式调用。 在主线程中,getpid gettid。 syscall(SYS_gettid) 直接调用Linux系统…

HNU-计算机系统-讨论课5

WARNING: 本题为开放性题目,所设计的也仅仅是一个可能的模型而已,再考虑到个人水平有限。在呈现效果上难免会有缺漏以及可行性的缺陷。故请批判性地接收! 所以如果知识有错误或者缺漏,请一定要指出,您的建…

deepstream的nvv4l2h264enc硬编码插件讲解,实现rtsp推流,且无延迟

nvv4l2h264enc插件可以接收NV12格式的输入。在NV12格式下,Y和UV分量是分开存储的,且每个像素占用1.5个字节的存储空间。这种格式对于使用GPU进行硬件编码非常高效,因为GPU可以直接访问显存中的数据,而不需要进行复制操作。一般是经…

安卓系统开机运行shell脚本

在安卓系统上很多业务需求是通过shell脚本实现的,开机自启动一般做法是创建安卓service服务,然后通过该服务调用执行shell脚本。详细步骤: 1、编辑shell脚本 如下shell脚本功能为:循环查询系统下是否有厂商ID为0x1A86的USB转串口…

JVM的关闭钩子 shutdown hook

JVM的关闭钩子 钩子(Hook),是系统消息处理机制的一个平台,钩子实际上是一个处理消息的程序段,通过系统调用,把它挂入系统,以监视指定窗口的某种消息。每当特定的消息发出,在没有到达目的窗口前&#xff0c…