当我在 Windows 10 上运行命令
pg restart
时,出现以下错误:
pg_ctl: no database directory specified and environment variable PGDATA unset
为什么?怎么解决?
您需要指定数据库目录安装到哪里。
例如
pg_ctl restart -D [insert directory location here]
如果失败,您将需要设置环境变量 PGDATA。 类似于
set $PGDATA = [directory location here]
您需要设置一个环境变量来指向您的数据库目录所在的位置, 例如:
setx PGDATA D:\Program Files\PostgreSQL\13\data
在 MacOS 中
$ sudo -u postgres
$ ps -f -u postgres # should list postgres processes
$./pg_ctl -D /Library/PostgreSQL/13/data restart
作为最后的手段,您也可以尝试重新安装:
brew services stop postgres
brew uninstall --force postgres
brew install postgresql
brew services start postgres