codekingpro/portable-devtools
115k
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 16.3 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">3CREATE 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 current9 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 script12 file. The script will typically create new <acronym class="acronym">SQL</acronym> objects such as13 functions, data types, operators and index support methods.14 <code class="command">CREATE EXTENSION</code> additionally records the identities15 of all the created objects, so that they can be dropped again if16 <code class="command">DROP EXTENSION</code> is issued.17 </p><p>18 The user who runs <code class="command">CREATE EXTENSION</code> becomes the19 owner of the extension for purposes of later privilege checks, and20 normally also becomes the owner of any objects created by the21 extension's script.22 </p><p>23 Loading an extension ordinarily requires the same privileges that would24 be required to create its component objects. For many extensions this25 means superuser privileges are needed.26 However, if the extension is marked <em class="firstterm">trusted</em> in27 its control file, then it can be installed by any user who has28 <code class="literal">CREATE</code> privilege on the current database.29 In this case the extension object itself will be owned by the calling30 user, but the contained objects will be owned by the bootstrap superuser31 (unless the extension's script explicitly assigns them to the calling32 user). This configuration gives the calling user the right to drop the33 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 already36 exists. A notice is issued in this case. Note that there is no37 guarantee that the existing extension is anything like the one that38 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 be41 installed. <span class="productname">PostgreSQL</span> will create the42 extension using details from the file43 <code class="literal">SHAREDIR/extension/</code><em class="replaceable"><code>extension_name</code></em><code class="literal">.control</code>.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's46 objects, given that the extension allows its contents to be47 relocated. The named schema must already exist.48 If not specified, and the extension's control file does not specify a49 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 its52 control file, then that schema cannot be overridden with53 a <code class="literal">SCHEMA</code> clause. Normally, an error will be raised if54 a <code class="literal">SCHEMA</code> clause is given and it conflicts with the55 extension's <code class="literal">schema</code> parameter. However, if56 the <code class="literal">CASCADE</code> clause is also given,57 then <em class="replaceable"><code>schema_name</code></em> is58 ignored when it conflicts. The59 given <em class="replaceable"><code>schema_name</code></em> will be60 used for installation of any needed extensions that do not61 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 any64 schema: extensions have unqualified names that must be unique65 database-wide. But objects belonging to the extension can be within66 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 as69 either an identifier or a string literal. The default version is70 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 on73 that are not already installed. Their dependencies are likewise74 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 to77 automatically-installed extensions; in particular, their default78 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 extension81 into a database, the extension's supporting files must be installed.82 Information about installing the extensions supplied with83 <span class="productname">PostgreSQL</span> can be found in84 <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 the87 <a class="link" href="view-pg-available-extensions.html" title="54.2. pg_available_extensions"><code class="structname">pg_available_extensions</code></a>88 or89 <a class="link" href="view-pg-available-extension-versions.html" title="54.3. 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 the93 extension's author wrote the extension installation script in a secure94 fashion. It is not terribly difficult for a malicious user to create95 trojan-horse objects that will compromise later execution of a96 carelessly-written extension script, allowing that user to acquire97 superuser privileges. However, trojan-horse objects are only hazardous98 if they are in the <code class="varname">search_path</code> during script99 execution, meaning that they are in the extension's installation target100 schema or in the schema of some extension it depends on. Therefore, a101 good rule of thumb when dealing with extensions whose scripts have not102 been carefully vetted is to install them only into schemas for which103 CREATE privilege has not been and will not be granted to any untrusted104 users. Likewise for any extensions they depend on.105 </p><p>106 The extensions supplied with <span class="productname">PostgreSQL</span> are107 believed to be secure against installation-time attacks of this sort,108 except for a few that depend on other extensions. As stated in the109 documentation for those extensions, they should be installed into secure110 schemas, or installed into the same schemas as the extensions they111 depend on, or both.112 </p></div><p>113 For information about writing new extensions, see114 <a class="xref" href="extend-extensions.html" title="38.17. Packaging Related Objects into an Extension">Section 38.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.18. hstore — hstore key/value datatype">hstore</a> extension into the117 current database, placing its objects in schema <code class="literal">addons</code>:118</p><pre class="programlisting">119CREATE EXTENSION hstore SCHEMA addons;120</pre><p>121 Another way to accomplish the same thing:122</p><pre class="programlisting">123SET search_path = addons;124CREATE 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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE FOREIGN DATA WRAPPER</td></tr></table></div></body></html>