3.9. Databases

In the object hierarchy under every cluster are Databases. You can create, alter variables, comment on, and drop a database. In this example, you will create a database named web_store.

  1. A database is an object under a cluster, so to create a database, first expand the cluster under which you wish to create the database (click the [O-] beside the cluster name).

  2. Right-click on Databases and select CREATE DATABASE.

  3. The first field is the name for the database. Type: web_store

  4. Optionally, set the Owner. The default owner is the user creating the database; however, you can select any existing user by clicking on the drop-down list.

  5. Optionally, set the Location. The default location is that specified by the environment variable PGDATA, but you can specify another previously initialized location.

    NoteNote
     

    The standard installation does not allow absolute paths to be used as locations, only environment variables known to the database backend. You must recompile the backend to allow the use of absolute paths.

  6. Optionally, set the Template. The default template used is template1; however, you can specify any other existing database in the cluster to be used as the template for the new database.

  7. Optionally, set the Encoding. The default encoding is SQL_ASCII; however, you can view the available encodings by clicking on the drop-down list.

    Figure 3-34. The CREATE DATABASE Dialog

  8. Click OK to create the database.

Figure 3-35. The DATABASE Tree View and Detail View

Note that the database web_store has been added under the Database node in the Tree View.

Administrator also enables you to perform the following operations on an existing database:

Altering Variables

To alter a variable for a database and set it as the session default, right-click on it and select ALTER DATABASE =>Set Variable. A dialog box asks for the values that need to be set/reset. The SET field takes the arguments that would be passed to SET in the ALTER DATABASE command. Similar, RESET takes the arguments that would be passed to RESET in the ALTER DATABASE command. RESET ALL restores all changeable variables to the default values.

Commenting

PostgreSQL allows commenting on databases, which makes them easier to identify. To comment on a database, right-click on it and select COMMENT. A dialog asks for the comment. If there is already a comment on the database, this comment is displayed. Type the new comment in the edit box and click OK to save the new comment.

Dropping

To drop a database, right-click on it and select DROP DATABASE. If Preferences => Ask For Confirmations is enabled, you are asked to confirm that you want the database dropped; if it is disabled, the database is dropped immediately. This action cannot be undone.

Refer to the PostgreSQL 7.3 Administrator's Guide for more information on database locations, templates, and encodings.