• Windows安装PostgreSQL数据库 无法初始化数据库问题


    背景

    由于项目的需要,使用PostgreSQL数据库,因此在Windows上安装PostgreSQL数据库。但是在安装后,无法访问本地数据库,这个时候查看/data目录,没有任何文件。而且安装过程中,弹出提示框

    Problem running post-install step.Installation may not complete correctly the database cluster initialisation failed.
    意思是:安装过程中,初始化数据库集群失败

    系统环境

    • 操作系统:Windows 10 Pro
    • PostgreSQL版本:10.4-1
    • 账号:非超级管理员账号

    原因

    在Windows 10中,如果用的是Microsoft账号,则不是超级管理员,这个时候无法创建用户,导致通过安装包进行安装时,无法创建相应的DB用户。而且在账号中无法看到postgres这个用户,因此可猜测出,权限不足时,无法创建相应用户的账号,而无相应账号时,无法初始化DB。

    解决方案

    查看用户

    net  user
    

    创建Postgres用户

    net user postgres postgres /add
    

    在数据库根目录建立data目录

    D:DevPostgreSQL10>md data
    

    移除超级管理员对data目录的权限

    D:DevPostgreSQL10>cacls data /e /t /r administrator
    处理目录:D:DevPostgreSQL10data
    

    将data目录的权限赋给postgres用户

    D:DevPostgreSQL10>cacls data /e /t /r postgres:C
    处理目录:D:DevPostgreSQL10data
    

    初始化数据库

    D:DevPostgreSQL10in>initdb.exe -D ../data -E UTF-8 --locale=chs -U postgres -W
    

    初始化后,需要输入新的用户密码,用于登录数据库。

    启动数据库

    D:DevPostgreSQL10in>pg_ctl.exe -D D:DevPostgreSQL10data -l logfile start
    

    注册PostgresSQL服务

    D:DevPostgreSQL10in>pg_ctl.exe register -N PostgreSQL -D D:DevPostgreSQL10data
    

    常用命令

    启动PostgresSQL服务

    net start PostgreSQL
    

    停止PostgresSQL服务

    net stop PostgreSQL
    

    删除PostgresSQL服务

    D:DevPostgreSQL10in>pg_ctl.exe unregister -N PostgreSQL
    
  • 相关阅读:
    Jenkins与Hudson的关系
    Jenkins企业版与CloudBees
    NSLookup命令
    XCopy提示“访问遭到拒绝”问题解决
    npm配置文件
    npm下载包时代理配置
    Jenkins实现测试环境到生产环境一键部署(Windows)
    可能是迄今为止最好的GitHub代码浏览插件--赞
    Ali OSS服务端签名直传并设置上传回调
    导入https证书
  • 原文地址:https://www.cnblogs.com/jianxuanbing/p/9160896.html
Copyright © 2020-2023  润新知