I'm looking to clone a PostgreSQL 10 cluster from server1 to server2, which is running the same Postgres version on identical hardware. The purpose is load-balancing and HA. Things to keep in mind:
- The databases are very large (terabytes) and the network is excellent. I want to avoid using intermediate files.
- Cloning the live databases would be cool, but I can also shut down the cluster if needed.
Options I've considered:
pg_dump | psqlof course, but this requires re-creating the indexes and seems really slow and incredibly inefficient for a complete copy between identical systems.
- Set up streaming replication with server2 as slave, wait for it to sync with server1, then reconfigure both to disable replication again (I don't need it). Seems like a bunch of pointless config work with room for mistakes.
- Shut down the cluster,
rsyncall the Postgres folders and files. With so much data there's a risk of data corruption, and I need to be sure I get everything (presumably just the data directories are not enough).
- Can I pipe
pg_receivewalsomehow to make this work? Can't find instructions for my use case.
What's the best way to do this? Seems like a pretty common situation.