Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I started to use psycopg2 to connect my little python script to a PostgreSQL database few days ago. After some research I found that a lot of database connector, like psycopg, work using cursors.

I know what is a cursor and how to use it. But I still wonder if it's safe to use the same cursor all along the script life.

Is it safe?

Or would it be preferable to use a different cursor for each query?

share|improve this question
up vote 1 down vote accepted

I believe creating a cursor starts a transaction in postgresql.

If that's the case (I don't know for sure) then:

  • INSERTS and UPDATES would not be reflected in other sessions because of transaction isolation
  • you may overflow the transaction buffer given enough commands
share|improve this answer
I find nothing about the re-usability of a cursor on the Internet. But I think you're right then. Thank you. – lvictorino Jun 9 '12 at 21:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.