Install PostgreSQL 8.4 Database Server on CentOS, Fedora, Red Hat

This is quick guide howto install PostgreSQL 8.4 (current stable 8.4.7) database server on CentOS, Fedora and Red Hat. Fedora 14, Fedora 13, CentOS 5.5 and Red Hat (RHEL) 5.5 has PostgreSQL 8.4 database server as default so extra repositories is not needed. Personally, I like to use Postgres own repositories, because the latest version of PostgreSQL may be quickly and easily installed. The following commands run as root and postgres user, so “su -” or “sudo -i” first.

Install PostgreSQL 8.4 Database Server Using PostgreSQL’s repositories

Install PostgreSQL repository:

## CentOS
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-centos-8.4-2.noarch.rpm
 
## Fedora
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-fedora-8.4-2.noarch.rpm
 
## Red Hat
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-redhat-8.4-2.noarch.rpm

Install postgresql and postgresql-server packages from PostgreSQL’s repositories:

yum install postgresql postgresql-server postgresql-contrib

Alternative PostgreSQL 8.4 Install Method for Fedora 12, Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5

Install postgresql and postgresql-server packages on CentOS 5.5 and Red Hat (RHEL) 5.5:

yum install postgresql84 postgresql84-server postgresql84-contrib

Install postgresql and postgresql-server packages on Fedora 12 and Fedora 13:

yum install postgresql postgresql-server postgresql-contrib

Configure PostgreSQL 8.4 Database Server

Initialize the cluster first with initdb command:

service postgresql initdb
## OR ##
/etc/init.d/postgresql initdb

Edit /var/lib/pgsql/data/postgresql.conf file:

nano -w /var/lib/pgsql/data/postgresql.conf

Set PostgreSQL server to listen all addresses and Change PostgreSQL port (default is 5432). Add/Uncomment/Edit following lines:

listen_addresses = '*'
port = 5432

Edit /var/lib/pgsql/data/pg_hba.conf file:

nano -w /var/lib/pgsql/data/pg_hba.conf

Add (example) your local network with md5 passwords:

# Local networks
host	all	all	xx.xx.xx.xx/xx	md5
# Example
host	all	all	10.20.4.0/24	md5

Start/Restart PostgreSQL Server:

service postgresql start
## OR ##
/etc/init.d/postgresql start

Change to postgres user:

su postgres

Create test database (as postgres user):

createdb test

Login test database (as postgres user):

psql test

Create New “testuser” Role with Superuser and Password:

CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';

Open PostgreSQL Port (5432) on Iptables Firewall (as root user again)

Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

Add following line before COMMIT:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

Test remote connection:

psql -h dbserver -U testuser test
Follow If Not True Then False Updates!

37 Comments

  1. after editting hba file , I wasn’t able to start postgresql. Then I tried next thing that is iptable , but it says ‘having error in line 13′ which is the line I added before comet as you said.

    Don’t know what is wrong , my system is i686 archetecture and I have installed postgresql for that only but still their is problem. I can’t restart or start.

    • Hi Dhawal,

      It is impossible to say any reason without seeing to conf files.

      So could you post your /var/lib/pgsql/data/pg_hba.conf file and your /etc/sysconfig/iptables file?

  2. http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-fedora-8.4-1.noarch.rpm

    returns 404 error

    How to install PostgreSql 8.4 on FC 11 RC ?

    • Hi Andrus,

      Working address is currently:
      http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-fedora-8.4-2.noarch.rpm

      I updated it to this guide also.

      I have not tested this guide with Fedora 11, but I think this should work nicely with Fedora 11 (and even fc10, fc9…), because PostgreSQL 8.4 doesn’t have any dependencies to Fedora 12 or Fedora 13 packages.

      Please let me know, if you get it working or if you have any problems?

  3. Thank you.
    In Fedora 11 there is no /etc/sysconfig/iptables file mentioned.
    How to open 5432 port? How to find router IP address ? Maybe router needs also configured.

    Where to find instructions to install latest mono + mod_mono in Fedora 11 ?
    yum mod_mono installs old 2.4 version.

    Andrus.

    • In Fedora 11 try add configurations to /etc/iptables.up.rules file.

      It is difficult to say anything about network configuration without seeing it.

      • [root@server /etc]# ls /etc/ipt*
        ls: cannot access /etc/ipt*: No such file or directory

        There is no to /etc/iptables.up.rules in Fedora 11

        • Ok, I do not have Fedora 11 now, but then try simple something like following (as root):

          /sbin/iptables -I INPUT 1 -p tcp --dport 5432 -j ACCEPT
          ## OR ##
          /sbin/iptables -I INPUT 1 -p tcp --dport postgres -j ACCEPT

          Save rules (as root):

          /sbin/service iptables save
  4. CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD=’test’;

    is incorrect. correct is

    CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD ‘test’;

    • Yes you’re right, it’s typo.

      I fix it to guide.

      Thanks!

  5. Another typo that got me, because I was copy-n-pasting. That should be

    listen_addresses = ‘*’

    *not*

    listen_addressses = ‘*’

    Count the S’s

    • Hi Nick,

      Thans for the correction!

      Updated guide again… :)

  6. I would like to recommend to also install the contrib libraries (for VACUUMing etc),
    since v8.2 it is a separate package (postgresql84-contrib)

    yum install postgresql84 postgresql84-server postgresql84-contrib

    /patrick

    • Hi Patrick,

      Thanks for the tip!

      I added it in the guide.

  7. Hi
    i have followed your guide and installed the pgsql. i am using fedora 12.
    i have done the following

    # rpm -Uvh http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-fedora-8.4-2.noarch.rpm
    # yum install postgresql postgresql-server postgresql-contrib

    but when i run the below command i get the error like
    # service postgresql initdb

    the error i get
    /etc/init.d/postgresql: line 24: /etc/sysconfig/network: No such file or directory

    i have just started learning linux 2 days ago so i have no idea how do i solve problem. please guide me to fix it

    • Hi sankar,

      Are you running service postgresql initdb command as root?

      Could you post following command output:

      ls -la /etc/sysconfig/network
      • Hi,
        Yes i am running those command from root

        [root@localhost Sankar]# service postgresql initdb
        /etc/init.d/postgresql: line 24: /etc/sysconfig/network: No such file or directory

        [root@localhost Sankar]# ls -la /etc/sysconfig/network
        ls: cannot access /etc/sysconfig/network: No such file or directory

        [root@localhost Sankar]#

        please help i am stuck!!
        with regards………

        • Okey you don’t have /etc/sysconfig/network file. Is your network working normally?

          You could create /etc/sysconfig/network file with following command (as root):

          echo "NETWORKING=yes" > /etc/sysconfig/network

          Then try again and see what happens?

          Btw. I wonder just why you’ve installed Fedora 12 distro a few days ago? Fedora 14 is coming very soon.

  8. On RHEL 6, I am getting this after adding your repo successfully.

    http://yum.pgsqlrpms.org/8.4/redhat/rhel-6Server-x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 : http://yum.pgsqlrpms.org/8.4/redhat/rhel-6Server-x86_64/repodata/repomd.xml
    Trying other mirror.
    Error: Cannot retrieve repository metadata (repomd.xml) for repository: pgdg84. Please verify its path and try again

    • Hi Stephen,

      Actually pgsqlrmps not working with RHEL 6 so try pgrpms, install following instead:

      rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-redhat-8.4-2.noarch.rpm

      And then continue installation procedure normally. I updated this guide to use pgrpms.org…

  9. hi jr i am stuck..
    when trying to change to postgres i am getting
    bash 3.2$

    whats the problem???
    though there is user created in /etc/passwd as postgres by default
    please help me out

    • no problem at all , postgres is the account under it postmaster is running.

  10. GREAT!!!!! THANKS THANKS THANKS

  11. There are changes in Fedora 16 to init the database:

    sudo service postgresql initdb
    > Redirecting to /bin/systemctl initdb postgresql.service
    > Unknown operation initdb

    This command has changed in Fedora 16. The correct command is now:
    $ sudo postgresql-setup initdb

  12. Hi guys, i have Centos-5.8-i386-server-VMware workstation and wanna know, am i on the right track to install PostgreSQL 8.4 on this machine? Does it matter which version of Centos, Fedora or any platform we use or what i am ok so far! I will start from the beginning of this link, if you see something wrong here please let me know or just let me go through the learning curve. Thanks for sharing this link.

    bye now
    John

  13. I am finally installing postgreSQL on my Centos 5.8….using nano editor i Set PostgreSQL server to listen all addresses and Change PostgreSQL port (default is 5432). Just don’t know how to add local host when my IP looks likes this…..192.168.77.85….example shows something like 10.20.4.0/24
    *********************************************
    host all all xx.xx.xx.xx/xx md5
    # Example
    host all all 10.20.4.0/24 md5
    *********************************************
    Please help….assignment is haunting me. Thanks

    • Hi John,

      You can add single address, like following:

      # 127.0.0.1 #
      host    all         all         127.0.0.1/32          trust
       
      # 192.168.77.85 #
      host    all         all         192.168.77.85/32      md5
  14. Hi all,

    I can’t connect localhost to postgres in RHEL 6, I try:

    # psql -h localhost -U testuser test
    psql: FATAL: la autentificación Ident falló para el usuario «testuser»

    But in my /var/lib/pgsql/data/pg_hba.conf I have:

    host all all 127.0.0.1/32 ident
    host all all 0.0.0.0/0 md5

    Also I have disabled iptables too so, what can be happening?

    Regards,

    • Hi Pedro,

      You use ident-based authentication (uses your os user accounts), but I guess you want use trust or md5 instead?

  15. [root@localhost ~]# /etc/init.d/postgresql initdb
    Data directory is not empty! [FAILED]

    What am I missing?

    • Hi Tony,

      Do you want install just PostgreSQL 8.4? Or maybe latest PostgreSQL version 9.2?

      • Third party software requirements. I’m not sure if 9.2 works with Cisco DCNM. But I’ll give it a try.

        • I see.

          Actually PostgreSQL 8.4 should work still okay, so could you post output of following commands:

          uname -a
           
          ls -la /var/lib/pgsql/
           
          ls -la /var/lib/pgsql/data

          Do you have already database running, or tried to install it another way?

          • JR,

            I could’ve sworn I replied back with my results. Anyways thanks for the guide it helped me alot. I’m not sure why I couldn’t find the iptables for Cent0S6.4 but I skipped that step and tested. Everything is fine now. I ended up starting from scratch, uninstalled the software and removing psql folders, started the guide over using this guide and the 9.2 guide. Thanks again.

  16. So I have to install Postgres again on another server but I’m getting this error when installing repositories.

    Retrieving http://yum.pgrpms.org/reporpms/8.4/pgdg-redhat-8.4-2.noarch.rpm
    error: skipping http://yum.pgrpms.org/reporpms/8.4/pgdg-redhat-8.4-2.noarch.rpm – transfer failed – Unknown or unexpected error

    Is there another alternative route?

  17. Also even if I couldn’t add the repo I still ran:

    yum install postgresql84 postgresql84-server postgresql84-contrib

    I got a list of what was available:

    ================================================================================
    Installing:
    postgresql84 x86_64 8.4.13-1.el5_8 base 3.7 M
    postgresql84-contrib x86_64 8.4.13-1.el5_8 base 399 k
    postgresql84-server x86_64 8.4.13-1.el5_8 base 5.2 M
    Installing for dependencies:
    libxslt x86_64 1.1.17-4.el5_8.3 base 424 k
    postgresql84-libs x86_64 8.4.13-1.el5_8 base 211 k

    Transaction Summary
    ================================================================================
    Install 5 Package(s)
    Upgrade 0 Package(s)

    Total download size: 9.9 M
    Is this ok [y/N]:

    But when I hit y and enter I get this:

    Downloading Packages:
    http:///mrepo/rhel5-prod-x86_64/RPMS.os/postgresql84-libs-8.4.13-1.el5_8.x86_64.rpm: [Errno 14] HTTP Error 404: Not Found
    Trying other mirror.
    http:///mrepo/rhel5-prod-x86_64/RPMS.os/postgresql84-contrib-8.4.13-1.el5_8.x86_64.rpm: [Errno 14] HTTP Error 404: Not Found
    Trying other mirror.
    http:///mrepo/rhel5-prod-x86_64/RPMS.os/libxslt-1.1.17-4.el5_8.3.x86_64.rpm: [Errno 14] HTTP Error 404: Not Found
    Trying other mirror.
    http://puppet.unica.net/mrepo/rhel5-prod-x86_64/RPMS.os/postgresql84-8.4.13-1.el5_8.x86_64.rpm: [Errno 14] HTTP Error 404: Not Found
    Trying other mirror.
    http:///mrepo/rhel5-prod-x86_64/RPMS.os/postgresql84-server-8.4.13-1.el5_8.x86_64.rpm: [Errno 14] HTTP Error 404: Not Found
    Trying other mirror.

    Error Downloading Packages:
    postgresql84-contrib-8.4.13-1.el5_8.x86_64: failure: postgresql84-contrib-8.4.13-1.el5_8.x86_64.rpm from base: [Errno 256] No more mirrors to try.
    postgresql84-8.4.13-1.el5_8.x86_64: failure: postgresql84-8.4.13-1.el5_8.x86_64.rpm from base: [Errno 256] No more mirrors to try.
    postgresql84-libs-8.4.13-1.el5_8.x86_64: failure: postgresql84-libs-8.4.13-1.el5_8.x86_64.rpm from base: [Errno 256] No more mirrors to try.
    postgresql84-server-8.4.13-1.el5_8.x86_64: failure: postgresql84-server-8.4.13-1.el5_8.x86_64.rpm from base: [Errno 256] No more mirrors to try.
    libxslt-1.1.17-4.el5_8.3.x86_64: failure: libxslt-1.1.17-4.el5_8.3.x86_64.rpm from base: [Errno 256] No more mirrors to try.

Add Comment Register



Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackbacks/Pingbacks

  1. Fedora NetInstall (Net Install) with gPXE and BFO (boot.fedoraproject.org) | If Not True Then False - [...] Fedora 13Install Adobe (Acrobat PDF) Reader on Fedora 13Install VirtualBox (with yum) on Fedora 13Install PostgreSQL 8.4 Database Server …
  2. Upgrade to Fedora 13 from Fedora 12 with Preupgrade - [...] Fedora 13Install Adobe (Acrobat PDF) Reader on Fedora 13Install VirtualBox (with yum) on Fedora 13Install PostgreSQL 8.4 Database Server …
  3. cannot create database in postgreSQL please help - oBlurb - [...] http://www.if-not-true-then-false.co…edora-red-hat/ [...]