略python
对于性能型的软件,咱们采用编译的方式进行安装。sql
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
建立相应的目录并修改权限:centos
mkdir -pv /pgdata/pg_root chown -R postgres:postgres /pgdata/pg_root su - postgres # 初始化数据 # initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W # 会提示输入两次密码
在启动数据库以前,须要初始化数据库,在初始化的过程当中,会建立配置文件等。bash
在启动以前,须要修改下pg_hba.conf及postgresql.conf文件,app
最好调整一下内核参数:ide
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配置文件:post
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或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目录下。
能够下载安装Postgres.app便可,这样比较方便学习。