11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.32 2004/08/07 19:02:43 tgl Exp $
33-->
44
55<chapter id="managing-databases">
@@ -32,8 +32,8 @@ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Ex
3232 are accessible from each database within the cluster.) More
3333 accurately, a database is a collection of schemas and the schemas
3434 contain the tables, functions, etc. So the full hierarchy is:
35- server, database, schema, table (or something else instead of a
36- table ).
35+ server, database, schema, table (or some other kind of object,
36+ such as a function ).
3737 </para>
3838
3939 <para>
@@ -58,8 +58,8 @@ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Ex
5858
5959 <note>
6060 <para>
61- <acronym>SQL</> calls databases <quote>catalogs</>, but there is no
62- difference in practice.
61+ The <acronym>SQL</> standard calls databases <quote>catalogs</>, but there
62+ is no difference in practice.
6363 </para>
6464 </note>
6565 </sect1>
@@ -68,14 +68,16 @@ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Ex
6868 <title>Creating a Database</title>
6969
7070 <para>
71- In order to create a databases , the <productname>PostgreSQL</>
71+ In order to create a database , the <productname>PostgreSQL</>
7272 server must be up and running (see <xref
7373 linkend="postmaster-start">).
7474 </para>
7575
7676 <para>
77- Databases are created with the SQL command <command>CREATE
78- DATABASE</command>:<indexterm><primary>CREATE DATABASE</></>
77+ Databases are created with the SQL command
78+ <xref linkend="sql-createdatabase"
79+ endterm="sql-createdatabase-title">:<indexterm><primary>CREATE
80+ DATABASE</></>
7981<synopsis>
8082CREATE DATABASE <replaceable>name</>;
8183</synopsis>
@@ -105,7 +107,7 @@ CREATE DATABASE <replaceable>name</>;
105107 </para>
106108
107109 <para>
108- The name <literal>template1</literal> is no accident: When a new
110+ The name <literal>template1</literal> is no accident: when a new
109111 database is created, the template database is essentially cloned.
110112 This means that any changes you make in <literal>template1</> are
111113 propagated to all subsequently created databases. This implies that
@@ -280,8 +282,8 @@ createdb -T template0 <replaceable>dbname</>
280282 <acronym>GEQO</acronym> optimizer for a given database, you'd
281283 ordinarily have to either disable it for all databases or make sure
282284 that every connecting client is careful to issue <literal>SET geqo
283- TO off;</literal>. To make this setting the default you can
284- execute the command
285+ TO off;</literal>. To make this setting the default within a particular
286+ database, you can execute the command
285287<programlisting>
286288ALTER DATABASE mydb SET geqo TO off;
287289</programlisting>
@@ -299,12 +301,13 @@ ALTER DATABASE mydb SET geqo TO off;
299301 <title>Destroying a Database</title>
300302
301303 <para>
302- Databases are destroyed with the command <command>DROP
303- DATABASE</command>:<indexterm><primary>DROP DATABASE</></>
304+ Databases are destroyed with the command
305+ <xref linkend="sql-dropdatabase"
306+ endterm="sql-dropdatabase-title">:<indexterm><primary>DROP DATABASE</></>
304307<synopsis>
305308DROP DATABASE <replaceable>name</>;
306309</synopsis>
307- Only the owner of the database (i.e., the user that created it) or
310+ Only the owner of the database (i.e., the user that created it), or
308311 a superuser, can drop a database. Dropping a database removes all objects
309312 that were
310313 contained within the database. The destruction of a database cannot
@@ -335,7 +338,7 @@ dropdb <replaceable class="parameter">dbname</replaceable>
335338 <title>Tablespaces</title>
336339
337340 <para>
338- Tablespaces in <productname>PostgreSQL</> allow database superusers to
341+ Tablespaces in <productname>PostgreSQL</> allow database administrators to
339342 define locations in the file system where the files representing
340343 database objects can be stored. Once created, a tablespace can be referred
341344 to by name when creating database objects.
@@ -360,7 +363,37 @@ dropdb <replaceable class="parameter">dbname</replaceable>
360363 </para>
361364
362365 <para>
363- Databases, schemas, tables, indexes and sequences can all be placed in
366+ To define a tablespace, use the <xref linkend="sql-createtablespace"
367+ endterm="sql-createtablespace-title"> command, for
368+ example:<indexterm><primary>CREATE TABLESPACE</></>
369+ <programlisting>
370+ CREATE TABLESPACE fastspace LOCATION '/mnt/sda1/postgresql/data';
371+ </programlisting>
372+ The location must be an existing, empty directory that is owned by
373+ the <productname>PostgreSQL</> system user. All objects subsequently
374+ created within the tablespace will be stored in files underneath this
375+ directory.
376+ </para>
377+
378+ <note>
379+ <para>
380+ There is usually not much point in making more than one
381+ tablespace per logical filesystem, since you can't control the location
382+ of individual files within a logical filesystem. However,
383+ <productname>PostgreSQL</> does not enforce any such limitation, and
384+ indeed it's not directly aware of the filesystem boundaries on your
385+ system. It just stores files in the directories you tell it to use.
386+ </para>
387+ </note>
388+
389+ <para>
390+ Creation of the tablespace itself must be done as a database superuser,
391+ but after that you can allow ordinary database users to make use of it.
392+ To do that, grant them the <literal>CREATE</> privilege on it.
393+ </para>
394+
395+ <para>
396+ Databases, schemas, tables, and indexes can all be assigned to
364397 particular tablespaces. To do so, a user with the <literal>CREATE</>
365398 privilege on a given tablespace must pass the tablespace name as a
366399 parameter to the relevant command. For example, the following creates
@@ -385,7 +418,7 @@ CREATE TABLE foo(i int) TABLESPACE space1;
385418 A schema does not in itself occupy any storage (other than a system
386419 catalog entry), so assigning a tablespace to a schema does not in itself
387420 do anything. What this actually does is to set a default tablespace
388- for tables, indexes, and sequences later created within the schema. If
421+ for tables later created within the schema. If
389422 no tablespace is mentioned when creating a schema, it inherits its
390423 default tablespace from the current database.
391424 </para>
@@ -396,10 +429,10 @@ CREATE TABLE foo(i int) TABLESPACE space1;
396429 </para>
397430
398431 <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
432+ Another way to state the above rules is that when a schema, table, or index
433+ is created without specifying a tablespace, the object
401434 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
435+ current database's tablespace; a table will be created in the
403436 tablespace of the schema it is being created in; an index will be created
404437 in the tablespace of the table underlying the index.
405438 </para>
0 commit comments