Thread: debugging tools inside postgres
Hi,
I'm trying to debug a modification for the query planner. But I found it seems the data structure of my planned query is incorrect. I was trying to print out the data structure by use the "p" command in gdb which is quite inconvenient and takes time. May I know is there any embedded function in postgres to print out the node data structures, or any other plan related data structures? Thanks.
--
Best Regards
Huang Qi Victor
--
Best Regards
Huang Qi Victor
(2011/06/24 15:35), HuangQi wrote: > Hi, > I'm trying to debug a modification for the query planner. But I found it > seems the data structure of my planned query is incorrect. I was trying to > print out the data structure by use the "p" command in gdb which is quite > inconvenient and takes time. May I know is there any embedded function in > postgres to print out the node data structures, or any other plan related > data structures? Thanks. I think nodeToString() would help. This function converts node tree recursively into a string, and it's applicable for any Node-derived object, such as Expr, Var and Const. ex)elog(DEBUG1, "%s", nodeToString(plan)); Regards, -- Shigeru Hanada
2011/6/24 Shigeru Hanada <shigeru.hanada@gmail.com>
I think nodeToString() would help. This function converts node tree(2011/06/24 15:35), HuangQi wrote:
> Hi,
> I'm trying to debug a modification for the query planner. But I found it
> seems the data structure of my planned query is incorrect. I was trying to
> print out the data structure by use the "p" command in gdb which is quite
> inconvenient and takes time. May I know is there any embedded function in
> postgres to print out the node data structures, or any other plan related
> data structures? Thanks.
recursively into a string, and it's applicable for any Node-derived
object, such as Expr, Var and Const.
ex)
elog(DEBUG1, "%s", nodeToString(plan));
Regards,
--
Shigeru Hanada
Hi,
I don't know why but when I am debugging the query evaluation, the elog function can not output to shell.
--
Best Regards
Huang Qi Victor
--
Best Regards
Huang Qi Victor
(2011/06/24 19:14), HuangQi wrote: > 2011/6/24 Shigeru Hanada<shigeru.hanada@gmail.com> > >> (2011/06/24 15:35), HuangQi wrote: >> ex) >> elog(DEBUG1, "%s", nodeToString(plan)); > > Hi, > I don't know why but when I am debugging the query evaluation, the elog > function can not output to shell. What kind of tool do you use to execute the query to be evaluated? If you are using an interactive tool such as psql, please check setting of client_min_messages. Otherwise, please check settings of log_destination, logging_collector and log_min_messages to ensure that elog() prints debugging information into your server log file, or stderr of the terminal which has been used to start PostgreSQL server. Regards, -- Shigeru Hanada
Shigeru Hanada <shigeru.hanada@gmail.com> writes: > (2011/06/24 15:35), HuangQi wrote: >> I'm trying to debug a modification for the query planner. But I found it >> seems the data structure of my planned query is incorrect. I was trying to >> print out the data structure by use the "p" command in gdb which is quite >> inconvenient and takes time. May I know is there any embedded function in >> postgres to print out the node data structures, or any other plan related >> data structures? Thanks. > I think nodeToString() would help. For interactive use in gdb, I generally do call pprint(..node pointer..) which prints to the postmaster log. regards, tom lane
<div class="gmail_quote">On 24 June 2011 23:21, Tom Lane <span dir="ltr"><<a href="mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a>></span>wrote:<br /><blockquote class="gmail_quote" style="margin:00 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Shigeru Hanada <<a href="mailto:shigeru.hanada@gmail.com">shigeru.hanada@gmail.com</a>>writes:<br /> > (2011/06/24 15:35), HuangQi wrote:<br/></div><div class="im">>> I'm trying to debug a modification for the query planner. But I found it<br />>> seems the data structure of my planned query is incorrect. I was trying to<br /> >> print out the data structureby use the "p" command in gdb which is quite<br /> >> inconvenient and takes time. May I know is there anyembedded function in<br /> >> postgres to print out the node data structures, or any other plan related<br /> >>data structures? Thanks.<br /><br /> > I think nodeToString() would help.<br /><br /></div>For interactive usein gdb, I generally do<br /><br /> call pprint(..node pointer..)<br /><br /> which prints to the postmaster log.<br/><br /> regards, tom lane<br /></blockquote></div><br /><br clear="all" />Thanks, Tom, thiscall pprint() works very nice.<br />-- <br />Best Regards<br />Huang Qi Victor<br />
On Fri, Jun 24, 2011 at 02:35:08PM +0800, HuangQi wrote: > Hi, > I'm trying to debug a modification for the query planner. But I found it > seems the data structure of my planned query is incorrect. I was trying to > print out the data structure by use the "p" command in gdb which is quite > inconvenient and takes time. May I know is there any embedded function in > postgres to print out the node data structures, or any other plan related > data structures? Thanks. I don't know if anyone has done it, but recent versions of gdb apparenly can use python scripts, and use them to dump c++ library structures in readable formats. I guess someone could write some script to make debugging postgresql nicer (pretty printing snapshots, locks, etc). Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > Patriotism is when love of your own people comes first; nationalism, > when hate for people other than your own comes first. > - Charles de Gaulle