mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-11-28 16:40:27 +08:00
We are working on a solution to set overcommit_ratio or overcommit_kb based on the instance memory size. Until that is ready, this is a temporary fix because overcommit_ratio=80 is too restrictive.
41 lines
1.3 KiB
Ruby
41 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../../common/lib/util"
|
|
require "logger"
|
|
|
|
class PostgresSetup
|
|
def initialize(version)
|
|
@version = version
|
|
end
|
|
|
|
def install_packages
|
|
# Check if the package list exist before installing packages, as Lantern
|
|
# images do not have a packages list and have the packages pre installed.
|
|
if File.exist?("/usr/local/share/postgresql/packages/#{@version}.txt")
|
|
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
|
|
end
|
|
|
|
def configure_memory_overcommit
|
|
r "sudo sysctl -w vm.overcommit_memory=2"
|
|
r "echo 'vm.overcommit_memory=2' | sudo tee -a /etc/sysctl.conf"
|
|
|
|
r "sudo sysctl -w vm.overcommit_ratio=150"
|
|
r "echo 'vm.overcommit_ratio=150' | sudo tee -a /etc/sysctl.conf"
|
|
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
|