Debian上安装PostgreSQL的故障和排除

命令如下:

bash 复制代码
apt install postgresql

#可能是apt信息错误,报错

bash 复制代码
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/postgresql-15/postgresql-client-15_15.12-0%2bdeb12u2_amd64.deb  404  Not Found [IP: 146.75.46.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/postgresql-15/postgresql-15_15.12-0%2bdeb12u2_amd64.deb  404  Not Found [IP: 146.75.46.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我没有运行apt-get update,而是用了apt install postgresql --fix-missing,错误依旧,就自己在网上找安装包,结果没有这个版本,就下载了另一个相近的版本。

复制代码
wget http://ftp.us.debian.org/debian/pool/main/p/postgresql-15/postgresql-client-15_15.13-0+deb12u1_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/p/postgresql-15/postgresql-15_15.13-0+deb12u1_amd64.deb

dpkg -i postgresql-client-15_15.13-0+deb12u1_amd64.deb安装的时候,又报错说

bash 复制代码
dpkg: dependency problems prevent configuration of postgresql-client-15:
 postgresql-client-15 depends on libpq5 (>= 15.13); however:
  Version of libpq5:amd64 on system is 15.12-0+deb12u2.

又下载了个同版本的wget http://ftp.de.debian.org/debian/pool/main/p/postgresql-15/libpq5_15.13-0+deb12u1_amd64.deb,安装了这个版本的libpq5后,安装客户端不报错了。
dpkg -i postgresql-15_15.13-0+deb12u1_amd64.deb后启动数据库还是有错

bash 复制代码
/usr/lib/postgresql/15/bin/pg_ctl start -D  /var/lib/postgresql/15/main
waiting for server to start....postgres: could not access the server configuration file "/var/lib/postgresql/15/main/postgresql.conf": No such file or directory
 stopped waiting

那个目录下确实没有postgresql.conf文件,但有postgresql.auto.conf 文件,而且它的内容是空白的,网上说建立空白postgresql.conf也行,于是cp postgresql.auto.conf postgresql.conf后再次启动,继续报错,比上次有进步:

bash 复制代码
waiting for server to start....2025-05-31 07:40:55.082 GMT [16] LOG:  starting PostgreSQL 15.13 (Debian 15.13-0+deb12u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
2025-05-31 07:40:55.082 GMT [16] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2025-05-31 07:40:55.085 GMT [16] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-05-31 07:40:55.087 GMT [16] LOG:  could not open configuration file "/var/lib/postgresql/15/main/pg_hba.conf": No such file or directory
2025-05-31 07:40:55.087 GMT [16] FATAL:  could not load pg_hba.conf

继续照抄网上的内容,自己编辑pg_hba.conf的内容如下:

bash 复制代码
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" 是仅在本地机器上通过UNIX域套接字连接的服务。
# "host" 是仅在本地机器上通过TCP/IP连接的服务。
# IPv4 支持 IPv4 和 IPv6 连接协议。
# IPv6 仅支持 IPv6 连接协议。
local   all             all                                     trust
# "local" connections, 无需身份验证
host    all             all             127.0.0.1/32            trust

# "host" connections, 身份验证方法是 md5
host    all             all             0.0.0.0/0               md5

# "hostssl" connections, 身份验证方法是 cert
hostssl all             all             0.0.0.0/0               cert

再次启动就不报错了。用psql测试连接成功。

bash 复制代码
psql -d postgres
psql (15.13 (Debian 15.13-0+deb12u1))
Type "help" for help.

postgres=# select version();
#测试连接字符串也成功了
psql postgres://postgres@127.0.0.1/postgres

在duckdb中,

bash 复制代码
duckdb> load postgres;
duckdb> ATTACH 'dbname=postgres user=postgres host=127.0.0.1' AS db (TYPE postgres);
duckdb> create table db.t(a int);
duckdb> insert into db.t values(1);
duckdb> select * from db.t;

之所以出现这么多问题,估计是没有运行apt-get update造成的,以后要注意。

相关推荐
猫头虎44 分钟前
OpenClaw开源汉化发行版:介绍、下载、安装、配置教程
运维·windows·开源·aigc·ai编程·agi·csdn
大尚来也1 小时前
双库协同,各取所长:.NET Core 中 PostgreSQL 与 SQLite 的优雅融合实战
postgresql·sqlite·.netcore
晚风_END1 小时前
Linux|操作系统|elasticdump的二进制方式部署
运维·服务器·开发语言·数据库·jenkins·数据库开发·数据库架构
独自归家的兔1 小时前
Ubuntu 系统 systemd timers 详解:替代 crontab 的定时任务进阶方案
linux·运维·ubuntu
Lsir10110_1 小时前
【Linux】深入解剖页表——分页式存储
linux·运维·服务器
victory04311 小时前
服务器病毒处理记录
运维·服务器·chrome
爱吃生蚝的于勒1 小时前
【Linux】线程概念(一)
java·linux·运维·服务器·开发语言·数据结构·vim
风指引着方向1 小时前
昇腾 AI 开发生产力工具:CANN CLI 的高级使用与自动化脚本编写
运维·人工智能·自动化
数据知道1 小时前
PostgreSQL 故障排查:紧急排查与 SQL 熔断处理(CPU 占用 100% 等情况)
数据库·sql·postgresql
fengyehongWorld1 小时前
Linux yq命令
linux·运维·服务器