在ubuntu 24安装 postgresql 17 (源码安装)

1 操作系统(ubuntu24 最小化安装)

root@u24-pg-110:~# cat /etc/issue

Ubuntu 24.04.2 LTS \n \l

2 安装依赖

apt install systemtap-sdt-dev -y

apt install build-essential -y

apt install libssl-dev -y

apt install libicu-dev icu-devtools pkg-config -y

apt install liblz4-dev -y

apt install libzstd-dev -y

apt install bison -y

apt install flex -y

apt install readline -y

apt install libreadline-dev -y

apt install zlib1g-dev -y

apt install krb5-user libkrb5-dev libgssapi-krb5-2 -y

apt install libpam0g-dev -y

apt install libxml2-dev -y

apt install libxslt1-dev -y

apt install libldap2-dev libsasl2-dev libssl-dev -y

apt install libselinux1-dev -y

apt install uuid-dev -y

apt install gettext -y

apt install tcl-dev tcl8.6-dev -y

apt install perl libperl-dev -y

apt install python3-dev -y

3 postgresql编译

./configure --prefix=/usr/local/postgresql-17 \

--with-icu \

--with-perl \

--with-python \

--with-tcl \

--with-tclconfig=/usr/lib/tcl8.6 \

--with-openssl \

--with-includes=/usr/include/openssl \

--with-readline \

--with-pam \

--with-gssapi \

--with-libraries=/usr/lib64 \

--enable-nls \

--enable-dtrace \

--with-uuid=e2fs \

--with-libxml \

--with-libxslt \

--with-ldap \

--with-selinux \

--with-system-tzdata=/usr/share/zoneinfo \

--with-lz4 \

--with-zstd

make -j 2

make install

4 创建postgres 用户

adduser postgres

5 初始化数据库

mkdir /postgresql/data -p

chown -R postgres:postgres /postgresql/data/

su - postgres

#初始化数据库

/usr/local/postgresql-17/bin/initdb -D /postgresql/data/

#启动postgresql

/usr/local/postgresql-17/bin/pg_ctl -D /postgresql/data/ -l logfile start

#测试

postgres@u24-pg-110:~$ /usr/local/postgresql-17/bin/psql

psql (17.5)

Type "help" for help.

postgres=#

6 配置systemd和环境变量

vi ~/.bashrc

export PATH=/usr/local/postgresql-17/bin:$PATH

source ~/.bashrc

root@u24-pg-110:~# vi /lib/systemd/system/postgresql.service

Unit

Description=PostgreSQl database server

After=network.target

Service

Type=forking

User=postgres

Group=postgres

Environment=PGDATA=/postgresql/data

ExecStart=/usr/local/postgresql-17/bin/pg_ctl start -D ${PGDATA}

ExecStop=/usr/local/postgresql-17/bin/pg_ctl stop -D ${PGDATA} -s -m fast

ExecReload=/usr/local/postgresql-17/bin/pg_ctl reload -D ${PGDATA} -s

TimeoutSec=300

KillMode=mixed

Install

WantedBy=multi-user.target

#启动和设置开机启动

systemctl start postgresql

systemctl enable postgresql

相关推荐
mCell1 小时前
从删库到跑路?这50个Linux命令能保你职业生涯
linux·windows·macos
杰克逊的日记1 小时前
GPU运维常见问题处理
linux·运维·gpu
誰能久伴不乏2 小时前
Linux系统调用概述与实现:深入浅出的解析
linux·运维·服务器
程序员学习随笔2 小时前
Linux进程深度解析(2):fork/exec写时拷贝性能优化与exit资源回收机制(进程创建和销毁)
linux·运维·服务器
mmoyula2 小时前
【RK3568 PWM 子系统(SG90)驱动开发详解】
android·linux·驱动开发
-SGlow-3 小时前
MySQL相关概念和易错知识点(2)(表结构的操作、数据类型、约束)
linux·运维·服务器·数据库·mysql
代码改变世界ctw3 小时前
Linux内核设计与实现 - 第14章 块I/O层
linux·运维·服务器
van叶~5 小时前
Linux网络-------1.socket编程基础---(TCP-socket)
linux·网络·tcp/ip
风吹落叶花飘荡6 小时前
Ubuntu系统 系统盘和数据盘扩容具体操作
linux·运维·ubuntu
zoulingzhi_yjs6 小时前
haproxy配置详解
linux·云原生