mirror of https://github.com/postgres/postgres
This patch adds the server infrastructure to support extensions. There is still one significant loose end, namely how to make it play nice with pg_upgrade, so I am not yet committing the changes that would make all the contrib modules depend on this feature. In passing, fix a disturbingly large amount of breakage in AlterObjectNamespace() and callers. Dimitri Fontaine, reviewed by Anssi Kääriäinen, Itagaki Takahiro, Tom Lane, and numerous otherspull/1/head
parent
414c5a2ea6
commit
d9572c4e3b
@ -0,0 +1,98 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/alter_extension.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-ALTEREXTENSION"> |
||||
<refmeta> |
||||
<refentrytitle>ALTER EXTENSION</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER EXTENSION</refname> |
||||
<refpurpose> |
||||
change the definition of an extension |
||||
</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-alterextension"> |
||||
<primary>ALTER EXTENSION</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable> |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER EXTENSION</command> changes the definition of an existing extension. |
||||
Currently there is only one subform: |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><literal>SET SCHEMA</literal></term> |
||||
<listitem> |
||||
<para> |
||||
This form moves the extension's objects into another schema. The |
||||
extension has to be <firstterm>relocatable</> for this command to |
||||
succeed. See <xref linkend="extend-extensions"> for details. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<para> |
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="PARAMETER">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an installed extension. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="PARAMETER">new_schema</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The new schema for the extension. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
To change the schema of the extension <literal>hstore</literal> |
||||
to <literal>utils</literal>: |
||||
<programlisting> |
||||
ALTER EXTENSION hstore SET SCHEMA utils; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="SQL-ALTEREXTENSION-see-also"> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createextension"></member> |
||||
<member><xref linkend="sql-dropextension"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
</refentry> |
@ -0,0 +1,118 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/create_extension.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-CREATEEXTENSION"> |
||||
<refmeta> |
||||
<refentrytitle>CREATE EXTENSION</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CREATE EXTENSION</refname> |
||||
<refpurpose>install an extension</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-createextension"> |
||||
<primary>CREATE EXTENSION</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CREATE EXTENSION <replaceable class="parameter">extension_name</replaceable> |
||||
[ WITH ] [ SCHEMA [=] <replaceable class="parameter">schema</replaceable> ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CREATE EXTENSION</command> loads a new extension into the current |
||||
database. There must not be an extension of the same name already loaded. |
||||
</para> |
||||
|
||||
<para> |
||||
Loading an extension essentially amounts to running the extension's script |
||||
file. The script will typically create new <acronym>SQL</> 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. |
||||
</para> |
||||
|
||||
<para> |
||||
For information about writing new extensions, see |
||||
<xref linkend="extend-extensions">. |
||||
</para> |
||||
|
||||
<para> |
||||
Only superusers can execute <command>CREATE EXTENSION</command>. |
||||
</para> |
||||
|
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">extension_name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the extension to be |
||||
installed. <productname>PostgreSQL</productname> will create the |
||||
extension using details from the file |
||||
<literal>SHAREDIR/contrib/</literal><replaceable class="parameter">extension</replaceable><literal>.control</literal>. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">schema</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
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. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Install the <link linkend="hstore">hstore</link> extension into the |
||||
current database: |
||||
<programlisting> |
||||
CREATE EXTENSION hstore; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>CREATE EXTENSION</command> is a <productname>PostgreSQL</> |
||||
extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alterextension"></member> |
||||
<member><xref linkend="sql-dropextension"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
@ -0,0 +1,121 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/drop_extension.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-DROPEXTENSION"> |
||||
<refmeta> |
||||
<refentrytitle>DROP EXTENSION</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP EXTENSION</refname> |
||||
<refpurpose>remove an extension</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-dropextension"> |
||||
<primary>DROP EXTENSION</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP EXTENSION [ IF EXISTS ] <replaceable class="PARAMETER">extension_name</replaceable> [, ...] [ CASCADE | RESTRICT ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP EXTENSION</command> removes extensions from the database. |
||||
Dropping an extension causes its component objects to be dropped as well. |
||||
</para> |
||||
|
||||
<para> |
||||
An extension can only be dropped by a superuser. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
|
||||
<varlistentry> |
||||
<term><literal>IF EXISTS</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Do not throw an error if the extension does not exist. A notice is issued |
||||
in this case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="PARAMETER">extension_name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an installed extension. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>CASCADE</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Automatically drop objects that depend on the extension. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>RESTRICT</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Refuse to drop the extension if any objects depend on it (other than |
||||
its own member objects and other extensions listed in the same |
||||
<command>DROP</> command). This is the default. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
To remove the extension <literal>hstore</literal> from the current |
||||
database: |
||||
<programlisting> |
||||
DROP EXTENSION hstore; |
||||
</programlisting> |
||||
This command will fail if any of <literal>hstore</literal>'s objects |
||||
are in use in the database, for example if any tables have columns |
||||
of the <type>hstore</> type. Add the <literal>CASCADE</> option to |
||||
forcibly remove those dependent objects as well. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>DROP EXTENSION</command> is a <productname>PostgreSQL</> |
||||
extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createextension"></member> |
||||
<member><xref linkend="sql-alterextension"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_extension.h |
||||
* definition of the system "extension" relation (pg_extension) |
||||
* along with the relation's initial contents. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* src/include/catalog/pg_extension.h |
||||
* |
||||
* NOTES |
||||
* the genbki.pl script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_EXTENSION_H |
||||
#define PG_EXTENSION_H |
||||
|
||||
#include "catalog/genbki.h" |
||||
|
||||
/* ----------------
|
||||
* pg_extension definition. cpp turns this into |
||||
* typedef struct FormData_pg_extension |
||||
* ---------------- |
||||
*/ |
||||
#define ExtensionRelationId 3079 |
||||
|
||||
CATALOG(pg_extension,3079) |
||||
{ |
||||
NameData extname; /* extension name */ |
||||
Oid extowner; /* extension owner */ |
||||
Oid extnamespace; /* namespace of contained objects */ |
||||
bool extrelocatable; /* if true, allow ALTER EXTENSION SET SCHEMA */ |
||||
|
||||
/*
|
||||
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too. |
||||
*/ |
||||
text extversion; /* extension version ID, if any */ |
||||
Oid extconfig[1]; /* dumpable configuration tables */ |
||||
text extcondition[1]; /* WHERE clauses for config tables */ |
||||
} FormData_pg_extension; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_extension corresponds to a pointer to a tuple with |
||||
* the format of pg_extension relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_extension *Form_pg_extension; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_extension |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#define Natts_pg_extension 7 |
||||
#define Anum_pg_extension_extname 1 |
||||
#define Anum_pg_extension_extowner 2 |
||||
#define Anum_pg_extension_extnamespace 3 |
||||
#define Anum_pg_extension_extrelocatable 4 |
||||
#define Anum_pg_extension_extversion 5 |
||||
#define Anum_pg_extension_extconfig 6 |
||||
#define Anum_pg_extension_extcondition 7 |
||||
|
||||
/* ----------------
|
||||
* pg_extension has no initial contents |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#endif /* PG_EXTENSION_H */ |
@ -0,0 +1,40 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* extension.h |
||||
* Extension management commands (create/drop extension). |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* src/include/commands/extension.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef EXTENSION_H |
||||
#define EXTENSION_H |
||||
|
||||
#include "nodes/parsenodes.h" |
||||
|
||||
|
||||
/*
|
||||
* creating_extension is only true while running a CREATE EXTENSION command. |
||||
* It instructs recordDependencyOnCurrentExtension() to register a dependency |
||||
* on the current pg_extension object for each SQL object created by its |
||||
* installation script. |
||||
*/ |
||||
extern bool creating_extension; |
||||
extern Oid CurrentExtensionObject; |
||||
|
||||
|
||||
extern void CreateExtension(CreateExtensionStmt *stmt); |
||||
|
||||
extern void RemoveExtensions(DropStmt *stmt); |
||||
extern void RemoveExtensionById(Oid extId); |
||||
|
||||
extern Oid get_extension_oid(const char *extname, bool missing_ok); |
||||
extern char *get_extension_name(Oid ext_oid); |
||||
|
||||
extern void AlterExtensionNamespace(List *names, const char *newschema); |
||||
|
||||
#endif /* EXTENSION_H */ |
Loading…
Reference in new issue