<commit_before>---
layout: post
title: Postgres replication behind China's GFW
date:   2021-03-18 15:50:22 +0800
categories: GFW bucardo postgres
---

A draft on how to replicate Postgres database through China's Great Firewall without breaking the law.
# Requirements and issues

I had the need to setup a master to master Postgres replication system in a very specific environment.

1. One of the server is located in mainland China behind the GFW
1. The other server is running on a managed database from a famous cloud provider outside China.

The main issue is that our Chinese office often has trouble communicating with the network located outside the GFW. Sometimes the connection might drop or it will be just impossible to access our external cloud provider. China has strict regulation regarding the use of VPN/Proxy and it was important to abide the law. Hopefully we had a server in another office in a China-friendly environment (CN2). You can replicate this setup by renting a CN2 VPS outside mainland China. They are quite expensive but they work well.
<commit_msg>Set the excerpt variable in Postgres replication behind China's GFW<commit_after>---
layout: post
title: Postgres replication behind China's GFW
date:   2021-03-18 15:50:22 +0800
categories: GFW bucardo postgres
excerpt: A draft on how to replicate Postgres database through China's Great Firewall without breaking the law.
---
# Requirements and issues

I had the need to setup a master to master Postgres replication system in a very specific environment.

1. One of the server is located in mainland China behind the GFW
1. The other server is running on a managed database from a famous cloud provider outside China.

The main issue is that our Chinese office often has trouble communicating with the network located outside the GFW. Sometimes the connection might drop or it will be just impossible to access our external cloud provider. China has strict regulation regarding the use of VPN/Proxy and it was important to abide the law. Hopefully we had a server in another office in a China-friendly environment (CN2). You can replicate this setup by renting a CN2 VPS outside mainland China. They are quite expensive but they work well.

{'fraction_non_alphanumeric': 0.03327338129496403, 'fraction_numerical': 0.019784172661870502, 'mean_word_length': 4.426829268292683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831839', 'n_tokens_mistral': 562, 'n_tokens_neox': 508, 'n_words': 352}