By: Tom Sydney Kerckhove <syd@cs-syd.eu>
Stop waiting for a spread checkpoint, and start the standby on demand Two things made a replica cost far more than taking a copy should. pg_basebackup waits for a checkpoint, and by default that checkpoint is spread over the checkpoint interval rather than taken at once. The wait is proportional to how busy the server is, and a server a standby is taken from is busy by definition: a suite is running against it. Asking for the checkpoint immediately is what --checkpoint=fast is for. This package's own suite goes from 78 seconds to a little over one. The standby was also started whether or not anything read from it. A suite that never touches its replica paid for one anyway, which is invisible amortised over a suite and is the whole cost under mutation testing, where the suite is rerun once per mutant and each run would take a base backup to serve tests that never look at it. So replicatedDBStandby became an IO Standby, started by the first test that asks and by nothing else, and the bracket became an acquire/release pair so it could be. StandbySpec asks the primary what is streaming from it: nothing until something asks for a standby, and the same standby however often it is asked for after that.
Total
6m39s
Created Started Finished
| Time to Start | Worker time | Duration | Time to finish | Idle | |
|---|---|---|---|---|---|
| Config | 0s | 1s | 1s | 1s | 0s |
| Eval | 1s | 1m52s | 1m52s | 1m53s | 0s |
| Build | 1m52s | 17m10s | 4m46s | 6m39s | 0s |
| Suite | 0s | 19m04s | 6m39s | 6m39s | 0s |