2020-01-10 09:01:07.456 UTC [9359] LOG: duration: 0.127 ms parse <unnamed>: select pg_sleep($1)
2020-01-10 09:01:07.457 UTC [9359] LOG: duration: 0.078 ms bind <unnamed>: select pg_sleep($1)
2020-01-10 09:01:07.457 UTC [9359] DETAIL: parameters: $1 = '2'
2020-01-10 09:01:09.461 UTC [9359] LOG: duration: 2004.025 ms execute <unnamed>: select pg_sleep($1)
2020-01-10 09:01:09.461 UTC [9359] DETAIL: parameters: $1 = '2'
2020-01-10 09:00:22.449 UTC [9355] LOG: duration: 0.253 ms parse <unnamed>: select pg_sleep($1)
2020-01-10 09:00:22.450 UTC [9355] LOG: duration: 0.083 ms bind <unnamed>: select pg_sleep($1)
2020-01-10 09:00:22.450 UTC [9355] DETAIL: parameters: $1 = '2'
2020-01-10 09:00:22.450 UTC [9355] LOG: execute <unnamed>: select pg_sleep($1)
2020-01-10 09:00:22.450 UTC [9355] DETAIL: parameters: $1 = '2'
2020-01-10 09:00:24.456 UTC [9355] LOG: duration: 2005.667 ms
Batch prepared steps together, match final duration against the LOG execute/DETAIL parameters lines and rewrite the timestamp to be the duration, and the execute statement to have the duration prefix.