无法在unix - shell中安装Postgres



我正在使用nix-shell管理的Phoenix/Elixir项目。我有关于postgres设置的问题。

我正在使用pg_ctl -D $PGDATA start启动服务器,它输出为:

pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....2021-09-01 19:19:00.780 PKT [72367] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2021-09-01 19:19:00.784 PKT [72367] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-09-01 19:19:00.806 PKT [72369] LOG:  database system was interrupted; last known up at 2021-09-01 19:14:57 PKT
2021-09-01 19:19:00.848 PKT [72369] LOG:  database system was not properly shut down; automatic recovery in progress
2021-09-01 19:19:00.849 PKT [72369] LOG:  redo starts at 0/16D84A0
2021-09-01 19:19:00.849 PKT [72369] LOG:  invalid record length at 0/16D8580: wanted 24, got 0
2021-09-01 19:19:00.849 PKT [72369] LOG:  redo done at 0/16D8548
2021-09-01 19:19:00.862 PKT [72367] LOG:  database system is ready to accept connections
done
server started

当我在unix -shell环境中执行createuser postgres --createdb --echo时,即使运行目录存在,也会产生以下错误:

createuser: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"?

没有其他postgres实例正在运行。pg_hba.conf中auth方法设置为trust

设置unix_socket_directories/tmp

shell.nix看起来像

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
inherit (lib) optional optionals;
elixir = beam.packages.erlangR22.elixir_1_10;
postgresql = postgresql_11;
in
mkShell {
buildInputs = [
ps
elixir
coreutils
which
git
postgresql
redis
doxygen
mongodb-tools
redis-dump
(python37.withPackages(ps: with ps; [ credstash awscli ]))
cmake
nix-prefetch-git
zlib
jq
teleport
]);
# Fix GLIBC Locale
LOCALE_ARCHIVE = lib.optionalString stdenv.isLinux
"${pkgs.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
# Put the PostgreSQL and Redis databases in the project diretory.
PGDATA="./.db/postgres";
RDDATA="./.db/redis";
shellHook = ''
ERL_INCLUDE_PATH="${erlangR22}/lib/erlang/usr/include";
}

我对Nix完全是个新手,不知道如何使用它。如有任何帮助,我将不胜感激。

您必须告诉createuser通过/tmp中的套接字进行连接:

createuser -h /tmp -U postgres --createdb --echo newuser

您已经在postgres配置中设置了自定义路径,因此您可能还需要在pqsl/createuser中指定该路径。也就是createuser -h /tmp/ ....

最新更新