ubicloud/rhizome/postgres/lib/postgres_setup.rb
shikharbhardwaj f1b2414954 Make PG run with unified image
For major version upgrades, we change the boot image to allow running
multiple versions of PG simultaneously. For this, we only **download**
the relevant packages for all supported PG versions at image generation
time. Additionally, the image generation step places the required
package list as text files at
/usr/local/share/postgresql/packages/#{version}.txt,common.txt.

While initializing a new server, we install the
required packages by referring to the package list. With the download
already completed at image generation time, this step should be fairly
quick to allow for quick startup and upgrades. For rolling out this
change , we need to ensure all older servers have these files in place.
2025-09-23 20:59:30 +02:00

29 lines
829 B
Ruby

# frozen_string_literal: true
require_relative "../../common/lib/util"
require "logger"
class PostgresSetup
def initialize(version)
@version = version
end
def install_packages
r "sudo apt-get -y install $(cat /usr/local/share/postgresql/packages/#{@version}.txt | tr \"\n\" \"\")"
r "sudo apt-get -y install $(cat /usr/local/share/postgresql/packages/common.txt | tr \"\n\" \"\")"
end
def setup_data_directory
r "chown postgres /dat"
# Below commands are required for idempotency
r "rm -rf /dat/#{@version}"
r "rm -rf /etc/postgresql/#{@version}"
r "echo \"data_directory = '/dat/#{@version}/data'\" | sudo tee /etc/postgresql-common/createcluster.d/data-dir.conf"
end
def create_cluster
r "pg_createcluster #{@version} main --port=5432 --start --locale=C.UTF8"
end
end