Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New functionality, show query real execution plan #149

Open
banlex73 opened this issue Oct 27, 2021 · 9 comments
Open

New functionality, show query real execution plan #149

banlex73 opened this issue Oct 27, 2021 · 9 comments
Assignees

Comments

@banlex73
Copy link

banlex73 commented Oct 27, 2021

Hello wonderful powa-team
I've been using powa for 3 years already and feel like we are missing one thing here - query's execution plan.
It would be nice to have real execution plans from targets available in powa.
I tried pg_show_plans extension but it provides only execution plans for active sessions, no historical data. I think, that auto_explain is the best in this case. Execution plan can be extracted from a postgres log file and loaded into a table.
My vision is something like:

  • on a monitored postgres cluster enable auto_explain
  • start a service what periodically parses postgres log, extracts plans and inserts into a table on postgres cluster
  • powa_collector connects to the monitored cluster and copy execution plans into repository
  • powa-web shows queries and their real execution plans

wondering what do you think about it?

@rjuju rjuju self-assigned this Oct 28, 2021
@rjuju
Copy link
Member

rjuju commented Oct 28, 2021

Hi @banlex73,

I agree that having plan information would be tremendously useful. Unfortunately I don't think that this approach could reliably work. There's no guarantee that the logs are actually available locally (or at least from the powa / powa-collector user), and in a well known location, so this would be mostly incompatible with anyone using syslog for instance.

Then there's the question of log retention, log format and adequate auto_explain configuration. At best, you would partial information which won't really help for the really problematic cases like a fast query that suddenly becomes a bit slower but is still too fast to be logged with any reasonable auto_explain.log_min_duration_statement value. Indeed, the useful information isn't the plan in itself but detecting a plan change that impact the query runtime enough that a DBA should investigate and fix the root issue.

Unfortunately I don't see any solution being really great as retrieving and storing the plan will always be quite expensive.

Have you looked at https://github.com/ossc-db/pg_store_plans? This is probably the most promising approach. Unfortunately, I think that this extension is for now incompatible with powa as it's not really compatible with pg_stat_statements. Maybe things will change there with postgres 14 as there's a new API to use the queryid calculation in other extensions, but as-is I don't see how we could integrate it. It would also be interesting to do some benchmarking of that extension, as it may be too expensive from OLTP workload.

@banlex73
Copy link
Author

banlex73 commented Oct 29, 2021 via email

@rjuju
Copy link
Member

rjuju commented Oct 29, 2021

Have you already implemented this or is it some general approach that you would like? Unfortunately the images are not displayed.

Because as far as data collection goes, you could entirely do it in a pluggable way. If your python script inserts the explain plans with a timestamp on your local instance (or anywhere where a query source could retrieve it, like using foreign data wrapper or something else), you could write custom snapshot / coalesce / purge functions and therefore implement a custom datasource that powa and powa-collector will handle like the rest of the data sources (see https://powa.readthedocs.io/en/latest/components/powa-archivist/development.html). Maybe that's what you already did? Note that I don't personally maintain such custom datasources and I don't know if anyone does, so maybe there are some small issues with that, but nothing that can't be fixed.

The bigger problem would come from the UI. For now it's not possible to have custom widgets on powa-web, but that's also probably doable. If you want to be able to do that I can try to make that work.

@banlex73
Copy link
Author

banlex73 commented Oct 29, 2021 via email

@banlex73
Copy link
Author

banlex73 commented Oct 29, 2021 via email

@rjuju
Copy link
Member

rjuju commented Oct 29, 2021

Yes, I have already implemented it as a draft version.

Ah nice! So would you like to be able to do that using a system of custom plugins and maybe additional API for enabling custom extension on the powa side rather than forking powa-web and plain INSERTs?

just installed pg_store_plans
Looks great, there is everything what I need. Hope one day it will support PG14!

Oh I didn't know that it wasn't compatible with postgres 14. I will try to ping some of the developers to see if they plan do to something about it or would welcome some PR.

@banlex73
Copy link
Author

banlex73 commented Nov 2, 2021 via email

@rjuju
Copy link
Member

rjuju commented Nov 25, 2021

@banlex73 good news, the current development version of pg_store_plans is now compatible with pg14. It should also be way easier to integrate with powa as they kindly agreed to have the extension rely on a single queryid source.

@banlex73
Copy link
Author

banlex73 commented Nov 25, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants