我试图在NixOS上使用postgresql,在运行$ psql -U postgres
$ psql -U postgres
psql: FATAL: role "postgres" does not exist
当使用默认用户(我的用户名)运行
$ psql
时,我也会遇到类似的错误。看来我的postgres安装没有可以用来创建其他角色或运行任何命令的角色。如何为postgres用户创建角色以便发出命令?
我已经安装了带有
$ nix-env -i postgres
的postgres,并按照NixOS manual配置,添加services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql94;
到我的配置文件。
我还添加了postgres身份验证,如本example configuration所示,因此我的
/etc/nixos/configuration.nix
文件的postgresql行看起来像 # postgres
services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql94;
services.postgresql.authentication = lib.mkForce ''
# Generated file; do not edit!
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
'';
最佳答案
在NixOS中,当初始化数据库集群时(使用postgres的initdb),数据库超级用户被设置为root,而不是默认的postgres。所以psql -U root
应该起作用。
关于postgresql - NixOS错误:psql:致命:角色“postgres”不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45122893/