Install PostgreSQL extension pglogical on macos

Tom Harrison
Tom Harrison’s Blog
2 min readFeb 21, 2022

--

pglogical is a third party postgreSQL extension allowing two PostgreSQL nodes to replicate. I am working on building a zero-downtime major version upgrade tool for PostgreSQL on AWS, so wanted to be able to run tests locally.

The extension is provided by 2ndQuadrant and is not part of PostgreSQL. Some of it is written in C++, so must be compiled and built on the platform that it runs on. While many prebuilt tools and packages are available for macos via homebrew, pglogical is not one.

Build and Install pglogical on macos

Building and installing on macos is pretty straightforward. In my case, I have installed PostgreSQL version 14.1 using homebrew.

Environment

My environment as of 21 Feb, 2022:

  • macos 12.2.1
  • xcode 13.2.1 with command line tools
  • gnu make 3.8.1
  • homebrew 3.3.15
  • PostgreSQL 14.1 installed via homebrew

Build:

  • clone the pglogical extension from github
  • follow instructions for “unix-like platforms” here:
  • make PG_CONFIG=/usr/local/Cellar/postgresql/14.1_1/bin/pg_config
  • make PG_CONFIG=/usr/local/Cellar/postgresql/14.1_1/bin/pg_config install

Start extension when postgresql starts

Next, add the extension to shared_preload_libraries in postgresql.conf:

  • cd /usr/local/var/postgres
  • edit postgresql.conf
  • find the commented line shared_preload_libraries
  • uncomment and change toshared_preload_libraries = 'pglogical'; (add a comma and append pglogical if there are others)
  • restart postgres (with homebrew: brew services restart postgresql)

Enable the extension

Finally, create the extension in your local server:

  • psql
  • CREATE EXTENSION pglogical which should respond with
  • CREATE EXTENSION

This all worked for me! Hope your luck is as good.

--

--

30 Years of Developing Software, 20 Years of Being a Parent, 10 Years of Being Old. (Effective: 2020)