【PostgreSQL】Windows安装教程

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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

太空眼睛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值