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

Commit 2467394

Browse files
committed
Tablespaces. Alternate database locations are dead, long live tablespaces.
There are various things left to do: contrib dbsize and oid2name modules need work, and so does the documentation. Also someone should think about COMMENT ON TABLESPACE and maybe RENAME TABLESPACE. Also initlocation is dead, it just doesn't know it yet. Gavin Sherry and Tom Lane.
1 parent 474875f commit 2467394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3765
-1588
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.87 2004/06/16 01:26:33 tgl Exp $
3+
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.88 2004/06/18 06:13:02 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -178,6 +178,11 @@
178178
<entry>planner statistics</entry>
179179
</row>
180180

181+
<row>
182+
<entry><link linkend="catalog-pg-tablespace"><structname>pg_tablespace</structname></link></entry>
183+
<entry>tablespaces within this database cluster</entry>
184+
</row>
185+
181186
<row>
182187
<entry><link linkend="catalog-pg-trigger"><structname>pg_trigger</structname></link></entry>
183188
<entry>triggers</entry>
@@ -1058,6 +1063,17 @@
10581063
<entry>Name of the on-disk file of this relation; 0 if none</entry>
10591064
</row>
10601065

1066+
<row>
1067+
<entry><structfield>reltablespace</structfield></entry>
1068+
<entry><type>oid</type></entry>
1069+
<entry><literal><link linkend="catalog-pg-tablespace"><structname>pg_tablespace</structname></link>.oid</literal></entry>
1070+
<entry>
1071+
The tablespace in which this relation is stored. If zero,
1072+
the database's default tablespace is implied. (Not meaningful
1073+
if the relation has no on-disk file.)
1074+
</entry>
1075+
</row>
1076+
10611077
<row>
10621078
<entry><structfield>relpages</structfield></entry>
10631079
<entry><type>int4</type></entry>
@@ -1602,13 +1618,15 @@
16021618
</row>
16031619

16041620
<row>
1605-
<entry><structfield>datpath</structfield></entry>
1606-
<entry><type>text</type></entry>
1607-
<entry></entry>
1621+
<entry><structfield>dattablespace</structfield></entry>
1622+
<entry><type>oid</type></entry>
1623+
<entry><literal><link linkend="catalog-pg-tablespace"><structname>pg_tablespace</structname></link>.oid</literal></entry>
16081624
<entry>
1609-
If the database is stored at an alternative location then this
1610-
records the location. It's either an environment variable name
1611-
or an absolute path, depending how it was entered.
1625+
The default tablespace for the database.
1626+
Within this database, all tables for which
1627+
<structname>pg_class</>.<structfield>reltablespace</> is zero
1628+
will be stored in this tablespace; in particular, all the non-shared
1629+
system catalogs will be there.
16121630
</entry>
16131631
</row>
16141632

@@ -2386,6 +2404,17 @@
23862404
<entry>Owner of the namespace</entry>
23872405
</row>
23882406

2407+
<row>
2408+
<entry><structfield>nsptablespace</structfield></entry>
2409+
<entry><type>oid</type></entry>
2410+
<entry><literal><link linkend="catalog-pg-tablespace"><structname>pg_tablespace</structname></link>.oid</literal></entry>
2411+
<entry>
2412+
The default tablespace in which to place relations created in this
2413+
namespace. If zero, the database's default tablespace is implied.
2414+
(Changing this does not affect pre-existing relations.)
2415+
</entry>
2416+
</row>
2417+
23892418
<row>
23902419
<entry><structfield>nspacl</structfield></entry>
23912420
<entry><type>aclitem[]</type></entry>
@@ -3232,6 +3261,73 @@
32323261
</sect1>
32333262

32343263

3264+
<sect1 id="catalog-pg-tablespace">
3265+
<title><structname>pg_tablespace</structname></title>
3266+
3267+
<indexterm zone="catalog-pg-tablespace">
3268+
<primary>pg_tablespace</primary>
3269+
</indexterm>
3270+
3271+
<para>
3272+
The catalog <structname>pg_tablespace</structname> stores information
3273+
about the available tablespaces. Tables can be placed in particular
3274+
tablespaces to aid administration of disk layout.
3275+
</para>
3276+
3277+
<para>
3278+
Unlike most system catalogs, <structname>pg_tablespace</structname>
3279+
is shared across all databases of a cluster: there is only one
3280+
copy of <structname>pg_tablespace</structname> per cluster, not
3281+
one per database.
3282+
</para>
3283+
3284+
<table>
3285+
<title><structname>pg_tablespace</> Columns</title>
3286+
3287+
<tgroup cols=4>
3288+
<thead>
3289+
<row>
3290+
<entry>Name</entry>
3291+
<entry>Type</entry>
3292+
<entry>References</entry>
3293+
<entry>Description</entry>
3294+
</row>
3295+
</thead>
3296+
3297+
<tbody>
3298+
<row>
3299+
<entry><structfield>spcname</structfield></entry>
3300+
<entry><type>name</type></entry>
3301+
<entry></entry>
3302+
<entry>Tablespace name</entry>
3303+
</row>
3304+
3305+
<row>
3306+
<entry><structfield>spcowner</structfield></entry>
3307+
<entry><type>int4</type></entry>
3308+
<entry><literal><link linkend="catalog-pg-shadow"><structname>pg_shadow</structname></link>.usesysid</literal></entry>
3309+
<entry>Owner of the tablespace, usually the user who created it</entry>
3310+
</row>
3311+
3312+
<row>
3313+
<entry><structfield>spclocation</structfield></entry>
3314+
<entry><type>text</type></entry>
3315+
<entry></entry>
3316+
<entry>Location (directory path) of the tablespace</entry>
3317+
</row>
3318+
3319+
<row>
3320+
<entry><structfield>spcacl</structfield></entry>
3321+
<entry><type>aclitem[]</type></entry>
3322+
<entry></entry>
3323+
<entry>Access privileges</entry>
3324+
</row>
3325+
</tbody>
3326+
</tgroup>
3327+
</table>
3328+
</sect1>
3329+
3330+
32353331
<sect1 id="catalog-pg-trigger">
32363332
<title><structname>pg_trigger</structname></title>
32373333

doc/src/sgml/manage-ag.sgml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.29 2003/11/29 19:51:37 pgsql Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.30 2004/06/18 06:13:02 tgl Exp $
33
-->
44

55
<chapter id="managing-databases">
@@ -298,6 +298,11 @@ ALTER DATABASE mydb SET geqo TO off;
298298
<sect1 id="manage-ag-alternate-locs">
299299
<title>Alternative Locations</title>
300300

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+
301306
<para>
302307
It is possible to create a database in a location other than the
303308
default location for the installation. But remember that all database access
@@ -368,21 +373,6 @@ CREATE DATABASE <replaceable>name</> WITH LOCATION '<replaceable>location</>';
368373
Databases created in alternative locations can be
369374
accessed and dropped like any other database.
370375
</para>
371-
372-
<note>
373-
<para>
374-
It can also be possible to specify absolute paths directly to the
375-
<command>CREATE DATABASE</> command without defining environment
376-
variables. This is disallowed by default because it is a security
377-
risk. To allow it, you must compile <productname>PostgreSQL</> with
378-
the C preprocessor macro <literal>ALLOW_ABSOLUTE_DBPATHS</>
379-
defined. One way to do this is to run the compilation step like
380-
this:
381-
<programlisting>
382-
gmake CPPFLAGS=-DALLOW_ABSOLUTE_DBPATHS all
383-
</programlisting>
384-
</para>
385-
</note>
386376
</sect1>
387377

388378
<sect1 id="manage-ag-dropdb">

doc/src/sgml/ref/allfiles.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.56 2004/04/20 01:11:49 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.57 2004/06/18 06:13:05 tgl Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -44,6 +44,7 @@ Complete list of usable sgml source files in this directory.
4444
<!entity createSequence system "create_sequence.sgml">
4545
<!entity createTable system "create_table.sgml">
4646
<!entity createTableAs system "create_table_as.sgml">
47+
<!entity createTableSpace system "create_tablespace.sgml">
4748
<!entity createTrigger system "create_trigger.sgml">
4849
<!entity createType system "create_type.sgml">
4950
<!entity createUser system "create_user.sgml">
@@ -66,6 +67,7 @@ Complete list of usable sgml source files in this directory.
6667
<!entity dropSchema system "drop_schema.sgml">
6768
<!entity dropSequence system "drop_sequence.sgml">
6869
<!entity dropTable system "drop_table.sgml">
70+
<!entity dropTableSpace system "drop_tablespace.sgml">
6971
<!entity dropTrigger system "drop_trigger.sgml">
7072
<!entity dropType system "drop_type.sgml">
7173
<!entity dropUser system "drop_user.sgml">

doc/src/sgml/ref/create_database.sgml

Lines changed: 25 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.38 2004/03/23 02:47:35 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.39 2004/06/18 06:13:05 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -22,9 +22,9 @@ PostgreSQL documentation
2222
<synopsis>
2323
CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
2424
[ [ WITH ] [ OWNER [=] <replaceable class="parameter">dbowner</replaceable> ]
25-
[ LOCATION [=] '<replaceable class="parameter">dbpath</replaceable>' ]
2625
[ TEMPLATE [=] <replaceable class="parameter">template</replaceable> ]
27-
[ ENCODING [=] <replaceable class="parameter">encoding</replaceable> ] ]
26+
[ ENCODING [=] <replaceable class="parameter">encoding</replaceable> ]
27+
[ TABLESPACE [=] <replaceable class="parameter">tablespace</replaceable> ] ]
2828
</synopsis>
2929
</refsynopsisdiv>
3030

@@ -50,29 +50,6 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
5050
privilege can only create databases owned by themselves.
5151
</para>
5252

53-
<para>
54-
An alternative location can be specified in order to,
55-
for example, store the database on a different disk.
56-
The path must have been prepared with the
57-
<xref linkend="APP-INITLOCATION" endterm="APP-INITLOCATION-title">
58-
command.
59-
</para>
60-
61-
<para>
62-
If the path name does not contain a slash, it is interpreted
63-
as an environment variable name, which must be known to the
64-
server process. This way the database administrator can
65-
exercise control over locations in which databases can be created.
66-
(A customary choice is, e.g., <envar>PGDATA2</envar>.)
67-
If the server is compiled with <literal>ALLOW_ABSOLUTE_DBPATHS</literal>
68-
(not so by default), absolute path names, as identified by
69-
a leading slash
70-
(e.g., <filename>/usr/local/pgsql/data</filename>),
71-
are allowed as well.
72-
In either case, the final path name must be absolute and must not
73-
contain any single quotes.
74-
</para>
75-
7653
<para>
7754
By default, the new database will be created by cloning the standard
7855
system database <literal>template1</>. A different template can be
@@ -83,13 +60,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
8360
version of <productname>PostgreSQL</productname>. This is useful
8461
if you wish to avoid copying
8562
any installation-local objects that may have been added to
86-
<literal>template1</>.
87-
</para>
88-
89-
<para>
90-
The optional encoding parameter allows selection of the database
91-
encoding. When not specified, it defaults to the encoding used by
92-
the selected template database.
63+
<literal>template1</>.
9364
</para>
9465
</refsect1>
9566

@@ -101,7 +72,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
10172
<term><replaceable class="parameter">name</replaceable></term>
10273
<listitem>
10374
<para>
104-
The name of a database to create.
75+
The name of a database to create.
10576
</para>
10677
</listitem>
10778
</varlistentry>
@@ -110,41 +81,43 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
11081
<listitem>
11182
<para>
11283
The name of the database user who will own the new database,
113-
or <literal>DEFAULT</literal> to use the default (namely, the
114-
user executing the command).
84+
or <literal>DEFAULT</literal> to use the default (namely, the
85+
user executing the command).
11586
</para>
11687
</listitem>
11788
</varlistentry>
11889
<varlistentry>
119-
<term><replaceable class="parameter">dbpath</replaceable></term>
90+
<term><replaceable class="parameter">template</replaceable></term>
12091
<listitem>
12192
<para>
122-
An alternate file-system location in which to store the new database,
123-
specified as a string literal;
124-
or <literal>DEFAULT</literal> to use the default location.
93+
The name of the template from which to create the new database,
94+
or <literal>DEFAULT</literal> to use the default template
95+
(<literal>template1</literal>).
12596
</para>
12697
</listitem>
12798
</varlistentry>
12899
<varlistentry>
129-
<term><replaceable class="parameter">template</replaceable></term>
100+
<term><replaceable class="parameter">encoding</replaceable></term>
130101
<listitem>
131102
<para>
132-
The name of the template from which to create the new database,
133-
or <literal>DEFAULT</literal> to use the default template
134-
(<literal>template1</literal>).
103+
Character set encoding to use in the new database. Specify
104+
a string constant (e.g., <literal>'SQL_ASCII'</literal>),
105+
or an integer encoding number, or <literal>DEFAULT</literal>
106+
to use the default encoding. The character sets supported by the
107+
<productname>PostgreSQL</productname> server are described in
108+
<xref linkend="multibyte-charset-supported">.
135109
</para>
136110
</listitem>
137111
</varlistentry>
138112
<varlistentry>
139-
<term><replaceable class="parameter">encoding</replaceable></term>
113+
<term><replaceable class="parameter">tablespace</replaceable></term>
140114
<listitem>
141115
<para>
142-
Character set encoding to use in the new database. Specify
143-
a string constant (e.g., <literal>'SQL_ASCII'</literal>),
144-
or an integer encoding number, or <literal>DEFAULT</literal>
145-
to use the default encoding. The character sets supported by the
146-
<productname>PostgreSQL</productname> server are described in
147-
<xref linkend="multibyte-charset-supported">.
116+
Specifies the default tablespace for the new database.
117+
If not specified, the same tablespace that is default for
118+
the template database is used. See
119+
<xref linkend="sql-createtablespace" endterm="sql-createtablespace-title">
120+
for more information.
148121
</para>
149122
</listitem>
150123
</varlistentry>
@@ -167,9 +140,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
167140
<para>
168141
Errors along the line of <quote>could not initialize database directory</>
169142
are most likely related to insufficient permissions on the data
170-
directory, a full disk, or other file system problems. When using an
171-
alternate location, the user under
172-
which the database server is running must have access to the location.
143+
directory, a full disk, or other file system problems.
173144
</para>
174145

175146
<para>
@@ -181,13 +152,6 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
181152
wrapper program around this command, provided for convenience.
182153
</para>
183154

184-
<para>
185-
There are security issues involved with using alternate database
186-
locations specified with absolute path names; this is why the feature
187-
is not enabled by default. See <xref
188-
linkend="manage-ag-alternate-locs"> for more information.
189-
</para>
190-
191155
<para>
192156
Although it is possible to copy a database other than <literal>template1</>
193157
by specifying its name as the template, this is not (yet) intended as
@@ -205,24 +169,6 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
205169

206170
<programlisting>
207171
CREATE DATABASE lusiadas;
208-
</programlisting>
209-
</para>
210-
211-
<para>
212-
To create a new database in an alternate area
213-
<filename>~/private_db</filename>, execute the following from the
214-
shell:
215-
216-
<programlisting>
217-
mkdir private_db
218-
initlocation ~/private_db
219-
</programlisting>
220-
221-
Then execute the following from within a
222-
<application>psql</application> session:
223-
224-
<programlisting>
225-
CREATE DATABASE elsewhere WITH LOCATION '/home/olly/private_db';
226172
</programlisting>
227173
</para>
228174
</refsect1>

0 commit comments

Comments
 (0)