Under PostgreSQL, the currently executing queries can be
obtained using the following query:
However, this feature must be enabled explicitly
in the server configuration. There is also a configurable
reporting delay, which means that it may return a string
containing '<IDLE>' rather than the current query,
unless the query executes for a long time.
SELECT current_query FROM
Query 1 - Self-referential query for
It also seems that the process that retrieves the
queries from the
pg_stat_activity is never
included in the results, only in other processes' results,
which makes it impossible to use it for a virus.
To access the
pg_stat_activity table, the
user must be an administrator or be retrieving information
on a process owned by the same user, which means that any
user can obtain its own queries.