Re: closing a connection from "outside" an application (for testing)
"Webb Sprague" <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
> Two methods I'm aware of: > > 1) Open a new connection to the database, get the process id of the > connection you want to die (select procpid from pg_stat_activity where > [...]), and kill that process using a stored procedure (or os.kill if your > running your tests as a unix user with relevant permissions). > > 2) Make psycopg connect to a tcp proxy rather than directly to PostgreSQL. > Kill the proxy and restart it. > > Ideally you want to test both cases - the first will be what your app sees > when the database kills your connection and it will be terminated somewhat > nicely. The second case is what your app sees when the network connection dies. Huh -- the things you learn.... Is there a way for psycopg to return the PID of the process it is connected to, primarily for logging (and killing)? I am still trying to figure out how to stop a run of my program in mid-stream (besides a sleep() or waiting on a signal...), but that will get me started. Also -- if the program running psycopg2 dies, what happens to the "idle in transaction" postgres process? My apologies if these are easily findable in the docs. Thanks!