{"id":26237955,"url":"https://github.com/tom-sato/ansible-postgresql-cluster","last_synced_at":"2025-04-22T22:24:17.933Z","repository":{"id":199577242,"uuid":"335322590","full_name":"tom-sato/ansible-postgresql-cluster","owner":"tom-sato","description":"Ansible playbooks that set up various PostgreSQL clusters for testing, such as streaming replication, Pgpool-II, Pacemaker and DRBD.","archived":false,"fork":false,"pushed_at":"2025-03-08T07:06:43.000Z","size":125,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T19:22:55.154Z","etag":null,"topics":["ansible","drbd","pacemaker","paf","pgpool-ii","pgpool2","postgresql","repmgr"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tom-sato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-02T14:49:16.000Z","updated_at":"2025-03-21T22:19:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"7340c69e-42f6-4c8c-a4c2-006883634ca6","html_url":"https://github.com/tom-sato/ansible-postgresql-cluster","commit_stats":null,"previous_names":["tom-sato/ansible-postgresql-cluster"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sato%2Fansible-postgresql-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sato%2Fansible-postgresql-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sato%2Fansible-postgresql-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sato%2Fansible-postgresql-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tom-sato","download_url":"https://codeload.github.com/tom-sato/ansible-postgresql-cluster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250332681,"owners_count":21413248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","drbd","pacemaker","paf","pgpool-ii","pgpool2","postgresql","repmgr"],"created_at":"2025-03-13T05:31:12.347Z","updated_at":"2025-04-22T22:24:17.905Z","avatar_url":"https://github.com/tom-sato.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Ansible Playbooks for PostgreSQL Clusters\n=========================================\n\nAnsible playbooks that set up various [PostgreSQL](https://www.postgresql.org/) clusters for testing, such as streaming replication, Pgpool-II, Pacemaker and DRBD.\n\nRequirements\n------------\n\nThe requirements are as follow:\n\n* VirtualBox 7.1.x\n* Vagrant 2.4.x\n* Vagrant box\n  * [centos/7](https://app.vagrantup.com/centos/boxes/7)\n  * [rockylinux/8](https://app.vagrantup.com/rockylinux/boxes/8)\n  * [rockylinux/9](https://app.vagrantup.com/rockylinux/boxes/9)\n* Ansible 2.10.x\n\nUsage\n-----\n\nFor example, when setting up a PostgreSQL cluster with Pgpool-II, the usage is as follows:\n\n```ShellSession\n$ git clone https://github.com/tom-sato/ansible-postgresql-cluster.git\n$ cd ansible-postgresql-cluster\n$ PLAYBOOK=pgpool2 vagrant up --provision\n(snip)\nPLAY RECAP *********************************************************************\nnode-1                     : ok=64   changed=47   unreachable=0    failed=0    skipped=28   rescued=0    ignored=0\nnode-2                     : ok=61   changed=44   unreachable=0    failed=0    skipped=31   rescued=0    ignored=0\nnode-3                     : ok=61   changed=44   unreachable=0    failed=0    skipped=31   rescued=0    ignored=0\n\n$ PLAYBOOK=pgpool2 vagrant ssh node-1\n$ sudo su - postgres\n$ psql -c \"SHOW pool_nodes\" -h vip-1 -p 9999\n node_id | hostname | port | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change\n---------+----------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------\n 0       | node-1   | 5432 | up     | 0.333333  | primary | 0          | true              | 0                 |                   |                        | 2021-02-02 23:56:16\n 1       | node-2   | 5432 | up     | 0.333333  | standby | 0          | false             | 0                 | streaming         | async                  | 2021-02-02 23:56:16\n 2       | node-3   | 5432 | up     | 0.333333  | standby | 0          | false             | 0                 | streaming         | async                  | 2021-02-02 23:56:16\n(3 rows)\n\n```\n\nEnvironment Variables\n---------------------\n\nThe `Vagrantfile` file receives the following environment variables:\n\n* `PLAYBOOK` - Specifies the playbook name. The default is `postgresql`. See [here](#user-content-playbooks) for available playbooks.\n* `NUM_NODES` - Specifies the number of nodes. The default is `3` for not using DRBD, and `2` otherwise.\n* `BOX` - Specifies the box name. The default is `centos/8`.\n* `PROXY` - Specifies the proxy to set for the virtual machine. The default is an empty string. The [vagrant-proxyconf](https://github.com/tmatilai/vagrant-proxyconf) plugin should be installed in advance.\n\nPlaybooks\n---------\n\nThe following playbooks are available:\n\n* `postgresql.yml` - Sets up a PostgreSQL cluster with streaming replication.\n* `pgpool2.yml` - Sets up a PostgreSQL cluster with [Pgpool-II](https://www.pgpool.net/).\n* `pacemaker-drbd.yml` - Sets up a PostgreSQL cluster with [Pacemaker](https://clusterlabs.org/pacemaker/) and [DRBD](https://www.linbit.com/drbd/).\n* `pacemaker-replication.yml` - Sets up a PostgreSQL cluster with Pacemaker and streaming replication.\n* `pacemaker-paf.yml` - Sets up a PostgreSQL cluster with Pacemaker and streaming replication using [PAF](https://clusterlabs.github.io/PAF/).\n* `lifekeeper-datakeeper.yml` - Sets up a PostgreSQL cluster with LifeKeeper and DataKeeper.\n* `repmgr.yml` - Sets up a PostgreSQL cluster with [repmgr](https://repmgr.org/). (experimental)\n\nRoles\n-----\n\nEach playbook calls the following roles. Some playbooks overwrite role variables as needed.\n\n### `locale`\n\nConfigures locale settings.\n\n* `locale` - Specifies the locale. The default is `ja_JP.UTF-8`.\n* `keymap` - Specifies the keymap. The default is `jp`.\n* `x11_keymap_layout` - Specifies the X11 keymap layout. The default is `jp`.\n* `x11_keymap_model` - Specifies the X11 keymap model. The default is `jp106`.\n* `timezone` - Specifies the timezone. The default is `Asia/Tokyo`.\n\n### `hosts`\n\nConfigures the `/etc/hosts` file.\n\n* `public_interface` - Specifies the device name of the public interface. The default is `eth1`.\n\n### `postgresql`\n\nSets up PostgreSQL servers.\n\n* `postgresql_version` - Specifies the PostgreSQL version. The default is `13`.\n* `postgresql_data_directory` - Specifies the data directory path. The default is `/var/lib/pgsql/{{ postgresql_version }}/data`.\n* `postgresql_syslog_facility` - Specifies the syslog facility. The default is `LOCAL0`.\n* `postgresql_syslog_file` - Specifies the syslog file path. The default is `/var/log/postgresql-{{ postgresql_version }}`.\n* `postgresql_port` - Specifies the port number. The default is `5432`.\n* `postgresql_password` - Specifies the password for the `postgres` user. The default is `postgres`.\n* `postgresql_auth_method` - Specifies the authentication method for local connections in `pg_hba.conf`. The default is `scram-sha-256` for PostgreSQL 10 or later, and `md5` otherwise.\n* `postgresql_extra_initdb_options` - Specifies extra options for the `initdb` command. The default is `-E UTF8 --locale=C`.\n* `postgresql_extra_config_parameters` - Specifies extra parameters in `postgresql.conf`. The default is an empty string.\n* `postgresql_extra_hba_records` - Specifies extra records in `pg_hba.conf`. The default is to use the authentication method specified by `postgresql_auth_method` for connections from the same network.\n* `postgresql_control_as_service` - Specifies whether to control as a service. The default is `yes`.\n* `postgresql_setup_stage` - Specifies which stage to set up. `install` installs PostgreSQL, `initdb` creates a database cluster, `basebackup` takes a base backup, `write_recovery_conf` writes settings for the standby server. The default is `write_recovery_conf`.\n* `postgresql_primary_hostname` - Specifies the host name of the primary server. The default is the host name of the first node of all.\n* `postgresql_extra_recovery_config_parameters` - Specifies extra parameters for the standby server in `postgresql.auto.conf` for PostgreSQL 12 or later, and in `recovery.conf` otherwise. The default is an empty string.\n* `postgresql_use_rewind` - Specifies whether to use the `pg_rewind` command when following the primary server with Pgpool-II. The default is `no`.\n* `postgresql_use_replication_slot` - Specifies whether to use the replication slot. The default is `yes`.\n\n### `pgpool2`\n\nSets up Pgpool-II servers.\n\n* `pgpool2_version` - Specifies the Pgpool-II version. The default is `4.2`.\n* `pgpool2_syslog_facility` - Specifies the syslog facility. The default is `LOCAL1`.\n* `pgpool2_syslog_file` - Specifies the syslog file path. The default is `/var/log/pgpool2`.\n* `pgpool2_delegate_ip` - Specifies the virtual IP address. The default is an unused IP address in all nodes.\n* `pgpool2_delegate_hostname` - Specifies the host name of the virtual IP address. The default is `vip-1`.\n* `pgpool2_pcp_port` - Specifies the PCP port number. The default is `9898`.\n* `pgpool2_pcp_username` - Specifies the PCP user name. The default is `postgres`.\n* `pgpool2_pcp_password` - Specifies the PCP password. The default is `postgres`.\n* `pgpool2_backend_clustering_mode` - Specifies the backend clustering mode. Valid values are `streaming_replication` (the default), `native_replication`, `snapshot_isolation` (for Pgpool-II 4.2 or later), and `raw`. `logical_replication` and `slony` are not supported.\n* `pgpool2_port` - Specifies the port number. The default is `9999`.\n* `pgpool2_trusted_servers` - Specifies trusted servers separated by commas. The default is the IP address of the default gateway.\n* `pgpool2_wd_port` - Specifies the watchdog port number. The default is `9000`.\n* `pgpool2_heartbeat_port` - Specifies the heartbeat port umber. The default is `9694`.\n* `pgpool2_extra_config_parameters` - Specifies extra parameters in `pgpool.conf`. The default is an empty string.\n* `pgpool2_extra_hba_records` - Specifies extra records in `pool_hba.conf`. The default is to use the authentication method specified by `postgresql_auth_method` for connections from the same network.\n* `pgpool2_encryption_key` - Specifies the encryption key stored in the `~/.pgpoolkey` file. The default is `postgres`.\n\n### `drbd`\n\nSets up a DRBD filesystem.\n\n* `drbd_version` - Specifies the DRBD version. The default is `9.0`.\n* `drbd_disk` - Specifies the disk device path. The default is `/dev/sdb1`.\n* `drbd_resource_name` - Specifies the resource name. The default is `my_resource`.\n* `drbd_device` - Specifies the DRBD device path. The default is `/dev/drbd0`.\n* `drbd_port` - Specifies the port number. The default is `7789`.\n* `drbd_control_as_service` - Specifies whether to control as a service. The default is `no`.\n* `drbd_mount_directory` - Specifies the mount directory path. The default is `/mnt/mirror`.\n* `drbd_fstype` - Specifies the filesystem type. The default is `xfs`.\n* `drbd_primary_hostname` - Specifies the host name of the primary server. The default is the host name of the first node of all.\n\n### `pacemaker`\n\nSets up a Pacemaker cluster.\n\n* `pacemaker_password` - Specifies the password for the `hacluster` user. The default is `hacluster`.\n* `pacemaker_cluster_name` - Specifies the cluster name. The default is `my_cluster`.\n* `pacemaker_migration_threshold` - Specifies the value of the `migration-threshold` attribute. The default is `2`. See the [Resource Meta-Attributes](https://clusterlabs.org/pacemaker/doc/en-US/Pacemaker/2.0/html/Pacemaker_Explained/s-resource-options.html#_resource_meta_attributes) in the Pacemaker Explained for details.\n* `pacemaker_failure_timeout` - Specifies the value of the `failure-timeout` attribute. The default is `60s`. See the [Resource Meta-Attributes](https://clusterlabs.org/pacemaker/doc/en-US/Pacemaker/2.0/html/Pacemaker_Explained/s-resource-options.html#_resource_meta_attributes) in the Pacemaker Explained for details.\n* `pacemaker_no_quorum_policy` - Specifies the value of the `no-quorum-policy` options. The default is `stop`, and `ignore` for 2 nodes. See the [Cluster Options](https://clusterlabs.org/pacemaker/doc/en-US/Pacemaker/2.0/html/Pacemaker_Explained/s-cluster-options.html#s-cluster-options) in the Pacemaker Explained for details.\n* `pacemaker_use_softdog` - Specifies whether to use the software watchdog. The default is `no`.\n\n### `pacemaker-*`\n\nCreates resources on the Pacemaker cluster.\n\n* `pacemaker_resource_prefix` - Specifies the prefix to be added to the beginning of the resource name. The default is `my_`.\n* `pacemaker_virtual_ip` - Specifies the virtual IP address. The default is an unused IP address in all nodes.\n* `pacemaker_virtual_hostname` - Specifies the host name of the virtual IP address. The default is `vip-1`.\n* `pacemaker_pgsql_rep_mode` - Specifies the replication mode in the `pacemaker-replication` role. Valid values are `async` (the default), `sync`, and `slave`.\n* `pacemaker_pgsql_replication_slot_name` - Specifies the slot name when using the replication slot in the `pacemaker-replication` role. The default is `{{ pacemaker_resource_prefix + 'slot' }}`.\n\n### `lifekeeper`\n\nSet up a LifeKeeper cluster.\n\n* `lifekeeper_media_file` - Specifies the media file path. The dafault is `/path/to/LKL_V951_100620.iso`.\n* `lifekeeper_license_file` - Specifies the license file path. The default is `/path/to/evalkeys-60day.txt`.\n* `lifekeeper_recovery_kits` - Specifies the recovery kits to install. The default is empty. Valid values are `steeleye-lkPGSQL` (PostgreSQL Recovery Kit), `steeleye-lkDR` (DataKeeper), and so on.\n\n### `lifekeeper-*`\n\nCreates resources on the LifeKeeper cluster.\n\n* `lifekeeper_resource_prefix` - Specifies the prefix to be added to the beginning of the resource name. The default is `my_`.\n* `lifekeeper_virtual_ip` - Specifies the virtual IP address. The default is an unused IP address in all nodes.\n* `lifekeeper_virtual_hostname` - Specifies the host name of the virtual IP address. The default is `vip-1`.\n* `lifekeeper_pinglist` - Specifies ping list separated by commas. The default is the IP address of the default gateway.\n\n### `datakeeper`\n\nSets up a DataKeeper resource on the LifeKeeper cluster.\n\n* `datakeeper_disk` - Specifies the disk device path. The default is `/dev/sdb1`.\n* `datakeeper_fstype` - Specifies the filesystem type. The default is `xfs`.\n* `datakeeper_mount_directory` - Specifies the mount directory path. The default is `/mnt/mirror`.\n* `datakeeper_source_hostname` - Specifies the host name of the source server. The default is the host name of the first node of all.\n\n### `repmgr`\n\nSets up repmgr servers.\n\n* `repmgr_syslog_facility` - Specifies the syslog facility. The default is `LOCAL1`.\n* `repmgr_syslog_file` - Specifies the syslog file path. The default is `/var/log/repmgr{{ postgresql_version | regex_replace('\\.') }}`.\n\nLicense\n-------\n\nBSD\n\nAuthor Information\n------------------\n\nTomoaki Sato\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-sato%2Fansible-postgresql-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftom-sato%2Fansible-postgresql-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-sato%2Fansible-postgresql-cluster/lists"}