Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 6e9fe7a8295badd66f8805a2566589de > files > 799

postgresql9.6-docs-9.6.21-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>CREATE EXTENSION</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.6.21 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="CREATE EVENT TRIGGER"
HREF="sql-createeventtrigger.html"><LINK
REL="NEXT"
TITLE="CREATE FOREIGN DATA WRAPPER"
HREF="sql-createforeigndatawrapper.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2021-02-27T18:26:08"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="4"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.6.21 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="CREATE EVENT TRIGGER"
HREF="sql-createeventtrigger.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="CREATE FOREIGN DATA WRAPPER"
HREF="sql-createforeigndatawrapper.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-CREATEEXTENSION"
></A
>CREATE EXTENSION</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN79880"
></A
><H2
>Name</H2
>CREATE EXTENSION&nbsp;--&nbsp;install an extension</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN79883"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>CREATE EXTENSION [ IF NOT EXISTS ] <TT
CLASS="REPLACEABLE"
><I
>extension_name</I
></TT
>
    [ WITH ] [ SCHEMA <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> ]
             [ VERSION <TT
CLASS="REPLACEABLE"
><I
>version</I
></TT
> ]
             [ FROM <TT
CLASS="REPLACEABLE"
><I
>old_version</I
></TT
> ]
             [ CASCADE ]</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79889"
></A
><H2
>Description</H2
><P
>   <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> loads a new extension into the current
   database.  There must not be an extension of the same name already loaded.
  </P
><P
>   Loading an extension essentially amounts to running the extension's script
   file.  The script will typically create new <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> objects such as
   functions, data types, operators and index support methods.
   <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> additionally records the identities
   of all the created objects, so that they can be dropped again if
   <TT
CLASS="COMMAND"
>DROP EXTENSION</TT
> is issued.
  </P
><P
>   Loading an extension requires the same privileges that would be
   required to create its component objects.  For most extensions this
   means superuser or database owner privileges are needed.
   The user who runs <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> becomes the
   owner of the extension for purposes of later privilege checks, as well
   as the owner of any objects created by the extension's script.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79899"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>IF NOT EXISTS</TT
></DT
><DD
><P
>        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.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>extension_name</I
></TT
></DT
><DD
><P
>        The name of the extension to be
        installed. <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> will create the
        extension using details from the file
        <TT
CLASS="LITERAL"
>SHAREDIR/extension/</TT
><TT
CLASS="REPLACEABLE"
><I
>extension_name</I
></TT
><TT
CLASS="LITERAL"
>.control</TT
>.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
></DT
><DD
><P
>        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 current default object creation schema is used.
       </P
><P
>        If the extension specifies a <TT
CLASS="LITERAL"
>schema</TT
> parameter in its
        control file, then that schema cannot be overridden with
        a <TT
CLASS="LITERAL"
>SCHEMA</TT
> clause.  Normally, an error will be raised if
        a <TT
CLASS="LITERAL"
>SCHEMA</TT
> clause is given and it conflicts with the
        extension's <TT
CLASS="LITERAL"
>schema</TT
> parameter.  However, if
        the <TT
CLASS="LITERAL"
>CASCADE</TT
> clause is also given,
        then <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> is
        ignored when it conflicts.  The
        given <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> will be
        used for installation of any needed extensions that do not
        specify <TT
CLASS="LITERAL"
>schema</TT
> in their control files.
       </P
><P
>        Remember that the extension itself is not considered to be within any
        schema: extensions have unqualified names that must be unique
        database-wide.  But objects belonging to the extension can be within
        schemas.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>version</I
></TT
></DT
><DD
><P
>        The version of the extension to install.  This can be written as
        either an identifier or a string literal.  The default version is
        whatever is specified in the extension's control file.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>old_version</I
></TT
></DT
><DD
><P
>        <TT
CLASS="LITERAL"
>FROM</TT
> <TT
CLASS="REPLACEABLE"
><I
>old_version</I
></TT
>
        must be specified when, and only when, you are attempting to install
        an extension that replaces an <SPAN
CLASS="QUOTE"
>"old style"</SPAN
> module that is just
        a collection of objects not packaged into an extension.  This option
        causes <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> to run an alternative installation
        script that absorbs the existing objects into the extension, instead
        of creating new objects.  Be careful that <TT
CLASS="LITERAL"
>SCHEMA</TT
> specifies
        the schema containing these pre-existing objects.
       </P
><P
>        The value to use for <TT
CLASS="REPLACEABLE"
><I
>old_version</I
></TT
> is determined by the
        extension's author, and might vary if there is more than one version
        of the old-style module that can be upgraded into an extension.
        For the standard additional modules supplied with pre-9.1
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, use <TT
CLASS="LITERAL"
>unpackaged</TT
>
        for <TT
CLASS="REPLACEABLE"
><I
>old_version</I
></TT
> when
        updating a module to extension style.
       </P
></DD
><DT
><TT
CLASS="LITERAL"
>CASCADE</TT
></DT
><DD
><P
>        Automatically install any extensions that this extension depends on
        that are not already installed.  Their dependencies are likewise
        automatically installed, recursively.  The <TT
CLASS="LITERAL"
>SCHEMA</TT
> clause,
        if given, applies to all extensions that get installed this way.
        Other options of the statement are not applied to
        automatically-installed extensions; in particular, their default
        versions are always selected.
       </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79957"
></A
><H2
>Notes</H2
><P
>   Before you can use <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> to load an extension
   into a database, the extension's supporting files must be installed.
   Information about installing the extensions supplied with
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> can be found in
   <A
HREF="contrib.html"
>Additional Supplied Modules</A
>.
  </P
><P
>   The extensions currently available for loading can be identified from the
   <A
HREF="view-pg-available-extensions.html"
><TT
CLASS="STRUCTNAME"
>pg_available_extensions</TT
></A
>
   or
   <A
HREF="view-pg-available-extension-versions.html"
><TT
CLASS="STRUCTNAME"
>pg_available_extension_versions</TT
></A
>
   system views.
  </P
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Caution</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>    Installing an extension as superuser requires trusting that the
    extension's author wrote the extension installation script in a secure
    fashion.  It is not terribly difficult for a malicious user to create
    trojan-horse objects that will compromise later execution of a
    carelessly-written extension script, allowing that user to acquire
    superuser privileges.  However, trojan-horse objects are only hazardous
    if they are in the <TT
CLASS="VARNAME"
>search_path</TT
> during script
    execution, meaning that they are in the extension's installation target
    schema or in the schema of some extension it depends on.  Therefore, a
    good rule of thumb when dealing with extensions whose scripts have not
    been carefully vetted is to install them only into schemas for which
    CREATE privilege has not been and will not be granted to any untrusted
    users.  Likewise for any extensions they depend on.
   </P
><P
>    The extensions supplied with <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> are
    believed to be secure against installation-time attacks of this sort,
    except for a few that depend on other extensions.  As stated in the
    documentation for those extensions, they should be installed into secure
    schemas, or installed into the same schemas as the extensions they
    depend on, or both.
   </P
></TD
></TR
></TABLE
></DIV
><P
>   For information about writing new extensions, see
   <A
HREF="extend-extensions.html"
>Section 36.15</A
>.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79975"
></A
><H2
>Examples</H2
><P
>   Install the <A
HREF="hstore.html"
>hstore</A
> extension into the
   current database, placing its objects in schema <TT
CLASS="LITERAL"
>addons</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE EXTENSION hstore SCHEMA addons;</PRE
><P>
   Another way to accomplish the same thing:
</P><PRE
CLASS="PROGRAMLISTING"
>SET search_path = addons;
CREATE EXTENSION hstore;</PRE
><P>
  </P
><P
>   Update a pre-9.1 installation of <TT
CLASS="LITERAL"
>hstore</TT
> into
   extension style:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE EXTENSION hstore SCHEMA public FROM unpackaged;</PRE
><P>
   Be careful to specify the schema in which you installed the existing
   <TT
CLASS="LITERAL"
>hstore</TT
> objects.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79986"
></A
><H2
>Compatibility</H2
><P
>   <TT
CLASS="COMMAND"
>CREATE EXTENSION</TT
> is a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
   extension.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN79991"
></A
><H2
>See Also</H2
><A
HREF="sql-alterextension.html"
>ALTER EXTENSION</A
>, <A
HREF="sql-dropextension.html"
>DROP EXTENSION</A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createeventtrigger.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createforeigndatawrapper.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>CREATE EVENT TRIGGER</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>CREATE FOREIGN DATA WRAPPER</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>