1.下載源碼包: http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2linux
2.安裝依賴:apt-get install gcc make libreadline6 libreadline6-dev (提醒缺乏什麼就安裝什麼,如提示缺乏,zlib庫,請參照http://greenzb.blog.51cto.com/745896/1212817,安裝)sql
3.開始編譯:數據庫
(1)解壓源碼包到 /home/linux/postgresql-9.2.3 ide
(2)./configure --prefix=/要安裝postgresql到哪一個目錄post
(3)sudo make(成功提示:All of PostgreSQL successfully made. Ready to install.)postgresql
(4)su(切換到root用戶)server
(5)make install(成功提示:PostgreSQL installation complete.)blog
(6)adduser postgresget
(7)建立數據目錄:mkdir /你安裝postgresql的目錄/data源碼
(8)修改擁有者:chown postgres /你安裝postgresql的目錄/data
(9)切換到postgres用戶:su - postgres
(10)初始化數據目錄:/你安裝postgresql的目錄/bin/initdb -D /你安裝postgresql的目錄/data(成功提示:Success. You can now start the database server using:
/opt/postgresql-9.2/bin/postgres -D /opt/postgresql-9.2/data
or
/opt/postgresql-9.2/bin/pg_ctl -D /opt/postgresql-9.2/data -l logfile start)
(11)啓動postgresql服務:/你安裝postgresql的目錄/bin/postgres -D /你安裝postgresql的目錄/data >logfile 2>&1 &
(12)建立數據庫:/你安裝postgresql的目錄/bin/createdb test
(13)鏈接到數據庫:/你安裝postgresql的目錄/bin/psql test
若是成功,你將會看到:(
psql (9.2.3) Type "help" for help.)