darold / pgbadger

A fast PostgreSQL Log Analyzer
http://pgbadger.darold.net/
PostgreSQL License
3.45k stars 348 forks source link

SQL generating TEMP not reported if failed #785

Closed ncalero-uy closed 11 months ago

ncalero-uy commented 1 year ago

Hi, I found an issue where the database temp space was exhausted by an SQL, and the pgBadger report is not reporting the SQL causing the problem, despite the SQL is in the log.

In this case, the SQL failed with the error message "ERROR: could not write to file "file_name": No space left on device"

The overall statistics section correctly reports the temp space used and files - it only misses the SQL in the Queries section for temp. Like this:

# pgbadger -f logplex -T "Heroku TMP issue" -o ./badger-tmp.txt ./heroku-temp-error-20230703.log
[========================>] Parsed 69690 bytes of 69690 (100.00%), queries: 2, events: 8
LOG: Ok, generating txt report...

# cat badger-tmp.txt 
...
- Overall statistics ---------------------------------------------------

Number of unique normalized queries: 2
Number of queries: 2
Total query duration: 399ms
First query: 2023-07-03 07:32:00
Last query: 2023-07-03 07:35:47
Query peak: 1 queries/s at 2023-07-03 07:32:00
Number of events: 8
Number of unique normalized events: 4
Number temporary files: 90
Max size of temporary files: 23.13 GiB
Average size of temporary files: 765.80 MiB
Total number of databases: 2
...
- Queries generating the most temporary files (N) ---------------------------

Rank   Count   Total size    Min/Max/Avg size    Query

- Queries generating the largest temporary files ----------------------------

Rank   Size    Query

- Slowest queries -----
- ...

Attaching the PostgreSQL log file to reproduce the report. It is from a Heroku database. heroku-temp-error-20230703.log

darold commented 11 months ago

Hi, this is normal, the SQL query is associated to the error "no space left". Normally if there was enough disk space it would not end as error and should be associated to the temporary files generation. Anyway I have found several parsing error with logplex format, they have been fixed in commits d51444a and 5945104.