pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabio Ugo Venchiarutti <f.venchiarutti@ocado.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
To: a <372660931@qq.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How do I get the SQL statement in a trigger?
Date: Thu, 10 May 2018 11:50:09 +0100
Message-ID: <ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com> (raw)
In-Reply-To: <CAFj8pRChg8EMSPNeLRv8zEzd1e=sxMvBOtPey6-CcDMJgNanYg@mail.gmail.com>
References: <tencent_6EF46BDD28A4F2AA52209B4B@qq.com>
	<CAFj8pRDiooLRVsfTe9JOzrCyL4c6D1ad5b=1NAvxLkMDw=93sg@mail.gmail.com>
	<tencent_1BB669D71C0472151E423D3E@qq.com>
	<CAFj8pRChg8EMSPNeLRv8zEzd1e=sxMvBOtPey6-CcDMJgNanYg@mail.gmail.com>

Querying over pg_stat_activity with clauses in a trigger can be quite 
expensive if your write transaction rate is high.


You may want to look into the current_query() function documented at 
https://www.postgresql.org/docs/current/static/functions-info.html








On 10/05/18 11:44, Pavel Stehule wrote:
> 
> 
> 2018-05-10 12:42 GMT+02:00 a <372660931@qq.com <mailto:372660931@qq.com>>:
> 
>     Thanks a lot, would you please be so kind to tell me more about what
>     is top level query??
> 
> 
> for example - if you run some queries from PLpgSQL functions (triggers), 
> then these queries are not top queries.
> 
> Regards
> 
> Pavel
> 
> 
> 
>     ------------------ Original message ------------------
>     *From:* "Pavel Stehule"__;
>     *Sendtime:* Thursday, May 10, 2018 6:38 PM
>     *To:* "a"<372660931@qq.com <mailto:372660931@qq.com>>;
>     *Cc:* "pgsql-general"__;
>     *Subject:* Re: How do I get the SQL statement in a trigger?
> 
>     Hi
> 
>     2018-05-10 12:23 GMT+02:00 a <372660931@qq.com
>     <mailto:372660931@qq.com>>:
> 
>         Hi I would like to write a trigger that recorded every sql
>         statement under the effected entry. So if it is possible to
>         retrieve the sql statement within a trigger??
> 
> 
>     You can read a tom command from pg_stat_activity table
> 
>       postgres=# select query from pg_stat_activity where pid =
>     pg_backend_pid();
>     +------------------------------------------------------------------+
>     |                              query       |
>     +------------------------------------------------------------------+
>     | select query from pg_stat_activity where pid = pg_backend_pid(); |
>     +------------------------------------------------------------------+
>     (1 row)
> 
>     But this information is available only for top level query.
> 
>     Regards
> 
>     Pavel
> 
> 

-- 
Regards

Fabio Ugo Venchiarutti
Data Services Department
Ocado Technology

-- 


Notice:  This email is confidential and may contain copyright material of 
members of the Ocado Group. Opinions and views expressed in this message 
may not necessarily reflect the opinions and views of the members of the 
Ocado Group. 

 

If you are not the intended recipient, please notify us 
immediately and delete all copies of this message. Please note that it is 
your responsibility to scan this message for viruses. 

 

Fetch and Sizzle 
are trading names of Speciality Stores Limited and Fabled is a trading name 
of Marie Claire Beauty Limited, both members of the Ocado Group.

 


References to the “Ocado Group” are to Ocado Group plc (registered in 
England and Wales with number 7098618) and its subsidiary undertakings (as 
that expression is defined in the Companies Act 2006) from time to time.  
The registered office of Ocado Group plc is Buildings One & Two, Trident 
Place, Mosquito Way, Hatfield, Hertfordshire, AL10 9UL.




view thread (6+ messages)  latest in thread

Message-ID: <ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com>
Permalink:  ../ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com/
Also on:    postgresql.org/message-id/ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: f.venchiarutti@ocado.com, pavel.stehule@gmail.com, 372660931@qq.com
  Subject: Re: How do I get the SQL statement in a trigger?
  In-Reply-To: <ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com>
  References: <tencent_6EF46BDD28A4F2AA52209B4B@qq.com> <CAFj8pRDiooLRVsfTe9JOzrCyL4c6D1ad5b=1NAvxLkMDw=93sg@mail.gmail.com> <tencent_1BB669D71C0472151E423D3E@qq.com> <CAFj8pRChg8EMSPNeLRv8zEzd1e=sxMvBOtPey6-CcDMJgNanYg@mail.gmail.com> <ad79c911-6f14-ca0c-c65f-3c7a387d7217@ocado.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox