ottob/gorp — pull request #2 by sqs (2013-04-21 05:32:18+00:00)
Title: Close prepared statement in transaction Exec to reduce PostgreSQL resource consumption

In PostgreSQL, prepared statements are not automatically cleaned up until the connection closes. (This may also be the case for MySQL and SQLite3, but I'm not sure.) So, running queries in transactions in gorp was leaving lots of prepared statements lying around, which was causing huge PostgreSQL memory usage.

This PR fixes that issue for transactional queries. For non-transactional queries, gorp correctly relies on the Execer interface to close statements. (From the database/sql/driver docs: "If a Conn does not implement Execer, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement.")

I've submitted this PR on top of my other one fixing the tests. If you want me to splice the test commit out of this PR (in case you don't want to commit the test fix), let me know.