|
1 | 1 | <!--
|
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 $ |
3 | 3 | -->
|
4 | 4 |
|
5 | 5 | <chapter id="managing-databases">
|
@@ -295,86 +295,6 @@ ALTER DATABASE mydb SET geqo TO off;
|
295 | 295 | </para>
|
296 | 296 | </sect1>
|
297 | 297 |
|
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 |
| - |
378 | 298 | <sect1 id="manage-ag-dropdb">
|
379 | 299 | <title>Destroying a Database</title>
|
380 | 300 |
|
@@ -410,6 +330,116 @@ dropdb <replaceable class="parameter">dbname</replaceable>
|
410 | 330 | the database with the current user name.)
|
411 | 331 | </para>
|
412 | 332 | </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> |
413 | 443 | </chapter>
|
414 | 444 |
|
415 | 445 | <!-- Keep this comment at the end of the file
|
|
0 commit comments