在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

相关推荐
waves浪游1 天前
基础开发工具(中)
linux
艾莉丝努力练剑1 天前
【C++模版进阶】如何理解非类型模版参数、特化与分离编译?
linux·开发语言·数据结构·c++·stl
wdfk_prog1 天前
[Linux]学习笔记系列 -- [kernel][irq]softirq
linux·笔记·学习
迎風吹頭髮1 天前
Linux服务器编程实践60-双向管道:socketpair函数的实现与应用场景
linux·运维·服务器
试试勇气1 天前
Linux学习笔记(九)--Linux进程终止与进程等待
linux·笔记·学习
盒马coding1 天前
第19节-非规范化数据类型-Drop-Type
数据库·postgresql
wheeldown1 天前
【Linux】Linux 进程信号核心拆解:pending/block/handler 三张表 + signal/alarm 实战
linux·运维·服务器
运维老司机1 天前
ThinkPad 安装 Ubuntu 系统教程
linux·运维·ubuntu
云飞云共享云桌面1 天前
替代传统电脑的共享云服务器如何实现1拖8SolidWorks设计办公
linux·运维·服务器·网络·电脑·制造
添砖java‘’1 天前
vim高效编辑:从入门到精通
linux·编辑器·操作系统·vim