Thread: /* */ comments showing up in pg_stat_activity

/* */ comments showing up in pg_stat_activity

From
Rajesh Kumar Mallah
Date:


Hmm ..
i just saw /* */ comments are being shown in current_query
is it ok ?

More importantly is it supposed to remain like that ?
In that case i can tag every query with some identifier
to know from which application it originated when i check
em in pg_stat_activity !


regds
mallah.
                   |
| 14655172 | tradein_clients |    5886 |      100 | tradein | /*
Inserting Branding Data
Expected Time: 5 mins
*/
INSERT into general.profile_master (userid, co_name, address, pincode, city, 
country_code, phone_no, mobile, fax_no, email, website, title1, fname1, 
mname1, lname1, desg1, title2, fname2, mname2, lname2, |
| 14655172 | tradein_clients |    3118 |      100 | tradein | <IDLE>



-- 
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)

Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.



Re: /* */ comments showing up in pg_stat_activity

From
Bruce Momjian
Date:
Yes, we support /* */ comments.

---------------------------------------------------------------------------

Rajesh Kumar Mallah wrote:
> 
> 
> 
> Hmm ..
> i just saw /* */ comments are being shown in current_query
> is it ok ?
> 
> More importantly is it supposed to remain like that ?
> In that case i can tag every query with some identifier
> to know from which application it originated when i check
> em in pg_stat_activity !
> 
> 
> regds
> mallah.
> 
>                     |
> | 14655172 | tradein_clients |    5886 |      100 | tradein | /*
> Inserting Branding Data
> Expected Time: 5 mins
> */
> INSERT into general.profile_master (userid, co_name, address, pincode, city, 
> country_code, phone_no, mobile, fax_no, email, website, title1, fname1, 
> mname1, lname1, desg1, title2, fname2, mname2, lname2, |
> | 14655172 | tradein_clients |    3118 |      100 | tradein | <IDLE>
> 
> 
> 
> -- 
> Rajesh Kumar Mallah,
> Project Manager (Development)
> Infocom Network Limited, New Delhi
> phone: +91(11)6152172 (221) (L) ,9811255597 (M)
> 
> Visit http://www.trade-india.com ,
> India's Leading B2B eMarketplace.
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 



Re: /* */ comments showing up in pg_stat_activity

From
Jan Wieck
Date:
We do, but that wasn't the question.

I think you can asume that it'll stay that way because it is part of the
query string the backend is currently chewing on. What shows up in
pg_stat_activity is whatever was in the received query buffer before
starting to parse it. So we would have a hard time at that point to
filter out the comments.

The question back is from where does such a query with a comment come?
If it is a standard client like psql, it could happen someday that this
client does some filtering. If you're using libpq or another API that is
basically a libpq wrapper, you're pretty safe.


Jan

Bruce Momjian wrote:
> 
> Yes, we support /* */ comments.
> 
> ---------------------------------------------------------------------------
> 
> Rajesh Kumar Mallah wrote:
> >
> >
> >
> > Hmm ..
> > i just saw /* */ comments are being shown in current_query
> > is it ok ?
> >
> > More importantly is it supposed to remain like that ?
> > In that case i can tag every query with some identifier
> > to know from which application it originated when i check
> > em in pg_stat_activity !
> >
> >
> > regds
> > mallah.
>

-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



Re: /* */ comments showing up in pg_stat_activity

From
Tom Lane
Date:
Jan Wieck <JanWieck@Yahoo.com> writes:
> The question back is from where does such a query with a comment come?
> If it is a standard client like psql, it could happen someday that this
> client does some filtering.

psql already does strip comments (and always has, AFAIK).

> If you're using libpq or another API that is
> basically a libpq wrapper, you're pretty safe.

Agreed, I doubt we'd ever bother to put comment-stripping logic in libpq.
        regards, tom lane



Re: /* */ comments showing up in pg_stat_activity

From
Rajesh Kumar Mallah
Date:
On Saturday 26 Apr 2003 8:35 am, Tom Lane wrote:
> Jan Wieck <JanWieck@Yahoo.com> writes:
> > The question back is from where does such a query with a comment come?
> > If it is a standard client like psql, it could happen someday that this
> > client does some filtering.


Yes its thru psql only , i run a SQL batch using
psql -e -h db -f batch.sql

In case future version of psql strips them it would
still be nice if libpq continue supporting it 
i feel it would be a nice feature for keeping track of
queries.


Regds
Mallah.



>
> psql already does strip comments (and always has, AFAIK).
>
> > If you're using libpq or another API that is
> > basically a libpq wrapper, you're pretty safe.
>
> Agreed, I doubt we'd ever bother to put comment-stripping logic in libpq.
>
>             regards, tom lane

-- 
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)

Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.



Re: /* */ comments showing up in pg_stat_activity

From
Bruce Momjian
Date:
Rajesh Kumar Mallah wrote:
> On Saturday 26 Apr 2003 8:35 am, Tom Lane wrote:
> > Jan Wieck <JanWieck@Yahoo.com> writes:
> > > The question back is from where does such a query with a comment come?
> > > If it is a standard client like psql, it could happen someday that this
> > > client does some filtering.
> 
> 
> Yes its thru psql only , i run a SQL batch using
> psql -e -h db -f batch.sql
> 
> In case future version of psql strips them it would
> still be nice if libpq continue supporting it 
> i feel it would be a nice feature for keeping track of
> queries.

[ After not replying to the proper question before, I will try again. :-) ]

The actual stripping of comments in psql is a little more complex.  For
example, this will not strip:
SELECT /* test */ 1;

while this will strip comments:
SELECT 1; /* test */

and leading comments are not stripped either:
/* test */ SELECT 1;

so if the comment is _inside_ a query, it will be OK, but outside and
trailing, psql processes the comment itself so it can display the proper
prompting:
test=> /*test*> test
           ^test*> */

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 



Re: /* */ comments showing up in pg_stat_activity

From
Bruce Momjian
Date:
Rajesh Kumar Mallah wrote:
> But if i were to use DBD::Perl (which probably uses libpq)
> is it safe to pass query indentifier in comments which u 
> said are not stripped by psql eg
> /* AppName: Xyzt */ Select foo from bar where cw='t' ;
> for years to come ?
> 
> why i ask is that i was always curious of the slow 
> long running queries in pg_stat_activity and not able
> to figure out the source had frustrated me , now
> this method if it works seems to me as a viable solution.

I think you have to look try perl to see how it handles it, but I think
it just passes the query whole, so all the comments should pass
themselves to the backend.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 



Re: /* */ comments showing up in pg_stat_activity

From
Rajesh Kumar Mallah
Date:
On Sat, 26 Apr 2003, Bruce Momjian wrote:

> Rajesh Kumar Mallah wrote:
> > On Saturday 26 Apr 2003 8:35 am, Tom Lane wrote:
> > > Jan Wieck <JanWieck@Yahoo.com> writes:
> > > > The question back is from where does such a query with a comment come?
> > > > If it is a standard client like psql, it could happen someday that this
> > > > client does some filtering.
> > 
> > 
> > Yes its thru psql only , i run a SQL batch using
> > psql -e -h db -f batch.sql
> > 
> > In case future version of psql strips them it would
> > still be nice if libpq continue supporting it 
> > i feel it would be a nice feature for keeping track of
> > queries.
> 
> [ After not replying to the proper question before, I will try again. :-) ]
> 


Thanks Bruce,

But if i were to use DBD::Perl (which probably uses libpq)
is it safe to pass query indentifier in comments which u 
said are not stripped by psql eg
/* AppName: Xyzt */ Select foo from bar where cw='t' ;
for years to come ?

why i ask is that i was always curious of the slow 
long running queries in pg_stat_activity and not able
to figure out the source had frustrated me , now
this method if it works seems to me as a viable solution.


regds
mallah.



> The actual stripping of comments in psql is a little more complex.  For
> example, this will not strip:
> 
>     SELECT /* test */ 1;
> 
> while this will strip comments:
> 
>     SELECT 1; /* test */
> 
> and leading comments are not stripped either:
> 
>     /* test */ SELECT 1;
> 
> so if the comment is _inside_ a query, it will be OK, but outside and
> trailing, psql processes the comment itself so it can display the proper
> prompting:
> 
>     test=> /*
>     test*> test
> 
>             ^
>     test*> */
> 
>