Thread: Getting

Getting

From
Dan Ng
Date:
Hello,
I am a newb in Postgres coming from Oracle. Does anyone know if it's possible to see the plan being executed by Postgres for an active sql statement (from pg_stat_activity). This is to be able to troubleshoot poor performing ones and in Oracle we are able to retrieve such a plan.
Additionally, how do I see the actual sql statement that shows as "<unnamed portal x>".
Thanks so much for any advice you all may have.
-Dan

Re: Getting

From
Raghavendra
Date:
On Wed, Jan 23, 2013 at 11:50 PM, Dan Ng <surfnet@yahoo.com> wrote:
Hello,
I am a newb in Postgres coming from Oracle. Does anyone know if it's possible to see the plan being executed by Postgres for an active sql statement (from pg_stat_activity). This is to be able to troubleshoot poor performing ones and in Oracle we are able to retrieve such a plan.
Additionally, how do I see the actual sql statement that shows as "<unnamed portal x>".
Thanks so much for any advice you all may have.
-Dan

Welcome...!!! 

You need to use additional module to write query plan in logs i.e., AUTO_EXPLAIN.

---
Regards,
Raghavendra
EnterpriseDB Corporation

Re: Getting

From
Michael Holt
Date:
Of course you can also see what the query plan will be without having to run the query through a standard explain query:

http://www.postgresql.org/docs/9.0/static/sql-explain.html

From: pgsql-admin-owner@postgresql.org [pgsql-admin-owner@postgresql.org] on behalf of Raghavendra [raghavendra.rao@enterprisedb.com]
Sent: Wednesday, January 23, 2013 9:52 PM
To: Dan Ng
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] Getting

On Wed, Jan 23, 2013 at 11:50 PM, Dan Ng <surfnet@yahoo.com> wrote:
Hello,
I am a newb in Postgres coming from Oracle. Does anyone know if it's possible to see the plan being executed by Postgres for an active sql statement (from pg_stat_activity). This is to be able to troubleshoot poor performing ones and in Oracle we are able to retrieve such a plan.
Additionally, how do I see the actual sql statement that shows as "<unnamed portal x>".
Thanks so much for any advice you all may have.
-Dan

Welcome...!!! 

You need to use additional module to write query plan in logs i.e., AUTO_EXPLAIN.

---
Regards,
Raghavendra
EnterpriseDB Corporation

Re: Getting

From
Greg Williamson
Date:
Dan --

>________________________________
> From: Michael Holt <MHolt@terapeak.com>
>To: Raghavendra <raghavendra.rao@enterprisedb.com>; Dan Ng <surfnet@yahoo.com>
>Cc: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
>Sent: Wednesday, January 23, 2013 9:55 PM
>Subject: Re: [ADMIN] Getting
>
>
>
>Of course you can also see what the query plan will be without having to run the query through a standard explain
query: 
>
>
>http://www.postgresql.org/docs/9.0/static/sql-explain.html
>
>
I am not familiar with the Oracle tools, but you should note that the "EXPLAIN ANALYZE" does actually do the
transaction,so if you doing an update / insert / delete you may want to wrap it in an explicit transaction and then
rollit back. 

HTH,

Greg Williamson



Re: Getting

From
Dan Ng
Date:
Hi,
The problem is the current_query (in pg_stat_activity) contains bind variables and I can't just take it to do the explain (and, of course I don't know the values of the bind variables).
 
On a related issue, how can I see the actual sql statement when the current_query shows "<unnamed portal x>".
pg_cursors is only accessible within the same transaction and as a DBA we want to see that cursor of any active transactions.
Thanks,
-Dan

From: Greg Williamson <gwilliamson39@yahoo.com>
To:
Cc: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
Sent: Thursday, January 24, 2013 1:08 AM
Subject: Re: [ADMIN] Getting

Dan --

>________________________________
> From: Michael Holt <MHolt@terapeak.com>
>To: Raghavendra <raghavendra.rao@enterprisedb.com>; Dan Ng <surfnet@yahoo.com>
>Cc: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
>Sent: Wednesday, January 23, 2013 9:55 PM
>Subject: Re: [ADMIN] Getting
>
>
>
>Of course you can also see what the query plan will be without having to run the query through a standard explain query:
>
>
>http://www.postgresql.org/docs/9.0/static/sql-explain.html
>
>
I am not familiar with the Oracle tools, but you should note that the "EXPLAIN ANALYZE" does actually do the transaction, so if you doing an update / insert / delete you may want to wrap it in an explicit transaction and then roll it back.

HTH,

Greg Williamson



--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin