postgresql - How to get current query inside a transaction -


i tried current query pg_stats_activity didn't work expected.

outside transaction works:

pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 1 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 1 not null; (1 row)  pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 2 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 2 not null; (1 row)  pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 3 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 3 not null; (1 row) 

but inside transaction wrong result:

pagetest=# begin; begin pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 1 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 1 not null; (1 row)  pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 2 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 1 not null; (1 row)  pagetest=# select query pg_stat_activity pid = pg_backend_pid() , 3 not null;                                        query                                         ------------------------------------------------------------------------------------  select query pg_stat_activity pid = pg_backend_pid() , 1 not null; (1 row)  pagetest=# rollback pagetest-# ; rollback 

it looks there strange visibility rules on stat collector views. there reasonable way around this?

try :

  begin;     select 1,current_query();     select 2,current_query();    rollback; 

Comments

Popular posts from this blog

ios - Is 'init' forbidden as *part* of a variable name? -

javascript - Why Selenium can't find an element that is graphically visible -

qt - Microsoft FTP Service 451 The parameter is incorrect -