ubicloud/rhizome/postgres/bin/initialize-database-from-backup
Burak Yucesoy daecad9b53 PostgreSQL HA standby set up
We are introducing new parameter for PostgresResource.assemble; ha_status, and
depending on its value we configure sync or async (or no) replication. If sync
replication is specified, we create 2 standbys and require acknowledgement from
at least one of them. If async replication is specified, we create 1 standby.
2024-02-15 14:19:35 +01:00

36 lines
1.2 KiB
Ruby
Executable file

#!/bin/env ruby
# frozen_string_literal: true
require_relative "../../common/lib/util"
if ARGV.count != 1
fail "Wrong number of arguments. Expected 1, Given #{ARGV.count}"
end
backup_label = ARGV[0]
r "chown postgres /dat"
# Below commands are required for idempotency
r "rm -rf /dat/16"
r "rm -rf /etc/postgresql/16"
r "sudo -u postgres wal-g backup-fetch /dat/16/data #{backup_label} --config /etc/postgresql/wal-g.env"
# We want to use pg_createcluster, even with an existing database folder because
# pg_createcluster does additonal things like configuring systemd. However, it
# also expect to see .conf files in the data directory, so that it can move them
# to /etc/postgresql/$VERSION/main. Thus we create a bunch of .conf files.
r "sudo -u postgres touch /dat/16/data/pg_ident.conf"
r "sudo -u postgres touch /dat/16/data/pg_hba.conf"
r "sudo -u postgres touch /dat/16/data/postgresql.conf"
# Technically LATEST label can be used for PITR as well, but we use the label
# name from backups in PITR case. So backup_label can be used to decide on
# which signal file to use.
if backup_label == "LATEST"
r "sudo -u postgres touch /dat/16/data/standby.signal"
else
r "sudo -u postgres touch /dat/16/data/recovery.signal"
end
r "pg_createcluster 16 main"