安裝前提:java
GUN make 版本:react
sudo make –versionlinux
GNU Make 3.81sql
#建議3.76.1或者更高版本數據庫
須要一個ISO/ANSIC編譯器(至少兼容C89)。GCCide
缺省時將自動使用GNU Readline 庫(這樣能夠方便地編輯和檢索命令歷史)。它容許psql(PostgreSQL命令行的SQL解釋)記住每一個命令類型,並容許您使用箭頭鍵召回和編輯之前的命令。這是很是有用的,而且強烈推薦。若是你不想用它,那麼你必需給configure聲明--without-readline選項。若是沒有發現 libreadline 能夠使用與其兼容的libedit 庫。爲configure指定--with-libedit-preferred選項將強制使用libedit 庫。 若是你使用的是一個基於包的 Linux 發佈,那麼要注意你須要readline和readline-devel 兩個包,特別是若是這兩個包在你的版本里是分開的時候工具
缺省的時候將使用zlib壓縮庫。若是你不想使用它,那麼你必須給configure聲明--without-zlib選項。使用這個選項關閉了在pg_dump 和pg_restore裏面壓縮歸檔的支持post
下載: sudo apt-get install zlib1g-dev sudo wget http://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz sudo tar xvf postgresql-9.3.4.tar cd postgresql-9.3.4/ sudo ./configure --prefix=/usr/local/postgresql--without-readlinesudo make world sudo make install-world 初始化數據庫 sudo mkdir -p /usr/local/postgresql/data sudo groupadd postgres useradd -g postgres postgres sudo passwd postgres sudo chown -R postgres:postgres /usr/local/postgresql/data/ sudo su postgres cd /usr/local/postgresql/bin/ ./initdb --encoding=utf8 -D ../data/
啓動數據庫: ./postgres -D ../data/ & 或者 ./pg_ctl -D ../data/ -l logfile start
若是想在同一臺機器中部署兩個數據庫實例,則能夠再使用initdb命令將數據庫初始化到另外一個目錄中,此目錄要更改成postgres用戶擁有權限,初始化完成後更改端口便可。ui
配置PostgreSQL遠程訪問鏈接:(注意這裏使用postgres帳戶操做)this
cd /usr/local/postgresql/data/ sed -i "/#listen_addresses = 'localhost'/s/localhost/listen_addresses= '0'/" postgresql.conf sed -i "/#port =5432/s/#port/port/" postgresql.conf sed -i "85a\host all all 0.0.0.0/0 md5" pg_hba.conf 重啓數據庫 ./pg_ctl -D ../data/ restart
啓動腳本以下: #! /bin/sh # chkconfig: 2345 98 02 # description: PostgreSQL RDBMS # This is an example of a start/stop scriptfor SysV-style init, such # as is used on Linux systems. You should edit some of the variables # and maybe the 'echo' commands. # # Place this file at /etc/init.d/postgresql(or # /etc/rc.d/init.d/postgresql) and makesymlinks to # /etc/rc.d/rc0.d/K02postgresql # /etc/rc.d/rc1.d/K02postgresql # /etc/rc.d/rc2.d/K02postgresql # /etc/rc.d/rc3.d/S98postgresql # /etc/rc.d/rc4.d/S98postgresql # /etc/rc.d/rc5.d/S98postgresql # Or, if you have chkconfig, simply: # chkconfig --add postgresql # # Proper init scripts on Linux systemsnormally require setting lock # and pid files under /var/run as well asreacting to network # settings, so you should treat this withcare. # Original author: Ryan Kirkpatrick <pgsql@rkirkpat.net> # contrib/start-scripts/linux ## EDIT FROM HERE # Installation prefix prefix=/usr/local/pgsql # Data directory PGDATA="/usr/local/pgsql/data" # Who to run the postmaster as, usually"postgres". (NOT"root") PGUSER=postgres # Where to keep a log file PGLOG="$PGDATA/serverlog" # It's often a good idea to protect thepostmaster from being killed by the # OOM killer (which will tend topreferentially kill the postmaster because # of the way it accounts for sharedmemory). Setting the OOM_SCORE_ADJ value # to -1000 will disable OOM killaltogether. If you enable this, youprobably # want to compile PostgreSQL with"-DLINUX_OOM_SCORE_ADJ=0", so that # individual backends can still be killedby the OOM killer. #OOM_SCORE_ADJ=-1000 # Older Linux kernels may not have/proc/self/oom_score_adj, but instead # /proc/self/oom_adj, which works similarlyexcept the disable value is -17. # For such a system, enable this andcompile with "-DLINUX_OOM_ADJ=0". #OOM_ADJ=-17 ## STOP EDITING HERE # The path that is to be used for thescript PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # What to use to start up thepostmaster. (If you want the script towait # until the server has started, you coulduse "pg_ctl start -w" here. # But without -w, pg_ctl adds no value.) DAEMON="$prefix/bin/postmaster" # What to use to shut down the postmaster PGCTL="$prefix/bin/pg_ctl" set -e # Only start if we can find the postmaster. test -x $DAEMON || { echo "$DAEMON not found" if [ "$1" = "stop" ] then exit 0 else exit 5 fi } # Parse command line parameters. case $1 in start) echo -n "Starting PostgreSQL: " test x"$OOM_SCORE_ADJ" != x && echo"$OOM_SCORE_ADJ" > /proc/self/oom_score_adj test x"$OOM_ADJ" != x && echo "$OOM_ADJ"> /proc/self/oom_adj su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG2>&1 echo "ok" ;; stop) echo -n "Stopping PostgreSQL: " su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast" echo "ok" ;; restart) echo -n "Restarting PostgreSQL: " su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w" test x"$OOM_SCORE_ADJ" != x && echo"$OOM_SCORE_ADJ" > /proc/self/oom_score_adj test x"$OOM_ADJ" != x && echo "$OOM_ADJ"> /proc/self/oom_adj su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG2>&1 echo "ok" ;; reload) echo -n "Reload PostgreSQL: " su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s" echo "ok" ;; status) su - $PGUSER -c "$PGCTL status -D '$PGDATA'" ;; *) # Print help echo "Usage: $0 {start|stop|restart|reload|status}"1>&2 exit 1 ;; esac exit 0
將此腳本修改而後放置到/etc/init.d/postgres01
sudo chmod +x /etc/init.d/postgres01 sudo update-rc.d -n postgresql01 defaults 98 查找安裝工具包(管理系統服務) sudo apt-cache search ^sysv sudo apt-get install sysv-rc-conf sudo sysv-rc-conf