SQL is a language where one task can be solved multiple ways with different efficiency. You can see effective use of PostgreSQL's possibilities on this page. Older tricks Processing PostgreSQL's logs in JSON format with jq Author: Pavel Stěhule The JSON logs are not too readable, but using jq is simple: cat postgresql-Sun.json | jq 'select(.error_severity=="ERROR").message'|sort -n | uniq -c 1 "ca