当前位置: 首页 > article >正文

Debian上安装PostgreSQL的故障和排除

命令如下:

apt install postgresql

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

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安装的时候,又报错说

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后启动数据库还是有错

/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 directorystopped waiting

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

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的内容如下:

# 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测试连接成功。

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中,

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造成的,以后要注意。

http://www.lryc.cn/news/2396288.html

相关文章:

  • linux文件管理(补充)
  • Python训练营---Day42
  • 基于空天地一体化网络的通信系统matlab性能分析
  • c++ opencv 形态学操作腐蚀和膨胀
  • Axure组件即拖即用:横向拖动菜单(支持左右拖动选中交互)
  • Hadoop MapReduce:大数据处理利器
  • RabbitMQ-Go 性能分析
  • 【c++】【数据结构】红黑树
  • 基于SpringBoot+Redis实现RabbitMQ幂等性设计,解决MQ重复消费问题
  • React从基础入门到高级实战:React 生态与工具 - React 单元测试
  • 使用lighttpd和开发板进行交互
  • DRF的使用
  • 2024年09月 C/C++(四级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • 免费且好用的PDF水印添加工具
  • mqtt协议连接阿里云平台
  • 一文详谈Linux中的时间管理和定时器编程
  • Ubuntu 安装 Miniconda 及配置国内镜像源完整指南
  • 性能优化 - 理论篇:常见指标及切入点
  • 青少年编程与数学 02-020 C#程序设计基础 08课题、字符和字符串
  • 【论文阅读 | PR 2024 |ICAFusion:迭代交叉注意力引导的多光谱目标检测特征融合】
  • Spring Security加密模块深度解析
  • 华为OD机试真题——模拟消息队列(2025A卷:100分)Java/python/JavaScript/C++/C语言/GO六种最佳实现
  • MySql(十三)
  • iOS —— UI 初探
  • day23-计算机网络-1
  • C语言基础(09)【数组的概念 与一维数组】
  • 【JavaScript】Ajax 侠客行:axios 轻功穿梭服务器间
  • Django数据库连接报错 django.db.utils.NotSupportedError: MySQL 8 or later is required
  • 2025年- H57-Lc165--994.腐烂的橘子(图论,广搜)--Java版
  • 2024 CKA模拟系统制作 | Step-By-Step | 16、题目搭建-sidecar 代理容器日志