安装前提:
GUN make 版本:
sudo make –version
GNU Make 3.81
#建议3.76.1或者更高版本
需要一个ISO/ANSIC编译器(至少兼容C89)。GCC
缺省时将自动使用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里面压缩归档的支持
下载: 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用户拥有权限,初始化完成后更改端口即可。
配置PostgreSQL远程访问连接:(注意这里使用postgres账户操作)
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