You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# PostgreSQL 安装指南Windows
由于网络限制无法自动下载,请按以下步骤手动安装:
## 方法一:官方安装包(推荐)
### 1. 下载 PostgreSQL
访问官网下载地址:
```
https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
```
或直接下载15.5 版本):
```
https://get.enterprisedb.com/postgresql/postgresql-15.5-1-windows-x64.exe
```
### 2. 安装步骤
1. 运行下载的安装程序
2. 安装目录:`C:\Program Files\PostgreSQL\15`
3. 数据目录:`C:\Program Files\PostgreSQL\15\data`
4. **密码设置**`postgres123`(与配置文件一致)
5. 端口:`5432`(默认)
6. Locale默认或 Chinese (Simplified)
### 3. 创建数据库
安装完成后,打开 **pgAdmin 4****SQL Shell (psql)**
```sql
-- 创建数据库
CREATE DATABASE marketdata;
-- 验证
\l
```
### 4. 启动服务
安装程序会自动创建 Windows 服务,确保服务已启动:
```powershell
# 查看服务状态
Get-Service postgresql*
# 启动服务
net start postgresql-x64-15
```
## 方法二:绿色免安装版
如果安装包下载慢,可以使用绿色版:
### 1. 下载绿色版
```
https://github.com/postgres/postgres/archive/refs/tags/REL_15_5.zip
```
或使用 scoop 安装(需要 scoop
```powershell
scoop install postgresql
```
### 2. 初始化数据库
```powershell
# 创建数据目录
mkdir D:\pgsql\data
# 初始化
initdb -D D:\pgsql\data -U postgres -W
# 启动服务
pg_ctl -D D:\pgsql\data start
# 创建数据库
createdb -U postgres marketdata
```
## 验证安装
```powershell
# 检查端口
netstat -ano | findstr 5432
# 连接测试
psql -U postgres -d marketdata -c "SELECT version();"
```
## 配置项目
安装完成后,修改项目配置:
**config.json**(已配置好):
```json
{
"database": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres123",
"database": "marketdata"
}
}
```
## 初始化数据库表
PostgreSQL 安装并启动后,运行:
```bash
cd d:\fs_workspace\market-data-service\python_market_data_service
python test_db.py
```
这将自动创建所有需要的表。
## 常见问题
### 1. 端口被占用
```powershell
# 查看占用 5432 端口的进程
netstat -ano | findstr 5432
# 如果是旧版 PostgreSQL停止它
net stop postgresql-x64-14
```
### 2. 连接失败
- 检查服务是否运行:`services.msc` 中找到 PostgreSQL 服务
- 检查防火墙设置
- 检查 pg_hba.conf 配置
### 3. 密码错误
```powershell
# 重置密码
psql -U postgres
\password postgres
```
## 下一步
安装完成后,启动服务:
```bash
python -m app.main
```
访问 http://localhost:8080/admin 查看管理后台