Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f5f448f

Browse files
committed
Rename the built-in tablespaces to pg_default and pg_global, and prohibit
creation of user-defined tablespaces with names starting with 'pg_', as per suggestion of Chris K-L. Also install admin-guide tablespace documentation from Gavin.
1 parent 483b7f8 commit f5f448f

File tree

7 files changed

+140
-117
lines changed

7 files changed

+140
-117
lines changed

doc/src/sgml/diskusage.sgml

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/diskusage.sgml,v 1.10 2003/11/29 19:51:36 pgsql Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/diskusage.sgml,v 1.11 2004/06/21 04:06:03 tgl Exp $
33
-->
44

55
<chapter id="diskusage">
@@ -124,20 +124,15 @@ SELECT relname, relpages FROM pg_class ORDER BY relpages DESC;
124124

125125
<para>
126126
If you cannot free up additional space on the disk by deleting
127-
other things you can move some of the database files to other file
128-
systems and create a symlink from the original location. But
129-
note that <application>pg_dump</> cannot save the location layout
130-
information of such a setup; a restore would put everything back in
131-
one place. To avoid running out of disk space, you can place the
132-
WAL files or individual databases in other locations while creating
133-
them. See the <command>initdb</> documentation and <xref
134-
linkend="manage-ag-alternate-locs"> for more information about that.
127+
other things, you can move some of the database files to other file
128+
systems by making use of tablespaces. See <xref
129+
linkend="manage-ag-tablespaces"> for more information about that.
135130
</para>
136131

137132
<tip>
138133
<para>
139134
Some file systems perform badly when they are almost full, so do
140-
not wait until the disk is full to take action.
135+
not wait until the disk is completely full to take action.
141136
</para>
142137
</tip>
143138
</sect1>

doc/src/sgml/manage-ag.sgml

+111-81
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.30 2004/06/18 06:13:02 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Exp $
33
-->
44

55
<chapter id="managing-databases">
@@ -295,86 +295,6 @@ ALTER DATABASE mydb SET geqo TO off;
295295
</para>
296296
</sect1>
297297

298-
<sect1 id="manage-ag-alternate-locs">
299-
<title>Alternative Locations</title>
300-
301-
<para>
302-
XXX this is entirely dead now, and needs to be replaced by a DBA-level
303-
description of tablespaces.
304-
</para>
305-
306-
<para>
307-
It is possible to create a database in a location other than the
308-
default location for the installation. But remember that all database access
309-
occurs through the
310-
database server, so any location specified must be
311-
accessible by the server.
312-
</para>
313-
314-
<para>
315-
Alternative database locations are referenced by an environment
316-
variable which gives the absolute path to the intended storage
317-
location. This environment variable must be present in the server's
318-
environment, so it must have been defined before the server
319-
was started. (Thus, the set of available alternative locations is
320-
under the site administrator's control; ordinary users can't
321-
change it.) Any valid environment variable name may
322-
be used to reference an alternative location, although using
323-
variable names with a prefix of <literal>PGDATA</> is recommended
324-
to avoid confusion and conflict with other variables.
325-
</para>
326-
327-
<para>
328-
To create the variable in the environment of the server process
329-
you must first shut down the server, define the variable,
330-
initialize the data area, and finally restart the server. (See also
331-
<xref linkend="postmaster-shutdown"> and <xref
332-
linkend="postmaster-start">.) To set an environment variable, type
333-
<programlisting>
334-
PGDATA2=/home/postgres/data
335-
export PGDATA2
336-
</programlisting>
337-
in Bourne shells, or
338-
<programlisting>
339-
setenv PGDATA2 /home/postgres/data
340-
</programlisting>
341-
in <command>csh</> or <command>tcsh</>. You have to make sure that this environment
342-
variable is always defined in the server environment, otherwise
343-
you won't be able to access that database. Therefore you probably
344-
want to set it in some sort of shell start-up file or server
345-
start-up script.
346-
</para>
347-
348-
<para>
349-
<indexterm><primary>initlocation</></>
350-
To create a data storage area in <envar>PGDATA2</>, ensure that
351-
the containing directory (here, <filename>/home/postgres</filename>)
352-
already exists and is writable
353-
by the user account that runs the server (see <xref
354-
linkend="postgres-user">). Then from the command line, type
355-
<programlisting>
356-
initlocation PGDATA2
357-
</programlisting>
358-
(<emphasis>not</emphasis> <literal>initlocation
359-
$PGDATA2</literal>). Then you can restart the server.
360-
</para>
361-
362-
<para>
363-
To create a database within the new location, use the command
364-
<synopsis>
365-
CREATE DATABASE <replaceable>name</> WITH LOCATION '<replaceable>location</>';
366-
</synopsis>
367-
where <replaceable>location</> is the environment variable you
368-
used, <envar>PGDATA2</> in this example. The <command>createdb</>
369-
command has the option <option>-D</> for this purpose.
370-
</para>
371-
372-
<para>
373-
Databases created in alternative locations can be
374-
accessed and dropped like any other database.
375-
</para>
376-
</sect1>
377-
378298
<sect1 id="manage-ag-dropdb">
379299
<title>Destroying a Database</title>
380300

@@ -410,6 +330,116 @@ dropdb <replaceable class="parameter">dbname</replaceable>
410330
the database with the current user name.)
411331
</para>
412332
</sect1>
333+
334+
<sect1 id="manage-ag-tablespaces">
335+
<title>Tablespaces</title>
336+
337+
<para>
338+
Tablespaces in <productname>PostgreSQL</> allow database superusers to
339+
define locations in the file system where the files representing
340+
database objects can be stored. Once created, a tablespace can be referred
341+
to by name when creating database objects.
342+
</para>
343+
344+
<para>
345+
By using tablespaces, a database administrator can control the disk
346+
layout of a <productname>PostgreSQL</> installation. This is useful in
347+
at least two ways. Firstly, if the partition or volume on which the cluster
348+
was initialized runs out of space and cannot be extended logically
349+
or otherwise, a tablespace can be created on a different partition
350+
and used until the system can be reconfigured.
351+
</para>
352+
353+
<para>
354+
Secondly, tablespaces allow a database administrator to arrange data
355+
locations based on the usage patterns of database objects. For
356+
example, an index which is very heavily used can be placed on very fast,
357+
highly available disk, such as an expensive solid state device. At the same
358+
time a table storing archived data which is rarely used or not performance
359+
critical could be stored on a less expensive, slower disk system.
360+
</para>
361+
362+
<para>
363+
Databases, schemas, tables, indexes and sequences can all be placed in
364+
particular tablespaces. To do so, a user with the <literal>CREATE</>
365+
privilege on a given tablespace must pass the tablespace name as a
366+
parameter to the relevant command. For example, the following creates
367+
a table in the tablespace <literal>space1</>:
368+
<programlisting>
369+
CREATE TABLE foo(i int) TABLESPACE space1;
370+
</programlisting>
371+
</para>
372+
373+
<para>
374+
The tablespace associated with a database is used to store the system
375+
catalogs of that database, as well as any temporary files created by
376+
server processes using that database. Furthermore, it is the default
377+
tablespace selected for any objects created within the database, if
378+
no specific <literal>TABLESPACE</> clause is given when those objects
379+
are created. If a database is created without specifying a tablespace
380+
for it, it uses the same tablespace as the template database it is copied
381+
from.
382+
</para>
383+
384+
<para>
385+
A schema does not in itself occupy any storage (other than a system
386+
catalog entry), so assigning a tablespace to a schema does not in itself
387+
do anything. What this actually does is to set a default tablespace
388+
for tables, indexes, and sequences later created within the schema. If
389+
no tablespace is mentioned when creating a schema, it inherits its
390+
default tablespace from the current database.
391+
</para>
392+
393+
<para>
394+
The default choice of tablespace for an index is the same tablespace
395+
already assigned to the table the index is for.
396+
</para>
397+
398+
<para>
399+
Another way to state the above rules is that when a schema, table, index
400+
or sequence is created without specifying a tablespace, the object
401+
inherits its logical parent's tablespace. A schema will be created in the
402+
current database's tablespace; a table or sequence will be created in the
403+
tablespace of the schema it is being created in; an index will be created
404+
in the tablespace of the table underlying the index.
405+
</para>
406+
407+
<para>
408+
Two tablespaces are automatically created by <literal>initdb</>. The
409+
<literal>pg_global</> tablespace is used for shared system catalogs. The
410+
<literal>pg_default</> tablespace is the default tablespace of the
411+
<literal>template1</> and <literal>template0</> databases (and, therefore,
412+
will be the default tablespace for everything else as well, unless
413+
explicit <literal>TABLESPACE</> clauses are used somewhere along the
414+
line).
415+
</para>
416+
417+
<para>
418+
Once created, a tablespace can be used from any database, provided
419+
the requesting user has sufficient privilege. This means that a tablespace
420+
cannot be dropped until all objects in all databases using the tablespace
421+
have been removed.
422+
</para>
423+
424+
<para>
425+
To simplify the implementation of tablespaces,
426+
<productname>PostgreSQL</> makes extensive use of symbolic links. This
427+
means that tablespaces can be used <emphasis>only</> on systems
428+
that support symbolic links.
429+
</para>
430+
431+
<para>
432+
The directory <filename>$PGDATA/pg_tblspc</> contains symbolic links that
433+
point to each of the non-built-in tablespaces defined in the cluster.
434+
Although not recommended, it is possible to adjust the tablespace
435+
layout by hand by redefining these links. Two warnings: do not do so
436+
while the postmaster is running; and after you restart the postmaster,
437+
update the <structname>pg_tablespace</> catalog to show the new
438+
locations. (If you do not, <literal>pg_dump</> will continue to show
439+
the old tablespace locations.)
440+
</para>
441+
442+
</sect1>
413443
</chapter>
414444

415445
<!-- Keep this comment at the end of the file

doc/src/sgml/ref/postmaster.sgml

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.49 2004/03/23 06:09:00 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.50 2004/06/21 04:06:04 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -417,18 +417,6 @@ PostgreSQL documentation
417417
</listitem>
418418
</varlistentry>
419419

420-
<varlistentry>
421-
<term>others</term>
422-
423-
<listitem>
424-
<para>
425-
Other environment variables may be used to designate alternative
426-
data storage locations. See <xref linkend="manage-ag-alternate-locs"> for more
427-
information.
428-
</para>
429-
</listitem>
430-
</varlistentry>
431-
432420
</variablelist>
433421
</refsect1>
434422

src/backend/catalog/catalog.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.53 2004/06/21 01:04:41 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.54 2004/06/21 04:06:05 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -119,8 +119,7 @@ GetDatabasePath(Oid dbNode, Oid spcNode)
119119
*
120120
* We now just test if the relation is in the system catalog namespace;
121121
* so it's no longer necessary to forbid user relations from having
122-
* names starting with pg_. Now only schema names have the pg_
123-
* distinction/requirement.
122+
* names starting with pg_.
124123
*/
125124
bool
126125
IsSystemRelation(Relation relation)
@@ -200,8 +199,8 @@ IsToastNamespace(Oid namespaceId)
200199
* True iff name starts with the pg_ prefix.
201200
*
202201
* For some classes of objects, the prefix pg_ is reserved for
203-
* system objects only. As of 7.3, this is now only true for
204-
* schema names.
202+
* system objects only. As of 7.5, this is only true for
203+
* schema and tablespace names.
205204
*/
206205
bool
207206
IsReservedName(const char *name)

src/backend/commands/tablespace.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* Thus the full path to an arbitrary file is
2020
* $PGDATA/pg_tblspc/spcoid/dboid/relfilenode
2121
*
22-
* There are two tablespaces created at initdb time: global (for shared
23-
* tables) and default (for everything else). For backwards compatibility
22+
* There are two tablespaces created at initdb time: pg_global (for shared
23+
* tables) and pg_default (for everything else). For backwards compatibility
2424
* and to remain functional on platforms without symlinks, these tablespaces
2525
* are accessed specially: they are respectively
2626
* $PGDATA/global/relfilenode
@@ -45,7 +45,7 @@
4545
*
4646
*
4747
* IDENTIFICATION
48-
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.2 2004/06/21 01:04:42 momjian Exp $
48+
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.3 2004/06/21 04:06:06 tgl Exp $
4949
*
5050
*-------------------------------------------------------------------------
5151
*/
@@ -233,6 +233,17 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
233233
errmsg("tablespace location \"%s\" is too long",
234234
location)));
235235

236+
/*
237+
* Disallow creation of tablespaces named "pg_xxx"; we reserve this
238+
* namespace for system purposes.
239+
*/
240+
if (!allowSystemTableMods && IsReservedName(stmt->tablespacename))
241+
ereport(ERROR,
242+
(errcode(ERRCODE_RESERVED_NAME),
243+
errmsg("unacceptable tablespace name \"%s\"",
244+
stmt->tablespacename),
245+
errdetail("The prefix \"pg_\" is reserved for system tablespaces.")));
246+
236247
/*
237248
* Check that there is no other tablespace by this name. (The
238249
* unique index would catch this anyway, but might as well give

src/include/catalog/catversion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.238 2004/06/21 01:04:45 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.239 2004/06/21 04:06:07 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200406201
56+
#define CATALOG_VERSION_NO 200406202
5757

5858
#endif

src/include/catalog/pg_tablespace.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_tablespace.h,v 1.1 2004/06/18 06:14:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_tablespace.h,v 1.2 2004/06/21 04:06:07 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -57,8 +57,8 @@ typedef FormData_pg_tablespace *Form_pg_tablespace;
5757
#define Anum_pg_tablespace_spclocation 3
5858
#define Anum_pg_tablespace_spcacl 4
5959

60-
DATA(insert OID = 1663 ( default PGUID "" _null_ ));
61-
DATA(insert OID = 1664 ( global PGUID "" _null_ ));
60+
DATA(insert OID = 1663 ( pg_default PGUID "" _null_ ));
61+
DATA(insert OID = 1664 ( pg_global PGUID "" _null_ ));
6262

6363
#define DEFAULTTABLESPACE_OID 1663
6464
#define GLOBALTABLESPACE_OID 1664

0 commit comments

Comments
 (0)