See the definition of a cursor From doing select * from pg_stat_activity;, I can see that some process is using a cursor.  The query column look like this:

FETCH FORWARD 50000 FROM "db"


Is there any way to see the SQL that was used to define "db"?
Use the pg_catalogs.pg_cursors view.

postgres=# BEGIN;
BEGIN
postgres=# DECLARE "db" CURSOR FOR SELECT * FROM book_lines;
DECLARE CURSOR
postgres=# SELECT * FROM pg_cursors ;
 name |                     statement                     | is_holdable | is_binary | is_scrollable |         creation_time         
------+---------------------------------------------------+-------------+-----------+---------------+-------------------------------
 db   | DECLARE "db" CURSOR FOR SELECT * FROM book_lines; | f           | f         | t             | 2016-03-05 21:17:01.565456+08
(1 row)


Note that it shows the whole statement defining the cursor, not just the query that underlies the cursor. I don't know of any way to get just the cursor's query, so you'd probably have to do text processing to get that.