在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

相关推荐
峥无32 分钟前
Linux系统编程基石:静态库·动态库·ELF文件·进程地址空间全景图
linux·运维·服务器
用户23678298016840 分钟前
从 chmod 755 说起:Unix 文件权限到底是怎么算的?
linux
Strugglingler1 小时前
【systemctl 学习总结】
linux·systemd·systemctl·journalctl·unit file
全球通史2 小时前
RDKS100 GPU量化环境配置
ubuntu
嵌入式×边缘AI:打怪升级日志2 小时前
100ASK-T113 Pro 开发板 Bootloader 完全开发指南
linux·ubuntu·bootloader
charlie1145141913 小时前
Linux 字符设备驱动:cdev、设备号与设备模型
linux·开发语言·驱动开发·c
handler013 小时前
Linux 内核剖析:进程优先级、上下文切换与 O(1) 调度算法
linux·运维·c语言·开发语言·c++·笔记·算法
zhouwy1134 小时前
Linux进程与线程编程详解
linux·c++
我星期八休息4 小时前
IT疑难杂症诊疗室:AI时代工程师Superpowers进化论
linux·开发语言·数据结构·人工智能·python·散列表
切糕师学AI4 小时前
深入解析 Zsh 与 Oh-My-Zsh:打造高效现代化终端
linux·终端·zsh