Split management chapter from start-ag.sgml to manage-ag.sgml.
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/Attic/admin.sgml,v 1.15 1999/06/03 04:21:47 thomas Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/Attic/admin.sgml,v 1.16 1999/06/23 06:15:13 thomas Exp $
Postgres Administrator's Guide.
Derived from postgres.sgml.
- thomas 1998-10-27
$Log: admin.sgml,v $
+Revision 1.16 1999/06/23 06:15:13 thomas
+Add backup/restore info to Admin Guide.
+Split management chapter from start-ag.sgml to manage-ag.sgml.
+
Revision 1.15 1999/06/03 04:21:47 thomas
Markup changes for v6.5 release.
Clean out duplicate stuff in odbc.sgml resulting from a faulty patch.
<!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
-<!entity about SYSTEM "about.sgml">
-<!entity history SYSTEM "history.sgml">
-<!entity info SYSTEM "info.sgml">
-<!entity legal SYSTEM "legal.sgml">
-<!entity notation SYSTEM "notation.sgml">
-<!entity y2k SYSTEM "y2k.sgml">
-
-<!entity config SYSTEM "config.sgml">
-<!entity intro-ag SYSTEM "intro-ag.sgml">
-<!entity install SYSTEM "install.sgml">
-<!entity installw SYSTEM "install-win32.sgml">
-<!entity layout SYSTEM "layout.sgml">
-<!entity ports SYSTEM "ports.sgml">
-<!entity recovery SYSTEM "recovery.sgml">
-<!entity regress SYSTEM "regress.sgml">
-<!entity release SYSTEM "release.sgml">
-<!entity runtime SYSTEM "runtime.sgml">
-<!entity security SYSTEM "security.sgml">
-<!entity start-ag SYSTEM "start-ag.sgml">
-<!entity trouble SYSTEM "trouble.sgml">
-
-<!entity biblio SYSTEM "biblio.sgml">
+<!entity about SYSTEM "about.sgml">
+<!entity history SYSTEM "history.sgml">
+<!entity info SYSTEM "info.sgml">
+<!entity legal SYSTEM "legal.sgml">
+<!entity notation SYSTEM "notation.sgml">
+<!entity y2k SYSTEM "y2k.sgml">
+
+<!entity config SYSTEM "config.sgml">
+<!entity intro-ag SYSTEM "intro-ag.sgml">
+<!entity install SYSTEM "install.sgml">
+<!entity installw SYSTEM "install-win32.sgml">
+<!entity layout SYSTEM "layout.sgml">
+<!entity manage-ag SYSTEM "manage-ag.sgml">
+<!entity ports SYSTEM "ports.sgml">
+<!entity recovery SYSTEM "recovery.sgml">
+<!entity regress SYSTEM "regress.sgml">
+<!entity release SYSTEM "release.sgml">
+<!entity runtime SYSTEM "runtime.sgml">
+<!entity security SYSTEM "security.sgml">
+<!entity start-ag SYSTEM "start-ag.sgml">
+<!entity trouble SYSTEM "trouble.sgml">
+
+<!entity biblio SYSTEM "biblio.sgml">
]>
<Book Id="admin">
&runtime;
&security;
&start-ag;
+ &manage-ag;
&trouble;
&recovery;
®ress;
--- /dev/null
+ <chapter id="manage-ag">
+ <title>Managing a Database</title>
+
+ <para>
+ If the <productname>Postgres</productname>
+ <application>postmaster</application> is up and running we can create
+ some databases to experiment with. Here, we describe the
+ basic commands for managing a database.
+ </para>
+
+ <sect1>
+ <title>Creating a Database</title>
+
+ <para>
+ Let's say you want to create a database named mydb.
+ You can do this with the following command:
+
+ <programlisting>
+% createdb <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+
+ <productname>Postgres</productname> allows you to create
+ any number of databases
+ at a given site and you automatically become the
+ database administrator of the database you just created.
+ Database names must have an alphabetic first
+ character and are limited to 16 characters in length.
+ Not every user has authorization to become a database
+ administrator. If <productname>Postgres</productname>
+ refuses to create databases
+ for you, then the site administrator needs to grant you
+ permission to create databases. Consult your site
+ administrator if this occurs.
+ </para>
+ </sect1>
+
+ <sect1>
+ <title>Accessing a Database</title>
+
+ <para>
+ Once you have constructed a database, you can access it
+ by:
+
+ <itemizedlist spacing="compact" mark="bullet">
+ <listitem>
+ <para>
+ running the <productname>Postgres</productname> terminal monitor program
+ (<application>psql</application>) which allows you to interactively
+ enter, edit, and execute <acronym>SQL</acronym> commands.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ writing a C program using the <literal>libpq</literal> subroutine
+ library. This allows you to submit <acronym>SQL</acronym> commands
+ from C and get answers and status messages back to
+ your program. This interface is discussed further
+ in the <citetitle>PostgreSQL Programmer's Guide</citetitle>.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ You might want to start up <application>psql</application>,
+ to try out the examples in this manual. It can be activated for the
+ <replaceable class="parameter">dbname</replaceable> database by typing the command:
+
+ <programlisting>
+% psql <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+
+ You will be greeted with the following message:
+
+ <programlisting>
+Welcome to the Postgres interactive sql monitor:
+
+ type \? for help on slash commands
+ type \q to quit
+ type \g or terminate with semicolon to execute query
+You are currently connected to the database: <replaceable>dbname</replaceable>
+
+<replaceable>dbname</replaceable>=>
+ </programlisting>
+ </para>
+
+ <para>
+ This prompt indicates that the terminal monitor is listening
+ to you and that you can type <acronym>SQL</acronym> queries into a
+ workspace maintained by the terminal monitor.
+ The <application>psql</application> program responds to escape
+ codes that begin
+ with the backslash character, "\". For example, you
+ can get help on the syntax of various
+ <productname>Postgres</productname> <acronym>SQL</acronym> commands by typing:
+
+ <programlisting>
+<replaceable>dbname</replaceable>=> \h
+ </programlisting>
+
+ Once you have finished entering your queries into the
+ workspace, you can pass the contents of the workspace
+ to the <productname>Postgres</productname> server by typing:
+
+ <programlisting>
+<replaceable>dbname</replaceable>=> \g
+ </programlisting>
+
+ This tells the server to process the query. If you
+ terminate your query with a semicolon, the backslash-g is not
+ necessary. <application>psql</application> will automatically
+ process semicolon terminated queries.
+ To read queries from a file, instead of
+ entering them interactively, type:
+
+ <programlisting>
+<replaceable>dbname</replaceable>=> \i <replaceable class="parameter">filename</replaceable>
+ </programlisting>
+
+ To get out of <application>psql</application> and return to UNIX, type
+
+ <programlisting>
+<replaceable>dbname</replaceable>=> \q
+ </programlisting>
+
+ and <application>psql</application> will quit and return
+ you to your command shell. (For more escape codes, type
+ backslash-h at the monitor prompt.)
+ White space (i.e., spaces, tabs and newlines) may be
+ used freely in <acronym>SQL</acronym> queries.
+ Single-line comments are denoted by two dashes
+ (<quote>--</quote>). Everything after the dashes up to the end of the
+ line is ignored. Multiple-line comments, and comments within a line,
+ are denoted by <quote>/* ... */</quote>, a convention borrowed
+ from <productname>Ingres</productname>.
+ </para>
+ </sect1>
+
+ <sect1>
+ <title>Destroying a Database</title>
+
+ <para>
+ If you are the database administrator for the database
+ mydb, you can destroy it using the following UNIX command:
+
+ <programlisting>
+% destroydb <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+
+ This action physically removes all of the UNIX files
+ associated with the database and cannot be undone, so
+ this should only be done with a great deal of forethought.
+ </para>
+
+ <para>
+ It is also possible to destroy a database from within an
+ <acronym>SQL</acronym> session by using
+
+ <programlisting>
+> drop database <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+ </para>
+ </sect1>
+
+ <sect1>
+ <title>Backup and Restore</title>
+
+ <caution>
+ <para>
+ Every database should be backed up on a regular basis. Since
+ <productname>Postgres</productname> manages it's own files in the
+ file system, it is <emphasis>not advisable</emphasis> to rely on
+ system backups of your file system for your database backups;
+ there is no guarantee that the files will be in a usable,
+ consistant state after restoration.
+ </para>
+ </caution>
+
+ <para>
+ <productname>Postgres</productname> provides two utilities to
+ backup your system: <application>pg_dump</application> to backup
+ individual databases and
+ <application>pg_dumpall</application> to backup your installation
+ in one step.
+ </para>
+
+ <para>
+ An individual database can be backed up using the following
+ command:
+
+ <programlisting>
+% pg_dump <replaceable class="parameter">dbname</replaceable> > <replaceable class="parameter">dbname</replaceable>.pgdump
+ </programlisting>
+
+ and can be restored using
+
+ <programlisting>
+cat <replaceable class="parameter">dbname</replaceable>.pgdump | psql <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+ </para>
+
+ <para>
+ This technique can be used to move databases to new
+ locations, and to rename existing databases.
+ </para>
+
+ <sect2>
+ <title>Large Databases</title>
+
+ <note>
+ <title>Author</title>
+ <para>
+ Written by <ulink url="hannu@trust.ee">Hannu Krosing</ulink> on
+ 1999-06-19.
+ </para>
+ </note>
+
+ <para>
+ Since <productname>Postgres</productname> allows tables larger
+ than the maximum file size on your system, it can be problematic
+ to dump the table to a file, since the resulting file will likely
+ be larger than the maximum size allowed by your system.</para>
+
+ <para>
+ As <application>pg_dump</application> writes to stdout,
+ you can just use standard *nix tools
+ to work around this possible problem:
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ Use compressed dumps:
+
+ <programlisting>
+% pg_dump <replaceable class="parameter">dbname</replaceable> | gzip > <replaceable class="parameter">filename</replaceable>.dump.gz
+ </programlisting>
+
+ reload with
+
+ <programlisting>
+% createdb <replaceable class="parameter">dbname</replaceable>
+% gunzip -c <replaceable class="parameter">filename</replaceable>.dump.gz | psql <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+
+or
+
+ <programlisting>
+% cat <replaceable class="parameter">filename</replaceable>.dump.gz | gunzip | psql <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Use split:
+
+ <programlisting>
+% pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 1m - <replaceable class="parameter">filename</replaceable>.dump.
+ </programlisting>
+
+reload with
+
+ <programlisting>
+% createdb <replaceable class="parameter">dbname</replaceable>
+% cat <replaceable class="parameter">filename</replaceable>.dump.* | pgsql <replaceable class="parameter">dbname</replaceable>
+ </programlisting>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <para>
+ Of course, the name of the file
+ (<replaceable class="parameter">filename</replaceable>) and the
+ content of the <application>pg_dump</application> output need not
+ match the name of the database. Also, the restored database can
+ have an arbitrary new name, so this mechanism is also suitable
+ for renaming databases.
+ </sect2>
+ </sect1>
+</chapter>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:nil
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:"./reference.ced"
+sgml-exposed-tags:nil
+sgml-local-catalogs:"/usr/lib/sgml/CATALOG"
+sgml-local-ecat-files:nil
+End:
+-->
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.27 1999/06/03 04:21:49 thomas Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.28 1999/06/23 06:15:12 thomas Exp $
Postgres integrated documentation.
Other subset docs should be copied and shrunk from here.
thomas 1998-02-23
$Log: postgres.sgml,v $
+Revision 1.28 1999/06/23 06:15:12 thomas
+Add backup/restore info to Admin Guide.
+Split management chapter from start-ag.sgml to manage-ag.sgml.
+
Revision 1.27 1999/06/03 04:21:49 thomas
Markup changes for v6.5 release.
Clean out duplicate stuff in odbc.sgml resulting from a faulty patch.
%allfiles;
<!-- administrator's guide -->
-<!entity config SYSTEM "config.sgml">
-<!entity install SYSTEM "install.sgml">
-<!entity installw SYSTEM "install-win32.sgml">
-<!entity intro-ag SYSTEM "intro-ag.sgml">
-<!entity layout SYSTEM "layout.sgml">
-<!entity ports SYSTEM "ports.sgml">
-<!entity runtime SYSTEM "runtime.sgml">
-<!entity recovery SYSTEM "recovery.sgml">
-<!entity regress SYSTEM "regress.sgml">
-<!entity release SYSTEM "release.sgml">
-<!entity security SYSTEM "security.sgml">
-<!entity start-ag SYSTEM "start-ag.sgml">
-<!entity trouble SYSTEM "trouble.sgml">
+<!entity config SYSTEM "config.sgml">
+<!entity intro-ag SYSTEM "intro-ag.sgml">
+<!entity install SYSTEM "install.sgml">
+<!entity installw SYSTEM "install-win32.sgml">
+<!entity layout SYSTEM "layout.sgml">
+<!entity manage-ag SYSTEM "manage-ag.sgml">
+<!entity ports SYSTEM "ports.sgml">
+<!entity recovery SYSTEM "recovery.sgml">
+<!entity regress SYSTEM "regress.sgml">
+<!entity release SYSTEM "release.sgml">
+<!entity runtime SYSTEM "runtime.sgml">
+<!entity security SYSTEM "security.sgml">
+<!entity start-ag SYSTEM "start-ag.sgml">
+<!entity trouble SYSTEM "trouble.sgml">
<!-- programmer's guide -->
<!entity intro-pg SYSTEM "intro-pg.sgml">
</Para>
</PartIntro>
+ &intro;
&syntax;
&datatype;
&oper;
&runtime;
&security;
&start-ag;
+ &manage-ag;
&trouble;
&recovery;
®ress;
Introduction for new users.
</Para>
</PartIntro>
- &intro;
&sql;
&arch;
&start;
- - thomas 1998-02-24
-->
- <Chapter Id="newuser">
- <Title>Adding and Deleting Users</Title>
-
- <Para>
- <Application>createuser</Application> enables specific users to access
- <ProductName>Postgres</ProductName>.
- <Application>destroyuser</Application> removes users and
- prevents them from accessing <ProductName>Postgres</ProductName>.
- Note that these
- commands only affect users with respect to
- <ProductName>Postgres</ProductName>;
- they have no effect on users other privileges or status with regards
- to the underlying
- operating system.
- </Para>
- </Chapter>
-
- <Chapter Id="disk">
- <Title>Disk Management</Title>
-
- <Sect1>
- <Title>Alternate Locations</Title>
-
- <Para>
+ <chapter id="newuser">
+ <title>Adding and Deleting Users</title>
+
+ <para>
+ <application>createuser</application> enables specific users to access
+ <productname>Postgres</productname>.
+ <application>destroyuser</application> removes users and
+ prevents them from accessing <productname>Postgres</productname>.
+ </para>
+
+ <para>
+ These commands only affect users with respect to
+ <productname>Postgres</productname>;
+ they have no effect on a user's other privileges or status with regards
+ to the underlying operating system.
+ </para>
+ </chapter>
+
+ <chapter id="disk">
+ <title>Disk Management</title>
+
+ <sect1>
+ <title>Alternate Locations</title>
+
+ <para>
It is possible to create a database in a location other than the default
location for the installation. Remember that all database access actually
occurs through the database backend, so that any location specified must
be accessible by the backend.
</para>
- <Para>
+ <para>
Alternate database locations are created and referenced by an environment variable
which gives the absolute path to the intended storage location.
This environment variable must have been defined before the backend was started
to avoid confusion and conflict with other variables.
</para>
- <Note>
- <Para>
- In previous versions of <ProductName>Postgres</ProductName>,
+ <note>
+ <para>
+ In previous versions of <productname>Postgres</productname>,
it was also permissable to use an absolute path name
to specify an alternate storage location.
The environment variable style of specification
is to be preferred since it allows the site administrator more flexibility in
managing disk storage.
If you prefer using absolute paths, you may do so by defining
- "ALLOW_ABSOLUTE_DBPATHS" and recompiling <ProductName>Postgres</ProductName>
+ "ALLOW_ABSOLUTE_DBPATHS" and recompiling <productname>Postgres</productname>
To do this, either add this line
- <ProgramListing>
+ <programlisting>
#define ALLOW_ABSOLUTE_DBPATHS 1
- </ProgramListing>
+ </programlisting>
to the file <filename>src/include/config.h</filename>, or by specifying
- <ProgramListing>
+ <programlisting>
CFLAGS+= -DALLOW_ABSOLUTE_DBPATHS
- </ProgramListing>
+ </programlisting>
in your <filename>Makefile.custom</filename>.
- </Para>
- </Note>
+ </para>
+ </note>
- <Para>
+ <para>
Remember that database creation is actually performed by the database backend.
Therefore, any environment variable specifying an alternate location must have
been defined before the backend was started. To define an alternate location
PGDATA2 pointing to <filename>/home/postgres/data</filename>, first type
- <ProgramListing>
+ <programlisting>
% setenv PGDATA2 /home/postgres/data
- </ProgramListing>
+ </programlisting>
to define the environment variable to be used with subsequent commands.
Usually, you will want to define this variable in the
- <ProductName>Postgres</ProductName> superuser's
+ <productname>Postgres</productname> superuser's
<filename>.profile</filename>
or
<filename>.cshrc</filename>
overwriting other variables.
</para>
- <Para>
+ <para>
To create a data storage area in PGDATA2, ensure
that <filename>/home/postgres</filename> already exists and is writable
by the postgres administrator.
Then from the command line, type
- <ProgramListing>
+ <programlisting>
% setenv PGDATA2 /home/postgres/data
% initlocation $PGDATA2
Creating Postgres database system directory /home/postgres/data
Creating Postgres database system directory /home/postgres/data/base
- </ProgramListing>
+ </programlisting>
</para>
- <Para>
- To test the new location, create a database <Database>test</Database> by typing
+ <para>
+ To test the new location, create a database <database>test</database> by typing
- <ProgramListing>
+ <programlisting>
% createdb -D PGDATA2 test
% destroydb test
- </ProgramListing>
+ </programlisting>
</para>
- </Sect1>
- </Chapter>
-
- <Chapter Id="manage-ag">
- <Title>Managing a Database</Title>
-
- <Para>
- Now that <ProductName>Postgres</ProductName> is up and running we can create
- some databases to experiment with. Here, we describe the
- basic commands for managing a database.
- </Para>
-
- <Sect1>
- <Title>Creating a Database</Title>
-
- <Para>
- Let's say you want to create a database named mydb.
- You can do this with the following command:
-
- <ProgramListing>
-% createdb mydb
- </ProgramListing>
-
- <ProductName>Postgres</ProductName> allows you to create
- any number of databases
- at a given site and you automatically become the
- database administrator of the database you just created.
- Database names must have an alphabetic first
- character and are limited to 16 characters in length.
- Not every user has authorization to become a database
- administrator. If <ProductName>Postgres</ProductName>
- refuses to create databases
- for you, then the site administrator needs to grant you
- permission to create databases. Consult your site
- administrator if this occurs.
- </Para>
- </Sect1>
-
- <Sect1>
- <Title>Accessing a Database</Title>
-
- <Para>
- Once you have constructed a database, you can access it
- by:
-
- <ItemizedList Mark="bullet" Spacing="compact">
- <ListItem>
- <Para>
- running the <ProductName>Postgres</ProductName> terminal monitor program
- (<Application>psql</Application>) which allows you to interactively
- enter, edit, and execute <Acronym>SQL</Acronym> commands.
- </Para>
- </ListItem>
- <ListItem>
- <Para>
- writing a C program using the <literal>libpq</literal> subroutine
- library. This allows you to submit <Acronym>SQL</Acronym> commands
- from C and get answers and status messages back to
- your program. This interface is discussed further
- in the <citetitle>PostgreSQL Programmer's Guide</citetitle>.
- </Para>
- </ListItem>
- </ItemizedList>
-
- You might want to start up <Application>psql</Application>,
- to try out the examples in this manual. It can be activated for the mydb
- database by typing the command:
-
- <ProgramListing>
-% psql mydb
- </ProgramListing>
-
- You will be greeted with the following message:
- <ProgramListing>
-Welcome to the Postgres interactive sql monitor:
-
- type \? for help on slash commands
- type \q to quit
- type \g or terminate with semicolon to execute query
-You are currently connected to the database: mydb
-
-mydb=>
- </ProgramListing>
- </Para>
-
- <Para>
- This prompt indicates that the terminal monitor is listening
- to you and that you can type <Acronym>SQL</Acronym> queries into a
- workspace maintained by the terminal monitor.
- The <Application>psql</Application> program responds to escape
- codes that begin
- with the backslash character, "\". For example, you
- can get help on the syntax of various
- <ProductName>Postgres</ProductName> <Acronym>SQL</Acronym> commands by typing:
-
- <ProgramListing>
-mydb=> \h
- </ProgramListing>
-
- Once you have finished entering your queries into the
- workspace, you can pass the contents of the workspace
- to the <ProductName>Postgres</ProductName> server by typing:
-
- <ProgramListing>
-mydb=> \g
- </ProgramListing>
-
- This tells the server to process the query. If you
- terminate your query with a semicolon, the backslash-g is not
- necessary. <Application>psql</Application> will automatically
- process semicolon terminated queries.
- To read queries from a file, say myFile, instead of
- entering them interactively, type:
-
- <ProgramListing>
-mydb=> \i fileName
- </ProgramListing>
-
- To get out of <Application>psql</Application> and return to UNIX, type
-
- <ProgramListing>
-mydb=> \q
- </ProgramListing>
-
- and <Application>psql</Application> will quit and return
- you to your command
- shell. (For more escape codes, type backslash-h at the monitor
- prompt.)
- White space (i.e., spaces, tabs and newlines) may be
- used freely in <Acronym>SQL</Acronym> queries.
- Single-line comments are denoted by two dashes
- (<Quote>--</Quote>). Everything after the dashes up to the end of the
- line is ignored. Multiple-line comments, and comments within a line,
- are denoted by <Quote>/* ... */</Quote>, a convention borrowed
- from <productname>Ingres</productname>.
- </Para>
- </Sect1>
-
- <Sect1>
- <Title>Destroying a Database</Title>
-
- <Para>
- If you are the database administrator for the database
- mydb, you can destroy it using the following UNIX command:
-
- <ProgramListing>
-% destroydb mydb
- </ProgramListing>
-
- This action physically removes all of the UNIX files
- associated with the database and cannot be undone, so
- this should only be done with a great deal of forethought.
- </Para>
- </Sect1>
-
- </Chapter>
+ </sect1>
+ </chapter>
<!-- Keep this comment at the end of the file
Local variables: