1
1
<!--
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 $
3
3
-->
4
4
5
5
<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
32
32
are accessible from each database within the cluster.) More
33
33
accurately, a database is a collection of schemas and the schemas
34
34
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 ).
37
37
</para>
38
38
39
39
<para>
@@ -58,8 +58,8 @@ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Ex
58
58
59
59
<note>
60
60
<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.
63
63
</para>
64
64
</note>
65
65
</sect1>
@@ -68,14 +68,16 @@ $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.31 2004/06/21 04:06:03 tgl Ex
68
68
<title>Creating a Database</title>
69
69
70
70
<para>
71
- In order to create a databases , the <productname>PostgreSQL</>
71
+ In order to create a database , the <productname>PostgreSQL</>
72
72
server must be up and running (see <xref
73
73
linkend="postmaster-start">).
74
74
</para>
75
75
76
76
<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</></>
79
81
<synopsis>
80
82
CREATE DATABASE <replaceable>name</>;
81
83
</synopsis>
@@ -105,7 +107,7 @@ CREATE DATABASE <replaceable>name</>;
105
107
</para>
106
108
107
109
<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
109
111
database is created, the template database is essentially cloned.
110
112
This means that any changes you make in <literal>template1</> are
111
113
propagated to all subsequently created databases. This implies that
@@ -280,8 +282,8 @@ createdb -T template0 <replaceable>dbname</>
280
282
<acronym>GEQO</acronym> optimizer for a given database, you'd
281
283
ordinarily have to either disable it for all databases or make sure
282
284
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
285
287
<programlisting>
286
288
ALTER DATABASE mydb SET geqo TO off;
287
289
</programlisting>
@@ -299,12 +301,13 @@ ALTER DATABASE mydb SET geqo TO off;
299
301
<title>Destroying a Database</title>
300
302
301
303
<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</></>
304
307
<synopsis>
305
308
DROP DATABASE <replaceable>name</>;
306
309
</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
308
311
a superuser, can drop a database. Dropping a database removes all objects
309
312
that were
310
313
contained within the database. The destruction of a database cannot
@@ -335,7 +338,7 @@ dropdb <replaceable class="parameter">dbname</replaceable>
335
338
<title>Tablespaces</title>
336
339
337
340
<para>
338
- Tablespaces in <productname>PostgreSQL</> allow database superusers to
341
+ Tablespaces in <productname>PostgreSQL</> allow database administrators to
339
342
define locations in the file system where the files representing
340
343
database objects can be stored. Once created, a tablespace can be referred
341
344
to by name when creating database objects.
@@ -360,7 +363,37 @@ dropdb <replaceable class="parameter">dbname</replaceable>
360
363
</para>
361
364
362
365
<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
364
397
particular tablespaces. To do so, a user with the <literal>CREATE</>
365
398
privilege on a given tablespace must pass the tablespace name as a
366
399
parameter to the relevant command. For example, the following creates
@@ -385,7 +418,7 @@ CREATE TABLE foo(i int) TABLESPACE space1;
385
418
A schema does not in itself occupy any storage (other than a system
386
419
catalog entry), so assigning a tablespace to a schema does not in itself
387
420
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
389
422
no tablespace is mentioned when creating a schema, it inherits its
390
423
default tablespace from the current database.
391
424
</para>
@@ -396,10 +429,10 @@ CREATE TABLE foo(i int) TABLESPACE space1;
396
429
</para>
397
430
398
431
<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
401
434
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
403
436
tablespace of the schema it is being created in; an index will be created
404
437
in the tablespace of the table underlying the index.
405
438
</para>
0 commit comments