pg16编译安装

1、postgresql安装-源代码安装

最新版本是v16.2 https://www.postgresql.org/ftp/source/v16.2/

 

下载源代码包,postgresql-16.2.tar.gz

解压

tar -xzvf postgresql-16.2.tar.gz

安装依赖

yum -y install gcc gcc-c++ make zlib zlib-devel openssl openssl-devel pcre pcre-devel libicudevel.x86_64

编译配置

./configure --prefix=/var/lib/pgsql --without-icu --without-readline

把所有文件装在目录/var/lib/pgsql中

 

编译

make

安装

make install

 

安装后配置环境变量,在/etc/profile文件末尾追加如下内容

LD_LIBRARY_PATH=/var/lib/pgsql/lib

export LD_LIBRARY_PATH

PATH=/var/lib/pgsql/bin:$PATH

export PATH

 

创建程序用户postgres

useradd postgres

 

给目录授权

chown postgres:postgres /var/lib/pgsql

 

初始化

initdb -D /var/lib/pgsql/data

 

启动数据库

切换到postgres用户

pg_ctl -D /var/lib/pgsql/data -l logfile start

关闭数据库

pg_ctl stop -D

 

配置开机启动项

创建postgresql.service

# It's not recommended to modify this file in-place, because it will be

# overwritten during package upgrades. If you want to customize, the # best way is to create a file "/etc/systemd/system/postgresql.service",

# containing

# .include /lib/systemd/system/postgresql.service # ...make your changes here...

# For more info about custom unit files, see

#

http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom _unit_file.3F

# For example, if you want to change the server's port number to 5433, # create a file named "/etc/systemd/system/postgresql.service" containing:

# .include /lib/systemd/system/postgresql.service

# [Service]

# Environment=PGPORT=5433

# This will override the setting appearing below.

# Note: changing PGPORT or PGDATA will typically require adjusting SELinux # configuration as well; see /usr/share/doc/postgresql-*/README.rpm-dist.

# Note: do not use a PGDATA pathname containing spaces, or you will # break postgresql-setup.

# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line # though /lib/... will still work.

[Unit] Description=PostgreSQL database server After=network.target

[Service]

Type=forking

User=postgres

Group=postgres

# Port number for server to listen on

Environment=PGPORT=5432

# Location of database directory

Environment=PGDATA=/var/lib/pgsql/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

#ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}

ExecStart=/var/lib/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t

 

300

ExecStop=/var/lib/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast

ExecReload=/var/lib/pgsql/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down

TimeoutSec=300

[Install]

WantedBy=multi-user.target

 

将文件放置在/usr/lib/systemd/system/下

 

重启服务

systemctl restart postgresql

 

异常问题处理:

1、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.

 

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.

 

解决办法,yum搜索,需要devel版本的包,安装。 yum search all icu yum install libicu-devel.x86_64

安装后检查头文件是否存在了

ls -l /usr/include/ | grep zlib

 

./configure --without-icu --without-readline

 

posted @   风语者的祝福  阅读(238)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示