Skip to content

Commit

Permalink
add postgres slow query note
Browse files Browse the repository at this point in the history
  • Loading branch information
ellie committed May 14, 2024
1 parent 779f172 commit c8b8323
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions content/notes/debugging slow postgres queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Debugging slow PostgreSQL queries
date: 2024-05-14
tags:
- postgresql
---

Earlier today I was trying to figure out why I was getting the occasional latency spike. I suspected I had some slow queries that needed optimising, but in order to check I needed to enable slow query logging.

If you wish to log all statements that take longer than 100ms with postgres, add this to your config file

```
log_min_duration_statement = 100
```

Then reload the postgres config with

```
select pg_reload_conf();
```

No restart of the server required!

Otherwise, the following options can be helpful

```ini
# Log all statements, not just the slow ones
# This may be very chatty, so make sure your log partition doesn't fill up
log_statement = all/ddl/none
```

```ini
# Log durations alongside statements
log_duration = on
```

0 comments on commit c8b8323

Please sign in to comment.