In Linux, I like source code installation. I personally feel that he will not lose all files.
Step 1: Download the source code package
: Http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.gz
If you need to install another version, you can go to http://www.postgresql.org/ftp/source/
Step 2: preparations before installation
Yum install-y zlib-devel Readline-devel
Step 3: decompress and compile
Tar-zxvf postgresql-9.1.4.tar.gz
CD postgresql-9.1.4
./Configure (add-H to the end to display the supported parameters)
Make & make install
Step 4: Add PostgreSQL users and initialize data
Useradd PostgreSQL
Su-PostgreSQL # switch to a PostgreSQL user
Passwd # Change User Password
Mkdir data # create a data directory
Chown-r PostgreSQL: PostgreSQL/usr/local/pgsql # It is installed in this directory by default after compilation, so the ownership of this directory is handed over to PostgreSQL
CD Data # enter the data directory
/Usr/local/pgsql/bin/initdb # Run the initialization script.
After completion, some PostgreSQL data and configuration files will be generated under the current directory.
Step 5: Set startup
Su # Switch to Super User
Cd ~ /Postgresql-9.1.4 # enter the source code folder, and decompress the source code folder
CP contrib/start-scripts/Linux/etc/init. d/PostgreSQL # Add the service script to init. d.
VI/etc/init. d/PostgreSQL # modify the data directory And change pgdata = "/usr/local/pgsql/Data" to pgdata = "/home/PostgreSQL/Data"
Chmod A + x/etc/init. d/PostgreSQL # Add execution permission
Chkconfig -- add PostgreSQL
Now you can use service PostgreSQL start to enable the postgresql service, and it will automatically start when it is started.
Step 6: the installation is successful.