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
相关推荐
程序员buddha1 小时前
TypeScript详细教程
javascript·ubuntu·typescript
comedate2 小时前
[TypeScript] TypeScript 学习从入门到精通
ubuntu·typescript·前端语言
l1t2 小时前
DeepSeek总结的PostgreSQL检查点和写入风暴
jvm·postgresql·oracle
gsls2008083 小时前
ubuntu安装HermesAgent接入Nous平台小米大模型和微信通道配置
ubuntu·hermesagent·小米大模型
丸辣,我代码炸了5 小时前
用 PostgreSQL 一库模拟 MySQL / MongoDB / Redis / Elasticsearch(附 ts_rank 详解)
mysql·mongodb·postgresql
木子欢儿5 小时前
Ubuntu 24.04 执行超微服务器 JNLP 程序
linux·运维·服务器·ubuntu
XDHCOM16 小时前
PostgreSQL 25001: active_sql_transaction 报错原因分析,故障修复步骤详解,远程处理解决方案
数据库·sql·postgresql
橘子编程17 小时前
JavaScript与TypeScript终极指南
javascript·ubuntu·typescript
卤炖阑尾炎17 小时前
PostgreSQL 日常运维全指南:从基础操作到备份恢复
运维·数据库·postgresql
12345,catch a tiger19 小时前
虚拟机ubuntu安装Vmware Tools
linux·运维·ubuntu