-
-
Managing a Database
-
-
-This section is currently a thinly disguised copy of the Tutorial. Needs to be augmented.
-- thomas 1998-01-12
-
-
-
-
-Although the site administrator is responsible for overall management
-of the
Postgres installation, some databases within the
-installation may be managed by another person,
-designated the database administrator.
-This assignment of responsibilities occurs when a database is created.
-A user may be assigned explicit privileges to create databases and/or to create new users.
-A user assigned both privileges can perform most administrative task
-within
Postgres, but will
-not by default have the same operating system privileges as the site administrator.
-
-
-The Database Administrator's Guide covers these topics in more detail.
-
-
-
-
Database Creation
-
-Databases are created by the create database issued from
-within
Postgres.
createdb is a command-line
-utility provided to give the same functionality from outside
Postgres.
-
-
-The
Postgres backend must be running for either method
-to succeed, and the user issuing the command must be the
Postgres
-superuser or have been assigned database creation privileges by the
-superuser.
-
-
-To create a new database named mydb
from the command line, type
+
+
Managing a Database
+
+
+ This section is currently a thinly disguised copy of the
+ Tutorial. Needs to be augmented.
+ - thomas 1998-01-12
+
+
+
+ Although the site administrator is responsible for overall management
+ of the
Postgres installation, some databases within the
+ installation may be managed by another person,
+ designated the database administrator.
+ This assignment of responsibilities occurs when a database is created.
+ A user may be assigned explicit privileges to create databases and/or to create new users.
+ A user assigned both privileges can perform most administrative task
+ within
Postgres, but will
+ not by default have the same operating system privileges as the site administrator.
+
+
+ The Database Administrator's Guide covers these topics in more detail.
+
+
+
+
Database Creation
+
+ Databases are created by the create database issued from
+ within
Postgres.
createdb is a command-line
+ utility provided to give the same functionality from outside
Postgres.
+
+
+ The
Postgres backend must be running for either method
+ to succeed, and the user issuing the command must be the
Postgres
+ superuser or have been assigned database creation privileges by the
+ superuser.
+
+
+ To create a new database named mydb
from the command line, type
% createdb mydb
-
+
-and to do the same from within
psql type
+
and to do the same from within
psql type
* CREATE DATABASE mydb;
-
-
+
+
-If you do not have the privileges required to create a database, you will see
-the following:
+ If you do not have the privileges required to create a database, you will see
+ the following:
% createdb mydb
WARN:user "your username" is not allowed to create/destroy databases
createdb: database creation failed on mydb.
-
-
-
-
Postgres 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 32 characters in length.
-
-
-
-
-
-
Alternate Database Locations
-
-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.
-
-
- 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
-and the location it points to must be writable by the postgres administrator account.
-Consult with the site administrator
-regarding preconfigured alternate database locations.
-Any valid environment variable name may be used to reference an alternate location,
-although using variable names with a prefix of PGDATA
is recommended
-to avoid confusion
-and conflict with other variables.
-
-
-
- In previous versions of
Postgres,
-it was also permissable to use an absolute path name to specify
-an alternate storage location.
-Although the environment variable style of specification
-is to be preferred since it allows the site administrator more flexibility in
-managing disk storage, it is also possible to use an absolute path
-to specify an alternate location.
-The administrator's guide discusses how to enable this feature.
-
-
-
-For security and integrity reasons,
-any path or environment variable specified has some
-additional path fields appended.
-
-
-Alternate database locations must be prepared by running
-
-
-To create a data storage area using the environment variable
-PGDATA2 (for this example set to /alt/postgres),
-ensure that /alt/postgres already exists and is writable by
-the Postgres administrator account.
-Then, from the command line, type
+
+
+
+
Postgres 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 32 characters in length.
+
+
+
+
+
+
Alternate Database Locations
+
+ 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.
+
+
+ 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
+ and the location it points to must be writable by the postgres administrator account.
+ Consult with the site administrator
+ regarding preconfigured alternate database locations.
+ Any valid environment variable name may be used to reference an alternate location,
+ although using variable names with a prefix of PGDATA
is recommended
+ to avoid confusion
+ and conflict with other variables.
+
+
+
+ In previous versions of
Postgres,
+ it was also permissable to use an absolute path name to specify
+ an alternate storage location.
+ Although the environment variable style of specification
+ is to be preferred since it allows the site administrator more flexibility in
+ managing disk storage, it is also possible to use an absolute path
+ to specify an alternate location.
+ The administrator's guide discusses how to enable this feature.
+
+
+
+ For security and integrity reasons,
+ any path or environment variable specified has some
+ additional path fields appended.
+ Alternate database locations must be prepared by running
+
+
+ To create a data storage area using the environment variable
+ PGDATA2 (for this example set to /alt/postgres),
+ ensure that /alt/postgres already exists and is writable by
+ the Postgres administrator account.
+ Then, from the command line, type
% initlocation $PGDATA2
Creating Postgres database system directory /alt/postgres/data
Creating Postgres database system directory /alt/postgres/data/base
-
-
+
+
-To create a database in the alternate storage area PGDATA2
-from the command line, use the following command:
+ To create a database in the alternate storage area PGDATA2
+ from the command line, use the following command:
% createdb -D PGDATA2 mydb
-
+
-
To do the same from within
psql type
+
and to do the same from within
psql type
* CREATE DATABASE mydb WITH LOCATION = 'PGDATA2';
-
-
+
+
-If you do not have the privileges required to create a database, you will see
-the following:
+ If you do not have the privileges required to create a database, you will see
+ the following:
% createdb mydb
WARN:user "your username" is not allowed to create/destroy databases
createdb: database creation failed on mydb.
-
-
-
-If the specified location does not exist or the database backend does not have
-permission to access it or to write to directories under it, you will see
-the following:
+
+
+
+ If the specified location does not exist or the database backend does not have
+ permission to access it or to write to directories under it, you will see
+ the following:
% createdb -D /alt/postgres/data mydb
ERROR: Unable to create database directory /alt/postgres/data/base/mydb
createdb: database creation failed on mydb.
-
-
+
+
-
+
Accessing a Database
+
+