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?

1 Answer 1


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
  • 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, 2012 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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