1下载pg的源码安装文件,下载地址:http://www.postgresql.org/download/
2下载好后的安装文件放到redhat上去,在安装pg的时候可以使用普通的用户,无需root。
3解压源码安装文件:$ tar xzvf postgresql-9.3.5.tar.gz
4配置编译
使用解压缩目录下的configure脚本来配置具体平台相应的参数,configure脚本设置控制PostgreSQL生成方法的变量,统计编译的平台,C编译器提供的功能等。configure脚本将自动设置安装的位置。默认的PostgreSQL安装位置位于/usr/local/pgsql,包含应用程序和数据的子目录。如果不想安装在默认的目录,可以使用参数来具体的指定安装位置。下面是配置脚本的选项
PostgreSQL配置脚本选项
选项 | 描述 |
--prefix=prefix | 安装到prefix指向的目录;默认为/usr/local/pgsql |
--bindir=dir | 安装应用程序到dir;默认为prefix/bin |
--with-docdir=dir | 安装文档到dir;默认为prefix/doc |
--with-pgport=port | 设置默认的服务器端网络连接服务TCP端口号 |
--with-tcl | 为服务端提供Tcl存储过程支持 |
--with-perl | 为服务端提供Perl存储过程支持 |
--with-python | 为服务端提供Python存储过程支持 |
[bai@dg2 postgresql-9.3.5]$ ./configure --help
`configure' configures PostgreSQL 9.3.5 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/pgsql]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/pgsql/bin', `/usr/local/pgsql/lib' etc. You can specify
an installation prefix other than `/usr/local/pgsql' using `--prefix',
for instance `--prefix=$HOME'.
............
我将pg安装在/orainst目录下面
$ ./configure --prefix=/orainst/pgsql
5编译完成后,开始构建软件
$make
6make 成功后,make install
All of PostgreSQL successfully made. Ready to install.-----make成功的提示
[bai@dg2 postgresql-9.3.5]$ make install
在安装完后,可以查看pg的配置信息
[bai@dg2 bin]$ ./pg_config
BINDIR = /orainst/pgsql/bin
DOCDIR = /orainst/pgsql/share/doc
HTMLDIR = /orainst/pgsql/share/doc
INCLUDEDIR = /orainst/pgsql/include
PKGINCLUDEDIR = /orainst/pgsql/include
INCLUDEDIR-SERVER = /orainst/pgsql/include/server
LIBDIR = /orainst/pgsql/lib
PKGLIBDIR = /orainst/pgsql/lib
LOCALEDIR = /orainst/pgsql/share/locale
MANDIR = /orainst/pgsql/share/man
SHAREDIR = /orainst/pgsql/share
SYSCONFDIR = /orainst/pgsql/etc
PGXS = /orainst/pgsql/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/orainst/pgsql'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE
CFLAGS = -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL = -fpic
LDFLAGS = -L../../../src/common -Wl,-rpath,'/orainst/pgsql/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgport -lpgcommon -lz -lreadline -ltermcap -lcrypt -ldl -lm
VERSION = PostgreSQL 9.3.5
-----------------------------------------------------------上面的安装步骤完成了,下面开始配置---------------------------
第一步,你需要建立一个叫postgres的用户,然后你需要为数据库建立一个目录并初始化数据库结构。然后,你可以通过启动postmaster进程启动PostgreSQL了。
1useradd postgres2mkdir /orainst/pgsql/data
3chown postgres /orainst/pgsql/data
4开始初始化数据库,要使用postgres用户来初始化库。
[postgres@dg2 bin]$ ./initdb -D /orainst/pgsql/data/
我们会看到下面的成功提示,提示如何启动数据库
Success. You can now start the database server using:
./postgres -D /orainst/pgsql/data/
or
./pg_ctl -D /orainst/pgsql/data/ -l logfile start
启动后,本地的postgres用户是可以连接上去的,但是远程用户无法连接
5配置远程连接,具体配置方法见http://blog.youkuaiyun.com/aoerqileng/article/details/39826037