Re: debugging plpgsql functions

From: justin <justin(at)emproshunts(dot)com>
To: Chris <dmagick(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: debugging plpgsql functions
Date: 2009-02-05 05:02:07
Message-ID: 498A72CF.2090008@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Chris wrote:
> Hi all,
>
> I have a few plpgsql functions to debug to see why they are slow.
>
> They consist of a bunch of sql statements using new.* / old.*
> variables (ie not using "EXECUTE", the sql is being called directly).
>
> Is there a way to capture the actual sql that's being executed with
> variables substituted in, or even an easy way to log the variables
> being used?
>
> I couldn't see anything in the manual but maybe I missed something -
> any pointers appreciated.
>
> I tried http://pgfoundry.org/projects/edb-debugger/ but after loading
> the module, the functions wouldn't run properly (can't remember the
> error message but I can do it again if need be).
Debugging sql functions is sometimes a not to fun event. pgdebugger
has some gotchas that will bite you big time. One big item don't run
pgdebugger in a production machine i've had lock process and its done
some other odd things. I normally run the pgdebugger on a windows
install as it will install it for you. and use pgadmin two step through
the code.

One option use Raise Notice to see whats in a variable example
RAISE NOTICE 'Var1 %, Var2 %, ' , MemoryVar1, MemoryVar2 ;

then look whats returned to the client. Again i use pgAdmin for this as
it shows me all the messages sent from the server and keeps a nice easy
to read history.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kusuma Pabba 2009-02-05 06:35:31 running postgres
Previous Message Osvaldo Kussama 2009-02-05 01:59:19 Re: Elapsed time between timestamp variables in Function