debugging tools inside postgres

Started by HuangQiover 14 years ago7 messages
#1HuangQi
huangqiyx@gmail.com

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

#2Shigeru Hanada
shigeru.hanada@gmail.com
In reply to: HuangQi (#1)
Re: debugging tools inside postgres

(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

#3HuangQi
huangqiyx@gmail.com
In reply to: Shigeru Hanada (#2)
Re: debugging tools inside postgres

2011/6/24 Shigeru Hanada <shigeru.hanada@gmail.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

#4Shigeru Hanada
shigeru.hanada@gmail.com
In reply to: HuangQi (#3)
Re: debugging tools inside postgres

(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

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Shigeru Hanada (#2)
Re: debugging tools inside postgres

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

#6HuangQi
huangqiyx@gmail.com
In reply to: Tom Lane (#5)
Re: debugging tools inside postgres

On 24 June 2011 23:21, Tom Lane <tgl@sss.pgh.pa.us> wrote:

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

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

#7Martijn van Oosterhout
kleptog@svana.org
In reply to: HuangQi (#1)
Re: debugging tools inside postgres

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/

Show quoted text

Patriotism is when love of your own people comes first; nationalism,
when hate for people other than your own comes first.
- Charles de Gaulle