4 CREATE EXTENSION — install an extension
8 CREATE EXTENSION [ IF NOT EXISTS ] extension_name
9 [ WITH ] [ SCHEMA schema_name ]
15 CREATE EXTENSION loads a new extension into the current database. There
16 must not be an extension of the same name already loaded.
18 Loading an extension essentially amounts to running the extension's
19 script file. The script will typically create new SQL objects such as
20 functions, data types, operators and index support methods. CREATE
21 EXTENSION additionally records the identities of all the created
22 objects, so that they can be dropped again if DROP EXTENSION is issued.
24 The user who runs CREATE EXTENSION becomes the owner of the extension
25 for purposes of later privilege checks, and normally also becomes the
26 owner of any objects created by the extension's script.
28 Loading an extension ordinarily requires the same privileges that would
29 be required to create its component objects. For many extensions this
30 means superuser privileges are needed. However, if the extension is
31 marked trusted in its control file, then it can be installed by any
32 user who has CREATE privilege on the current database. In this case the
33 extension object itself will be owned by the calling user, but the
34 contained objects will be owned by the bootstrap superuser (unless the
35 extension's script explicitly assigns them to the calling user). This
36 configuration gives the calling user the right to drop the extension,
37 but not to modify individual objects within it.
42 Do not throw an error if an extension with the same name already
43 exists. A notice is issued in this case. Note that there is no
44 guarantee that the existing extension is anything like the one
45 that would have been created from the currently-available script
49 The name of the extension to be installed. PostgreSQL will
50 create the extension using details from the file
51 extension_name.control, found via the server's extension control
52 path (set by extension_control_path.)
55 The name of the schema in which to install the extension's
56 objects, given that the extension allows its contents to be
57 relocated. The named schema must already exist. If not
58 specified, and the extension's control file does not specify a
59 schema either, the current default object creation schema is
62 If the extension specifies a schema parameter in its control
63 file, then that schema cannot be overridden with a SCHEMA
64 clause. Normally, an error will be raised if a SCHEMA clause is
65 given and it conflicts with the extension's schema parameter.
66 However, if the CASCADE clause is also given, then schema_name
67 is ignored when it conflicts. The given schema_name will be used
68 for installation of any needed extensions that do not specify
69 schema in their control files.
71 Remember that the extension itself is not considered to be
72 within any schema: extensions have unqualified names that must
73 be unique database-wide. But objects belonging to the extension
74 can be within schemas.
77 The version of the extension to install. This can be written as
78 either an identifier or a string literal. The default version is
79 whatever is specified in the extension's control file.
82 Automatically install any extensions that this extension depends
83 on that are not already installed. Their dependencies are
84 likewise automatically installed, recursively. The SCHEMA
85 clause, if given, applies to all extensions that get installed
86 this way. Other options of the statement are not applied to
87 automatically-installed extensions; in particular, their default
88 versions are always selected.
92 Before you can use CREATE EXTENSION to load an extension into a
93 database, the extension's supporting files must be installed.
94 Information about installing the extensions supplied with PostgreSQL
95 can be found in Additional Supplied Modules.
97 The extensions currently available for loading can be identified from
98 the pg_available_extensions or pg_available_extension_versions system
103 Installing an extension as superuser requires trusting that the
104 extension's author wrote the extension installation script in a secure
105 fashion. It is not terribly difficult for a malicious user to create
106 trojan-horse objects that will compromise later execution of a
107 carelessly-written extension script, allowing that user to acquire
108 superuser privileges. However, trojan-horse objects are only hazardous
109 if they are in the search_path during script execution, meaning that
110 they are in the extension's installation target schema or in the schema
111 of some extension it depends on. Therefore, a good rule of thumb when
112 dealing with extensions whose scripts have not been carefully vetted is
113 to install them only into schemas for which CREATE privilege has not
114 been and will not be granted to any untrusted users. Likewise for any
115 extensions they depend on.
117 The extensions supplied with PostgreSQL are believed to be secure
118 against installation-time attacks of this sort, except for a few that
119 depend on other extensions. As stated in the documentation for those
120 extensions, they should be installed into secure schemas, or installed
121 into the same schemas as the extensions they depend on, or both.
123 For information about writing new extensions, see Section 36.17.
127 Install the hstore extension into the current database, placing its
128 objects in schema addons:
129 CREATE EXTENSION hstore SCHEMA addons;
131 Another way to accomplish the same thing:
132 SET search_path = addons;
133 CREATE EXTENSION hstore;
137 CREATE EXTENSION is a PostgreSQL extension.
141 ALTER EXTENSION, DROP EXTENSION