mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Properly indent tablespace SGML section.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.54 2007/06/03 17:05:52 tgl Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.55 2007/11/04 19:43:33 momjian Exp $ -->
|
||||||
|
|
||||||
<chapter id="managing-databases">
|
<chapter id="managing-databases">
|
||||||
<title>Managing Databases</title>
|
<title>Managing Databases</title>
|
||||||
@ -344,156 +344,156 @@ dropdb <replaceable class="parameter">dbname</replaceable>
|
|||||||
<primary>tablespace</primary>
|
<primary>tablespace</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Tablespaces in <productname>PostgreSQL</> allow database administrators to
|
Tablespaces in <productname>PostgreSQL</> allow database administrators to
|
||||||
define locations in the file system where the files representing
|
define locations in the file system where the files representing
|
||||||
database objects can be stored. Once created, a tablespace can be referred
|
database objects can be stored. Once created, a tablespace can be referred
|
||||||
to by name when creating database objects.
|
to by name when creating database objects.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
By using tablespaces, an administrator can control the disk layout
|
By using tablespaces, an administrator can control the disk layout
|
||||||
of a <productname>PostgreSQL</> installation. This is useful in at
|
of a <productname>PostgreSQL</> installation. This is useful in at
|
||||||
least two ways. First, if the partition or volume on which the
|
least two ways. First, if the partition or volume on which the
|
||||||
cluster was initialized runs out of space and cannot be extended,
|
cluster was initialized runs out of space and cannot be extended,
|
||||||
a tablespace can be created on a different partition and used
|
a tablespace can be created on a different partition and used
|
||||||
until the system can be reconfigured.
|
until the system can be reconfigured.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Second, tablespaces allow an administrator to use knowledge of the
|
Second, tablespaces allow an administrator to use knowledge of the
|
||||||
usage pattern of database objects to optimize performance. For
|
usage pattern of database objects to optimize performance. For
|
||||||
example, an index which is very heavily used can be placed on a
|
example, an index which is very heavily used can be placed on a
|
||||||
very fast, highly available disk, such as an expensive solid state
|
very fast, highly available disk, such as an expensive solid state
|
||||||
device. At the same time a table storing archived data which is
|
device. At the same time a table storing archived data which is
|
||||||
rarely used or not performance critical could be stored on a less
|
rarely used or not performance critical could be stored on a less
|
||||||
expensive, slower disk system.
|
expensive, slower disk system.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To define a tablespace, use the <xref
|
To define a tablespace, use the <xref
|
||||||
linkend="sql-createtablespace" endterm="sql-createtablespace-title">
|
linkend="sql-createtablespace" endterm="sql-createtablespace-title">
|
||||||
command, for example:<indexterm><primary>CREATE TABLESPACE</></>:
|
command, for example:<indexterm><primary>CREATE TABLESPACE</></>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLESPACE fastspace LOCATION '/mnt/sda1/postgresql/data';
|
CREATE TABLESPACE fastspace LOCATION '/mnt/sda1/postgresql/data';
|
||||||
</programlisting>
|
</programlisting>
|
||||||
The location must be an existing, empty directory that is owned by
|
The location must be an existing, empty directory that is owned by
|
||||||
the <productname>PostgreSQL</> system user. All objects subsequently
|
the <productname>PostgreSQL</> system user. All objects subsequently
|
||||||
created within the tablespace will be stored in files underneath this
|
created within the tablespace will be stored in files underneath this
|
||||||
directory.
|
directory.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
|
||||||
<para>
|
|
||||||
There is usually not much point in making more than one
|
|
||||||
tablespace per logical file system, since you cannot control the location
|
|
||||||
of individual files within a logical file system. However,
|
|
||||||
<productname>PostgreSQL</> does not enforce any such limitation, and
|
|
||||||
indeed it is not directly aware of the file system boundaries on your
|
|
||||||
system. It just stores files in the directories you tell it to use.
|
|
||||||
</para>
|
|
||||||
</note>
|
|
||||||
|
|
||||||
|
<note>
|
||||||
<para>
|
<para>
|
||||||
Creation of the tablespace itself must be done as a database superuser,
|
There is usually not much point in making more than one
|
||||||
but after that you can allow ordinary database users to make use of it.
|
tablespace per logical file system, since you cannot control the location
|
||||||
To do that, grant them the <literal>CREATE</> privilege on it.
|
of individual files within a logical file system. However,
|
||||||
|
<productname>PostgreSQL</> does not enforce any such limitation, and
|
||||||
|
indeed it is not directly aware of the file system boundaries on your
|
||||||
|
system. It just stores files in the directories you tell it to use.
|
||||||
</para>
|
</para>
|
||||||
|
</note>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Tables, indexes, and entire databases can be assigned to
|
Creation of the tablespace itself must be done as a database superuser,
|
||||||
particular tablespaces. To do so, a user with the <literal>CREATE</>
|
but after that you can allow ordinary database users to make use of it.
|
||||||
privilege on a given tablespace must pass the tablespace name as a
|
To do that, grant them the <literal>CREATE</> privilege on it.
|
||||||
parameter to the relevant command. For example, the following creates
|
</para>
|
||||||
a table in the tablespace <literal>space1</>:
|
|
||||||
|
<para>
|
||||||
|
Tables, indexes, and entire databases can be assigned to
|
||||||
|
particular tablespaces. To do so, a user with the <literal>CREATE</>
|
||||||
|
privilege on a given tablespace must pass the tablespace name as a
|
||||||
|
parameter to the relevant command. For example, the following creates
|
||||||
|
a table in the tablespace <literal>space1</>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE foo(i int) TABLESPACE space1;
|
CREATE TABLE foo(i int) TABLESPACE space1;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Alternatively, use the <xref linkend="guc-default-tablespace"> parameter:
|
Alternatively, use the <xref linkend="guc-default-tablespace"> parameter:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SET default_tablespace = space1;
|
SET default_tablespace = space1;
|
||||||
CREATE TABLE foo(i int);
|
CREATE TABLE foo(i int);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
When <varname>default_tablespace</> is set to anything but an empty
|
When <varname>default_tablespace</> is set to anything but an empty
|
||||||
string, it supplies an implicit <literal>TABLESPACE</> clause for
|
string, it supplies an implicit <literal>TABLESPACE</> clause for
|
||||||
<command>CREATE TABLE</> and <command>CREATE INDEX</> commands that
|
<command>CREATE TABLE</> and <command>CREATE INDEX</> commands that
|
||||||
do not have an explicit one.
|
do not have an explicit one.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
There is also a <xref linkend="guc-temp-tablespaces"> parameter, which
|
There is also a <xref linkend="guc-temp-tablespaces"> parameter, which
|
||||||
determines the placement of temporary tables and indexes, as well as
|
determines the placement of temporary tables and indexes, as well as
|
||||||
temporary files that are used for purposes such as sorting large data
|
temporary files that are used for purposes such as sorting large data
|
||||||
sets. This can be a list of tablespace names, rather than only one,
|
sets. This can be a list of tablespace names, rather than only one,
|
||||||
so that the load associated with temporary objects can be spread over
|
so that the load associated with temporary objects can be spread over
|
||||||
multiple tablespaces. A random member of the list is picked each time
|
multiple tablespaces. A random member of the list is picked each time
|
||||||
a temporary object is to be created.
|
a temporary object is to be created.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The tablespace associated with a database is used to store the system
|
The tablespace associated with a database is used to store the system
|
||||||
catalogs of that database. Furthermore, it is the default tablespace
|
catalogs of that database. Furthermore, it is the default tablespace
|
||||||
used for tables, indexes, and temporary files created within the database,
|
used for tables, indexes, and temporary files created within the database,
|
||||||
if no <literal>TABLESPACE</> clause is given and no other selection is
|
if no <literal>TABLESPACE</> clause is given and no other selection is
|
||||||
specified by <varname>default_tablespace</> or
|
specified by <varname>default_tablespace</> or
|
||||||
<varname>temp_tablespaces</> (as appropriate).
|
<varname>temp_tablespaces</> (as appropriate).
|
||||||
If a database is created without specifying a tablespace for it,
|
If a database is created without specifying a tablespace for it,
|
||||||
it uses the same tablespace as the template database it is copied from.
|
it uses the same tablespace as the template database it is copied from.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Two tablespaces are automatically created by <literal>initdb</>. The
|
Two tablespaces are automatically created by <literal>initdb</>. The
|
||||||
<literal>pg_global</> tablespace is used for shared system catalogs. The
|
<literal>pg_global</> tablespace is used for shared system catalogs. The
|
||||||
<literal>pg_default</> tablespace is the default tablespace of the
|
<literal>pg_default</> tablespace is the default tablespace of the
|
||||||
<literal>template1</> and <literal>template0</> databases (and, therefore,
|
<literal>template1</> and <literal>template0</> databases (and, therefore,
|
||||||
will be the default tablespace for other databases as well, unless
|
will be the default tablespace for other databases as well, unless
|
||||||
overridden by a <literal>TABLESPACE</> clause in <command>CREATE
|
overridden by a <literal>TABLESPACE</> clause in <command>CREATE
|
||||||
DATABASE</>).
|
DATABASE</>).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Once created, a tablespace can be used from any database, provided
|
Once created, a tablespace can be used from any database, provided
|
||||||
the requesting user has sufficient privilege. This means that a tablespace
|
the requesting user has sufficient privilege. This means that a tablespace
|
||||||
cannot be dropped until all objects in all databases using the tablespace
|
cannot be dropped until all objects in all databases using the tablespace
|
||||||
have been removed.
|
have been removed.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To remove an empty tablespace, use the <xref
|
To remove an empty tablespace, use the <xref
|
||||||
linkend="sql-droptablespace" endterm="sql-droptablespace-title">
|
linkend="sql-droptablespace" endterm="sql-droptablespace-title">
|
||||||
command.
|
command.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To determine the set of existing tablespaces, examine the
|
To determine the set of existing tablespaces, examine the
|
||||||
<structname>pg_tablespace</> system catalog, for example
|
<structname>pg_tablespace</> system catalog, for example
|
||||||
<synopsis>
|
<synopsis>
|
||||||
SELECT spcname FROM pg_tablespace;
|
SELECT spcname FROM pg_tablespace;
|
||||||
</synopsis>
|
</synopsis>
|
||||||
The <xref linkend="app-psql"> program's <literal>\db</> meta-command
|
The <xref linkend="app-psql"> program's <literal>\db</> meta-command
|
||||||
is also useful for listing the existing tablespaces.
|
is also useful for listing the existing tablespaces.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<productname>PostgreSQL</> makes use of symbolic links
|
<productname>PostgreSQL</> makes use of symbolic links
|
||||||
to simplify the implementation of tablespaces. This
|
to simplify the implementation of tablespaces. This
|
||||||
means that tablespaces can be used <emphasis>only</> on systems
|
means that tablespaces can be used <emphasis>only</> on systems
|
||||||
that support symbolic links.
|
that support symbolic links.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The directory <filename>$PGDATA/pg_tblspc</> contains symbolic links that
|
The directory <filename>$PGDATA/pg_tblspc</> contains symbolic links that
|
||||||
point to each of the non-built-in tablespaces defined in the cluster.
|
point to each of the non-built-in tablespaces defined in the cluster.
|
||||||
Although not recommended, it is possible to adjust the tablespace
|
Although not recommended, it is possible to adjust the tablespace
|
||||||
layout by hand by redefining these links. Two warnings: do not do so
|
layout by hand by redefining these links. Two warnings: do not do so
|
||||||
while the server is running; and after you restart the server,
|
while the server is running; and after you restart the server,
|
||||||
update the <structname>pg_tablespace</> catalog to show the new
|
update the <structname>pg_tablespace</> catalog to show the new
|
||||||
locations. (If you do not, <literal>pg_dump</> will continue to show
|
locations. (If you do not, <literal>pg_dump</> will continue to show
|
||||||
the old tablespace locations.)
|
the old tablespace locations.)
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
</chapter>
|
</chapter>
|
||||||
|
Reference in New Issue
Block a user