知识库首页 知识库-世界 Neon数据库优化记录-2026-01-25.md

Neon数据库优化记录 2026 01 25

本地来源:Knowledge/World/项目/提效降本/Neon数据库优化记录-2026-01-25.md

Neon 数据库批量优化记录

执行日期: 2026-01-25 执行人: Claude Code 优化账户: [email protected]


一、优化背景

问题发现

指标 数值
项目总数 61 个
本月账单 $144.63
Compute 费用 $143.57 (99%)
Storage 费用 $1.02
主要问题 Scale to Zero 全部关闭,Max CU 设置过高

费用计算公式

Neon 计费 = CU-hours × $0.106

CU-hours = CU 大小 × 运行小时数

例如:1 CU × 24小时 × 30天 = 720 CU-hours = $76.32/月

二、优化前完整项目列表

有出单项目(保持不变)

项目名 用户数 本月费用 当前CU 操作
longcat-video.org 7,838 $13.55 0.25-8 不动
crystalupscaler.com 1,395 $13.68 0.25-2 不动
trellis-2.com 496 $3.15 0.25-8 不动
seedvr2.net - $2.40 0.25-8 不动
小计 $32.78

待优化项目(57个)

# 项目名 用户数 本月费用 原CU设置
1 z-image-turbo.net 120 $11.31 1-8
2 flashvsr.org - $8.46 0.25-2
3 animateimage.online - $8.45 0.25-2
4 aifloorplangenerator.org - $8.43 0.25-2
5 aigraphmaker.pro - $8.40 0.25-2
6 kandinsky5.com - $8.38 0.25-2
7 ypp.money - $8.35 0.25-2
8 ovisimage.org 26 $5.11 1-8
9 babydanceai.com 414 $3.70 0.25-8
10 3davatarmaker.org 293 $3.26 0.25-2
11 aicountrysong.org 5 $2.67 0.25-2
12 jujutsuzero.com - $2.58 0.25-8
13 pomelliai.org 81 $1.72 0.25-2
14 qwen360edit.com 52 $1.44 0.25-8
15 p-image-edit.com 35 $1.44 0.25-8
16 wan2-6.net 60 $1.30 0.25-8
17 realgen.org 43 $1.18 0.25-8
18 genflare2.org 95 $1.08 0.25-8
19 hunyuanmotion.org 32 $1.04 0.25-8
20 aimotionposter.org 34 $1.03 0.25-8
21 z-imageai.org 12 $1.02 0.25-2
22 imagetoimagevideoai.com 4 $1.02 0.25-8
23 garlicai.org 10 $0.96 0.25-8
24 seedance15pro.org 19 $0.96 0.25-8
25 glm-image.com 27 $0.96 0.25-8
26 gptimages15.com 7 $0.95 0.25-8
27 gpt-image-2.net 1 $0.95 0.25-8
28 aiportraiteditor.com 3 $0.95 0.25-2
29 longcat-image.com 29 $0.93 0.25-8
30 grokbikini.jp 10 $0.92 0.25-8
31 gwm-1.com 14 $0.91 0.25-8
32 fiercefalcon.net 3 $0.90 0.25-8
33 gpt-image-2.ai 14 $0.90 0.25-2
34 flux2max.org 25 $0.89 0.25-8
35 nafnet.org 4 $0.89 0.25-8
36 flashvsr.net 1 $0.88 0.25-2
37 longcatimageedit.com 5 $0.81 0.25-8
38 robinhigh.org 1 $0.78 0.25-8
39 robinhigh.com 1 $0.72 0.25-8
40 o1edit.com 11 $0.71 0.25-8
41 univideo.video 10 $0.63 0.25-8
42 robin-high.com - $0.56 0.25-8
43 niji-v7.com 5 $0.54 0.25-8
44 aiupscale.org - $0.44 0.25-8
45 animateimageai.net - $0.28 0.25-2
46 aicontractgenerator.org - $0.26 0.25-2
47 gpt-image-2.org - $0.25 0.25-2
48 animateimageai.app - $0.24 0.25-8
49 whisper-thunder.net - $0.24 0.25-2
50 flux2dev.org - $0.05 0.25-2
51 riftrunnerai.org - $0.03 0.25-2
52 longcatimage.org - $0.01 0.25-8
53 ghostfalcon.net - $0.01 0.25-8
54 kontextlora.ai - $0.01 0.25-8
55 animateimage.app - $0.00 0.25-8
56 kirkify.org - $0.00 0.25-2
57 ai3dmodelgenerator.org - $0.00 0.25-2
小计 $110.79

三、优化方案

优化设置

对 57 个非出单项目统一设置:

{
  "autoscaling_limit_min_cu": 0.25,
  "autoscaling_limit_max_cu": 0.25,
  "suspend_timeout_seconds": 300
}

设置说明

参数 说明
min_cu 0.25 最小计算单元(1GB RAM)
max_cu 0.25 最大计算单元(限制自动扩展)
suspend_timeout 300s 5分钟无请求后自动休眠

四、执行结果

执行统计

指标 数值
优化项目数 57
成功 57
失败 0
成功率 100%

验证结果

已优化项目(抽查):

项目 Min CU Max CU 休眠 状态
niji-v7.com 0.25 0.25 300s
z-image-turbo.net 0.25 0.25 300s
animateimage.online 0.25 0.25 300s
ypp.money 0.25 0.25 300s
babydanceai.com 0.25 0.25 300s

出单项目(保持不变):

项目 Min CU Max CU 休眠 状态
crystalupscaler.com 0.25 2 0s 不休眠
longcat-video.org 0.25 1 0s 不休眠
trellis-2.com 0.25 1 0s 不休眠
seedvr2.net 0.25 1 0s 不休眠

五、费用预估

预期费用变化

指标 优化前 优化后
57 个优化项目 $110.79/月 ~$15-25/月
4 个出单项目 $32.78/月 $32.78/月
总计 $143.57/月 ~$48-58/月
每月节省 ~$85-95
每年节省 ~$1,020-1,140

节省计算逻辑

优化前:数据库 24 小时运行
优化后:有请求时运行,5分钟无请求后休眠

假设平均每个项目每天活跃 2-4 小时:
节省比例 = (24 - 3) / 24 = 87.5%

$110.79 × 87.5% = $96.94 节省

六、注意事项

优化后的变化

  1. 冷启动延迟:休眠后首次请求需 1-3 秒启动时间
  2. 对 AI 工具站影响小:用户等待 AI 结果时间远超过冷启动时间
  3. 自动扩展被限制:高并发时可能稍慢,但对小流量站无影响

后续观察

  1. 下月账单出来后对比实际节省
  2. 如发现某些项目性能不足,可单独调高 Max CU
  3. 出单项目如流量增大,可考虑调整

七、技术参考

Neon API 批量修改脚本

NEON_KEY="your_api_key"

# 修改单个项目的 endpoint 设置
curl -X PATCH "https://console.neon.tech/api/v2/projects/{project_id}/endpoints/{endpoint_id}" \
  -H "Authorization: Bearer ${NEON_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": {
      "autoscaling_limit_min_cu": 0.25,
      "autoscaling_limit_max_cu": 0.25,
      "suspend_timeout_seconds": 300
    }
  }'

查询项目用户数 SQL

# 获取连接字符串
conn_uri=$(curl -s "https://console.neon.tech/api/v2/projects/{project_id}/connection_uri?database_name=neondb&role_name=neondb_owner" \
  -H "Authorization: Bearer ${NEON_KEY}" | jq -r '.uri')

# 查询用户数
psql "$conn_uri" -c "SELECT COUNT(*) FROM \"user\";"

八、Neon vs Turso 对比(备忘)

对比维度 Neon (PostgreSQL) Turso (SQLite)
计费模式 按运行时间 按读写行数
多数据库成本 贵(每个库单独计费) 便宜(100库免费)
功能丰富度 强大(完整 PostgreSQL) 够用(SQLite)
适合场景 单库高并发、复杂查询 多租户、边缘计算
迁移成本 - 需改代码和 Schema

什么时候考虑 Turso

  • 需要几百个独立数据库的多租户 SaaS
  • 简单 CRUD 操作,不需要复杂 SQL
  • 预算极度敏感

目前结论

继续使用 Neon,通过优化设置降低成本,性价比最高。


九、总结

项目 数值
优化日期 2026-01-25
优化项目数 57 个
保留项目数 4 个(有出单)
优化前费用 $143.57/月
优化后预估 $48-58/月
预计节省 $85-95/月
年度节省 $1,020-1,140

文档生成时间: 2026-01-25 执行工具: Claude Code + Neon API

本文档为站内渲染。原始文件本地路径:saas/source/knowledge-world/Knowledge-World-项目-提效降本-Neon数据库优化记录-2026-01-25-5e65dd.md(仅本地保留,不入库不部署)