PostgreSQL Server下载
- 官网下载页面:
https://www.postgresql.org/download/
EDB下
载页面:https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
15.3
版本下载地址:https://get.enterprisedb.com/postgresql/postgresql-15.3-2-windows-x64.exe
安装PostgreSQL Server
- 运行安装程序,根据提示一步步安装
- 安装过程会提示设置密码:
123456
- 假设安装的位置在:
D:\ProgramFiles\PostgreSQL\15
- 进入
bin
目录:cd D:\ProgramFiles\PostgreSQL\15\bin
- 初始化数据库:
initdb -D "D:\ProgramFiles\PostgreSQL\15\data" -E UTF8 -U postgres --locale="Chinese (Simplified)_China.936" --lc-messages="Chinese_China.936" -A scram-sha-256 -W
- 启动:
pg_ctl -D "D:\ProgramFiles\PostgreSQL\15\data" start
- 停止:
pg_ctl -D "D:\ProgramFiles\PostgreSQL\15\data" stop
- 注册Windows服务:
pg_ctl.exe register -D "D:\ProgramFiles\PostgreSQL\15\data" -PostgreSQL
- 默认情况下 PostgreSQL 数据库只能本机连接,我们调整为监听所有 IP 开启外部连接的功能
- 在
D:\ProgramFiles\PostgreSQL\15\data
文件夹中找到postgresql.conf
- 找到
#listen_addresses = 'localhost'
- 增加一行:
listen_addresses = '*'
- 在
D:\ProgramFiles\PostgreSQL\15\data
文件夹中找到pg_hba.conf
,参考下面修改
# IPv4 local connections: #host all all 127.0.0.1/32 scram-sha-256 host all all 0.0.0.0/0 scram-sha-256 # IPv6 local connections: #host all all ::1/128 scram-sha-256 host all all ::/0 scram-sha-256
- 在
- 通过Windows服务启动:
net start PostgreSQL
- 通过Windows服务停止:
net stop PostgreSQL
- 卸载Windows服务:
pg_ctl.exe unregister -PostgreSQL