Does logical replication supports bidirectional? - postgresql

I have created two publications one on each PostgreSQL instance but on the same table. Then I subscribed to these publications from each instance. I didn't see an error in the logs of two instances but I can see replication works on one side i.e. uni-directional.
Does logical replication support bi-directional or not?
Thanks

No, you cannot use logical replication to replicate the same table in both directions. This would necessitate complicated conflict resolution, which PostgreSQL doesn't have at the moment.

Related

Can A Postgres Replication Publication And Subscription Exist On The Same Server

I have a request asking for a read only schema replica for a role in postgresql. After reading documentation and better understanding replication in postgresql, I'm trying to identify whether or not I can create the publisher and subscriber within the same database.
Any thoughts on the best approach without having a second server would be greatly appreciated.
You asked two different question. Same database? No. Since Pub/Sub requires tables to have the same name (including schema) on both ends, you would be trying to replicate a table onto itself. Using logical replication plugins other than the built-in one might get around this restriction.
Same server? Yes. You can replicate between two databases of the same instance (but see the note in the docs about some extra hoops you need to jump through) or between two instances on the same host. So whichever of those things you meant by "same server", yes, you can.
But it seems like an odd way to do this. If the access is read only, why does it matter whether it is to a replica of the real data or to the real data itself?

Postgres replication betwenn 2 databases on same server

I need to create a replica of existing database, that would copy any changing operation from master to slave, I.e create a mirror some sort of. I found a lot of examples in web but they all describes process when master and slave are on different servers.
I would like to create a write replica on the same server where master is located , without spinning up second instance of Postgres.
Is it possible to do so and could you point me a direction where I could find a solution how to do it?
Thank you.
P.S. I understand that replication on 2 servers is better, but I just need to do it on one common server.
If you want physical replication, you will need to run two instances of PostgreSQL. If they are on the same server machine, they will need to have different port numbers. The different port numbers is the only complexity, otherwise it is just like running on two different servers.
If you want logical replication, you can do that within a single instance, but you will need to jump through some hoops to create the subscription intra-instance, as described in the "Notes" section
You could consider using a simple trigger to insert/update/delete data on the other database as soon as the main one get modified.
A more "professional" way would be to use synchronous replication.

Stop BDR from replicating DROP TABLE or CREATE TABLE

I have two databases with tables that I want to sync. I don't want to sync any other table. I'm using Postgres-BDR to do that.
Those tables are part of replication set common. There are some circumstances where other tables share a name across nodes (but are NOT in common), and a node will call DROP TABLE and then CREATE TABLE. Even though those tables aren't part of the common replication set, these commands are still replicated to the other nodes, causing the other node to lose all of its data in its table and then create an empty table.
How can I stop this? I only want commands that affect common to be replicated to the other nodes.
Nevermind, I found it. It's available with bdr.skip_ddl_replication.
I just put bdr.skip_ddl_replication = on in postgresql.conf, restarted the server, and BOOM! Works like a charm.
EDIT
It would be prudent of me to point out that the documentation warns that this option could break database replication if used improperly. But since I'll be VERY tightly controlling the table schema, it shouldn't cause any problems.

Sync/ replicate more than two databases in postgresql?

I have 5 users which uses 5 different servers(using openerp), each one uses the same database copy. Whenever the user enters data to his database, then it should sync to the 6th server's database an then sync the data in the 6th database to all other 4 users databases. So any data entry in any database should sync to the other databases running in different servers. Is that possible? how can I achieve it?
Edit:
I found Bucardo, but it need primary key for every table. But in openerp, there are many2many relation tables which doesn't have a primary key.
This is called master-master or multi-master replication:
http://en.wikipedia.org/wiki/Multi-master_replication#PostgreSQL
http://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling
You can also check out SymmetricDS or Daffodil which let you sync over HTTP.
A pure PostgreSQL installation supports currently only single master replication.
However you may achieve multi-master replication by installing additional tools http://wiki.postgresql.org/wiki/Clustering.
You should also check out Pg documentation on this topic Chapter 25. High Availability, Load Balancing, and Replication

MongoDB sync a specific database

I would like to know if it's possible to sync only 1 MongoDB, instead of all databases inside my server.
Best Regards
I assume you're referring to Replica Sets when you say "sync". In that case, no, it's not possible to replicate only one database, all databases on the server are replicated. This is by design, so that in case of failure of the primary, a secondary can step up and become a primary without any loss of functionality or data (except for whatever data may not have been replicated since when the former primary failed).