1- <!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.79 2010/02/05 18:11:46 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.80 2010/02/12 19:35:25 adunstan Exp $ -->
22
33 <chapter id="plperl">
44 <title>PL/Perl - Perl Procedural Language</title>
@@ -831,6 +831,13 @@ $$ LANGUAGE plperl;
831831 <literal>return $_SHARED{myquote}->($_[0]);</literal>
832832 at the expense of readability.)
833833 </para>
834+
835+ <para>
836+ The <varname>%_SHARED</varname> variable and other global state within
837+ the language is public data, available to all PL/Perl functions within a
838+ session. Use with care, especially in situations that involve use of
839+ multiple roles or <literal>SECURITY DEFINER</> functions.
840+ </para>
834841 </sect1>
835842
836843 <sect1 id="plperl-trusted">
@@ -1127,26 +1134,27 @@ CREATE TRIGGER test_valid_id_trig
11271134
11281135 <variablelist>
11291136
1130- <varlistentry id="guc-plperl-on-perl- init" xreflabel="plperl.on_perl_init ">
1131- <term><varname>plperl.on_perl_init </varname> (<type>string</type>)</term>
1137+ <varlistentry id="guc-plperl-on-init" xreflabel="plperl.on_init ">
1138+ <term><varname>plperl.on_init </varname> (<type>string</type>)</term>
11321139 <indexterm>
1133- <primary><varname>plperl.on_perl_init </> configuration parameter</primary>
1140+ <primary><varname>plperl.on_init </> configuration parameter</primary>
11341141 </indexterm>
11351142 <listitem>
11361143 <para>
1137- Specifies perl code to be executed when a perl interpreter is first initialized.
1144+ Specifies Perl code to be executed when a Perl interpreter is first initialized
1145+ and before it is specialized for use by <literal>plperl</> or <literal>plperlu</>.
11381146 The SPI functions are not available when this code is executed.
11391147 If the code fails with an error it will abort the initialization of the interpreter
11401148 and propagate out to the calling query, causing the current transaction
11411149 or subtransaction to be aborted.
11421150 </para>
11431151 <para>
1144- The perl code is limited to a single string. Longer code can be placed
1145- into a module and loaded by the <literal>on_perl_init </> string.
1152+ The Perl code is limited to a single string. Longer code can be placed
1153+ into a module and loaded by the <literal>on_init </> string.
11461154 Examples:
11471155<programlisting>
1148- plplerl.on_perl_init = '$ENV{NYTPROF}="start=no"; require Devel::NYTProf::PgPLPerl'
1149- plplerl.on_perl_init = 'use lib "/my/app"; use MyApp::PgInit;'
1156+ plplerl.on_init = '$ENV{NYTPROF}="start=no"; require Devel::NYTProf::PgPLPerl'
1157+ plplerl.on_init = 'use lib "/my/app"; use MyApp::PgInit;'
11501158</programlisting>
11511159 </para>
11521160 <para>
@@ -1160,6 +1168,56 @@ plplerl.on_perl_init = 'use lib "/my/app"; use MyApp::PgInit;'
11601168 </listitem>
11611169 </varlistentry>
11621170
1171+ <varlistentry id="guc-plperl-on-plperl-init" xreflabel="plperl.on_plperl_init">
1172+ <term><varname>plperl.on_plperl_init</varname> (<type>string</type>)</term>
1173+ <term><varname>plperl.on_plperlu_init</varname> (<type>string</type>)</term>
1174+ <indexterm>
1175+ <primary><varname>plperl.on_plperl_init</> configuration parameter</primary>
1176+ </indexterm>
1177+ <indexterm>
1178+ <primary><varname>plperl.on_plperlu_init</> configuration parameter</primary>
1179+ </indexterm>
1180+ <listitem>
1181+ <para>
1182+ These parameters specify Perl code to be executed when the
1183+ <literal>plperl</>, or <literal>plperlu</> language is first used in a
1184+ session. Changes to these parameters after the corresponding language
1185+ has been used will have no effect.
1186+ The SPI functions are not available when this code is executed.
1187+ Only superusers can change these settings.
1188+ The Perl code in <literal>plperl.on_plperl_init</> can only perform trusted operations.
1189+ </para>
1190+ <para>
1191+ The effect of setting these parameters is very similar to executing a
1192+ <literal>DO</> command with the Perl code before any other use of the
1193+ language. The parameters are useful when you want to execute the Perl
1194+ code automatically on every connection, or when a connection is not
1195+ interactive. The parameters can be used by non-superusers by having a
1196+ superuser execute an <literal>ALTER USER ... SET ...</> command.
1197+ For example:
1198+ <programlisting>
1199+ ALTER USER joe SET plplerl.on_plperl_init = '$_SHARED{debug} = 1';
1200+ </programlisting>
1201+ </para>
1202+ <para>
1203+ If the code fails with an error it will abort the initialization and
1204+ propagate out to the calling query, causing the current transaction or
1205+ subtransaction to be aborted. Any changes within Perl won't be undone.
1206+ If the language is used again the initialization will be repeated.
1207+ </para>
1208+ <para>
1209+ The difference between these two settings and the
1210+ <literal>plperl.on_init</> setting is that these can be used for
1211+ settings specific to the trusted or untrusted language variant, such
1212+ as setting values in the <varname>%_SHARED</> variable. By contrast,
1213+ <literal>plperl.on_init</> is more useful for doing things like
1214+ setting the library search path for <productname>Perl</> or
1215+ loading Perl modules that don't interact directly with
1216+ <productname>PostgreSQL</>.
1217+ </para>
1218+ </listitem>
1219+ </varlistentry>
1220+
11631221 <varlistentry id="guc-plperl-use-strict" xreflabel="plperl.use_strict">
11641222 <term><varname>plperl.use_strict</varname> (<type>boolean</type>)</term>
11651223 <indexterm>
0 commit comments