PostgreSQL创建新实例并指定目录
PostgreSQL创建新实例并指定目录
- initdb
- 命名参数说明
- 注册新实例到windows服务
- 命名参数说明
- 启动服务
initdb
进入PostgreSQL下的bin目录,管理员运行cmd,输入下面的命令
initdb -D "D:\PG\17\data" -E UTF8 --locale=chs -U postgres -W --auth-local=scram-sha-256 --auth-host=scram-sha-256
命名参数说明
-D "D:\PG\17\data":指定新实例的数据目录路径
-E UTF8:设置数据库编码为 UTF-8(中间不要有空格)
--locale=chs:设置本地化语言为中文(简体)
-U postgres:指定超级用户名为 "postgres"
-W:强制在初始化时设置超级用户密码
--auth-local=scram-sha-256:本地连接使用密码认证
--auth-host=scram-sha-256:远程连接使用密码认证
注册新实例到windows服务
pg_ctl register -N "postgresql-x64-17-1710" -D "D:\PG\db17\data"
命名参数说明
-N "postgresql-x64-17-1710":服务名
-D "D:\PG\db17\data":实例数据路径
启动服务
net start postgresql-x64-17-1710