Add PostgreSQL production backend to eliminate SQLite lock contention.

Support DATABASE_URL with connection pooling, pg_dump backups, SQLite migration script, and deploy_postgres.sh with docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-01 08:11:42 +08:00
parent 39eac983ff
commit 52aca456e9
23 changed files with 1208 additions and 150 deletions
+17 -2
View File
@@ -12,7 +12,7 @@
| 运行用户 | `root`(与 `deploy.sh` / PM2 配置一致) |
| 服务端口 | `6600` |
| 进程管理 | PM2,应用名 `qihuo` |
| 数据库 | SQLite `futures.db` |
| 数据库 | **生产推荐 PostgreSQL**(见 [POSTGRES.md](./POSTGRES.md));未配置 `DATABASE_URL` 时使用 SQLite `futures.db` |
| 仓库 | https://git.bz121.com/dekun/qihuo.git |
---
@@ -58,6 +58,21 @@ bash deploy.sh
部署完成后访问:`http://<服务器IP>:6600`
### PostgreSQL 生产库(推荐)
消除 SQLite 并发 `database is locked`,一键安装 PostgreSQL 并迁移:
```bash
cd /opt/qihuo
git pull
# 新装 PostgreSQL + 空库
sudo bash scripts/deploy_postgres.sh
# 从现有 futures.db 迁移
MIGRATE_SQLITE=1 sudo bash scripts/deploy_postgres.sh
```
完整说明、手动步骤、备份恢复见 **[POSTGRES.md](./POSTGRES.md)**。
> 再次部署只需 `cd /opt/qihuo && bash deploy.sh`,无需手工装 locale 或改前置地址。
---
@@ -334,7 +349,7 @@ ufw allow 6600/tcp
| **CTP 连接超时** | SimNow 地址/账号/非交易时段 | 核对 `.env` 与 SimNow 官网前置 |
| **下单监控无持仓** | 未连接 CTP 或确实无仓 | 先点「连接 CTP」 |
| **`Could not resolve host`** | 服务器 DNS 故障 | 配置 systemd-resolved 公共 DNS,见下方 |
| `database is locked` | SQLite 并发 | 更新代码后重启 |
| `database is locked` | SQLite 并发 | **推荐改 PostgreSQL**`MIGRATE_SQLITE=1 bash scripts/deploy_postgres.sh`,见 [POSTGRES.md](./POSTGRES.md) |
| `git pull` 冲突 | 本地有修改 / SCP 部署 | `git fetch && git reset --hard origin/main` |
查看应用是否在监听: