gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 line
11KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>41.1. Installing Procedural Languages</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="xplang.html" title="Chapter 41. Procedural Languages" /><link rel="next" href="plpgsql.html" title="Chapter 42. PL/pgSQL - SQL Procedural Language" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">41.1. Installing Procedural Languages</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="xplang.html" title="Chapter 41. Procedural Languages">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="xplang.html" title="Chapter 41. Procedural Languages">Up</a></td><th width="60%" align="center">Chapter 41. Procedural Languages</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="plpgsql.html" title="Chapter 42. PL/pgSQL - SQL Procedural Language">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="XPLANG-INSTALL"><div class="titlepage"><div><div><h2 class="title" style="clear: both">41.1. Installing Procedural Languages</h2></div></div></div><p>
  3. A procedural language must be <span class="quote">“<span class="quote">installed</span>”</span> into each
  4. database where it is to be used. But procedural languages installed in
  5. the database <code class="literal">template1</code> are automatically available in all
  6. subsequently created databases, since their entries in
  7. <code class="literal">template1</code> will be copied by <code class="command">CREATE DATABASE</code>.
  8. So the database administrator can
  9. decide which languages are available in which databases and can make
  10. some languages available by default if desired.
  11. </p><p>
  12. For the languages supplied with the standard distribution, it is
  13. only necessary to execute <code class="command">CREATE EXTENSION</code>
  14. <em class="replaceable"><code>language_name</code></em> to install the language into the
  15. current database.
  16. The manual procedure described below is only recommended for
  17. installing languages that have not been packaged as extensions.
  18. </p><div class="procedure" id="id-1.8.7.5.4"><p class="title"><strong>
  19. Manual Procedural Language Installation
  20. </strong></p><p>
  21. A procedural language is installed in a database in five steps,
  22. which must be carried out by a database superuser. In most cases
  23. the required SQL commands should be packaged as the installation script
  24. of an <span class="quote">“<span class="quote">extension</span>”</span>, so that <code class="command">CREATE EXTENSION</code> can be
  25. used to execute them.
  26. </p><ol class="procedure" type="1"><li class="step" id="XPLANG-INSTALL-CR1"><p>
  27. The shared object for the language handler must be compiled and
  28. installed into an appropriate library directory. This works in the same
  29. way as building and installing modules with regular user-defined C
  30. functions does; see <a class="xref" href="xfunc-c.html#DFUNC" title="37.10.5. Compiling and Linking Dynamically-Loaded Functions">Section 37.10.5</a>. Often, the language
  31. handler will depend on an external library that provides the actual
  32. programming language engine; if so, that must be installed as well.
  33. </p></li><li class="step" id="XPLANG-INSTALL-CR2"><p>
  34. The handler must be declared with the command
  35. </p><pre class="synopsis">
  36. CREATE FUNCTION <em class="replaceable"><code>handler_function_name</code></em>()
  37. RETURNS language_handler
  38. AS '<em class="replaceable"><code>path-to-shared-object</code></em>'
  39. LANGUAGE C;
  40. </pre><p>
  41. The special return type of <code class="type">language_handler</code> tells
  42. the database system that this function does not return one of
  43. the defined <acronym class="acronym">SQL</acronym> data types and is not directly usable
  44. in <acronym class="acronym">SQL</acronym> statements.
  45. </p></li><li class="step" id="XPLANG-INSTALL-CR3"><p>
  46. Optionally, the language handler can provide an <span class="quote">“<span class="quote">inline</span>”</span>
  47. handler function that executes anonymous code blocks
  48. (<a class="xref" href="sql-do.html" title="DO"><span class="refentrytitle">DO</span></a> commands)
  49. written in this language. If an inline handler function
  50. is provided by the language, declare it with a command like
  51. </p><pre class="synopsis">
  52. CREATE FUNCTION <em class="replaceable"><code>inline_function_name</code></em>(internal)
  53. RETURNS void
  54. AS '<em class="replaceable"><code>path-to-shared-object</code></em>'
  55. LANGUAGE C;
  56. </pre><p>
  57. </p></li><li class="step" id="XPLANG-INSTALL-CR4"><p>
  58. Optionally, the language handler can provide a <span class="quote">“<span class="quote">validator</span>”</span>
  59. function that checks a function definition for correctness without
  60. actually executing it. The validator function is called by
  61. <code class="command">CREATE FUNCTION</code> if it exists. If a validator function
  62. is provided by the language, declare it with a command like
  63. </p><pre class="synopsis">
  64. CREATE FUNCTION <em class="replaceable"><code>validator_function_name</code></em>(oid)
  65. RETURNS void
  66. AS '<em class="replaceable"><code>path-to-shared-object</code></em>'
  67. LANGUAGE C STRICT;
  68. </pre><p>
  69. </p></li><li class="step" id="XPLANG-INSTALL-CR5"><p>
  70. Finally, the PL must be declared with the command
  71. </p><pre class="synopsis">
  72. CREATE [<span class="optional">TRUSTED</span>] LANGUAGE <em class="replaceable"><code>language_name</code></em>
  73. HANDLER <em class="replaceable"><code>handler_function_name</code></em>
  74. [<span class="optional">INLINE <em class="replaceable"><code>inline_function_name</code></em></span>]
  75. [<span class="optional">VALIDATOR <em class="replaceable"><code>validator_function_name</code></em></span>] ;
  76. </pre><p>
  77. The optional key word <code class="literal">TRUSTED</code> specifies that
  78. the language does not grant access to data that the user would
  79. not otherwise have. Trusted languages are designed for ordinary
  80. database users (those without superuser privilege) and allows them
  81. to safely create functions and
  82. procedures. Since PL functions are executed inside the database
  83. server, the <code class="literal">TRUSTED</code> flag should only be given
  84. for languages that do not allow access to database server
  85. internals or the file system. The languages
  86. <span class="application">PL/pgSQL</span>,
  87. <span class="application">PL/Tcl</span>, and
  88. <span class="application">PL/Perl</span>
  89. are considered trusted; the languages
  90. <span class="application">PL/TclU</span>,
  91. <span class="application">PL/PerlU</span>, and
  92. <span class="application">PL/PythonU</span>
  93. are designed to provide unlimited functionality and should
  94. <span class="emphasis"><em>not</em></span> be marked trusted.
  95. </p></li></ol></div><p>
  96. <a class="xref" href="xplang-install.html#XPLANG-INSTALL-EXAMPLE" title="Example 41.1. Manual Installation of PL/Perl">Example 41.1</a> shows how the manual
  97. installation procedure would work with the language
  98. <span class="application">PL/Perl</span>.
  99. </p><div class="example" id="XPLANG-INSTALL-EXAMPLE"><p class="title"><strong>Example 41.1. Manual Installation of <span class="application">PL/Perl</span></strong></p><div class="example-contents"><p>
  100. The following command tells the database server where to find the
  101. shared object for the <span class="application">PL/Perl</span> language's call
  102. handler function:
  103. </p><pre class="programlisting">
  104. CREATE FUNCTION plperl_call_handler() RETURNS language_handler AS
  105. '$libdir/plperl' LANGUAGE C;
  106. </pre><p>
  107. </p><p>
  108. <span class="application">PL/Perl</span> has an inline handler function
  109. and a validator function, so we declare those too:
  110. </p><pre class="programlisting">
  111. CREATE FUNCTION plperl_inline_handler(internal) RETURNS void AS
  112. '$libdir/plperl' LANGUAGE C;
  113. CREATE FUNCTION plperl_validator(oid) RETURNS void AS
  114. '$libdir/plperl' LANGUAGE C STRICT;
  115. </pre><p>
  116. </p><p>
  117. The command:
  118. </p><pre class="programlisting">
  119. CREATE TRUSTED LANGUAGE plperl
  120. HANDLER plperl_call_handler
  121. INLINE plperl_inline_handler
  122. VALIDATOR plperl_validator;
  123. </pre><p>
  124. then defines that the previously declared functions
  125. should be invoked for functions and procedures where the
  126. language attribute is <code class="literal">plperl</code>.
  127. </p></div></div><br class="example-break" /><p>
  128. In a default <span class="productname">PostgreSQL</span> installation,
  129. the handler for the <span class="application">PL/pgSQL</span> language
  130. is built and installed into the <span class="quote">“<span class="quote">library</span>”</span>
  131. directory; furthermore, the <span class="application">PL/pgSQL</span> language
  132. itself is installed in all databases.
  133. If <span class="application">Tcl</span> support is configured in, the handlers for
  134. <span class="application">PL/Tcl</span> and <span class="application">PL/TclU</span> are built and installed
  135. in the library directory, but the language itself is not installed in any
  136. database by default.
  137. Likewise, the <span class="application">PL/Perl</span> and <span class="application">PL/PerlU</span>
  138. handlers are built and installed if Perl support is configured, and the
  139. <span class="application">PL/PythonU</span> handler is installed if Python support is
  140. configured, but these languages are not installed by default.
  141. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="xplang.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="xplang.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plpgsql.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 41. Procedural Languages </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 42. <span class="application">PL/pgSQL</span> - <acronym class="acronym">SQL</acronym> Procedural Language</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1