Hello Mike
Thanks for quick response as always :-) So I understand setting AUTOCOMMIT has no impact on the number of 'IDLE' connections and will look for different culprit.
About the single row in pg_stat_activity, I was actually running the query below, but sent you the shortened version because I didn't think it would make a difference.
engine = create_engine("postgresql://*@localhost:5432/postgres")
print("create engine")
print(engine.pool.status())
conn1 = engine.connect()
print("create conn1")
print(conn1.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
conn2 = engine.connect()
print("create conn2")
print(conn2.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
conn2.close()
print("close conn2")
print(conn1.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
I have run this query multiple times and get a single row every time in the last query against pg_stat_activity. However, if I close conn1 instead of conn2, I do get two rows [('idle in transaction',), ('active',)] in the last query against pg_stat_activity. I also noticed that if I only use conn1 to query pg_stat_activity then I get at most one row:
engine = create_engine("postgresql://souma:ppp@localhost:5432/postgres")
print("create engine")
print(engine.pool.status())
conn1 = engine.connect()
print("create conn1")
print(conn1.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
conn2 = engine.connect()
print("create conn2")
print(conn1.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
conn2.close()
print("close conn2")
print(conn1.execute("select state from pg_stat_activity where usename='souma'").fetchall())
print(engine.pool.status())
create engine
Pool size: 5 Connections in pool: 0 Current Overflow: -5 Current Checked out connections: 0
create conn1
[('active',)]
Pool size: 5 Connections in pool: 0 Current Overflow: -4 Current Checked out connections: 1
create conn2
[('active',)]
Pool size: 5 Connections in pool: 0 Current Overflow: -3 Current Checked out connections: 2
close conn2
[('active',)]
Pool size: 5 Connections in pool: 1 Current Overflow: -3 Current Checked out connections: 1
I'm guessing this is due to some difference about how "open" TCP/IP connections are treated by postgres/psycopg2?