环境进入操作目录mkdir data输入超级用户密码初始化数据库bin\initdb.exe -D data -U postgres -E UTF8 --localeC -W开启服务bin\pg_ctl.exe -D data start修改data\pg_hba.conf找到这一行host all all 127.0.0.1/32 md5改成host all all 127.0.0.1/32 trust重启bin\pg_ctl.exe -D data restart打开数据库操作终端这行命令 设置了一个环境变量其作用是告知 psql 命令行工具使用 postgres 作为数据库的 密码。set PGPASSWORDpostgresbin\psql.exe -h localhost -U postgres -c SELECT version();ALTER USER修改数据库用户的属性。postgres指定要修改的数据库用户这里是 postgres 用户。WITH PASSWORD postgres指定新的密码为 postgres。这条命令的效果是将 PostgreSQL 用户 postgres 的密码更改为 postgres。bin\psql.exe -U postgres -c ALTER USER postgres WITH PASSWORD postgres;用来 重新加载 PostgreSQL 配置文件bin\pg_ctl.exe -D data reload停止服务bin\pg_ctl.exe -D data stop需要设置全局变量1、setx PGDATA D:\software\postgresql\pgsql\data否则2、pg_ctl start -D D:\software\postgresql\pgsql\data以后启动服务只需要pg_ctl start另一种方法你每次都手动启动很麻烦建议 直接把 PostgreSQL 注册成服务pg_ctl register -N PostgreSQL -D D:\software\postgresql\pgsql\data net start PostgreSQL以后直接net start PostgreSQL