Re: debugging tools inside postgres

Lists: pgsql-hackers
From: HuangQi <huangqiyx(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: debugging tools inside postgres
Date: 2011-06-24 06:35:08
Message-ID: BANLkTindKuQm+Qh+dSoqbW0UD3USyg+Cvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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


From: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
To: HuangQi <huangqiyx(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-24 08:46:11
Message-ID: 4E044ED3.5060703@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

(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


From: HuangQi <huangqiyx(at)gmail(dot)com>
To: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-24 10:14:52
Message-ID: BANLkTimMtJ6QkUTBfk3omjDiMC0mZTb78w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2011/6/24 Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>

> (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
>

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


From: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
To: HuangQi <huangqiyx(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-24 12:53:51
Message-ID: 4E0488DF.2040801@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

(2011/06/24 19:14), HuangQi wrote:
> 2011/6/24 Shigeru Hanada<shigeru(dot)hanada(at)gmail(dot)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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
Cc: HuangQi <huangqiyx(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-24 15:21:53
Message-ID: 26054.1308928913@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)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


From: HuangQi <huangqiyx(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-24 15:27:52
Message-ID: BANLkTi=Gj9c2BU62usG5G8sv9tNqxvuSvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 24 June 2011 23:21, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)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
>

Thanks, Tom, this call pprint() works very nice.
--
Best Regards
Huang Qi Victor


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: HuangQi <huangqiyx(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: debugging tools inside postgres
Date: 2011-06-25 09:05:30
Message-ID: 20110625090530.GB20648@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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(at)svana(dot)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