PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 22nd, 2013, 01:05 PM
surfnetdz surfnetdz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 surfnetdz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 42 sec
Reputation Power: 0
Retrieving plan of active sqls

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. This is to be able to troubleshoot poor performing ones and in Oracle we are able to retrieve such a plan.
Thanks so much for any advice you all may have.
-Dan

Reply With Quote
  #2  
Old January 22nd, 2013, 04:16 PM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 37 m 6 sec
Reputation Power: 284
The only thing I'm aware of that is somewhat similar is the auto_explain module:

http://www.postgresql.org/docs/current/static/auto-explain.html

But it doesn't store the plan for each statement the way Oracle does it, only for those that exceed a certain threshold. Unlike Oracle PostgreSQL does not (does not need?) to store the plan for every statement.

You can always get the real execution plan using explain analyze in PostgreSQL (which shows what PostgreSQL is doing rather than what it planned to do).
__________________
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
http://forums.devshed.com/misc.php?do=bbcode#code

Tips on how to ask better questions:
http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
http://wiki.postgresql.org/wiki/SlowQueryQuestions
http://catb.org/esr/faqs/smart-questions.html

Reply With Quote
  #3  
Old January 22nd, 2013, 04:32 PM
surfnetdz surfnetdz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 surfnetdz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 42 sec
Reputation Power: 0
Hi,
The problem is I can't do explain analyze as the current_query (shown in pg_stat_activity) contains bind variable(s).
And, I also don't understand why Postgres would not have a plan. It needs one in order to execute any sql statement, right?
Thanks!
-Dan

Reply With Quote
  #4  
Old January 22nd, 2013, 05:37 PM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 37 m 6 sec
Reputation Power: 284
Quote:
Originally Posted by surfnetdz
And, I also don't understand why Postgres would not have a plan. It needs one in order to execute any sql statement, right?
It has a plan, it just doesn't store it beyond the execution of the statement.

Reply With Quote
  #5  
Old January 23rd, 2013, 11:26 AM
surfnetdz surfnetdz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 surfnetdz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 42 sec
Reputation Power: 0
Hello again,
On a related issue, is there a way to see what the actual current_query (as displayed in pg_stat_activity) when it only shows "<unnamed portal 2>".
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Retrieving plan of active sqls

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap