Installing PostgreSQL on Linux and Unix

Một phần của tài liệu Beginning PHP and Postgre SQL 8 From Novice to Professional phần 7 pot (Trang 75 - 78)

This section outlines installing PostgreSQL using both the RPMs and source code.

Installing PostgreSQL from RPMs

Installing PostgreSQL from an RPM is a trivial task; just execute the following command as root:

%>rpm -ivh postgresql-*.rpm

Next, proceed to the section “Linux Post-Installation Steps” to complete the configuration process.

Installing PostgreSQL from Source

Installing from source is the route you want to take if you want to modify the default settings, such as specifying whether documentation should be installed or changing the default location of the PostgreSQL applications. In fact, you might be forced to install from source if prebuilt packages are not available for your particular Unix variant. While newcomers to open source software might feel a bit intimidated by the idea of executing the unfamiliar commands involved in the configuration and installation process, it’s actually quite trivial. In fact, at its most basic level you can build from source simply by executing the following commands:

%> gunzip postgresql-X.X.X.tar.gz

%> tar xvf postgresql-X.X.X.tar

%> cd postgresql-X.X.X

%> ./configure

[Wait patiently while the configuration process completes]

%> make

[Wait patiently while the build process completes]

%> make install

[Wait patiently while the installation process completes]

If, when executing any of these commands, you receive a message stating something to the effect of command not found, then your operating system doesn’t have all of the requisite software installed. At a minimum, you need tar (http://www.gnu.org/software/tar/) and gzip (http://www.gnu.org/software/gzip/) (although tar can also unzip) or similar solutions for uncompressing and unarchiving the PostgreSQL package, respectively. You also need a solu- tion such as GNU make (http://www.gnu.org/software/make/) for building the package and, finally, a C compiler such as that found in the GNU Compiler Collection, better known as GCC (http://gcc.gnu.org/). If any of these applications is not presently installed on your system, you’re guaranteed to find it on the distribution CD or on your repository of choice.

Also, you need to execute the last command (make install) as a superuser, due to the need to create and write to directories; for security reasons, you should execute the first two commands as any non-superuser. However, executing these commands as just described causes PostgreSQL to be built using the default settings, some of which you may wish to change. To do so, you need to pass one or several options to the configure command. For example, to bypass instal- lation of the documentation, execute configure like so, and then execute make and make install as indicated above:

%> ./configure --without-docdir

Table 25-1 offers a list of some of the more commonplace configuration options. A complete list of configuration options is available by executing configure as follows (note that two dashes precede the help option, which may be difficult to distinguish in print):

%> ./configure --help

Therefore, to install PostgreSQL from source, simply execute configure with any appropriate options, execute make, and then change to the superuser and execute make install.

Note To minimize the amount of installation space, some Linux variants do not install the

readline-devel and zlib-devel packages by default. Because the availability of Readline improves the psql client’s capabilities, and zlib is used to compress dumped data, you need to install them if you receive messages during the configuration step indicating the script’s inability to locate them. If they are by chance installed in a nonstandard location, you can use the option --with-libs to point to them. If you choose to forego these capabilities, pass --without-readline and --without-zlib when configuring PostgreSQL.

Linux Post-Installation Steps

Once PostgreSQL has been successfully installed on the Linux/Unix operating system, you need to carry out a few more steps before the database server is fully operational. Those steps are outlined in this section.

Table 25-1. Useful Configuration Options

Option Description

--prefix=prefix Install PostgreSQL in the directory specified by prefix. The default directory is /usr/local/pgsql.

--bindir=dir Install the application directories in the directory specified by dir.

The default directory is prefix/bin.

--datadir=dir Designate the data directory as dir. The default directory is prefix/XXX.

--with-docdir=dir Install documentation in the directory specified by dir. The default directory is prefix/doc.

--without-docdir Do not install the documentation.

--with-perl Enable support for Perl-based stored procedures (Pl/Perl).

--with-pgport=port Set PostgreSQL’s default port to port.

--with-python Enable support for Python-based stored procedures (Pl/Python).

--with-tcl Enable support for Tcl-based stored procedures (P/Tcl).

584 C H A P T E R 2 5 ■ I N S T A L L I N G P O S T G R E S Q L

Step 1. Create the postgres User

Although it’s possible to run PostgreSQL as any non-root user—for instance, from your home directory, for testing purposes—for most typical uses, you’ll want to create a special user whose only purpose is to own the PostgreSQL daemon process (known as postmaster) and the database files. When properly configured, it will be impossible for others to log in as this user, thereby ensuring that the server’s operation can’t be interfered with and that the data files can’t be deleted or surreptitiously accessed. While the name of this user is completely up to you, the name postgres is commonly used. Therefore, go ahead and create this user, using either postgres or another name of your choosing:

%> useradd postgres

Note You need superuser privileges to execute this command. From this point forward, it’s presumed that you opted to use the username postgres; if you did not, please substitute any further references in this chapter with the appropriate name.

Step 2. Initialize the PostgreSQL Database

Next, you must initialize the PostgreSQL database cluster, which involves specifying the loca- tion of the database files and creating two initial databases, namely postgres and template1.

You accomplish this by using the PostgreSQL command initdb. You should execute this command as the newly created postgres user; however, because this user isn’t privileged and the database directory must be created first, you need to first create this directory as a privi- leged user:

%> mkdir /usr/local/pgsql/data

Note that this example presumes that /usr/local/pgsql/ is the location in which PostgreSQL has been installed. Keep in mind that you are by no means constrained to hosting the data- bases within the PostgreSQL installation directory and are free to choose any directory you please. However, for the sake of consistency, from this point forward it’s assumed that you chose that directory; therefore, substitute any further references in this chapter with the appropriate name if you chose a different default location.

Next, assign the ownership of this data directory to the postgres user created in the previous step:

%> chown postgres /usr/local/pgsql/data

Now it’s time to execute the initdb command, which will create the cluster. However, you should do so as the postgres user, so change over to that user before proceeding.

%>su postgres

postgres$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

Step 3. Add the PostgreSQL bin Directory to Your System Path

For reasons of convenience, add the location of PostgreSQL’s bin directory to your system path. Although this is not a requirement, doing so enables you to run the applications found in that directory regardless of your present location in the path. If you want to do this only for your user, add the following information to your shell configuration file (which typically resides in your home directory). Otherwise, add it to /etc/profile to make this convenience available to every user.

PATH=/usr/local/pgsql/bin:$PATH export PATH

Once these changes have been saved to the appropriate file, you need to either log out and log back in again or, depending on the shell you’re using, use the source command to effect the changes.

With these three steps completed, proceed to the section “Starting PostgreSQL for the First Time.”

Một phần của tài liệu Beginning PHP and Postgre SQL 8 From Novice to Professional phần 7 pot (Trang 75 - 78)

Tải bản đầy đủ (PDF)

(90 trang)