Neil Conway <neilc@samurai.com> writes:
> On Wed, 2003-01-29 at 12:58, Garo Hussenjian wrote:
>> Is there any way to view the query
>> that is being run from knowing a process id?
> You can use the pg_stat_activity view in PostgreSQL 7.2 and later -- see
However, he probably doesn't have stats_command_string turned on, or
he'd already be aware of pg_stat_activity :-(. So this isn't much help
if the problem is to determine what an already-running query is.
Another possibility is to attach to the runaway process with a debugger
and print debug_query_string. For example, with gdb:
$ gdb /path/to/postgres-executable
gdb> attach PID-OF-PROCESS
gdb> p debug_query_string
gdb> quit
This should work unless you are running a stripped backend executable.
(On many systems, the "file" command can tell you whether an executable
has been stripped of debug symbols.)
regards, tom lane