Why do some Django ORM queries end abruptly with the message "Killed"?
Sometimes, when fetching data from the database either through the python shell or through a python script, the python process dies, and one single word is printed to the terminal: Killed
That's literally all it says. It only happens with certain scripts, but it always happens for those scripts. It consistently happens with this one single query that takes a while to run, and also with a south migration that adds a bunch of rows one-by-one to the database.
My initial hunch was that a single transaction was taking too long, so I turned on autocommit for Postgres. Didn't solve the problem.
I checked the Postgres logs, and this is the only thing in there:
2010-08-19 22:06:34 UTC LOG: could not receive data from client: Connection reset by peer
2010-08-19 22:06:34 UTC LOG: unexpected EOF on client connection
I've tried googling, but as you might expect, a one-word error message is tough to google for.
I'm using Django 1.2 with Postgres 8.4 on a single Ubuntu 10.4 rackspace cloud VPS, stock config for eve开发者_开发百科rything.
Only one thing I could think of that will kill automatically a process on Linux - the OOM killer. What's in the system logs?
If psycopg is being used the issue is probably that the db connection isn't being closed.
As per the psycopg docs example:
# Connect to an existing database
>>> conn = psycopg2.connect("dbname=test user=postgres")
# Open a cursor to perform database operations
>>> cur = conn.cursor()
# Close communication with the database
>>> cur.close()
>>> conn.close()
Note that if you do delete the connection (using dbcon.close()
or by deleting the connection object you probably need to issue a commit or rollback, depending on what sort of transaction type your connection is working under.
See the close connection docs for more details.
精彩评论