Installing PostgreSQL


In this section, you take a closer look at the installation process of PostgreSQL on various platforms.

Installing on UNIX Systems

In contrast to Windows systems, UNIX systems can have many different faces; therefore the installation process on various UNIX systems can differ significantly.

Many Linux systems, such as RedHat and Debian Linux, provide package management software for simplifying the installation of PostgreSQL binaries or source code. This section provides an overview of how PostgreSQL is installed on UNIX systems.

Installing on RPM-Based Systems

Package management has always been a very desirable feature on Linux systems. With the help of the RedHat Package Manager (RPM), Linux offers a simple and efficient way to manage software packages on Linux systems. The RPM has been developed by RedHat and is available under the terms of the GPL. Packaging software means that files belonging together are compiled into an archive. But archiving files is not the key feature of a package manager; software products can be installed and uninstalled easily with the help of a simple shell command or GUIs available on the Internet.

It is also possible to assign rules to a package. Imagine a software product A that needs a library called B to be compiled correctly. If somebody wants to install the RPM package of A on a system, it seems logical that it can be installed only when package B is also available. RPM takes care of details such as that and makes sure that no packages can be installed or uninstalled that are still needed by other software components . RPM keeps information about all packages installed in a small database, so it is an easy task to find out whether a package is installed on your system. If you want to find out whether PostgreSQL is installed on your machine, try the following command:

 [root@notebook hs]$ rpm -qva  grep postgres postgresql-libs-7.1.2-4PGDG postgresql-python-7.1.2-4PGDG postgresql-7.1.2-4PGDG postgresql-test-7.1.2-4PGDG postgresql-perl-7.1.2-4PGDG postgresql-docs-7.1.2-4PGDG postgresql-tcl-7.1.2-4PGDG postgresql-odbc-7.1.2-4PGDG postgresql-devel-7.1.2-4PGDG postgresql-server-7.1.2-4PGDG postgresql-contrib-7.1.2-4PGDG postgresql-tk-7.1.2-4PGDG postgresql-jdbc-7.1.2-4PGDG 

The rpm -qva command lists all packages found on the system. You find out all packages related to PostgreSQL by using a simple grep command. On most Linux distributions, such as RedHat or Suse, PostgreSQL is already included and you do not have to install it manually.

Tip

It is possible that you won't find all packages, because some ”such as the PHP's PostgreSQL package ”do not contain the string postgres . Try searching for something like pgsql as well.


If no packages are found on the system, PostgreSQL is not installed. If you don't have the packages on one of your Linux CDs or if you want to upgrade your PostgreSQL installation, you have to download the sources from a mirror near you. To find the best mirror for downloading the files, check out www.postgresql.org. After finding the best mirror site for your location, click Software. Choose an FTP server near you and go to the binary directory of the FTP server. There you will find several subdirectories, where you can find the appropriate binaries for your system. Usually, binaries for x86 CPUs and the most widespread Linux distributions are available. If you do not have an x86 compatible processor (Intel Pentium or AMD, for example), you might have to compile the sources manually. To download the software, use a simple FTP client, a Web browser such as Netscape, Konqueror, Opera, or Internet Explorer. wget is another tool for downloading software and is included in most recent Linux distributions. wget is a powerful command-line tool for downloading and enables the user to start downloads as background processes (in combination with & ).

Now that you have downloaded all RPM packages on your machine, you can start installing the software. To install the database you use a simple command (assume that your current directory contains only PostgreSQL binaries):

 [root@notebook hs]$ rpm -Uvh *rpm postgresql-tk               ################################################## postgresql-test             ################################################## postgresql-tcl              ################################################## postgresql-server           ################################################## postgresql-python           ################################################## postgresql-perl             ################################################## postgresql-odbc             ################################################## postgresql-libs             ################################################## postgresql-jdbc             ################################################## postgresql-docs             ################################################## postgresql-devel            ################################################## postgresql-contrib          ################################################## postgresql                  ################################################## 

If no packages are missing, the installation is ready ”everything is done by RPM automatically. Updating packages that are already installed on the system works the same way as installing packages.

Uninstalling the software is as simple as installing the packages. Use this command:

 [root@notebook hs]$ rpm -e postgresql postgresql-jdbc postgresql-tk postgresql- contrib postgresql-server postgresql-tcl postgresql-devel postgresql-odbc postgresql-perl postgresql-test postgresql-docs postgresql-python postgresql- libs 

If no errors are displayed, the packages have been uninstalled correctly. Sometimes uninstalling does not work because PostgreSQL is needed by other packages. In that case, you either have to uninstall those packages related to PostgreSQL or leave everything on the server.

Installing on Debian-Based Systems

Debian is a Linux distribution that is not based on the RPM. Debian's package management tool is called dselect and can be compared with RPM. Both tools support a simple interface for installing packages from the command line.

To install a PostgreSQL package for Debian on your Debian system, use the dpkg :

 [root@debian deb]$ dpkg -i *deb 

This command installs all Debian packages in the current directory and is equal to the following:

 [root@debian deb]$ dpkg -install *deb 

If you cannot find recent Debian packages of PostgreSQL, you can easily convert RPM files to DEB files by using a program called Alien. To find out more about Alien, check out http://kitenet.net/programs/alien/.

Installing the Source Code

Some people prefer to install the source code themselves instead of relying on precompiled software packages. This has significant advantages because you know what is inside the binaries and what you have done. Compiling PostgreSQL manually is also necessary when you want to install the most recent version of PostgreSQL, because there might be no binary packages available for your system and CPU yet. Before you get to the installation process, you have to download the sources from a PostgreSQL mirror near you. The easiest way to download the source code is to use wget :

 [hs@notebook hs]$ wget ftp://ftp.postgresql.org/pub/postgresql-x.x.x.tar.gz 

To unpack the source, you use gzip and tar :

 [hs@notebook hs]$ tar xvfz postgresql-7.1.2.tar.gz 

If the z flag (which automatically unzips the archive) is not supported by your version of tar , the package can also be extracted like this:

 [hs@notebook hs]$ gunzip -c postgresql-7.1.2.tar.gz  tar xv 

This command creates a subdirectory containing the PostgreSQL package, so you need to install the database. The first thing to do when installing PostgreSQL is to run configure . The configure script has a lot of options that you can use to configure PostgreSQL exactly to your needs. Here is an overview of PostgreSQL's configure script:

 [hs@notebook postgresql-7.1.2]$ ./configure --help Usage: configure [options] [host] Options: [defaults in brackets after descriptions] Configuration:   --cache-file=FILE       cache test results in FILE   --help                  print this message   --no-create             do not create output files   --quiet, --silent       do not print `checking...' messages   --version               print the version of autoconf that created configure Directory and file names:   --prefix=PREFIX         install architecture-independent files in PREFIX                           [/usr/local/pgsql]   --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX                           [same as prefix]   --bindir=DIR            user executables in DIR [EPREFIX/bin]   --sbindir=DIR           system admin executables in DIR [EPREFIX/sbin]   --libexecdir=DIR        program executables in DIR [EPREFIX/libexec]   --datadir=DIR           read-only architecture-independent data in DIR                           [PREFIX/share]   --sysconfdir=DIR        read-only single-machine data in DIR [PREFIX/etc]   --sharedstatedir=DIR    modifiable architecture-independent data in DIR                           [PREFIX/com]   --localstatedir=DIR     modifiable single-machine data in DIR [PREFIX/var]   --libdir=DIR            object code libraries in DIR [EPREFIX/lib]   --includedir=DIR        C header files in DIR [PREFIX/include]   --oldincludedir=DIR     C header files for non-gcc in DIR [/usr/include]   --docdir=DIR            doc documentation in DIR [PREFIX/doc]   --mandir=DIR            man documentation in DIR [PREFIX/man]   --srcdir=DIR            find the sources in DIR [configure dir or ..]   --program-prefix=PREFIX prepend PREFIX to installed program names   --program-suffix=SUFFIX append SUFFIX to installed program names   --program-transform-name=PROGRAM                           run sed PROGRAM on installed program names Host type:   --build=BUILD           configure for building on BUILD [BUILD=HOST]   --host=HOST             configure for HOST [guessed]   --target=TARGET         configure for TARGET [TARGET=HOST] Features and packages:   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)   --x-includes=DIR        X include files are in DIR   --x-libraries=DIR       X library files are in DIR --enable and --with options recognized:   --with-includes=DIRS    look for additional header files in DIRS   --with-libraries=DIRS   look for additional libraries in DIRS   --with-libs=DIRS        alternative spelling of --with-libraries   --enable-locale         enable locale support   --enable-recode         enable character set recode support   --enable-multibyte      enable multibyte character support   --enable-unicode-conversion  enable unicode conversion support   --with-pgport=PORTNUM   change default port number [5432]   --with-maxbackends=N    set default maximum number of connections [32]   --disable-shared        do not build shared libraries   --disable-rpath         do not embed shared library search path in executables   --enable-debug          build with debugging symbols (-g)   --enable-depend         turn on automatic dependency tracking   --enable-cassert        enable assertion checks (for debugging)   --with-tcl              build Tcl and Tk interfaces   --without-tk            do not build Tk interfaces if Tcl is enabled   --with-tclconfig=DIR    tclConfig.sh and tkConfig.sh are in DIR   --with-tkconfig=DIR     tkConfig.sh is in DIR   --with-perl             build Perl interface and PL/Perl   --with-python           build Python interface module   --with-java             build JDBC interface and Java tools   --with-krb4[=DIR]       build with Kerberos 4 support [/usr/athena]   --with-krb5[=DIR]       build with Kerberos 5 support [/usr/athena]   --with-krb-srvnam=NAME  name of the service principal in Kerberos [postgres]   --with-openssl[=DIR]    build with OpenSSL support [/usr/local/ssl]   --enable-odbc           build the ODBC driver package   --with-odbcinst=DIR     default directory for odbcinst.ini [sysconfdir]   --with-CXX              build C++ modules (libpq++)   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]   --enable-syslog         enable logging to syslog 

As you can see, the number of options you can define is nearly endless. Before you start compiling the software, let's take a closer look at some of these options:

  • cache-file=FILE makes configure.cache the results of a test run in a file defined by FILE . Normally results are cached in config.cache . If the file generated by the test run contains test results you don't want, the file can be edited or removed. Using --cache-file=/dev/null disables caching because the output is sent to the electronic trash can.

  • version displays the version of autoconf that is currently used on the screen. If --version is passed to configure, no testing will be performed. Only the version is displayed on the screen.

  • prefix=PREFIX defines where to install architecture-independent files. If no other options, such as --bindir or --libexecdir , are defined, the entire system is installed in PREFIX .

  • exec-prefix=EPREFIX installs architecture-dependent files in EPREFIX . If this option is not defined, PREFIX is used.

  • sbindir=DIR defines the directory in which to define system administrator executables. If DIR is not defined, EPREFIX/sbin is used.

  • libexecdir=DIR determines that program executables will be installed in DIR . If this option is not defined, EPREFIX/libexec is used.

  • datadir=DIR defines the directory in which to install the system-independent data (database templates ”not the actual databases yet). If this option is not defined, DIR is set to PREFIX/share . If this option is not defined, PREFIX/etc is used.

  • libdir=DIR tells the system where to install the libraries. The default value is set to EPREFIX/lib . Knowing the exact position of your modules might be important if you are planning to install additional software, such as Perl's PostgreSQL module (DBI + DBD module).

  • includedir=DIR defines the location in which to install the C header files. When installing PostgreSQL binaries on Linux systems, the location of header files is usually set to /usr/include or /usr/include/pgsql . The default value is PREFIX/include .

  • oldincludedir=DIR sets the location for C header files for non-gcc compilers. The default value is /usr/include .

  • program-suffix=SUFFIX indicates that SUFFIX will be appended to the end of the name of every program.

  • program-transform-name=PROGRAM will be run to change the names of the programs that will be installed. Use this option very carefully .

  • x-includes=DIR defines the position of the X include files. On most Linux distributions, the files can be found in /usr/include/X11 .

  • x-libraries=DIR defines the location of the X11 libraries. On most Linux distributions, such as Linux RedHat, the files can be found in /usr/lib/X11 .

  • with-includes=DIR indicates that if additional header files are required for compiling PostgreSQL, header files can be added by defining a colon -separated list. If you have things such as GNU Readline installed in an unusual directory, this option is essential for you.

  • with-libraries=DIR is often used in combination with --with-includes to add additional libraries to PostgreSQL.

  • enable-local enables local settings for PostgreSQL. The problem with local settings is that they decrease the overall performance of your server.

  • enable-recode was formally known as "Cyrillic recode support." This flag makes PostgreSQL support all types of single-byte character-set recoding.

  • enable-multibyte enables multibyte characters . For languages such as Japanese, 1 byte is not enough to store a character. To deal with multibyte character sets, the --enable-multibyte flag has to be set at compile time. Multibyte characters can also be used with regular expressions and other functions provided by PostgreSQL. Several multibyte character sets are available: SQL_ASCII (ASCII), EUC_JP (Japanese EUC), EUC_CN (Chinese EUC), EUC_KR (Korean EUC), EUC_TW (Taiwan EUC), UNICODE (Unicode), MULE_INTERNAL (mule internal), LATIN1 (ISO 8859-1), LATIN2 (ISO 8859-2), LATIN3 (ISO 8859-3), LATIN4 (ISO 8859-4), LATIN5 (ISO 8859-5), KOI8 (KOI8-R), WIN (Windows CP1251), and ALT (Windows CP866). To use one character set as the default one, you have to define it at compile time. Here is an example:

     ./configure --enable-multibyte=SQL-ASCII. 

    If --enable-multibyte is used with no parameter, SQL_ASCII is assumed.

  • with-perl adds Perl support to your PostgreSQL server. PostgreSQL's support for Perl consists of the Pg module, which you can use in your Perl scripts, and PL/Perl (an embedded version of Perl used for writing functions, which can be used in SQL). On some systems (RedHat 7.1 with PostgreSQL 7.1.2, for example), PL/Perl cannot be built in combination with Perl 5.6.

  • with-python tells the system to build the Python module for PostgreSQL. You will have a closer look at this module later in this book.

To continue the installation process, you create a group and a user called postgres . The user does not have to be called postgres , but people normally use that name for running the database server. To add the group and the user, you use these two commands:

 [root@notebook postgresql-7.1.2]$ groupadd postgres [root@notebook postgresql-7.1.2]$ adduser postgres -g postgres 

You want the PostgreSQL binaries to be installed in /usr/local/postgresql; the database should be located in /data/postgresql. Both directories can be created by using a simple mkdir command. The two directories should be owned by the postgres user, so you have to change the permissions of the directories with the help of the chown (change owner) command. Now that precompilation is finished, you can write a small shell script. Using a script has many advantages: On the one hand it documents how you have compiled the server, and on the other hand you can easily use the same script for updating PostgreSQL. Documentation is important and can save you a lot of headaches . Here is a simple script called compile.sh:

 #!/bin/sh # configuring the PostgreSQL server env CFLAGS='-O3' ./configure --cache-file=/tmp/postgres_test.txt \        --prefix=/usr/local/postgresql --enable-multibyte\        --datadir=/data/postgresql --with-maxbackends=128 \        --with-tcl --with-perl --with-python --enable-odbc \        --with-CXX # building the binaries make # installing the binaries make install 

Let's have a closer look. First, you call configure with the parameters you want PostgreSQL to be compiled with (Perl, Python, multibyte support, and so forth). You also pass an additional compiler flag to the script by using env . The -O3 option does everything -O2 does, and also turns on -finline functions . Passing compiler options to configure is not necessary; don't use it if you don't know exactly what you are doing.

To show you an easier way to compile the server, here is another script:

 #/bin/sh ./configure --prefix=/usr/local/postgresql --datadir=/data/postgresql --with-tcl \         --with-perl --with-python --enable-odbc --with-CXX make make install 

Let's get back to the more complex installation script ”we will use it for the rest of this section. To execute the script you add execute rights to compile.sh by typing the following:

 [root@notebook postgresql-7.1.2]$ chmod +x compile.sh 

Now that the shell script is ready and the correct rights are set, you can start the installation process by executing your script:

 [root@notebook postgresql-7.1.2]$ ./compile.sh 

Configuring and compiling the server takes some time, but when the script is ready, you can go on with the installation process. In the next step, you initialize the database templates that you will need to work with PostgreSQL. Therefore, you have to use the initdb command, which can be found in the bin directory of the database server. Here is an overview of the command's syntax:

 [postgres@notebook bin]$ ./initdb --help initdb initializes a PostgreSQL database cluster. Usage:   initdb [options] datadir Options:  [-D, --pgdata] DATADIR      Location for this database cluster   -W, --pwprompt             Prompt for a password for the new superuser   -E, --encoding ENCODING    Set the default multibyte encoding for new databases   -i, --sysid SYSID          Database sysid for the superuser Less commonly used options:   -L DIRECTORY               Where to find the input files   -d, --debug                Generate lots of debugging output   -n, --noclean              Do not clean up after errors Report bugs to <pgsql-bugs@postgresql.org>. 

Now you can initialize the database:

 [postgres@notebook bin]$ ./initdb -L /data/postgresql -D /data/postgresql/data 

-L defines the directory containing the input (template) files for your database (defined by --datadir in compile.sh).

Note

The extension of the template files is .bki. Some more recent PostgreSQL distributions store the template files in a subfolder of datadir; the extension of the templates will help you find the right directory.


-D defines the location where your databases are going to reside, the place where all the data you will insert will be stored by PostgreSQL. Initializing a new database should, in most cases, work without any problems. The database has successfully been installed now and you can start the PostgreSQL daemon.

Installing on Windows

Windows differs from UNIX-based operating systems, but PostgreSQL is a flexible piece of software. Like most open source programmers, the PostgreSQL developers have implemented a software that is capable of running on various platforms ”one of those platforms is Microsoft Windows.

The easiest way to install PostgreSQL on Windows is to use Cygwin, a UNIX-like environment that provides all tools commonly known under UNIX (for example, Bash, gcc, and so forth).

With the help of the Cygnus tools, it is easy to install PostgreSQL under Windows. To install Cygwin on your system, check out http://sources.redhat.com/cygwin/ and press the Install Cygwin now button to download a file called setup.exe. This file contains the installation process for the software. Start setup.exe and you will be guided through the installation process.

A binary version of PostgreSQL is included in the Cygwin distribution, so you do not have to worry about installing PostgreSQL separately.

After installing Cygwin, you have to initialize a PostgreSQL database. Therefore, you have to install the cygipc package available at:

http://www.neuro.gatech.edu/users/cwilson/cygutils/v1.1/index.html)

This can be done by extracting the tar archive containing the software in the root directory of the Cygnus environment. Installing this package is necessary to run the server because PostgreSQL needs System V IPC system calls. ipc is a common kernel entry point for the System V IPC calls for messages, semaphores, and shared memory. If the package is not installed, PostgreSQL can't initialize the database.

Now that the software is installed, you have to add the bin directory in the Cygnus environment to the environment variable PATH of your Windows system; otherwise , cygipc won't be able to find the DLLs it needs for starting.

First you install the daemon as a service:

 ipc-daemon --install-as-service 

Then you start the daemon:

 net start ipc-daemon         # NT/2000 or ipc-daemon &                 # 9X/Me 

After that you can go on with PostgreSQL by initializing the database with the initdb command:

 initdb -L /usr/share/postgresql -D /data/postgresql 

-L defines the location of the templates PostgreSQL must use it to generate the system databases. -D defines the directory in which to store the files of the database you want to generate using initdb . Keep in mind that the directory specified by -D must be empty or nonexistent.



PostgreSQL Developer's Handbook2001
PostgreSQL Developer's Handbook2001
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net