Ubuntu22.04安装postgresql16.8

1.下载已经编译好的二进制包

安装包直达:pgsql16.8

二进制打包方式见:postgresql16.8二进制包编译

2.解压

shell 复制代码
sudo tar -xvf pgsql16.8-ubuntu.tar.gz -C /opt/

3.编辑 postgresql.service

shell 复制代码
sudo nano /etc/systemd/system/postgresql.service
shell 复制代码
[Unit]
Description=PostgreSQL 16.8 Server
After=network.target

[Service]
Type=forking
User=postgres
Group=postgres
PIDFile=/opt/pgsql16.8/data/postmaster.pid
Environment=PGDATA=/opt/pgsql16.8/data
Environment=PATH=/opt/pgsql16.8/bin:/usr/bin:/bin

ExecStart=/opt/pgsql16.8/bin/pg_ctl start -D /opt/pgsql16.8/data -l /opt/pgsql16.8/data/logfile
ExecStop=/opt/pgsql16.8/bin/pg_ctl stop -D /opt/pgsql16.8/data
ExecReload=/opt/pgsql16.8/bin/pg_ctl reload -D /opt/pgsql16.8/data

PermissionsStartOnly=true
Restart=on-failure
RestartSec=3
LimitNOFILE=65535
LimitNPROC=65535

[Install]
WantedBy=multi-user.target

4.启动pgsql

shell 复制代码
## 加载service
sudo systemctl daemon-reload
## 启动pgsql
sudo systemctl start postgresql
## 加入开机启动
sudo systemctl enable postgresql
## 查看状态
sudo systemctl status postgresql

5.配置环境变量

shell 复制代码
echo 'export PATH=/opt/pgsql16.8/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/pgsql16.8/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

6.修改密码

bash 复制代码
ALTER USER postgres PASSWORD 'root@2025';

7.设置远程连接

bash 复制代码
# 修改 pg_hba.conf ,添加如下配置

host    all    all    0.0.0.0/0    md5

# 修改 postgresql.conf
listen_addresses = '*'

# 重启服务
sudo systemctl restart postgresql

8.登录验证

bash 复制代码
sudo psql -U postgres
相关推荐
秉承初心4 天前
PostgreSQL 数据性能瓶颈突破实战
数据库·postgresql·oracle
张飞飞飞飞飞4 天前
Tmux命令使用教程
linux·服务器·ubuntu
IvorySQL4 天前
PostgreSQL 技术日报 (6月15日)|PG19 性能优化推进,POSETTE 大会倒计时 2 天
数据库·人工智能·postgresql·开源
盼小辉丶5 天前
Ubuntu极速部署OpenClaw完全指南(本地模型+DeepSeek)
linux·ubuntu·openclaw
黑白园5 天前
【环境搭建】Ubuntu安装(一)
linux·ubuntu
Moshow郑锴5 天前
Ubuntu用SDKMAN轻松管理多个Java 版本
java·ubuntu·sdkman
error:(5 天前
Ubuntu 22.04 GNOME远程桌面配置问题排查与解决全流程
linux·运维·ubuntu
Java知识技术分享5 天前
在windows上使用wsl安装Ubuntu~linux系统
linux·人工智能·windows·ubuntu
天疆说5 天前
在 Ubuntu 24.04 上安装 MATLAB R2021b
数据库·ubuntu·matlab
Clang's Blog5 天前
Ubuntu(20.04/22.04/24.04)国内环境一键安装 Docker、JDK17 和 Maven
ubuntu·docker·maven