PostgreSQL::PLPerl::Trace - Simple way to trace execution of Perl statements in PL/Perl
version 1.001
Load via a line in your plperlinit.pl file:
use PostgreSQL::PLPerl::Trace;
Load via the PERL5OPT environment variable:
PERL5OPT
$ PERL5OPT='-MPostgreSQL::PLPerl::Trace' pg_ctl ...
Writes a line to the PostgreSQL log file for every PL/Perl statement executed. This can generate truly massive amounts of log data and also slows excution of PL/Perl code by at least a couple of orders of magnitude.
Why would you want to do this? Well, there are times when it's a simple and effective way to see what PL/Perl code is actually being executed.
This module is based on Devel::Trace but modified to work with PostgreSQL PL/Perl for both the plperlu language and, more significantly, for the plperl language as well. It also shows the subroutine name whenever execution moves from one subroutine to another.
plperlu
plperl
In order to use this module you need to arrange for it to be loaded when PostgreSQL initializes a Perl interpreter.
Create a plperlinit.pl file in the same directory as your postgres.conf file, if it doesn't exist already.
In the plperlinit.pl file write the code to load this module:
When it's no longer needed just comment it out by prefixing with a #.
#
Set the PERL5OPT before starting postgres, to something like this:
PERL5OPT='-e "require q{plperlinit.pl}"'
The code in the plperlinit.pl should also include delete $ENV{PERL5OPT}; to avoid any problems with nested invocations of perl, e.g., via a plperlu function.
delete $ENV{PERL5OPT};
For PostgreSQL 9.0 you can still use the PERL5OPT method described above. Alternatively, and preferably, you can use the plperl.on_init configuration variable in the postgres.conf file.
plperl.on_init
plperl.on_init='require q{plperlinit.pl};'
It you're not already using the PERL5OPT environment variable to load a plperlinit.pl file, as described above, then you can use it as a quick way to load the module for ad-hoc use:
Tim Bunce http://www.tim.bunce.name
Copyright (c) Tim Bunce, Ireland, 2010. All rights reserved. You may use and distribute on the same terms as Perl 5.10.1.
With thanks to http://www.TigerLead.com for sponsoring development.
To install PostgreSQL::PLPerl::Trace, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PostgreSQL::PLPerl::Trace
CPAN shell
perl -MCPAN -e shell install PostgreSQL::PLPerl::Trace
For more information on module installation, please visit the detailed CPAN module installation guide.