How can I store XML explain plan (or any other format) in PostgreSQL database?
Test data: explain (verbose, format xml) select 1
Table to store results: create table tmp.explain_plan_data (expp xml);
My naive test failed:
insert into tmp.explain_plan_data values (explain (verbose, format xml) select 1);
It seems that explain cannot be used in any other select statement, the following statement does not work either:
select * from (explain (verbose, format xml) select 1) a
We are using PostreSQL 9.1.6
It is not possible to capture
EXPLAINoutput using subqueries, you should go for a PL/pgSQL procedure:Now you can query it like this:
And insert into your target table:
Perhaps explain output alone in the table is not so handy, I would rather added
original query and
timestamptzof the insert.