2 .\" Title: CREATE EXTENSION
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "CREATE EXTENSION" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 CREATE_EXTENSION \- install an extension
35 CREATE EXTENSION [ IF NOT EXISTS ] \fIextension_name\fR
36 [ WITH ] [ SCHEMA \fIschema_name\fR ]
37 [ VERSION \fIversion\fR ]
42 \fBCREATE EXTENSION\fR
43 loads a new extension into the current database\&. There must not be an extension of the same name already loaded\&.
45 Loading an extension essentially amounts to running the extension\*(Aqs script file\&. The script will typically create new
47 objects such as functions, data types, operators and index support methods\&.
48 \fBCREATE EXTENSION\fR
49 additionally records the identities of all the created objects, so that they can be dropped again if
54 \fBCREATE EXTENSION\fR
55 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\*(Aqs script\&.
57 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
59 in its control file, then it can be installed by any user who has
61 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\*(Aqs 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\&.
66 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\&.
71 The name of the extension to be installed\&.
73 will create the extension using details from the file
74 \fIextension_name\fR\&.control, found via the server\*(Aqs extension control path (set by
75 extension_control_path\&.)
80 The name of the schema in which to install the extension\*(Aqs objects, given that the extension allows its contents to be relocated\&. The named schema must already exist\&. If not specified, and the extension\*(Aqs control file does not specify a schema either, the current default object creation schema is used\&.
82 If the extension specifies a
84 parameter in its control file, then that schema cannot be overridden with a
86 clause\&. Normally, an error will be raised if a
88 clause is given and it conflicts with the extension\*(Aqs
90 parameter\&. However, if the
92 clause is also given, then
94 is ignored when it conflicts\&. The given
96 will be used for installation of any needed extensions that do not specify
98 in their control files\&.
100 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\&.
105 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\*(Aqs control file\&.
110 Automatically install any extensions that this extension depends on that are not already installed\&. Their dependencies are likewise automatically installed, recursively\&. The
112 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\&.
117 \fBCREATE EXTENSION\fR
118 to load an extension into a database, the extension\*(Aqs supporting files must be installed\&. Information about installing the extensions supplied with
121 Additional Supplied Modules\&.
123 The extensions currently available for loading can be identified from the
124 pg_available_extensions
126 pg_available_extension_versions
133 .nr an-no-space-flag 1
141 Installing an extension as superuser requires trusting that the extension\*(Aqs 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
143 during script execution, meaning that they are in the extension\*(Aqs 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\&.
145 The extensions supplied with
147 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\&.
151 For information about writing new extensions, see
157 extension into the current database, placing its objects in schema
164 CREATE EXTENSION hstore SCHEMA addons;
170 Another way to accomplish the same thing:
176 SET search_path = addons;
177 CREATE EXTENSION hstore;
184 \fBCREATE EXTENSION\fR
189 ALTER EXTENSION (\fBALTER_EXTENSION\fR(7)), DROP EXTENSION (\fBDROP_EXTENSION\fR(7))