NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.81k stars 13.91k forks source link

sqitchPg does not work with SCRAM authentication for PostgreSQL #72781

Closed datafoo closed 10 months ago

datafoo commented 4 years ago

I am trying to use sqitchPg (Sqitch with PostgreSQL). When I initialize my PostgreSQL cluster with initdb --auth=scram-sha-256 then Sqitch does not work and displays:

SCRAM authentication requires libpq version 10 or above

It works correctly when I initialize my PostgreSQL cluster with initdb --auth=md5.

To Reproduce

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
  inherit (lib) optional optionals;

  postgresql = postgresql_11.withPackages (ps: [
    ps.pgtap
  ]);

  vscodeWithExtension = vscode-with-extensions.override {
    # When the extension is already available in the default extensions set.
    vscodeExtensions = with vscode-extensions; [
      bbenoist.Nix
    ];
  };
in

mkShell {
  buildInputs = [
      git
      postgresql
      perlPackages.TAPParserSourceHandlerpgTAP
      sqitchPg
      pgadmin
      vscodeWithExtension
    ]
    ++ optional stdenv.isLinux libnotify # For ExUnit Notifier on Linux.
    ++ optional stdenv.isLinux inotify-tools # For file_system on Linux.
    ++ optional stdenv.isDarwin terminal-notifier # For ExUnit Notifier on macOS.
    ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
      # For file_system on macOS.
      CoreFoundation
      CoreServices
    ]);

  # Set up PostgreSQL cluster in the project diretory.
  shellHook = ''
    export PGDATA=$PWD/pgsql/data
    export PGHOST=localhost
    export PGUSER=postgres
    local PGPASSWORD=postgres
    local SOCKET_DIR=$PWD/pgsql/socket
    local LOG_DIR=$PWD/pgsql/log
    if [ ! -d $PGDATA ]; then
      echo "Initializing PostgreSQL cluster…"
      initdb --auth=scram-sha-256 --pgdata=$PGDATA --encoding=UTF-8 --no-locale --username=$PGUSER --pwfile=<(echo "$PGPASSWORD") >/dev/null
      # initdb --auth=md5 --pgdata=$PGDATA --encoding=UTF-8 --no-locale --username=$PGUSER --pwfile=<(echo "$PGPASSWORD") >/dev/null
      local CONF_PATH=$PGDATA/postgresql.conf
      echo "unix_socket_directories = '$SOCKET_DIR'" >> $CONF_PATH
      echo "listen_addresses = '*'" >> $CONF_PATH
      echo "logging_collector = on" >> $CONF_PATH
      echo "log_directory = '$LOG_DIR'" >> $CONF_PATH
      echo "log_min_messages = debug1" >> $CONF_PATH
      echo "log_connections = on" >> $CONF_PATH
      echo "log_disconnections = on" >> $CONF_PATH
      echo "log_statement = 'all'" >> $CONF_PATH
    fi
    if [ ! -d $SOCKET_DIR ]; then
      mkdir -p $SOCKET_DIR
    fi
    if [ ! -d $LOG_DIR ]; then
      mkdir -p $LOG_DIR
    fi
    export PG_LOG_PATH=$LOG_DIR/pg_ctl.log
    echo -e 'Start PostgreSQL by running:\n\tpg_ctl start -l $PG_LOG_PATH'
  '';
}
[core]
    engine = pg
[deploy]
    verify = true
[rebase]
    verify = true
[engine "pg"]
    target = local_test
[target "local_test"]
    uri = db:pg://localhost:5432/
stale[bot] commented 4 years ago

Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on irc.freenode.net.