• This repository has been archived on 19/Dec/2022
  • Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    Shell
  • Created about 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PostgreSQL clustering with corosync/pacemaker test environment

our-postgresql-setup

ARCHIVED: This configuration is no longer used by GoCardless, see the replacement at https://github.com/gocardless/stolon-pgbouncer

Overview

This repo is an extracted version of how we run PostgreSQL clusters at GoCardless.

It helps you quickly spin up a 3-node cluster of PostgreSQL, managed by Pacemaker, and proxied by PgBouncer.

It's intended as a playground for us, and a learning resource that we wanted to share with the community.

You can hear more about how the cluster works in our talk - Zero-downtime Postgres upgrades.

What's in the cluster?

When you start the cluster, you get 3 nodes, each running:

  • PostgreSQL
  • Pacemaker
  • PgBouncer

All packages are from Ubuntu 14.04, except for PostgreSQL itself, which is at version 9.4.

The cluster is configured with a single primary, one synchronous replica, and one asynchronous replica.

Dependencies

  1. Virtualbox
  2. Vagrant
  3. git clone https://github.com/gocardless/our-postgresql-setup.git
  4. [Recommended] tmux

Getting started

With tmux (recommended)

  1. ./tmux-session.sh start

By hand

  1. On 3 separate windows:
  2. vagrant up pg01 && vagrant ssh pg01
  3. vagrant up pg02 && vagrant ssh pg02
  4. vagrant up pg03 && vagrant ssh pg03

Viewing cluster status

You can run crm_mon -Afr on any node to see the current state of the cluster and all resources in it. Press ^c to quit.

Connecting to PostgreSQL

Once the cluster is up, you have two options:

  • Connect directly to Postgres on the PostgresqlVIP at 172.28.33.10
  • Connect via PgBouncer at 172.28.33.9

Note: The migrator.py script will only give you zero-downtime migrations if you connect via PgBouncer.

Running a zero-downtime migration

  1. Ensure clients are connected to the PgBouncerVIP.
  2. Run /vagrant/migrator.py on the node that has the PgBouncerVIP (you can find out where the PgBouncerVIP is by viewing the cluster status).
  3. Follow the prompts.
    1. It is safe to ignore the Make sure you have the following command ready... prompt. This is aimed at cases where you'd want to quickly re-enable traffic, and doesn't matter when running locally.
  4. Assuming everything went well, the primary will migrate to the synchronous replica, and the clients won't have received any connection resets.

I have a question!

We're happy to receive questions as issues on this repo, so don't be shy!

It's hard to know exactly what documentation/guidance is useful to people, so we'll use the questions we answer to improve this README and link out to more places you can read up on the technologies we're using.

Further reading

References

More Repositories

1

statesman

A statesmanlike state machine library.
Ruby
1,775
star
2

angularjs-style-guide

AngularJS style guide used at GoCardless
1,443
star
3

business

Ruby business day calculations
Ruby
498
star
4

http-api-design

HTTP Design Guidelines
419
star
5

airflow-dbt

Apache Airflow integration for dbt
Python
395
star
6

es6-angularjs

JavaScript
180
star
7

coach

Alternative controllers with middleware
Ruby
165
star
8

logjam

a log shipping tool
Go
136
star
9

nandi

Fear free PostgreSQL migrations for Rails
Ruby
124
star
10

activerecord-safer_migrations

Safer ActiveRecord migrations for Postgres
Ruby
117
star
11

amqpc

AMQP CLI tool
Go
115
star
12

pgreplay-go

Postgres load testing tool
Go
113
star
13

ibandit

Convert national banking details into IBANs, and vice-versa.
Ruby
101
star
14

rspec-activejob

RSpec matchers for testing ActiveJob
Ruby
98
star
15

gocardless-pro-php

GoCardless Pro PHP Client
PHP
97
star
16

gocardless-legacy-php

The PHP client library for the GoCardless Legacy API
PHP
66
star
17

stolon-pgbouncer

Add-on to stolon for providing zero-downtime failover and PgBouncer integration
Go
62
star
18

gocardless-legacy-ruby

The Ruby client library for the GoCardless API
Ruby
52
star
19

draupnir

Anonymised database instances as-a-service
Go
45
star
20

gc-http-factory

A factory for creating $http services in Angular.
JavaScript
44
star
21

gocardless-pro-python

GoCardless Pro Python Client
Python
37
star
22

bump

Automated dependency management for Ruby, Python and Javascript
Ruby
36
star
23

gocardless-pro-ruby

GoCardless Pro Ruby Client
Ruby
30
star
24

stubby

Your favourite pretender stubber
JavaScript
29
star
25

gocardless-dotnet

GoCardless .NET Client
C#
28
star
26

gocardless-nodejs

GoCardless Node.js client
TypeScript
24
star
27

prius

Environmentally-friendly application config
Ruby
24
star
28

utopia-getting-started

Sharing a copy of our getting-started tutorial, as a demonstration of how our infrastructure works with utopia
23
star
29

resque-sentry

A Resque failure backend that sends errors to Sentry
Ruby
23
star
30

statesman-events

Event support for Statesman (UNMAINTAINED)
Ruby
23
star
31

anony

A small library that defines how ActiveRecord models should be anonymised for deletion purposes.
Ruby
23
star
32

theatre

GoCardless' collection of Kubernetes extensions
Go
23
star
33

systemjs-assetgraph

AssetGraph transform for optimizing SystemJS pages for production
JavaScript
22
star
34

gocardless-legacy-python

The Python client library for the GoCardless API
Python
22
star
35

gocardless-pro-java

GoCardless Pro Java Client
Java
19
star
36

javascript-style-guide

The GoCardless JavaScript styleguide
18
star
37

pgsql-cluster-manager

Daemon and migration tool that manages Postgres cluster using etcd/corosync/pacemaker
Go
17
star
38

slo-builder

Templates for building SLOs with Prometheus rules and alerts
Go
16
star
39

drydock

DryDock is a utility to clean up Docker images
Go
16
star
40

business-python

Python business day calculations
Python
15
star
41

ng-gc-components

JavaScript
14
star
42

legacy-api-docs

Docs for GoCardless legacy API
JavaScript
14
star
43

companies-house-rest

Ruby wrapper for the Companies House REST API.
Ruby
13
star
44

gocardless-legacy-dotnet

The .NET client library for the GoCardless Legacy API
C#
12
star
45

bump-core

The core logic powering Bump
Ruby
12
star
46

gocardless-legacy-node

The Node.js client library for the GoCardless Legacy API
JavaScript
11
star
47

html-style-guide

How we write HTML at GoCardless
11
star
48

atum

Ruby HTTP client generator for APIs represented with JSON schema
Ruby
9
star
49

gocardless-legacy-java

The Java client library for the GoCardless Legacy API
Java
9
star
50

codeigniter-gocardless

The CodeIgniter spark for the GoCardless API
PHP
8
star
51

sample-legacy-django-app

A sample Django app demonstrating the use of the GoCardless Legacy API and the Python client.
Python
8
star
52

logsearch

Search Logstash / Elasticsearch logs from the command line
Go
7
star
53

companies-house-gateway-ruby

Ruby wrapper for the Companies House XML Gateway
Ruby
6
star
54

react-dropin

React bindings for the GoCardless Dropin checkout flow
TypeScript
6
star
55

airflow-looker

A collection of Airflow extensions to provide integration with Looker
Python
6
star
56

uk_phone_numbers

A Ruby library for validating and formatting UK phone numbers.
Ruby
6
star
57

callcredit-ruby

Ruby wrapper for Callcredit's CallValidate API
Ruby
6
star
58

sample-legacy-rails-app

A sample Rails app demonstrating the use of GoCardless Legacy API and the Ruby client.
Ruby
6
star
59

gocardless-pro-go

Go
6
star
60

creditsafe-ruby

Ruby library for the Creditsafe SOAP API
Ruby
5
star
61

github-archive

Easy way to archive an entire organisation repos on S3
Go
5
star
62

cli-releases

Release repo for the gocardless cli
Dockerfile
4
star
63

simple-swag

Dead simple swagger/openapi docs server
Go
3
star
64

bank-webfont

A webfont of prominent UK banks
CSS
3
star
65

bucket-store

Helper library to access cloud storage services
Ruby
3
star
66

gc_ruboconfig

GoCardless Engineering shared rubocop config
Ruby
3
star
67

slackify

Update your Slack status with what you're listening to in Spotify
Elixir
3
star
68

gocardless-legacy-example-django

An example site using the GoCardless Legacy API
Python
3
star
69

belongs-to-one-of

Gem to support activemodel relations where one model can be a child of one of many models
Ruby
3
star
70

coach-demo

Ruby
3
star
71

gocardless-pro-ruby-example

Example of using the GoCardless Pro Ruby client library
HTML
3
star
72

gocardless-php

Placeholder explaining our PHP API libraries.
2
star
73

prometheus-client-ruby-data-stores-experiments

Ruby
2
star
74

que

A Ruby job queue that uses PostgreSQL's advisory locks for speed and reliability.
Ruby
2
star
75

gocardless-pro-java-example

Example of using the GoCardless Pro Java client library
Java
2
star
76

gocardless-legacy-partner-example-ruby

An example GoCardless partner app, written in Sinatra
Ruby
1
star
77

open-charities

A Ruby library for querying the OpenCharities database
Ruby
1
star
78

slackify-dot-rb

Take 2: this time without a language barrier
Ruby
1
star
79

gocardless-pro-java-maven-example

An example java app that handles webhooks
Java
1
star
80

gocardless-pro-ios-sdk

GoCardless Pro iOS SDK
Swift
1
star
81

publish-techdocs-action

Action to generate and publish TechDocs
Shell
1
star
82

salesforce_wrapper

A wrapper around Restforce, catching exceptions and performing a configurable action with them (e.g. sending an email).
Ruby
1
star
83

passfort

Ruby client library for the PassFort API
Ruby
1
star
84

homebrew-taps

Ruby
1
star
85

gocardless-pro-php-demo

Pro client PHP demo
PHP
1
star
86

rspec-que

RSpec matchers for testing Que
Ruby
1
star