]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/sql-createextension.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / sql-createextension.html
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>CREATE EXTENSION</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 Vsnapshot" /><link rel="prev" href="sql-createeventtrigger.html" title="CREATE EVENT TRIGGER" /><link rel="next" href="sql-createforeigndatawrapper.html" title="CREATE FOREIGN DATA WRAPPER" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE EXTENSION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createeventtrigger.html" title="CREATE EVENT TRIGGER">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createforeigndatawrapper.html" title="CREATE FOREIGN DATA WRAPPER">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATEEXTENSION"><div class="titlepage"></div><a id="id-1.9.3.64.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE EXTENSION</span></h2><p>CREATE EXTENSION — install an extension</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 CREATE EXTENSION [ IF NOT EXISTS ] <em class="replaceable"><code>extension_name</code></em>
4     [ WITH ] [ SCHEMA <em class="replaceable"><code>schema_name</code></em> ]
5              [ VERSION <em class="replaceable"><code>version</code></em> ]
6              [ CASCADE ]
7 </pre></div><div class="refsect1" id="id-1.9.3.64.5"><h2>Description</h2><p>
8    <code class="command">CREATE EXTENSION</code> loads a new extension into the current
9    database.  There must not be an extension of the same name already loaded.
10   </p><p>
11    Loading an extension essentially amounts to running the extension's script
12    file.  The script will typically create new <acronym class="acronym">SQL</acronym> objects such as
13    functions, data types, operators and index support methods.
14    <code class="command">CREATE EXTENSION</code> additionally records the identities
15    of all the created objects, so that they can be dropped again if
16    <code class="command">DROP EXTENSION</code> is issued.
17   </p><p>
18    The user who runs <code class="command">CREATE EXTENSION</code> becomes the
19    owner of the extension for purposes of later privilege checks, and
20    normally also becomes the owner of any objects created by the
21    extension's script.
22   </p><p>
23    Loading an extension ordinarily requires the same privileges that would
24    be required to create its component objects.  For many extensions this
25    means superuser privileges are needed.
26    However, if the extension is marked <em class="firstterm">trusted</em> in
27    its control file, then it can be installed by any user who has
28    <code class="literal">CREATE</code> privilege on the current database.
29    In this case the extension object itself will be owned by the calling
30    user, but the contained objects will be owned by the bootstrap superuser
31    (unless the extension's script explicitly assigns them to the calling
32    user).  This configuration gives the calling user the right to drop the
33    extension, but not to modify individual objects within it.
34   </p></div><div class="refsect1" id="id-1.9.3.64.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">IF NOT EXISTS</code></span></dt><dd><p>
35         Do not throw an error if an extension with the same name already
36         exists.  A notice is issued in this case.  Note that there is no
37         guarantee that the existing extension is anything like the one that
38         would have been created from the currently-available script file.
39        </p></dd><dt><span class="term"><em class="replaceable"><code>extension_name</code></em></span></dt><dd><p>
40         The name of the extension to be
41         installed. <span class="productname">PostgreSQL</span> will create the
42         extension using details from the file <code class="filename"><em class="replaceable"><code>extension_name</code></em>.control</code>,
43         found via the server's extension control path (set by <a class="xref" href="runtime-config-client.html#GUC-EXTENSION-CONTROL-PATH">extension_control_path</a>.)
44        </p></dd><dt><span class="term"><em class="replaceable"><code>schema_name</code></em></span></dt><dd><p>
45         The name of the schema in which to install the extension's
46         objects, given that the extension allows its contents to be
47         relocated.  The named schema must already exist.
48         If not specified, and the extension's control file does not specify a
49         schema either, the current default object creation schema is used.
50        </p><p>
51         If the extension specifies a <code class="literal">schema</code> parameter in its
52         control file, then that schema cannot be overridden with
53         a <code class="literal">SCHEMA</code> clause.  Normally, an error will be raised if
54         a <code class="literal">SCHEMA</code> clause is given and it conflicts with the
55         extension's <code class="literal">schema</code> parameter.  However, if
56         the <code class="literal">CASCADE</code> clause is also given,
57         then <em class="replaceable"><code>schema_name</code></em> is
58         ignored when it conflicts.  The
59         given <em class="replaceable"><code>schema_name</code></em> will be
60         used for installation of any needed extensions that do not
61         specify <code class="literal">schema</code> in their control files.
62        </p><p>
63         Remember that the extension itself is not considered to be within any
64         schema: extensions have unqualified names that must be unique
65         database-wide.  But objects belonging to the extension can be within
66         schemas.
67        </p></dd><dt><span class="term"><em class="replaceable"><code>version</code></em></span></dt><dd><p>
68         The version of the extension to install.  This can be written as
69         either an identifier or a string literal.  The default version is
70         whatever is specified in the extension's control file.
71        </p></dd><dt><span class="term"><code class="literal">CASCADE</code></span></dt><dd><p>
72         Automatically install any extensions that this extension depends on
73         that are not already installed.  Their dependencies are likewise
74         automatically installed, recursively.  The <code class="literal">SCHEMA</code> clause,
75         if given, applies to all extensions that get installed this way.
76         Other options of the statement are not applied to
77         automatically-installed extensions; in particular, their default
78         versions are always selected.
79        </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.64.7"><h2>Notes</h2><p>
80    Before you can use <code class="command">CREATE EXTENSION</code> to load an extension
81    into a database, the extension's supporting files must be installed.
82    Information about installing the extensions supplied with
83    <span class="productname">PostgreSQL</span> can be found in
84    <a class="link" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Additional Supplied Modules</a>.
85   </p><p>
86    The extensions currently available for loading can be identified from the
87    <a class="link" href="view-pg-available-extensions.html" title="53.3. pg_available_extensions"><code class="structname">pg_available_extensions</code></a>
88    or
89    <a class="link" href="view-pg-available-extension-versions.html" title="53.4. pg_available_extension_versions"><code class="structname">pg_available_extension_versions</code></a>
90    system views.
91   </p><div class="caution"><h3 class="title">Caution</h3><p>
92     Installing an extension as superuser requires trusting that the
93     extension's author wrote the extension installation script in a secure
94     fashion.  It is not terribly difficult for a malicious user to create
95     trojan-horse objects that will compromise later execution of a
96     carelessly-written extension script, allowing that user to acquire
97     superuser privileges.  However, trojan-horse objects are only hazardous
98     if they are in the <code class="varname">search_path</code> during script
99     execution, meaning that they are in the extension's installation target
100     schema or in the schema of some extension it depends on.  Therefore, a
101     good rule of thumb when dealing with extensions whose scripts have not
102     been carefully vetted is to install them only into schemas for which
103     CREATE privilege has not been and will not be granted to any untrusted
104     users.  Likewise for any extensions they depend on.
105    </p><p>
106     The extensions supplied with <span class="productname">PostgreSQL</span> are
107     believed to be secure against installation-time attacks of this sort,
108     except for a few that depend on other extensions.  As stated in the
109     documentation for those extensions, they should be installed into secure
110     schemas, or installed into the same schemas as the extensions they
111     depend on, or both.
112    </p></div><p>
113    For information about writing new extensions, see
114    <a class="xref" href="extend-extensions.html" title="36.17. Packaging Related Objects into an Extension">Section 36.17</a>.
115   </p></div><div class="refsect1" id="id-1.9.3.64.8"><h2>Examples</h2><p>
116    Install the <a class="link" href="hstore.html" title="F.17. hstore — hstore key/value datatype">hstore</a> extension into the
117    current database, placing its objects in schema <code class="literal">addons</code>:
118 </p><pre class="programlisting">
119 CREATE EXTENSION hstore SCHEMA addons;
120 </pre><p>
121    Another way to accomplish the same thing:
122 </p><pre class="programlisting">
123 SET search_path = addons;
124 CREATE EXTENSION hstore;
125 </pre></div><div class="refsect1" id="id-1.9.3.64.9"><h2>Compatibility</h2><p>
126    <code class="command">CREATE EXTENSION</code> is a <span class="productname">PostgreSQL</span>
127    extension.
128   </p></div><div class="refsect1" id="id-1.9.3.64.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-alterextension.html" title="ALTER EXTENSION"><span class="refentrytitle">ALTER EXTENSION</span></a>, <a class="xref" href="sql-dropextension.html" title="DROP EXTENSION"><span class="refentrytitle">DROP EXTENSION</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createeventtrigger.html" title="CREATE EVENT TRIGGER">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createforeigndatawrapper.html" title="CREATE FOREIGN DATA WRAPPER">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE EVENT TRIGGER </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE FOREIGN DATA WRAPPER</td></tr></table></div></body></html>