You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FastAPI连接PostgreSQL时出现connection timeout expired错误求助

FastAPI连接PostgreSQL出现connection timeout expired错误

连接PostgreSQL服务器时触发connection timeout expired错误,输入密码后加载耗时远超正常情况,最终超时。pgAdmin可正常连接,此前相同配置也能正常工作。

连接配置信息

Alembic目录配置

sqlalchemy.url = postgresql+asyncpg://%(DB_USER)s:%(DB_PASS)s@%(DB_HOST)s:%(DB_PORT)s/%(DB_NAME)s?async_fallback=True

Database目录配置

DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
Base = declarative_base()
metadata = MetaData()
engine = create_async_engine(DATABASE_URL)
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)

.env目录配置

DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASS=XXXXX

已尝试的操作

  • 安装标准WebSocket
  • 将数据库升级至7.1版本
  • 检查数据库日志

内容的提问来源于stack exchange,提问作者Monte-Cristo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 14:22:05