4

My question is somewhat related to: https://stackoverflow.com/questions/19331577/does-postgres-replication-native-support-per-database-level-replication

We have master-slave replication set up on our Postgres server (1 master and 1 slave). We have all our app tables in database DB1.

Our reporting group reads from DB1 and creates tables in a separate database DB2. The queries look like this:

INSERT INTO DB2.<some_table> 
(SELECT ... FROM ... DB1 tables ...)

The READ queries that run against DB1 take a long time to run, so ideally we want to run these queries on the slave. But the WRITEs have to go to the master, so we end up running our entire SQL on master now.

Is there a way to make DB2 available only on the slave server and let the slave server be the master for DB2?

The alternative would be to write a script that reads from slave and writes to master, but I would like to avoid that since most people know only SQL.

0

You have a few options. You could use DBLINK for your queries to run them on slave and get the data over to DB2 on master. You could also do that with FDW's set up in DB2 on master.

The other option which sounds more like what you want in your title would require you running 2 separate Postgres clusters on the machines. So you'd have two separate installs, 2 different data directories, running on different ports. DB2 would live on a different cluster than DB1. You could set up your streaming replication differently for each of those databases at that point (where as if they're on the same cluster, you can't pick and choose).

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.