Search code examples
pythonpython-3.xpostgresqlcursorpsycopg2

Python psycopg2: Find all opened cursors


I am working on application with postgreSQL and using psycopg2 to connect to the database.

  1. Is there a way to check all opened cursors via connection.cursor()
  2. When connection.cursor() is executed should a cursor be visible in the pg_cursors view?
  3. Are cursors object created from psycopg the same as the cursors in postgres pg_cursors?

Solution

    1. Not that I know of.

    2. & 3) No and yes.

    No) A 'regular' cursor is a client side cursor and will not be seen.

    Yes) If you use a 'named' cursor then it is a server side cursor that has been DECLAREd. For more information see Cursor and Server side cursor