我正在尝试在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;
到我的/etc/nixos/configuration.nix
配置文件。
我还按照example configuration中的建议添加了postgres身份验证,因此我的/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
'';
答案 0 :(得分:1)
在NixOS中初始化数据库 cluster 时(使用postgres&#39; initdb),数据库超级用户设置为 root 而不是默认的 postgres < / em>的。所以psql -U root
应该做到这一点。