mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-09 00:01:59 +08:00
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.
29 lines
799 B
Ruby
29 lines
799 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 "xargs -a /usr/local/share/postgresql/packages/#{@version}.txt sudo apt-get -y install"
|
|
r "xargs -a /usr/local/share/postgresql/packages/common.txt sudo apt-get -y install"
|
|
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
|