惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
Recorded Future
Recorded Future
T
Tenable Blog
S
Securelist
C
CERT Recently Published Vulnerability Notes
T
Threatpost
S
Schneier on Security
A
Arctic Wolf
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Register - Security
The Register - Security
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
K
Kaspersky official blog
T
True Tiger Recordings
T
Threat Research - Cisco Blogs
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
T
The Exploit Database - CXSecurity.com
小众软件
小众软件
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tor Project blog
Spread Privacy
Spread Privacy
Malwarebytes
Malwarebytes
P
Proofpoint News Feed
F
Fox-IT International blog
F
Fortinet All Blogs
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
量子位
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
Project Zero
Project Zero
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
I
Intezer
博客园_首页
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Darknet – Hacking Tools, Hacker News & Cyber Security

PostgreSQL

五年过去了,结论有什么变化吗? 适配信创数据库的人的精神状态 be like 用了十几年的 MySQL 了,突然发现 PostgreSQL 可能更加适合我,大家怎么看? postgresql 多进程改多线程 二键安装一个 postgresql 服务 通过 pg_roaringbitmap 优化标签查询的话,有没有必要做高频标签映射和结合普通复合索引? PostgreSQL + TimescaleDB 方案不按主键索引走,有什么办法吗? 看看大家现在用 pg 的最佳实践是怎么样的 用 PostgreSQL 存图片等 binary 有什么坑吗 [求助] 在哪个网址能够下载 PostgresSQL 9.3.0 版本的 Windows 二进制安装包?官方/ftp/old/binary 里没有。 [请教]pgvector 的性能问题 多笔记本离线 PostgreSQL 数据库同步问题: UUID vs 自增主键 PostgreSQL 通过分 Database 做多租户可行吗? PostgreSQL 多租户的正确姿势 Postgresql 放 K8S 里,大家目前都用的什么方案呢? 2025 年 postgresql 有什么优秀的备份解决方案 有大神研究过 pg_resetwal 的原理吗,为什么会丢 user 表的数据 按照 stackoverflow 教程执行 pg_resetwal, postgresql 的数据库被清空了 求国内高性价比的 postgresql 服务,纳米项目 PostgreSQL 18 JSONB 增加能取代 MongoDB 吗? PostgreSql Oracle 迁移 postgreSQL ,有什么经验分享 有什么权限管理最佳实践吗 请教 PostgreSQL 和 PostGIS 使用问题 pg 的毫秒级时间戳转换 关于 PostgreSQL 中的 max_connections 和 pg_stat_activity 的疑惑 目前国内最高性价比的 postgresql 服务是? 新手,请问 postgres 怎么配置 vacuum 学习 PostgreSQL,有什么资料推荐? Apache AGE 和 Neo4j 哪个更好? 有没有像 Citus 那样方便分片的图数据库? 怎样使用 C 语言访问 PostgreSQL 集群? 小系统 数据库 mysql 和 postgresql 比对 和 wordpress 数据库技术选型 PostgreSQL 没有 on update current_timestamp 感觉好麻烦 主从同步使用的端口号可以和数据库端口号不同吗? 为什么有时 PostgreSQL 有时会表现得比较卡? 第一次使用 PostgreSQL,连建表都不会,请教点经验 Java 有没有针对 PostgreSQL 好用一点的 ORM 请教,有无简单易用的 PostgreSQL 表结构、数据的同步工具? PostgreSQL 启动失败 PostgreSQL 数据库 正常情况下指定了 locale=C 与 encoding=UTF8 (最简单) 错误迁移 pgsql 导致日志报 warning,请问如何解决? 从 Mongodb 到 PostgreSQL 的大迁移 有无 pg 的入门精进博客或者视频推荐 有什么不通过写脚本的方式,将 postgreSQL 的建表语句转换为 doris 的建表语句吗? 新的 PostgreSQL 语言插件 PL/PRQL 请教一个经典的 postgres 的 sql 怎么写 洗数据:如何将 Contact 和 ContactTag 多对多关联起来 Postgres 在中国还能起来么? PostgreSQL 17 增加增量备份的功能
请教一个关于 PostgreSQL 连接被 Server 关闭的问题
Koril · 2025-03-11 · via PostgreSQL

背景

我在自己的阿里云服务器上( 2C2G ,3M ,Debian 12 )装了一个 PostgreSQL ( 15 ),安装后,仅仅做了以下配置改动:

pg_hba.conf:

添加:host all all 0.0.0.0/0 md5

postgresql.conf

开放端口:listen_addresses = '*'

给 postgres 设置了密码,sudo -i -u postgres -> psql -> \password


异常

无论是 Navicat 还是 Python 的 Psycopg2 在超过一定时间(大概 3-5 分钟),就会连接失效了。

Navicat 报错如下:

Server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.

Psycopg2 报错如下:

psycopg2.OperationalError: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request. 

已知

服务器没有太大的负载,cpu ,内存,磁盘,网络,占用率都很低,除了 Prometheus/Grafana/nginx 之外,这个机器上只有刚刚安装的 PostgreSQL 。

重新获取连接,能够正常访问,但是我使用的 Psycopg2 的 ThreadedConnectionPool 连接池,连接池没法保持连接么?代码如下:


def get_pg_pool(pg_config):
    pool = psycopg2.pool.ThreadedConnectionPool(
        minconn=1,
        maxconn=200,
        host=pg_config['PG_HOST'],
        port=pg_config['PG_PORT'],
        dbname=pg_config['PG_DB'],
        user=pg_config['PG_USER'],
        password=pg_config['PG_PASSWORD'],
        connect_timeout=5,
    )
    return pool
    
@flask_app.route('/task/log', methods=['GET'])
    def task_log():
        task_log_list = []
        # 在进程启动时,给 flask_app 初始化了一个 pg_pool 对象
        conn = flask_app.pg_pool.getconn()
        try:
            with conn.cursor() as cur:
                cur.execute('SELECT * FROM t_log')
                task_log_list = cur.fetchall()
        except psycopg2.Error as e:
            return JsonResult.failed('获取日志列表失败')
        finally:
            flask_app.pg_pool.putconn(conn)

        return JsonResult.successful(task_log_list)


问题

这个问题是和 Linux 服务器配置有关呢?还是跟 PostgreSQL 配置有关?请问如何排查和解决呢?