【问题标题】:NixOS error: psql: FATAL: role "postgres" does not existNixOS 错误:psql:致命:角色“postgres”不存在
【发布时间】:2017-12-20 17:32:42
【问题描述】:

我尝试在 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
    '';

【问题讨论】:

    标签: postgresql configuration nixos


    【解决方案1】:

    在 NixOS 中,当初始化数据库 cluster(使用 postgres 的 initdb)时,数据库超级用户设置为 root 而不是默认的 postgres。所以psql -U root 应该可以解决问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-24
    • 2015-03-28
    • 2021-01-07
    • 2021-03-21
    • 2018-02-18
    • 1970-01-01
    相关资源
    最近更新 更多