7

I have a RDS for PostgreSQL setup in ASIA and would like to have a read copy in US.

But unfortunately just found from the official site that only RDS for MySQL has cross-region replica but not for PostgreSQL.

And I saw this page introduced other ways to migrate data in to and out of RDS for PostgreSQL.

If not buy an EC2 to install a PostgreSQL by myself in US, is there any way the synchronize data from ASIA RDS to US RDS?

2 Answers 2

6

It all depends on the purpose of your replication. Is it to provide a local data source and avoid network latencies ?

Assuming that your goal is to have cross-region replication, you have a couple of options.

Custom EC2 Instances

You can create your own EC2 instances and install PostgreSQL so you can customize replication behavior.

I've documented configuring master-slave replication with PostgreSQL on my blog: http://thedulinreport.com/2015/01/31/configuring-master-slave-replication-with-postgresql/

Of course, you lose some of the benefits of AWS RDS, namely automated multi-AZ redundancy, etc., and now all of a sudden you have to be responsible for maintaining your configuration. This is far from perfect.

Two-Phase Commit

Alternate option is to build replication into your application. One approach is to use a database driver that can do this, or to do your own two-phase commit. If you are using Java, some ideas are described here: JDBC - Connect Multiple Databases

Use SQS to uncouple database writes

Ok, so this one is the one I would personally prefer. For all of your database writes you should use SQS and have background writer processes that take messages off the queue.

You will need to have a writer in Asia and a writer in the US regions. To publish on SQS across regions you can utilize SNS configuration that publishes messages onto multiple queues: http://docs.aws.amazon.com/sns/latest/dg/SendMessageToSQS.html

Of course, unlike a two phase commit, this approach is subject to bugs and it is possible for your US database to get out of sync. You will need to implement a reconciliation process -- a simple one can be a pg_dump from Asian and pg_restore into US on a weekly basis to re-sync it, for instance. Another approach can do something like a Cassandra read-repair: every 10 reads out of your US database, spin up a background process to run the same query against Asian database and if they return different results you can kick off a process to replay some messages.

This approach is common, actually, and I've seen it used on Wall St.


So, pick your battle: either you create your own EC2 instances and take ownership of configuration and devops (yuck), implement a two-phase commit that guarantees consistency, or relax consistency requirements and use SQS and asynchronous writers.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your suggestions. Yes, I would like to provide a local data source in US site.
But create my own EC2 instances and install PostgreSQL would be my last choice because RDS service has perfect features like High Availability (Multi-AZ) and backup.
Ok, I agree. Let me amend my answer.
3

This is now directly supported by RDS.

Example of creating a cross region replica using the CLI:

aws rds create-db-instance-read-replica \ --db-instance-identifier DBInstanceIdentifier \ --region us-west-2 \ --source-db-instance-identifier arn:aws:rds:us-east-1:123456789012:db:my-postgres-instance 

5 Comments

Looks like you're referring to mysql, whereas the question was about Postgres.
@influent Just wrote the CLI command wrong, updated now. If you follow the link you can see the announcement about Postgres support.
Ohh thanks, I was thinking of master-master, which is still only available for mysql aurora.
I know this is an old post, but it looks like this isn't supported anymore: An error occurred (InvalidDBInstanceState) when calling the CreateDBInstanceReadReplica operation: Cross-Region Read Replicas are not supported for the provided source DB Instance engine version. Please upgrade to a supported engine version and try again. This is Aurora PostgreSQL v 10.11
That's because Aurora behaves differently to non Aurora RDS. You should raise a separate question about that and consider linking back to this one to show what you've tried.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.