Iaroslav Kozlov Русский

Databases Deep dive

Deploying Greenplum 6 with Ansible

A Greenplum 6 cluster rolled out by Ansible in two layers. The first prepares every host in the same way and can be run again at any time. The second initialises the cluster once, on the master, and is guarded so that a second run cannot touch it. The last play asks the cluster itself whether it is healthy.

My part

  • I automated the Greenplum 6 rollout with Ansible: a cluster is rolled out by a playbook, not by hand.
  • For the same cluster I automated LDAP authentication: users were put into LDAP groups by department, and the TLS certificates were issued by the admins.

Architecture

A generalised layout from the Greenplum 6 installation guide and the Ansible documentation. Two segment hosts are an example: the numbers of hosts and segments of a real site are not shown. Greenplum 6 calls the first host the master; from version 7 it is the coordinator.

data control

Step by step

  1. Ansible prepares every host over SSH: kernel parameters, limits, XFS mounts, the gpadmin user, the package, time synchronisation. The play is idempotent: a second run reports no change.
  2. On the master, as gpadmin: SSH keys are exchanged between all hosts, disks and network are measured with gpcheckperf, and gpinitsystem creates the master, the primary segments and their mirrors from one templated config.
  3. Each primary segment replicates to its mirror, which always sits on another host.
  4. The standby follows the master by transaction-log replication.
  5. The last play runs gpstate and a query, and fails if a segment is down, out of sync or not in its preferred role.

Point at a step and its path lights up on the diagram.

Components

Ansible
Holds the inventory grouped by role (master, standby, segments) and the roles: host preparation, package, initialisation, verification.
Master
The entry point for clients. Holds the global catalog and no user data, plans queries and hands the work to the segments.
Standby
A copy of the master kept current by transaction-log replication. An administrator promotes it; it does not take over by itself.
Primaries
Primary segments of the first host: independent PostgreSQL instances, each holding a slice of the data and doing most of the query work.
Mirrors
Mirrors that the first host keeps for the primaries of the second one.
Primaries
Primary segments of the second host.
Mirrors
Mirrors that the second host keeps for the primaries of the first. A mirror never shares a host with its primary.

Decisions

  • Two layers: repeatable and one-time

    Host preparation is done with modules that hold state (sysctl, mount, pam_limits, user), so a repeat run changes nothing. gpinitsystem is not idempotent, so it runs once and behind a guard: for example, the task is skipped when the master data directory already exists. 2 9

  • Kernel settings from the host's own memory

    shmall and shmmax are computed from the number of physical pages, not copied from an example. The vm.dirty settings differ above and below 64 GB of RAM, and min_free_kbytes is about three per cent of memory. The role takes all of it from the facts of each host. 1

  • What must survive a reboot is made persistent

    Read-ahead of 16384 set with blockdev is gone after a restart, and switching transparent huge pages off needs one. So read-ahead gets a persistent mechanism, the XFS options live in fstab, and the role calls a reboot handler when it has changed something that needs it. 1 6

  • The hardware is measured before there is data

    gpcheckperf tests disks, memory bandwidth and the network between hosts before initialisation. Its disk test writes a file twice the size of RAM into the data directories, so it belongs before the first table, not after. 4

  • Config and host files come from the inventory

    The number of DATA_DIRECTORY entries is the number of segments per host, and there are as many mirror directories. Segment ports stay outside the range the kernel hands to outgoing connections. Mirrors go to other hosts; spread placement is allowed only when there are more hosts than segments per host. 2 31

  • Batches, and a check that can fail

    Preparation goes through the hosts in batches (serial) with a limit on failures, so one bad host stops the rollout instead of spreading. The result of gpstate is not printed for a human to read: it is an assert, and the play fails on it. 8 5

Where it breaks

  • gpinitsystem cannot simply be run again

    After a failure it leaves a backout script in ~/gpAdminLogs that has to be run before a retry. A playbook that blindly repeats the step risks a half-built cluster. 2

  • run_once under serial runs once per batch

    A step meant to happen once for the whole cluster is repeated for every batch of hosts. And ignore_errors does not cover an unreachable host or an undefined variable. 8 11

  • A clean --check proves little

    The command module reports correctly in check mode only when it is given creates or removes, and tasks that depend on the result of a skipped task say nothing. A dry run validates the preparation layer, not the cluster steps. 9 10

  • Sized for the healthy case

    When a host dies, its mirrors on the neighbours become primaries, and those hosts run more segments than on a good day. Memory limits are computed from that number: overestimating what a host can carry is a common cause of poor performance. 6

  • An address changed after initialisation

    A cluster initialised with IP addresses loses its mirror replication when an address changes; one initialised with host names is stopped before a name is pointed at another address. Hosts get stable, resolvable names before the cluster exists. 3

  • gpstate on a stopped cluster reads a stale file

    With the cluster down it shows a saved dump, which is not updated in real time. Its output then cannot be the condition for passing the verification. 5

What to check

  • gpstate -e lists no problem pairs: nothing down, out of sync or out of its preferred role.
  • gpstate -f shows the standby master in sync.
  • A second run of the preparation play reports zero changes.
  • ulimit -u for gpadmin gives the configured value: a file in limits.d can quietly override it.
  • After a segment host reboots, read-ahead, huge pages and mounts are still as configured.

Next deep dive

Greenplum backups to S3

WAL-G backups of a Greenplum cluster to MinIO: base backups, continuous WAL archiving, restore points, retention as a dry run, object lock and restore tests.

Read Databases