6.4. Tutorial

An excellent way to understand the functionality of a tool is through a tutorial. The following section is a tutorial on how to use Control Center.

It is assumed that during the installation of PostgreSQL - Red Hat Edition, the post-installer was run, which created a database cluster in /var/lib/pgsql/data. It is also assumed that Control Center was started by the superuser postgres.

Topics to be covered in this tutorial are:

6.4.1. Browsing for a Database Engine

There is the possibility that a server may have many PostgreSQL versions that have different, sometimes incompatible, file formats. Before you initialize a database cluster, you must associate or assign a Database Engine to the cluster.

For this tutorial, there is just one available database engine. For future reference, to assign a database engine to a cluster, from the Menu Bar select Init => Assign Engine. The Assign Engine dialog appears.

For this tutorial, selecting Init => Assign Engine displays the following informational dialog.

Figure 6-7. No Other Compatible Database Engines Found Informational Dialog

6.4.2. Initializing a Database Cluster

After a clean install, when you start Control Center (as described in Section 6.3 Starting Control Center), you will notice that the cluster icon beside the rhdb cluster name is blue and the Engine State is Not Initialized. This is due to the fact that the rpm post install step creates the cluster but does not initialize it. The rhdb cluster name is associated with the service script of the same name.

Figure 6-8. Default Cluster Not Initialized

The first task is to initialize the default database cluster. To initialize a database cluster, from the Menu Bar choose Init => Initialize Main Storage Area.

Figure 6-9. Accessing the Initialize Main Storage Area Dialog

The Initialize Main Storage Area dialog appears. For the purpose of this tutorial, you will just select the defaults. The Cluster Name, rhdb, is the name of the service script. The PGDATA path will be /var/lib/pgsql/data and the Database Engine will be selected from /usr/bin, which contains the PostgreSQL - Red Hat Edition 7.3.4 enhanced postmaster.

Figure 6-10. The Initialize Main Storage Area Dialog

Select OK to initialize the default database cluster. Once the cluster has been successfully initialized, notice that the Summary Area has been updated to display a red cluster icon and an Engine State of Stopped. This means that the cluster has been initialized but the database engine has not been started.

Figure 6-11. Default Cluster Initialized

6.4.3. Modifying Database Cluster Configuration Files

For the purposes of the other tutorials in this manual, you will update the configuration files for the cluster to allow connections over TCP/IP with the postmaster listening on port 5432.

To allow the postmaster to accept TCP/IP connections on port 5432, you will need to modify two configuration files, postgresql.conf and pg_hba.conf, located in the /var/lib/pgsql/data directory. In this section, you will use Control Center to modify these files.

6.4.3.1. Allowing TCP/IP Connections

To allow the postmaster to accept TCP/IP connections, from the Menu Bar select Edit => Cluster. The Edit Cluster dialog appears.

Figure 6-12. The Edit Cluster Dialog

Enable TCP/IP by selecting the TCP/IP Enabled checkbox and selecting OK.

Figure 6-13. Updated Control Center Window Displaying TCP/IP Enabled

Notice that the Detail Area states that TCP/IP has been enabled, but is not currently listening on the port. This is due to the engine not being started yet. You can also display the current setting of the tcpip_socket option by selecting the Options tab in the Detail Area.

Figure 6-14. The Detail Area Options

Another method of altering the TCP/IP setting is to edit the Run Time Options. To edit the Run Time Options, from the Menu Bar select Edit => Run Time Options. The Edit Run Time Options dialog appears. This dialog displays the current run time options for the cluster. Select the Connections & Authentication tab.

Figure 6-15. The Edit Run Time Options Dialog

Notice that tcpip_socket already has a value of true. If you wish to change this value to false, select tcpip_socket to highlight the choice and select Edit.

6.4.3.2. Modifying Host-Based Authentication Configuration

Now that TCP/IP has been enabled, you must modify the Host-Based Authentication (HBA) file, pg_hba.conf, to allow connections using TCP/IP. For more information on Host-Based Authentication, refer to the PostgreSQL 7.3 Administrator's Guide. For the purposes of this tutorial, you will add the following line to the pg_hba.conf file to allow connections from anywhere, with trust authentication.

host    all    all    0.0.0.0    0.0.0.0  trust

NoteNote
 

This setting is for tutorial purposes only. This may or may not be acceptable for your installation. Refer to the PostgreSQL 7.3 Adminstrator's Guide for more information on Host-Based Authentication.

To alter the pg_hba.conf information, from the Menu Bar select Edit => HBA. The Edit HBA dialog appears.

Figure 6-16. The Edit HBA Dialog

To add a new line in the pg_hba.conf file, select Add. The Add HBA Entry dialog appears. Click on the Type combo box to select the host. Enter an IP-Address and IP-Mask of 0.0.0.0 and select a Method of trust.

Figure 6-17. The Updated Add HBA Entry Dialog

Select OK to submit the changes. Notice that the Edit HBA dialog has been updated to include the modifications.

Figure 6-18. Updated Edit HBA Dialog

Select OK to close the Edit HBA dialog.

6.4.4. Starting a Database Engine

You have now successfully configured the default database cluster to accept TCP/IP connections on port 5432 using trust host-based authentication. The next task is to start the database engine associated with the cluster. To start the database engine, you can either select Control => Start from the Menu Bar or select the Start Engine button from the Toolbar.

Figure 6-19. Database Engine Started

Notice that the cluster icon beside the rhdb cluster in the Summary Area is now green (representing Started) and that the Engine State has changed to Started. At this point, you can start using the other PostgreSQL - Red Hat Edition Graphical Tools against the default cluster.

6.4.5. Stopping a Database Engine

Now that you have started database engine successfully, the next task is to stop the database engine. To stop the database engine, you can either select Control => Stop from the Menu Bar or select the Stop Engine button from the Toolbar.

Figure 6-20. Database Engine Stopped

Notice that the cluster icon beside the rhdb name in the Summary Area is now red (representing Stopped) and that the Engine State has changed to Stopped.