Updated on 2024-06-03 GMT+08:00

CREATE EXTENSION

The extended function is for internal use only. You are advised not to use it.

Description

Installs an extension.

Precautions

  • Before running the CREATE EXTENSION command to load an extension into the database, you must install the support file for the extension first.
  • The CREATE EXTENSION command installs a new extension to a database. Ensure that no extension with the same name has been installed.
  • Installing an extension means to execute an extended script file that creates an SQL entity, such as a function, data type, operator, and index-supported method.
  • Installing an extension requires the same permissions as creating its component objects. For most extensions, this means that the superuser or database owner's permissions are required. For subsequent permission checks and entities created by the extension script, the role that runs the CREATE EXTENSION command becomes the owner of the extension.
  • During the execution of CREATE EXTENSION, if the database contains database objects with the same name as that in the EXTENSION, such as packages, synonyms, operators, directories, functions, stored procedures, views, and tables, the execution will fail.
  • Do not directly create extensions for the database to avoid unexpected errors and incompatibility problems after the upgrade. To create an extension, set enable_extension to true.
  • During the execution of CREATE EXTENSION, if the GUC parameter enable_object_special_character is set to off and "@extschema@" is used in the extension script file, the value of the schema parameter in the extension support file cannot contain any special characters in ["$'\].

Syntax

CREATE EXTENSION [ IF NOT EXISTS ] extension_name
[ WITH ] [ SCHEMA schema_name ]
[ VERSION version ]
[ FROM old_version ];

Parameters

  • IF NOT EXISTS

    If an extension with the same name exists in the system, no error is reported. However, a message is displayed. Note that this parameter does not ensure that the existing extensions of the system are the same as those created by the script.

  • extension_name

    Specifies the name of the extension to be installed. The database creates the extension by using the information in the SHAREDIR/extension/extension_name.control file.

  • schema_name

    The extension instance is installed in this schema, and the extended content can be reinstalled. The specified schema must exist. If it is not specified, the extended control file does not specify a schema either. In this case, the default schema is used.

    Extensions do not belong to any schema (no restriction is posed on the name of extensions within the scope of a database), but an extension instance belongs to a schema.

  • version

    Version of an extension to be installed, which can be written as an identifier or a string. The default version is specified in the extended control file.

  • old_version

    If you want to upgrade the content that is not contained in the old style module, you need to specify FROM old_version. This option makes CREATE EXTENSION run an installation script to install new content into the extension instead of creating an entity. Note that SCHEMA specifies the schema that includes these existing entities.

Examples

Install an extension in the current database. For example, install security_plugin:

-- Before installing the extension, set enable_extension to true.
gaussdb=# SET enable_extension = true;

-- Install the extension.
gaussdb=# CREATE EXTENSION IF NOT EXISTS security_plugin;

-- Delete the extension.
gaussdb=# DROP EXTENSION security_plugin;

Helpful Links

ALTER EXTENSION and DROP EXTENSION