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·架构
IvorySQL34 分钟前
PostgreSQL 的 SQL 查询之旅
数据库·人工智能·postgresql·开源
Web极客码4 小时前
释放WordPress磁盘空间并减少Inode使用量
服务器·数据库·ubuntu
朝阳5814 小时前
树莓派 Ubuntu 系统登录问题完整指南:解决 Permission denied (publickey)错误
linux·运维·ubuntu
oMcLin6 小时前
如何在 Ubuntu 22.04 上部署并优化 Jenkins 2.x 流水线,提升持续集成与自动化测试的效率?
ubuntu·ci/cd·jenkins
rfidunion6 小时前
ubuntu下使用qemu模拟ARM(一)-------安装samba服务器
服务器·arm开发·ubuntu
HIT_Weston6 小时前
90、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(四)
linux·运维·ubuntu
EndingCoder7 小时前
函数基础:参数和返回类型
linux·前端·ubuntu·typescript
济6177 小时前
linux(第十三期)--filezilla使用方法(实现ubuntu和windows11文件互传)-- Ubuntu20.04
linux·运维·ubuntu
HIT_Weston7 小时前
91、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(五)
linux·运维·ubuntu