Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_extension.sgml`
89de6abe29ca9aea0ffe5fd6b92eff513f23ab63a3274eab0000000100000fa1
<!--
doc/src/sgml/ref/create_extension.sgml
PostgreSQL documentation
-->

<refentry id="sql-createextension">
 <indexterm zone="sql-createextension">
  <primary>CREATE EXTENSION</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>CREATE EXTENSION</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE EXTENSION</refname>
  <refpurpose>install an extension</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE EXTENSION [ IF NOT EXISTS ] <replaceable class="parameter">extension_name</replaceable>
    [ WITH ] [ SCHEMA <replaceable class="parameter">schema_name</replaceable> ]
             [ VERSION <replaceable class="parameter">version</replaceable> ]
             [ CASCADE ]
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE EXTENSION</command> loads a new extension into the current
   database.  There must not be an extension of the same name already loaded.
  </para>

  <para>
   Loading an extension essentially amounts to running the extension's script
   file.  The script will typically create new <acronym>SQL</acronym> objects such as
   functions, data types, operators and index support methods.
   <command>CREATE EXTENSION</command> additionally records the identities
   of all the created objects, so that they can be dropped again if
   <command>DROP EXTENSION</command> is issued.
  </para>

  <para>
   The user who runs <command>CREATE EXTENSION</command> becomes the
   owner of the extension for purposes of later privilege checks, and
   normally also becomes the owner of any objects created by the
   extension's script.
  </para>

  <para>
   Loading an extension ordinarily requires the same privileges that would
   be required to create its component objects.  For many extensions this
   means superuser privileges are needed.
   However, if the extension is marked <firstterm>trusted</firstterm> in
   its control file, then it can be installed by any user who has
   <literal>CREATE</literal> privilege on the current database.
   In this case the extension object itself will be owned by the calling
   user, but the contained objects will be owned by the bootstrap superuser
   (unless the extension's script explicitly assigns them to the calling
   user).  This configuration gives the calling user the right to drop the
   extension, but not to modify individual objects within it.
  </para>

 </refsect1>

 <refsect1>
  <title>Parameters</title>

    <variablelist>
     <varlistentry>
      <term><literal>IF NOT EXISTS</literal></term>
      <listitem>
       <para>
        Do not throw an error if an extension with the same name already
        exists.  A notice is issued in this case.  Note that there is no
        guarantee that the existing extension is anything like the one that
        would have been created from the currently-available script file.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">extension_name</replaceable></term>
      <listitem>
       <para>
        The name of the extension to be
        installed. <productname>PostgreSQL</productname> will create the
        extension using details from the file <filename><replaceable
        class="parameter">extension_name</replaceable>.control</filename>,
        found via the server's extension control path (set by <xref
        linkend="guc-extension-control-path"/>.)
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">schema_name</replaceable></term>
      <listitem>
       <para>
        The name of the schema in which to install the extension's
        objects, given that the extension allows its contents to be
        relocated.  The named schema must already exist.
        If not specified, and the extension's control file does not specify a
        schema either, the

Title: CREATE EXTENSION
Summary
The CREATE EXTENSION command loads a new extension into the current database. It executes the extension's script file, creating SQL objects and recording their identities for later removal. The user running the command becomes the extension owner. Trusted extensions can be installed by users with CREATE privilege, with the bootstrap superuser owning the contained objects.