バージョンごとのドキュメント一覧

CREATE EXTENSION

CREATE EXTENSION <refpurpose>install an extension</refpurpose> — 拡張をインストールする

概要

CREATE EXTENSION [ IF NOT EXISTS ] extension_name
    [ WITH ] [ SCHEMA schema_name ]
             [ VERSION version ]
             [ CASCADE ]

説明

<title>Description</title>

<command>CREATE EXTENSION</command> loads a new extension into the current database. There must not be an extension of the same name already loaded. CREATE EXTENSIONは現在のデータベース内に新しい拡張を読み込みます。 読み込み済みの拡張と同じ名前の拡張を読み込むことはできません。

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. 拡張の読み込みは基本的に拡張のスクリプトファイルを実行することと同じです。 スクリプトは通常、関数、データ型、演算子、インデックスサポートメソッドなどのSQLオブジェクトを新しく作成するものです。 CREATE EXTENSIONはさらに作成したすべてのオブジェクト識別子を記録して、DROP EXTENSIONが発行された時に削除できるようにします。

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. CREATE EXTENSIONを実行するユーザは、後で実施される権限検査のためにその拡張の所有者となります。また通常このユーザは拡張のスクリプトにより作成されたすべてのオブジェクトの所有者となります。

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. 拡張の読み込みでは、通常その要素オブジェクトを作成するために必要となるいくつかの権限が必要です。 多くの拡張では、これはスーパーユーザの権限が必要であることを意味します。 しかしながら、制御ファイルでtrustedと印付けされた拡張は、現在のデータベースに対してCREATE権限を持つユーザであれば誰でもインストールできます。 この場合拡張オブジェクト自身は呼び出したユーザが所有しますが、そこに含まれるオブジェクトは(拡張スクリプトが明示的に呼び出したユーザに対して割り当てない限り)ブートストラップスーパーユーザが所有します。 この設定は呼び出したユーザに拡張を削除する権限を与えますが、その中の個々のオブジェクトを修正する権限は与えません。

パラメータ

<title>Parameters</title>
IF NOT EXISTS

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. 同じ名前の拡張がすでに存在していてもエラーにしません。 この場合注意が発せられます。 既存の拡張が、現在利用可能なスクリプトファイルより作成されるものと何かしら似たものであることは保証されません。

extension_name

The name of the extension to be installed. <productname>PostgreSQL</productname> will create the extension using details from the file <literal>SHAREDIR/extension/</literal><replaceable class="parameter">extension_name</replaceable><literal>.control</literal>. インストールする拡張の名前です。 PostgreSQLはファイルSHAREDIR/extension/extension_name.controlから詳細を読み取り、拡張を作成します。

schema_name

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. 拡張の内容を再配置させることができる場合に、拡張のオブジェクトをインストールするスキーマの名前です。 指定されたスキーマは事前に存在していなければなりません。 指定がなく、拡張の制御ファイルでもスキーマを指定していない場合、現在のデフォルトのオブジェクト生成用スキーマが使用されます。

If the extension specifies a <literal>schema</literal> parameter in its control file, then that schema cannot be overridden with a <literal>SCHEMA</literal> clause. Normally, an error will be raised if a <literal>SCHEMA</literal> clause is given and it conflicts with the extension's <literal>schema</literal> parameter. However, if the <literal>CASCADE</literal> clause is also given, then <replaceable class="parameter">schema_name</replaceable> is ignored when it conflicts. The given <replaceable class="parameter">schema_name</replaceable> will be used for installation of any needed extensions that do not specify <literal>schema</literal> in their control files. 拡張がその制御ファイルでschemaパラメータを指定している場合、そのスキーマをSCHEMA句で上書きすることはできません。 SCHEMA句が指定され、それが拡張のschemaパラメータと相容れない場合、通常はエラーが発生します。 しかし、CASCADE句も指定されている場合は、schema_nameが相容れなければ、それを無視します。 必要なすべての拡張のインストールにおいて、それぞれの制御ファイルでschemaが指定されていなければ、指定されたschema_nameが使用されます。

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. 拡張自体が任意のスキーマの中にあるとみなされていないことを思い出してください。 拡張は修飾がない名前を持ちますので、データベース全体で一意でなければなりません。 しかし拡張に属するオブジェクトはスキーマの中に置くことができます。

version

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. インストールする拡張のバージョンです。 これは識別子あるいは文字列リテラルのいずれかとして記述できます。 デフォルトのバージョンは拡張の制御ファイル内で規定したものになります。

CASCADE

Automatically install any extensions that this extension depends on that are not already installed. Their dependencies are likewise automatically installed, recursively. The <literal>SCHEMA</literal> 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. この拡張が依存し、まだインストールされていないすべての拡張を自動的にインストールします。 それらが依存するものも同様に再帰的にインストールされます。 SCHEMA句が指定されている場合は、これによってインストールされるすべての拡張に適用されます。 この文の他のオプションは自動的にインストールされる拡張には適用されません。 特に、そのデフォルトバージョンは常に選択されます。

注釈

<title>Notes</title>

Before you can use <command>CREATE EXTENSION</command> to load an extension into a database, the extension's supporting files must be installed. Information about installing the extensions supplied with <productname>PostgreSQL</productname> can be found in <link linkend="contrib">Additional Supplied Modules</link>. 拡張をデータベースにロードするためにCREATE EXTENSIONを使用できるようになる前に、拡張のサポートファイルがインストールされていなければなりません。 PostgreSQLが提供する拡張のインストールに関する情報は、追加で提供されるモジュールで説明します。

The extensions currently available for loading can be identified from the <link linkend="view-pg-available-extensions"><structname>pg_available_extensions</structname></link> or <link linkend="view-pg-available-extension-versions"><structname>pg_available_extension_versions</structname></link> system views. 現在ロード可能な拡張はpg_available_extensionsまたはpg_available_extension_versionsシステムビューで識別できます。

注意

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 <varname>search_path</varname> 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. スーパーユーザとして拡張をインストールするには、拡張の作者が安全な方法で拡張のインストールスクリプトを書いたと信用することが必要です。 悪意のあるユーザが、不注意に書かれた拡張スクリプトの以降の実行を危険に晒すトロイの木馬オブジェクトを作り、そのユーザがスーパーユーザの権限を得るようにするのは、それほど難しいことではありません。 しかしながら、トロイの木馬オブジェクトはスクリプト実行時にsearch_pathにある場合にのみ危険です。これは拡張のインストール対象スキーマや依存する拡張のスキーマにあるということを意味します。 そのため、スクリプトが注意深く検査されていない拡張を扱う優れた経験則は、信頼できないユーザにCREATE権限を許可していないし、今後も許可することのないスキーマにのみ、その拡張をインストールすることです。 その拡張が依存する拡張についても同様です。

The extensions supplied with <productname>PostgreSQL</productname> 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. PostgreSQLが提供する拡張は、他の拡張に依存する少数のものを除いて、この種のインストール時の攻撃に対して安全であると信じられています。 各拡張の文書で述べているように、拡張は安全なスキーマにインストールするか、依存する拡張と同じスキーマにインストールするか、あるいはその両方であるスキーマにインストールすべきです。

For information about writing new extensions, see <xref linkend="extend-extensions"/>. 新しい拡張の作成に関しては38.17を参照してください。

<title>Examples</title>

Install the <link linkend="hstore">hstore</link> extension into the current database, placing its objects in schema <literal>addons</literal>: そのオブジェクトをaddonsスキーマに配置して、現在のデータベースにhstore拡張をインストールします。

CREATE EXTENSION hstore SCHEMA addons;

Another way to accomplish the same thing: 以下は同様のことを行なう別の方法です。

SET search_path = addons;
CREATE EXTENSION hstore;

互換性

<title>Compatibility</title>

<command>CREATE EXTENSION</command> is a <productname>PostgreSQL</productname> extension. CREATE EXTENSIONPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER EXTENSION, DROP EXTENSION