Friday, June 17, 2011

Installing PostgreSQL from source in Linux


The following steps are commonly used to install postgressql in linux systems with the source type mentioned above.
  1. Download a postgresql*.tar.gz from a mirror listed here.
  2. Then from your download directory
      $ sudo mv postgresql*.tar.gz /usr/local/src $ cd /usr/local/src $ sudo tar -xzvf postgresql*.tar.gz
  3. Configure and install PostgreSQL:
Using configure, you can add/remove the features you want before install. This will change the installation source tree accordingly. If you are finding that some features are missing after complie you can reconfigure and continue the susequent steps to build and and install. If you choose to reconfigure the PostgreSQL source before you install, make sure you use the gmake clean command within the source tree. This will delete all object files and partially compiled files.
      $ cd /usr/local/src/postgres*
      $ ./configure –with-libxml –without-readline –without-zlib –with-libraries=/usr/local/lib
      $ makeIf you want to
      $ sudo make install
      Hopefully you’ll get a “PostgreSQL installation complete.”
  1. Do user related stuff:
      create the postgres user,
      $ sudo adduser postgres
      Make a folder to store the Postgresql data. This folder can be created at anywhere and no restriction about that. After creating the folder owner of that folder should be made as 'postgres'.
      $ sudo mkdir /usr/local/pgsql/data
      $ sudo chown postgres /usr/local/pgsql/data
  2. Change to the postgres user and continue
      $ sudo su - postgres
  3. Initialize the data directory
    $ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
    create the log dir
    $ mkdir /usr/local/pgsql/data/log
  4. Sample to start the server
    $ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/log/logfile 2>&1 &
    create a sample database
    $ /usr/local/pgsql/bin/createdb mysampledb
    Now test it
    $ /usr/local/pgsql/bin/psql mysampledb

No comments:

Post a Comment