码迷,mamicode.com
首页 > 数据库 > 详细

PostgreSQL编译安装

时间:2018-01-14 11:10:07      阅读:880      评论:0      收藏:0      [点我收藏+]

标签:art   版本库   一个   普通用户   localhost   figure   ice   hba   utf8   

获取源码

编译安装

对于性能型的软件,我们采用编译的方式进行安装。

安装依赖

yum install -y systemtap-sdt-devel perl-ExtUtils-Embed pam-devel libxml2-devel libxslt-devel python-devel

编译

./configure --prefix=/opt/pgsql-9.3.2 --with-perl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16 --enable-dtrace --enable-debug
gmake world # 安装了包含文档,所有的contrib
gmake check-world -- (需要普通用户执行。可选,耗时较长)
gmake install-world

启动服务

软件安装完毕,在操作系统中新建一个普通用户,用于初始化数据库、开启和关闭数据库。

useradd postgres
su - postgres
vi ~/.bash_profile
# add
export PGDATA=/pgdata/pg_root
export LANG=en_US.utf8
export PGHOME=/opt/pgsql-9.3.2
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres

创建相应的目录并修改权限:

mkdir -pv /pgdata/pg_root
chown -R postgres:postgres /pgdata/pg_root
su - postgres
# 初始化数据
# initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
# 会提示输入两次密码

在启动数据库之前,需要初始化数据库,在初始化的过程中,会创建配置文件等。

修改配置文件

在启动之前,需要修改下pg_hba.conf及postgresql.conf文件,

  • pg_hba.conf用于配置控制访问数据库的来源
  • postgresql.conf是数据库的主要配置文件

最好调整一下内核参数:

vi /etc/sysctl.conf
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 7672460
net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576 
sysctl -p

修改limits.conf配置文件:

vi /etc/security/limits.conf
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000

启动数据库

# pg_ctl start -D $PGDATA
# 或者使用如下的方式启动
pg_ctl -D /var/lib/pgsql/data -l logfile start
-bash-4.2$ lsof logfile
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 30772 postgres 1w REG 8,3 0 34606128 logfile
postgres 30772 postgres 2w REG 8,3 0 34606128 logfile
-bash-4.2$ lsof -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 30771 postgres 3u IPv6 37671946 0t0 TCP localhost:postgres (LISTEN)
postgres 30771 postgres 4u IPv4 37671947 0t0 TCP localhost:postgres (LISTEN)

允许外网访问:

echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf

停止

pg_ctl stop -m fast|smart|immediate -D $PGDATA

CentOS二进制包安装

如果认为CentOS或RedHat自带的PostgreSQL版本太低,想要使用新的版本,可以使用下面的方法安装。安装PostgreSQL官方提供的RPM包,将新版本信息加入到版本库中:

rpm -ivh https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm

然后使用yum install命令进行安装:

yum install -y postgresql94-server.x86_64

安装第三方贡献包:

yum install -y postgresql94-contrib.x86_64

新版本的PostgreSQL的数据目录在/var/lib/pgsql/<version>/data目录下,version表示PostgreSQL的版本,如9.4版本就安装在/var/lib/pgsql/9.4/data目录下。

MacOS安装PostgreSQL

可以下载安装Postgres.app即可,这样比较方便学习。

PostgreSQL编译安装

标签:art   版本库   一个   普通用户   localhost   figure   ice   hba   utf8   

原文地址:http://blog.51cto.com/lavenliu/2060704

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!