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
欧云服务器5 天前
怎么让脚本命令可以同时在centos、debian、ubuntu执行?
ubuntu·centos·debian
智渊AI5 天前
Ubuntu 20.04/22.04 下通过 NVM 安装 Node.js 22(LTS 稳定版)
ubuntu·node.js·vim
IvorySQL5 天前
揭开 PostgreSQL 读取效率问题的真相
数据库·postgresql·开源
The️5 天前
Linux驱动开发之Read_Write函数
linux·运维·服务器·驱动开发·ubuntu·交互
再战300年5 天前
Samba在ubuntu上安装部署
linux·运维·ubuntu
qwfys2005 天前
How to install golang 1.26.0 to Ubuntu 24.04
ubuntu·golang·install
科技D人生5 天前
PostgreSQL学习总结(17)—— PostgreSQL 插件大全:25款核心扩展解锁数据库全能力
数据库·postgresql·pgsql 插件·postgresql插件大全
木尧大兄弟5 天前
Ubuntu 系统安装 OpenClaw 并接入飞书记录
linux·ubuntu·飞书·openclaw
小虾爬滑丫爬5 天前
ubuntu上设置Tomcat 开机启动
ubuntu·tomcat·开机启动