From MARSPRJ
0. Compiling the Environment
- Linux:centos 5.5
- gcc:4.1.2
1. Installing PostgreSQL
1) Unzip the POSTGRESQL-9.1.7.TAR.BZ2
#tar JXVF postgresql-9.1.7.tar.bz2
2) Enter the postgresql-9.1.7 directory after decompression
#cd postgresql-9.1.7
3) Compile PostgreSQL source code
#./configure--prefix=/opt/pgsql-9.1.7
#make
#make Install
At this point, complete the installation of PostgreSQL. Enter the/opt/pgsql-9.1.7 directory to see the installed PostgreSQL files.
#ls/opt/pgsql-9.1.7
2. Create a PostgreSQL database
1) Create Postgres user
#useradd Postgres
Modify Postgres Password
#passwd Postgres
2) Set environment variables for postgres users
Switch to Postgres user
#su-postgres
Go to Postgres's home directory
#cd ~
Edit ~/.bash_profile File
#vi ~/.bash_profile
Set the following environment variables
Export pghome=/opt/pgsql-9.1.7
Export Pgdata=~/data
Save, Exit VI. Execute the following command to make the environment variable effective
#source ~/.bash_profile
3) Initialize the Postgres database
#initdb
This completes the initialization of the Postgres database.
4) Start Postgres DB instance
#pg_ctl start
You can see that the PostgreSQL DB instance has been started and you can see the postgres process running in the system by following the command
#ps-ef | grep postgres
5) Connect the PostgreSQL database
#psql-H 127.0.0.1-d postgres-u Postgres
6) Stop PostgreSQL DB instance
#pg_ctl stop
#ps-ef | grep postgres
You can see that no postgres process has been
3. Set up the PostgreSQL boot boot
PostgreSQL's boot-up script is located under the contrib/start-scripts path of the PostgreSQL source directory
The Linux file is the startup script on the Linux system
1) Modify the Linux file properties and add the X attribute
#chmod A+x Linux
2) Copy the Linux file to the/ETC/INIT.D directory and rename it to PostgreSQL
#cp Linux/etc/init.d/postgresql
3) Modify the two variables of the/etc/init.d/postgresql file
Prefix installation path set to PostgreSQL:/opt/pgsql-9.1.2
Pgdata Data Directory path set to PostgreSQL:
4) The PostgreSQL service can be started by executing service PostgreSQL start
#service PostgreSQL Start
5) Set up PostgreSQL service to boot from
#chkconfig--add PostgreSQL
Execute the above command to enable the start-up of the PostgreSQL service.
Installing the PostgreSQL database (Linux) [go]