How do I debug an Idle Query?
First thing you have to separate here are the words query, transaction and connection.


Clue: your query gets executed - it is in the active state. After that the query ends but the connection stays on - the idle state. There is no transaction (it has been committed) so the xact_start is null. So you have to close the connection after the query is succesful.
Clue: Before the autocommit was on the query was left in the middle of the transaction so first you would have to commit and then close connection.