0

I'm supporting a new system that's going live next month. I'm trying to have PostgreSQL log any long-running (over 1 second) queries to the error log. I've set the following parameters:

log_duration: 1
log_min_duration_statement: 1000
log_statement: all

However, the DB seems to be writing all queries to the log; e.g.:

2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  duration: 0.080 ms
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  duration: 0.096 ms
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  execute <unnamed>: UPDATE [...]
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:DETAIL:  Parameters: $1 = [...]
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  duration: 0.467 ms
2025-11-20 15:49:42 UTC:100.126.169.109(36852):foo@bar:[63912]:LOG:  duration: 0.125 ms
2025-11-20 15:49:42 UTC:100.126.169.109(36852):foo@bar:[63912]:LOG:  execute S_112/C_144: SELECT [...]
2025-11-20 15:49:42 UTC:100.126.169.109(36852):foo@bar:[63912]:DETAIL:  Parameters: $1 = [...]
2025-11-20 15:49:42 UTC:100.126.169.109(36852):foo@bar:[63912]:LOG:  duration: 0.036 ms
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  duration: 0.008 ms
2025-11-20 15:49:42 UTC:100.126.191.233(49316):foo@bar:[63907]:LOG:  execute S_13: COMMIT

(all proprietary information has been redacted)

What am I doing wrong? This is Aurora PostgreSQL 17.5

2 Answers 2

3

OK, figured out the problem; apparently setting log_statement: all actually logs all statements, no matter the duration.

1

You're seeing every query in the logs because of one parameter:

log_statement = all

This setting forces PostgreSQL to log every SQL statement, regardless of how long it takes. It overrides your log_min_duration_statement setting, so even statements that take less than a millisecond will still appear in the logs.

In addition, you have:

log_duration = 1

log_duration logs the duration for all statements. It doesn’t filter — it only controls whether durations are printed. So with these two settings combined, PostgreSQL logs:

every statement (log_statement = all)

plus the duration of every statement (log_duration = 1)

That's exactly why your logs are full of extremely fast queries like 0.008 ms.

If your goal is to log only queries that take longer than 1 second, you should disable log_statement and rely entirely on log_min_duration_statement:

log_statement = none log_min_duration_statement = 1000 # log only statements taking > 1 second log_duration = off # optional, removes duration for fast queries

On Aurora PostgreSQL, make these changes in the parameter group and reboot if required.

Once you remove log_statement = all, only the slow queries (those exceeding 1 second) will appear in the logs.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.