PostgreSQL – Does PostgreSQL Support Multi-Threaded Replication?

mariadbpostgresqlreplication

Is PostgreSQL replication single-threaded ? Are there any tools to achieve multi-threaded replication ?

I'm asking this since Mariadb support this and currently I'm learning both these dbs.

Best Answer

The standard streaming replication on PostgreSQL is single threaded and there is no way to change this. However the question is why would you want to?

PostgreSQL's streaming replication works through the write ahead log which is kinda of like a set of instructions "change block 3525 to this", "change block 2424 to this", etc. This makes the replication process very fast as it not re-executing SQL, its simply doing the same data file updates that the master has done. Typically the slowness with replication on PostgreSQL is IO bound rather than CPU bound so executing the recovery in parallel will actually make it slower not faster. This is because the effect of interleaving the IO requests will potentially make sequential IO random. Of course modern SAS drives should be able to reorder the requests for data back into sequential order.

I suspect the question came about because of the statement shipping type of replication MySQL and MariaDB can do, in this case yes of course it makes perfect sense to interleave the statements as there will be a much higher CPU cost and running this on multi-core hardware will offer a great performance improvement.