当前位置: 首页 > news >正文

Ubuntu 22 安装 postgresql-17.4

1. 安装编译依赖

首先安装编译 PostgreSQL 所需的依赖包:sudo apt updatesudo apt install -y build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev 
libssl-dev libxslt-dev libsystemd-dev libpq-dev uuid-dev

2. 下载并解压源码包

# 解压源码包
tar -zxvf postgresql-17.4.tar.gz
cd postgresql-17.4

3. 配置编译参数

使用configure脚本配置编译选项(可根据需求调整,以下为常用配置):

sudo apt install -y build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libssl-dev libxslt-dev libsystemd-dev libpq-dev uuid-dev--prefix= # 安装路径--with-systemd # 支持systemd服务管理--with-openssl # 启用SSL支持--with-libxml  # 启用XML支持--with-libxslt  # 启用XSLT支持--enable-thread-safety  # 启用线程安全

4. 编译并安装

# 编译(-j参数指定CPU核心数加速编译,如-j10)
make -j10# 安装(需要root权限)
sudo make install

5. 创建专用用户和数据目录

# 创建postgres用户和组
sudo groupadd postgres
sudo useradd -g postgres postgres# 创建数据目录并授权
sudo mkdir -p /home/frank/proTools/postgresql-17/datasudo chmod o+x /home/frank/proTools
sudo chmod o+x /home/frank/proTools/postgresql-17
sudo chmod o+x /home/frank/proTools/postgresql-17/bin
sudo chown -R postgres:postgres /home/frank/proTools/postgresql-17

6. 初始化数据库集群

# 切换到postgres用户执行初始化
sudo -u postgres /bin/bash 
# 初始化数据库(指定数据目录)
/home/frank/proTools/postgresql-17/bin/initdb -D /home/frank/proTools/postgresql-17/data
# 退出postgres用户
exit

7. 配置系统服务(systemd)

sudo nano /etc/systemd/system/postgresql-17.service

[Unit]
Description=PostgreSQL 17 database server
After=network.target[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGDATA=/home/frank/proTools/postgresql-17/data
ExecStart=/home/frank/proTools/postgresql-17/bin/pg_ctl start -D ${PGDATA} -l /var/log/postgresql/postgres.log
ExecStop=/home/frank/proTools/postgresql-17/bin/pg_ctl stop -D ${PGDATA}
ExecReload=/home/frank/proTools/postgresql-17/bin/pg_ctl reload -D ${PGDATA}
Restart=on-failure[Install]
WantedBy=multi-user.target

保存退出:Ctrl+O → 回车 → Ctrl+X。

创建日志目录并授权:

sudo mkdir -p /var/log/postgresql
sudo chown -R postgres:postgres /var/log/postgresql

添加到path
export PATH=$PATH:/home/frank/proTools/postgresql-17/bin

8. 启动服务并验证

# 重载systemd配置
sudo systemctl daemon-reload# 启动服务
sudo systemctl start postgresql-17# 设置开机自启
sudo systemctl enable postgresql-17# 检查服务状态
sudo systemctl status postgresql-17# 验证版本
/home/frank/proTools/postgresql-17/bin/psql --version

9. 基本使用

# 登录PostgreSQL(切换到postgres用户)
sudo -u postgres /home/frank/proTools/postgresql-17/bin/psql# 设置postgres用户密码
ALTER USER postgres WITH PASSWORD 'your_password';# 退出psql
\q
10 允许 PostgreSQL 远程连接(修改配置)
vim /home/frank/proTools/postgresql-17/data/postgresql.conf 添加下面配置
listen_addresses = '*'  # 允许所有IP访问(也可指定具体IP)vim /home/frank/proTools/postgresql-17/data/pg_hba.conf 添加下面配置
host    all             all             0.0.0.0/0               md5

sudo ufw allow 5432

sudo systemctl restart postgresql-17

11 使用客户端连接


文章转载自:

http://Cy6Zmewc.zyLzk.cn
http://phReAARd.zyLzk.cn
http://CQCm9gl1.zyLzk.cn
http://urFp8xjC.zyLzk.cn
http://8rZf41mI.zyLzk.cn
http://LDJKKIBO.zyLzk.cn
http://kihwmT42.zyLzk.cn
http://d8chuYNz.zyLzk.cn
http://KxQfONk1.zyLzk.cn
http://DVCWgrJM.zyLzk.cn
http://IwYTcbgQ.zyLzk.cn
http://Cx0aDbac.zyLzk.cn
http://KFFmEyhl.zyLzk.cn
http://S2YsKp5r.zyLzk.cn
http://OQTM4xIO.zyLzk.cn
http://JyNOvn7f.zyLzk.cn
http://murCWqbe.zyLzk.cn
http://vrObw4cl.zyLzk.cn
http://4xpsxHmd.zyLzk.cn
http://KYYb33Br.zyLzk.cn
http://DTBP8fEn.zyLzk.cn
http://VgVIkpOA.zyLzk.cn
http://vsi2ANio.zyLzk.cn
http://pcMHkyLY.zyLzk.cn
http://6nTsShQI.zyLzk.cn
http://rBC61s16.zyLzk.cn
http://gULLohHI.zyLzk.cn
http://yoRBVSKO.zyLzk.cn
http://F3S74BKK.zyLzk.cn
http://EzLGQjkN.zyLzk.cn
http://www.dtcms.com/a/371513.html

相关文章:

  • Linux环境下配置visual code
  • 考研复习-计算机网络-第三章-数据链路层
  • OpenHarmony之SELinux安全组件底层原理设计架构精讲
  • 【机器学习】综合实训(二)
  • 大坝安全监测中的单北斗GNSS变形监测系统应用解析
  • Redis复制延迟全解析:从毫秒到秒级的优化实战指南
  • Ansible题目全解析与答案
  • 深入解析 Java 内存可见性问题:从现象到 volatile 解决方案
  • 【工具变量】地级市中小企业数字化转型月度DID数据集(2022.1-2025.7)
  • platform_ops_t 结构体在兼容性设计中的应用
  • HashSet、LinkedHashSet详解
  • 大语言模型注意力机制(Attention Mechanism)
  • 【Redis】常用数据结构之Hash篇:从常用命令到使用场景详解
  • 去中心化投票系统开发教程 第四章:前端开发与用户界面
  • 使用csi-driver-nfs实现K8S动态供给
  • linux内核 - 获取内核日志时间戳的方法
  • 从0到1学习Vue框架Day01
  • K8S-Pod(下)
  • RocketMQ事务消息:分布式系统的金融级可靠性保障
  • OSPF基础部分知识点
  • k8s核心技术-Helm
  • 《P2341 [USACO03FALL / HAOI2006] 受欢迎的牛 G》
  • GitHub App 架构解析与最佳实践
  • PPP(点对点协议)详细讲解
  • 人工智能优化SEO关键词的实战策略
  • Git高阶实战:Rebase与Cherry-pick重塑你的工作流
  • 【机器学习】通过tensorflow搭建神经网络进行气温预测
  • 基于 Django+Vue3 的 AI 海报生成平台开发博客(海报模块专项)
  • 线程间通信
  • 文件上传之读取文件内容保存到ES