Postgres Transactions

Display current transactions in a Postgres databse.

SELECT pid, datid, xact_start, 
    date_trunc('second', current_timestamp - xact_start) AS xact_runtime, 
    age(date_trunc('second', current_timestamp), date_trunc('second', state_change)),
    state, query 
  FROM pg_stat_activity
  ORDER BY xact_start;

Enable Long Transaction Logging

# Edit postgresql.conf
# millisecond duiration to log
log_min_duration_statement = -1