Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Last active January 10, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencejones/090586479bfcff65f0c4d7b467051a2c to your computer and use it in GitHub Desktop.
Save lawrencejones/090586479bfcff65f0c4d7b467051a2c to your computer and use it in GitHub Desktop.
Comparison of Postgres logs

Formats

log_min_duration_statement=0, log_statement=none

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'

log_min_duration_statement=0, log_statement=all

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

How fix?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment