Skip to content

Instantly share code, notes, and snippets.

@brianz
Last active September 1, 2015 19:44
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 brianz/39a22f52c7b0fe5e6bea to your computer and use it in GitHub Desktop.
Save brianz/39a22f52c7b0fe5e6bea to your computer and use it in GitHub Desktop.
"""Simple script to read stdin postgresql csv logs and output the SQL statements
To use, do something like this:
tail -f /path/to/your/postgres.log | python -u parse-postgresql-logs.py
"""
import csv
import sys
from functools import partial
try:
import sqlparse
formatter = partial(sqlparse.format, reindent=True)
except ImportError:
formatter = lambda l: l
reader = csv.reader(iter(sys.stdin.readline, ''))
for row in reader:
try:
print formatter(row[13])
except IndexError:
print row
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment