Postgres Node Setup

Hardware Configuration

Make sure that the node's partition doesn't have any RAID configured. By default, OVHcloud uses RAID 1 (Mirroring), which will basically cut your write performance in half in the case of two disks since every write operation must be completed on both disks. In Kubernetes, nodes are ephemeral, so treat them as ephemeral.

Sample Terraform code for the OS installation:

resource "ovh_dedicated_server_reinstall_task" "server_install_two" {
  service_name = ovh_dedicated_server.postgres_two.service_name
  os           = "ubuntu2404-server_64"
  customizations {
    hostname                 = "postgres-two"
    ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCVyMY0kkW2GyoMCx47nJ+/ClYrztaL8euOKaEUWKUOnfnHYGKIhc9MksQreEdjogJiamtlrXSayM+P3oHZ0ZXuPifWJ7Cc4/wKi6vTvpPrAyvTCvt24z1Ff8jCwrsayorjK4riXtthwLWWSZkudUDiH4oQboOPMUmJOOjZvjJvQtY4aRJFOgiUdpeHyNTDWOPEYQwGnL1Zapre8E/+rvydbWnyNRVAO7/jdCiXT2B8hlui9yoixPD9u7/TjPDgF+n1UIj3UVnv4E6N0f8gFcy7JfF1ga3pDCUNaW38LYsvms2M+sLzgx2B/Rc7ZQ6dDHRv7jOQXQNfWgoSTNYJCSYK9RqyJ/F3x0dekfafo5+//lAsMFXxjhdG0/nwVZ7rO/N/2d8N0RD2wt+zi0vOQ0wpHCDXy7HIvcqtzdmJVv2freCE84hqYNxROcylhAQ3QxeMx2h4SerJJXGQvke9En5qOSW24Y4WPNEXgJq5TbyX86EptJb9QU2GILKJJQoEIw3EHQ68O/N8ZCx2cp6/cwzQ9Vw+iVGSs5e519JDiw/9Pf57jZuyiCF30JhhL3hFEtLuy8pUcruuclPs+jAhT6dxOabGntO80agQ85jgENaznjO+Yks+x57yZi2U4HUbAKbUwBQCSBhkEAr2DPZhu6VjKmey/9OwxA6efLg27aigJw== sibi@hask"
  }
  storage {
    disk_group_id = 1
    partitioning {
      disks = 1
      layout {
        file_system = "ext4"
        mount_point = "/boot"
        raid_level = 0
        size = 1024
      }
      layout {
        file_system = "swap"
        mount_point = "swap"
        size        = 2048
      }
      layout {
        file_system = "ext4"
        mount_point = "/"
        raid_level = 0
        size = 0
      }
    }
  }
}

Apply appropriate node labels and taints based on your k3s cluster setup.

Partition Volumes

Motivation: Formatting block devices to be used for Postgres data storage.

First, check the current status of block devices:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
nvme2n1     259:0    0 894.3G  0 disk
nvme0n1     259:1    0 894.3G  0 disk
├─nvme0n1p1 259:2    0   511M  0 part /boot/efi
├─nvme0n1p2 259:3    0     1G  0 part /boot
├─nvme0n1p3 259:4    0     2G  0 part [SWAP]
├─nvme0n1p4 259:5    0 890.7G  0 part /
└─nvme0n1p5 259:6    0     2M  0 part
nvme1n1     259:7    0 894.3G  0 disk
nvme3n1     259:8    0 894.3G  0 disk

From this output, we know that we have to format these block devices:

  • nvme2n1
  • nvme1n1
  • nvme3n1

Here is a plan for how we might want to map the partitions to mount points:

PartitionNameMount pointNotes
nvme2n1pg-data/mnt/pg-data
nvme1n1pg-wal/mnt/pg-wal
nvme3n1pg-whole-one/mnt/pg-oneFor both data and wal storage

Partition Device

Let's assume we want to format the device nvme2n1. These are the steps:

Open the fdisk prompt for the target device:

sudo fdisk /dev/nvme2n1

Inside the fdisk prompt, enter the following commands:

  • g - Create a new empty GPT partition table.
  • n - Create a new partition. Press Enter to accept the defaults for partition number, first sector, and last sector (this will use the whole disk).
  • w - Write the changes to the disk and exit.

After writing changes, find the partition number from lsblk:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
nvme2n1     259:0    0 894.3G  0 disk
└─nvme2n1p1 259:9    0 894.3G  0 part
nvme0n1     259:1    0 894.3G  0 disk
├─nvme0n1p1 259:2    0   511M  0 part /boot/efi
├─nvme0n1p2 259:3    0     1G  0 part /boot
├─nvme0n1p3 259:4    0     2G  0 part [SWAP]
├─nvme0n1p4 259:5    0 890.7G  0 part /
└─nvme0n1p5 259:6    0     2M  0 part
nvme1n1     259:7    0 894.3G  0 disk
nvme3n1     259:8    0 894.3G  0 disk

Format the new partition as ext4:

sudo mkfs.ext4 /dev/nvme2n1p1

Create Mount Point

Note that the mount point changes based on its intended purpose. For example, to create a mount point for pg-data:

sudo mkdir -p /mnt/pg-data

Or to create mount points for WAL or a whole-disk storage volume:

sudo mkdir -p /mnt/pg-wal
sudo mkdir -p /mnt/pg-one

Make Mount Permanent

Find the UUID of the formatted partition:

sudo blkid /dev/nvme2n1p1

Example Output:

/dev/nvme2n1p1: UUID="bfd67316-8028-4e46-ac5c-a1b6f3a8296f" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="afcc0e41-1500-48ba-b086-e6c26656af11"

Take a backup of the original fstab file:

sudo cp -v /etc/fstab /etc/fstab.bak

Edit the fstab file to add the mount:

sudo env TERM=xterm nano /etc/fstab

And add the mount entry at the end of the file, using the UUID from earlier:

UUID=bfd67316-8028-4e46-ac5c-a1b6f3a8296f       /mnt/pg-data  ext4  defaults  0  2

Test the new fstab entries to ensure there are no errors:

sudo systemctl daemon-reload
sudo mount -a
lsblk

See if the partition is successfully mounted by verifying the MOUNTPOINTS column in the lsblk output.