mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-11-28 16:40:27 +08:00
When OOM killer kills one of the PostgreSQL processes, there is risk of process leaving the shared memory in an inconsistent state. To prevent this, when one of its processes is killed, postmaster intentionally crashes itself and then performs crash recovery on the next startup. This is required to ensure data consistency. Still, it is not a good experience to have PostgreSQL crash due to OOM killer, so we configure memory overcommit to be strict.
37 lines
1.3 KiB
Ruby
Executable file
37 lines
1.3 KiB
Ruby
Executable file
#!/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require_relative "../../common/lib/util"
|
|
require_relative "../lib/postgres_setup"
|
|
|
|
if ARGV.count != 2
|
|
fail "Wrong number of arguments. Expected 2, Given #{ARGV.count}"
|
|
end
|
|
|
|
v = ARGV[0]
|
|
backup_label = ARGV[1]
|
|
|
|
pg_setup = PostgresSetup.new(v)
|
|
pg_setup.install_packages
|
|
pg_setup.configure_memory_overcommit
|
|
pg_setup.setup_data_directory
|
|
|
|
r "sudo -u postgres wal-g backup-fetch /dat/#{v}/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/#{v}/data/pg_ident.conf"
|
|
r "sudo -u postgres touch /dat/#{v}/data/pg_hba.conf"
|
|
r "sudo -u postgres touch /dat/#{v}/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/#{v}/data/standby.signal"
|
|
else
|
|
r "sudo -u postgres touch /dat/#{v}/data/recovery.signal"
|
|
end
|
|
r "pg_createcluster #{v} main"
|