在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

相关推荐
赵渝强老师2 小时前
【赵渝强老师】PostgreSQL中表的碎片
数据库·postgresql
chlk1231 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑1 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件1 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号2 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash2 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行3 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端