Search code examples
postgresqlwalpatroni

wal-g backup-push tries to use wrong database


When trying to use wal-g with Patroni, I've got the following configuration as the Postgres section of patroni.yml:

postgresql:
  use_pg_rewind: true
  use_slots: true
  parameters:
    wal_level: logical
    hot_standby: "on"
    wal_keep_segments: 8
    max_wal_senders: 8
    max_replication_slots: 8
    checkpoint_timeout: 30
    archive_mode: "on"
    archive_command: PGUSER=dba PGPASSWORD=xx WALG_FILE_PREFIX=file://localhost/backup-disk/ wal-g wal-push "%p"
  recovery_conf:
    restore_command: PGUSER=dba PGPASSWORD=xx WALG_FILE_PREFIX=file://localhost/backup-disk/ wal-g wal-fetch "%f" "%p"

However if I then try to create a backup using PGHOST=/var/run/postgresql PGUSER=dba PGPASSWORD=xx envdir /data/conf/wal-e.env wal-g backup-push /data/postgresql/current, it tries to connect to the dba database which doesn't exist:

INFO:  Doing full backup.
ERROR: Connect: postgres connection failed: FATAL: database "dba" does not exist (SQLSTATE 3D000)

From the wal-g docs and searching, it's not obvious why this is not the case, so in an attempt to make things more discoverable I'm asking the question.


Solution

  • The answer turned out to be quite simple once I checked out the WAL-G source code and found that examples of their environment config for their tests contained the following setting:

    PGDATABASE=postgres
    

    So to have a backup apparently work, I now have the following:

    PGDATABASE=postgres PGHOST=/var/run/postgresql PGUSER=dba PGPASSWORD=xx WALG_FILE_PREFIX=file://localhost/backup-disk/ wal-g backup-push /data/postgresql/current
    

    This creates the expected files in /backup-disk/, so now all I need to do is sort out scheduling some backups of the correct database.