申明

当前文章使用的 PostgreSQL 版本: 9.3.2 stable 下载

.bz2 解压命令 $ tar jxf file-name

.gz 解压命令 $ tar zxf file-name

推荐事先安装的一些依赖

$ yum install -y gcc gcc-c++ make cmake autoconf libtool \
libtool-ltdl-devel pcre pcre-devel gd-devel freetype-devel \
libxml2-devel libjpeg-devel libpng-devel openssl-devel \
curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel \
sudo bzip2 bzip2-devel bison perl-devel perl-ExtUtils-Embed \
libcurl-devel libjpeg-devel libpng-devel freetype-devel \
t1lib-devel libicu-devel mhash libmcrypt libmcrypt libiconv \
libxslt-devel openldap-devel

添加一个 postgres 用户

$ adduser postgres
$ passwd postgres
$ chmod +w /etc/sudoers
$ vim /etc/sudoers

## Allows people in group wheel to run all commands
# %wheel    ALL=(ALL)    ALL   // 去掉前面的 #

变为

## Allows people in group wheel to run all commands
%wheel    ALL=(ALL)    ALL   // 去掉前面的 #

修改postgres的用户组

$ usermod -g wheel postgres
$ chmod -w /etc/sudoers

添加用户组

$ groupadd postgres
$ useradd -g postgres -s /sbin/nologin postgres

新建数据目录和日志目录

$ mkdir -p /var/pg/data
$ mkdir -p /var/pg/log
$ chown -R postgres:postgres /var/pg

编译安装

编译参数

$ ./configure \
--prefix=/usr/local/pgsql \
--datadir=/var/pg \
--enable-thread-safety \
--with-gssapi \
--with-krb5 \
--with-ldap \
--with-openssl \
--with-libxml \
--with-libxslt \
--without-readline > out

安装

$ make > out
$ make install

ln -s /usr/local/pgsql/bin/pg_ctl /usr/local/bin

初始化数据库

$ su postgres

$ /usr/local/pgsql/bin/initdb -E UNICODE -D /var/pg/data

启动数据库

$ pg_ctl start -D /var/pg/data/ -l /var/pg/log/serverlog

设置远程连接

$ vim /var/pg/data/pg_hba.conf

修改如下:

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               trust

$ vim /var/pg/data/postgresql.conf

找到:

#listen_addresses = 'localhost'

修改如下:

listen_addresses = '*'

重启

pg_ctl restart -D /var/pg/data/ -l /var/pg/log/serverlog

MkkHou
515 声望8 粉丝

个人简介都不给


引用和评论

0 条评论