Chinaunix首页 | 论坛 | 博客
  • 博客访问: 639899
  • 博文数量: 263
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 2555
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-26 11:20
文章分类

全部博文(263)

文章存档

2011年(10)

2010年(19)

2009年(170)

2008年(64)

我的朋友

分类:

2009-05-05 10:06:49

First we'd like to thank Devrim of for working hard on making this new YUM repository available. In this article we will go over using the new PostgreSQL YUM repository for Redhat Fedora, Enterprise Linux and CentOS distros that is available at .

We are gearing the content of this article to the described user profile

  • Person has SSH root access to their PostgreSQL box
  • Person is new to using Red Hat Linux
  • Person may be new to using Linux in general

Steps before getting started

  1. SSH into your Linux box. For windows users, you can use Putty which we covered in
  2. Log in as root
  3. Determine which version of Linux you are running with the following commands:
    uname –a
    If this returns something with el4 (then you are running Enterprise Linux 4), el5 (Enterprise Linux 5), centos (ELsmp). Also pay attention to the bit 32-bit or 64-bit. 64bit will generally have an x64 and 32-bit will have i386 and/or i686 (for intel based).
    vi /etc/redhat-release
    also gives details of the version you are running

Backing up Old Version

If you are running a prior version of PostgreSQL, most likely it was installed in the /usr/local/pgsql/ folder. The first thing you want to do if you care about your data is to back it up with commands similar to the below.


  1. mkdir dbbackup
    cd dbbackup
    /usr/local/pgsql/bin/pg_dumpall –U postgres postgresqlserverdbs.sql

    You may also want to download the backup if its really important to you and in case you screw up the server really badly.
  2. Now shut down the postgresql service

    su postgres
    /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data

  3. For extra good measure rename the old folder with and backup the postgresql.conf and pga_hba.conf to a safe location
    mv /usr/local/pgsql /usr/local/pgsqlold
    1. Installing new Version

      1. Login as root
      2. Follow the instructions at to prevent your YUM update from getting postgresql from other sources
      3. Select the appropriate repository config file for your OS and choose 8.3 from here and navigating thru:
      4. Note the install file - should look something like
      5. Do a wget of the appropriate one: e.g.
        wget
      6. Next install the rpm config file with:
        rpm -ivh pgdg-redhat-8.3-2.noarch.rpm
      7. Install the things that you want. For 8.3.5+ you need to add the item in red to also install the server. These are the ones we tend to install
        yum install postgresql
        yum install postgresql-devel
        yum install postgresql-server

        yum install postgis
        yum install pgadmin3
        yum install postgresql-contrib

      8. We tend to like PostgreSQL in the /usr/local/pgsql/data folder since thats where we are used to finding it. So we init there. The default location of new install is different for each system. On EL its /var/lib/pgsql/data so you may want to init there although why its there feels so counter intuitive. Consider the below an example use case.

        mkdir /usr/local/pgsql
        mkdir /usr/local/pgsql/data
        chown postgres /usr/local/pgsql/data
        su postgres
        initdb –D /usr/local/pgsql/data

      9. cd /usr/local/pgsql/data
        and edit the postgresql.conf and pg_hba.conf files to your hearts content. It is fairly safe to copy over the pg_hba.conf file from your backup (using e.g cp /usr/local/pgsqlold/data/pg_hba.conf /usr/local/pgsql/data
        ) but for the postgresql.conf file, we would work with the new and cut in changes from the old since new things have been added between 8.2 and 8.3

      Having PostgreSQL start as a service

      The PostgreSQL install puts in a postgresql service script that you can tweak for your specific need. On RHEL 5, its located in /etc/rc.d/init.d. For other installs, it varies
      1. emacs /etc/rc.d/init.d/postgresql
        Note: if you don't have emacs, you can use vi, but I tend to prefer emacs for simple edits.
      2. Replace all references of /var/lib/pgsql/data with whereever you initD your database cluster
      3. In emacs Ctrlx+Ctrlc to save
      4. service postgresql start
        to test to make sure the service can start
      5. Next to make sure it starts automatically on boot - do the following command
        		chkconfig --list (to see list of services)
        chkconfig postgresql on

        the chkconfig on thing automatically copies symlinks to those rc.1 , rc.n locations that linux looks for in bootup. If you don't have chkconfig on your box for some reason, you have to manually copy those symlinks to the right locations - a pain.

      Installing PgAdmin pack

      The PgAdmin pack comes with PgAdmin3. This comes in handy if you use PgAdmin3 a lot as it gives you stats activity, and allows you to change pg_hba.conf and postgresql.conf files directly from PgAdmin3 even if accessing from a different computer

      psql -U postgres -d postgres -f /usr/share/pgsql/contrib/adminpack.sql
阅读(694) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~