PG closes connection after exception
James William Pye
x at jwp.io
Fri Sep 7 07:40:27 UTC 2012
On Sep 6, 2012, at 11:51 PM, Сергей Мелехин <cpro29a at gmail.com> wrote:
> Hello there!
> I am new to pg and python programming and I stumbled into wierd problem:
> I use py-postgresql driver to connect to postgresql 9.2 in my wsgi app. After application gets postgres exception (eg. when trying to access non-existant field of a table) - connection closes and I have to make another one.
Is it possible that the close is occurring elsewhere?
db.close() performed in another thread? context manager? atexit? (Just listing some cases that come to mind)
> Is it normal to close connection after exception?
Only in the case of FATAL errors from the server and protocol errors identified by the client.
> Example trace of an error, after which connection is closed:
> Traceback (most recent call last):
> postgresql.exceptions.UndefinedColumnError: column s0.industry_id does not exist
> CONNECTION: [closed]
> client_address: 127.0.0.1/32
> client_port: 44449
> PostgreSQL 9.2rc1 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 32-bit
This is what I get when I induce an UndefinedColumnError from an interactive console:
postgresql.exceptions.UndefinedColumnError: column "foo" does not exist
LOCATION: File 'parse_expr.c', line 766, in transformColumnRef from SERVER
select foo from pg_type limit 1
^ [line 1, character 8]
string: select foo from pg_type limit 1
PostgreSQL 9.1.5 on x86_64-apple-darwin12.0.0, compiled by Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn), 64-bit
CONNECTOR: [Host] pq://firstname.lastname@example.org:5432
More information about the Python-general