2017-07-15 74 views
0

我試圖在NixOS使用PostgreSQL,面對下面的錯誤,我收到了類似的錯誤,當只運行$ psql ,使用默認用戶(我的用戶名)。看來我的postgres安裝沒有可用於創建其他角色或運行任何命令的角色。

如何爲我的postgres用戶創建一個角色,以便我可以發出命令?

我已經安裝postgres的與$ nix-env -i postgres和根據NixOS manual配置,加入

services.postgresql.enable = true; 
services.postgresql.package = pkgs.postgresql94; 

到我/etc/nixos/configuration.nix配置文件。

我還添加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 
    ''; 

回答

1

在NixOS當數據庫集羣被初始化(使用Postgres的initdb的)的數據庫超級用戶設置爲根目錄而不是默認的postgres。所以psql -U root應該做的伎倆。

+0

我還推薦閱讀NixOS手冊中的postgresql部分https://nixos.org/nixos/manual/index.html#module-postgresql – iElectric

+1

請注意,這不會再發生在stateVersion> = 17.09的系統上,其中'postgres '現在是默認的超級用戶。 – danbst

相關問題