Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b1ea2f

Browse files
committed
Cause library-preload feature to report error if specified initialization
function is not found. Also, make all the PL libraries have initializationfunctions with standard names. Patch from Joe Conway.
1 parent8488f25 commit8b1ea2f

File tree

8 files changed

+176
-57
lines changed

8 files changed

+176
-57
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.197 2003/07/29 00:03:17 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.198 2003/07/31 18:36:17 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1004,29 +1004,35 @@ SET ENABLE_SEQSCAN TO OFF;
10041004
<listitem>
10051005
<para>
10061006
This variable specifies one or more shared libraries that are
1007-
to be preloaded at server start.An initialization function
1008-
canalso beoptionally specified by adding a colon followed by
1009-
the name of the initialization function after the library
1010-
name. For example
1011-
<literal>'$libdir/mylib:init_mylib'</literal> would cause
1012-
<literal>mylib</> to be preloaded and <literal>init_mylib</>
1013-
to be executed. If more than one library is to be loaded,they
1014-
must be delimitedwitha comma.
1007+
to be preloaded at server start.A parameterless initialization
1008+
functioncanoptionally becalled for each library. To specify
1009+
that, add a colon andthe name of the initialization function after
1010+
the library name. For example
1011+
<literal>'$libdir/mylib:mylib_init'</literal> would cause
1012+
<literal>mylib</> to be preloaded and <literal>mylib_init</>
1013+
to be executed. If more than one library is to be loaded,separate
1014+
their nameswithcommas.
10151015
</para>
10161016

10171017
<para>
1018-
If <literal>mylib</> is not found, the server will fail to
1019-
start. However, if <literal>init_mylib</> is not found,
1020-
<literal>mylib</> will still be preloaded without executing
1021-
the initialization function.
1018+
If <literal>mylib</> or <literal>mylib_init</> are not found, the
1019+
server will fail to start.
1020+
</para>
1021+
1022+
<para>
1023+
PostgreSQL procedural language libraries may be preloaded in this way,
1024+
typically by using the syntax
1025+
<literal>'$libdir/plXXX:plXXX_init'</literal>
1026+
where <literal>XXX</literal> is <literal>pgsql</>,
1027+
<literal>perl</>, <literal>tcl</>, or <literal>python</>.
10221028
</para>
10231029

10241030
<para>
10251031
By preloading a shared library (and initializing it if
10261032
applicable), the library startup time is avoided when the
10271033
library is first used. However, the time to start each new
1028-
server process may increase, even if that process never
1029-
uses the library.
1034+
server process may increase, even if that process never
1035+
uses the library.
10301036
</para>
10311037
</listitem>
10321038
</varlistentry>

‎src/backend/utils/init/miscinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.108 2003/07/28 00:09:16 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.109 2003/07/31 18:36:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1165,7 +1165,7 @@ process_preload_libraries(char *preload_libraries_string)
11651165
}
11661166

11671167
initfunc= (func_ptr)load_external_function(filename,funcname,
1168-
false,NULL);
1168+
true,NULL);
11691169
if (initfunc)
11701170
(*initfunc)();
11711171

‎src/pl/plperl/plperl.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.37 2003/07/25 23:37:28 tgl Exp $
36+
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.38 2003/07/31 18:36:28 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -101,6 +101,7 @@ static void plperl_init_all(void);
101101
staticvoidplperl_init_interp(void);
102102

103103
Datumplperl_call_handler(PG_FUNCTION_ARGS);
104+
voidplperl_init(void);
104105

105106
staticDatumplperl_func_handler(PG_FUNCTION_ARGS);
106107

@@ -128,12 +129,15 @@ perm_fmgr_info(Oid functionId, FmgrInfo *finfo)
128129
}
129130

130131
/**********************************************************************
131-
* plperl_init_all()- Initialize all
132+
* plperl_init()- Initialize everything that can be
133+
* safely initialized during postmaster
134+
* startup.
135+
*
136+
* DO NOT make this static --- it has to be callable by preload
132137
**********************************************************************/
133-
staticvoid
134-
plperl_init_all(void)
138+
void
139+
plperl_init(void)
135140
{
136-
137141
/************************************************************
138142
* Do initialization only once
139143
************************************************************/
@@ -168,6 +172,26 @@ plperl_init_all(void)
168172
plperl_firstcall=0;
169173
}
170174

175+
/**********************************************************************
176+
* plperl_init_all()- Initialize all
177+
**********************************************************************/
178+
staticvoid
179+
plperl_init_all(void)
180+
{
181+
182+
/************************************************************
183+
* Execute postmaster-startup safe initialization
184+
************************************************************/
185+
if (plperl_firstcall)
186+
plperl_init();
187+
188+
/************************************************************
189+
* Any other initialization that must be done each time a new
190+
* backend starts -- currently none
191+
************************************************************/
192+
193+
}
194+
171195

172196
/**********************************************************************
173197
* plperl_init_interp() - Create the Perl interpreter
@@ -222,10 +246,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
222246
Datumretval;
223247

224248
/************************************************************
225-
* Initialize interpreter on first call
249+
* Initialize interpreter
226250
************************************************************/
227-
if (plperl_firstcall)
228-
plperl_init_all();
251+
plperl_init_all();
229252

230253
/************************************************************
231254
* Connect to SPI manager

‎src/pl/plpgsql/src/pl_comp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.63 2003/07/27 21:49:54 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.64 2003/07/31 18:36:35 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -106,7 +106,6 @@ static PLpgSQL_type *build_datatype(HeapTuple typeTup, int32 typmod);
106106
staticvoidcompute_function_hashkey(FmgrInfo*flinfo,
107107
Form_pg_procprocStruct,
108108
PLpgSQL_func_hashkey*hashkey);
109-
staticvoidplpgsql_HashTableInit(void);
110109
staticPLpgSQL_function*plpgsql_HashTableLookup(PLpgSQL_func_hashkey*func_key);
111110
staticvoidplpgsql_HashTableInsert(PLpgSQL_function*function,
112111
PLpgSQL_func_hashkey*func_key);
@@ -1743,7 +1742,8 @@ compute_function_hashkey(FmgrInfo *flinfo,
17431742
}
17441743
}
17451744

1746-
staticvoid
1745+
/* exported so we can call it from plpgsql_init() */
1746+
void
17471747
plpgsql_HashTableInit(void)
17481748
{
17491749
HASHCTLctl;

‎src/pl/plpgsql/src/pl_handler.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.15 2003/07/27 17:10:07 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.16 2003/07/31 18:36:35 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -44,6 +44,45 @@
4444
#include"utils/builtins.h"
4545
#include"utils/syscache.h"
4646

47+
staticintplpgsql_firstcall=1;
48+
49+
voidplpgsql_init(void);
50+
staticvoidplpgsql_init_all(void);
51+
52+
53+
/*
54+
* plpgsql_init()- postmaster-startup safe initialization
55+
*
56+
* DO NOT make this static --- it has to be callable by preload
57+
*/
58+
void
59+
plpgsql_init(void)
60+
{
61+
/* Do initialization only once */
62+
if (!plpgsql_firstcall)
63+
return;
64+
65+
plpgsql_HashTableInit();
66+
67+
plpgsql_firstcall=0;
68+
}
69+
70+
/*
71+
* plpgsql_init_all()- Initialize all
72+
*/
73+
staticvoid
74+
plpgsql_init_all(void)
75+
{
76+
/* Execute any postmaster-startup safe initialization */
77+
if (plpgsql_firstcall)
78+
plpgsql_init();
79+
80+
/*
81+
* Any other initialization that must be done each time a new
82+
* backend starts -- currently none
83+
*/
84+
85+
}
4786

4887
/* ----------
4988
* plpgsql_call_handler
@@ -61,6 +100,9 @@ plpgsql_call_handler(PG_FUNCTION_ARGS)
61100
PLpgSQL_function*func;
62101
Datumretval;
63102

103+
/* perform initialization */
104+
plpgsql_init_all();
105+
64106
/*
65107
* Connect to SPI manager
66108
*/

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.37 2003/07/01 21:47:09 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.38 2003/07/31 18:36:35 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -613,6 +613,7 @@ extern PLpgSQL_row *plpgsql_build_rowtype(Oid classOid);
613613
externvoidplpgsql_adddatum(PLpgSQL_datum*new);
614614
externintplpgsql_add_initdatums(int**varnos);
615615
externvoidplpgsql_yyerror(constchar*s);
616+
externvoidplpgsql_HashTableInit(void);
616617

617618
/* ----------
618619
* Functions in pl_handler.c

‎src/pl/plpython/plpython.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
*$Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.35 2003/07/25 23:37:30 tgl Exp $
32+
*$Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.36 2003/07/31 18:36:39 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -170,10 +170,12 @@ typedef struct PLyResultObject
170170
/* function declarations
171171
*/
172172

173-
/* the only exported function, with the magic telling Postgresql
174-
* what function call interface it implements.
173+
/* Two exported functions: first is the magic telling Postgresql
174+
* what function call interface it implements. Second allows
175+
* preinitialization of the interpreter during postmaster startup.
175176
*/
176177
Datumplpython_call_handler(PG_FUNCTION_ARGS);
178+
voidplpython_init(void);
177179

178180
PG_FUNCTION_INFO_V1(plpython_call_handler);
179181

@@ -329,8 +331,7 @@ plpython_call_handler(PG_FUNCTION_ARGS)
329331

330332
enter();
331333

332-
if (PLy_first_call)
333-
PLy_init_all();
334+
PLy_init_all();
334335

335336
if (SPI_connect()!=SPI_OK_CONNECT)
336337
elog(ERROR,"could not connect to SPI manager");
@@ -2302,11 +2303,22 @@ PLy_spi_error_string(int code)
23022303
/* language handler and interpreter initialization
23032304
*/
23042305

2306+
/*
2307+
* plpython_init()- Initialize everything that can be
2308+
* safely initialized during postmaster
2309+
* startup.
2310+
*
2311+
* DO NOT make this static --- it has to be callable by preload
2312+
*/
23052313
void
2306-
PLy_init_all(void)
2314+
plpython_init(void)
23072315
{
23082316
staticvolatileintinit_active=0;
23092317

2318+
/* Do initialization only once */
2319+
if (!PLy_first_call)
2320+
return;
2321+
23102322
enter();
23112323

23122324
if (init_active)
@@ -2327,6 +2339,20 @@ PLy_init_all(void)
23272339
leave();
23282340
}
23292341

2342+
staticvoid
2343+
PLy_init_all(void)
2344+
{
2345+
/* Execute postmaster-startup safe initialization */
2346+
if (PLy_first_call)
2347+
plpython_init();
2348+
2349+
/*
2350+
* Any other initialization that must be done each time a new
2351+
* backend starts -- currently none
2352+
*/
2353+
2354+
}
2355+
23302356
void
23312357
PLy_init_interp(void)
23322358
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp