postgresql安装简单记录

环境:centos 7,postgresql 9.5

1、配置centos 7环境

1)使用安装相关依赖:

yum -y install lrzsz sysstat e4fsprogs ntp readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make
smartmontools flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel

2)配置好系统语言和系统时间

查看系统语言echo $LANG,由于系统默认是UTF-8,因此无需修改,若不是最好修改为UTF-8

查看系统时间clock -r,查看时间是否准确,若不准确,使用ntpdate进行系统时间校验

3)关闭selinux

vi /etc/sysconfig/selinux
SELINUX=disabled
setenforce 0

4)安装flex

yum -y install flex

完成后使用命令查看:

flex -V

版本必须要在2.5以上

5)创建用户postgres

groupadd postgres
useradd -g postgres postgres
passwd postgres


6)修改postgres用户的bash_profile

vi /home/postgres/.bash_profile

export PGPORT=5432
export PGDATA=/var/postgres/pgdata
export LANG=en_US.utf8
export PGHOME=/usr/local/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGHOST=$PGDATA
export PGDATABASE=postgres
alias rm='rm -i'
alias ll='ls -lh'

要让文件立即生效需要

source .bash_profile


2、安装postgresql

1)将postgresql源码包上传到/data目录

postgresql-9.5.0.tar.gz

2)解压

tar -zxvf postgresql-9.5.0.tar.gz

3)配置安装文件

./configure --prefix=/usr/local/pgsql9.5.0 --with-pgport=5432 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap 

--with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=8 --with-blocksize=8--enable-dtrace --enable-debug  --enable-cassert

其中红色部分是用户调试和追踪,在生产环境不需要安装

--enable-dtrace 需要安装systemtap否则会出现无法找到 configure: error: dtrace not found

4)安装systemtap

vi /etc/yum.repos.d/CentOS-Debuginfo.repo

按下图修改为1

在安装systemtap前,要保证kernel对应的kernel-devel包的版本保持一致

使用uname -r查看

我的是:

yum install -y kernel-devel-3.10.0-327.el7.x86_64 kernel-debuginfo-3.10.0-327.el7.x86_64 kernel-debuginfo-common-x86_64-3.10.0-327.el7.x86_64 systemtap

安装systemtap

yum install systemtap systemtap-sdt-devel

检查systemtap是否正常

stap -ve 'probe begin { log("hello world") exit() }'


出现问题:

checking for flags to link embedded Perl... Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
no
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is not
installed.

解决办法

yum install perl-ExtUtils-Embed

重新执行配置编译通过

执行

gmake world

接着安装(带world参数可以安装PG的附属信息,如文档,帮助等)

 gmake install-world

创建软链接,以后升级数据库可以直接修改软链接即可

ln -s /usr/local/pgsql9.5.0/ /usr/local/pgsql

创建数据库的数据目录并设置其权限

mkdir /var/postgres/pgdata -p

chown -R postgres:postgres /var/postgres

查看环境变量是否配置成功

psql -V

如果输出:

sql (PostgreSQL) 9.5.0

配置成功,否则需要检查/home/postgres/.bast_profile是否配置成功或是使用source命令使其生效


初始化数据库

切换postgres用户

su postgres

initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W

出现:

You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.


Success. You can now start the database server using:


    pg_ctl -D /var/postgres/pgdata -l logfile start

说明安装初始化成功


对数据库文件进行配置


cd $PGDATA

vi postgresql.conf

调整数据库postgresql.conf参数. 打开日志, SQL统计, 跟踪, 以及性能参数, 便于优化过程中取证.


监听IPv4的所有IP.
listen_addresses = '0.0.0.0'


启动postgres数据

pg_ctl start -D $PGDATA

出现server starting 表示运行成功


查看postgres

ps -ef | grep postgres


postgres 19638 19637  0 07:25 pts/0    00:00:00 bash
root     29414 19660  0 07:34 pts/0    00:00:00 su postgres
postgres 29415 29414  0 07:34 pts/0    00:00:00 bash
postgres 29429 29415  0 07:34 pts/0    00:00:00 vi /home/
root     29461 29434  0 07:41 pts/0    00:00:00 su postgres
postgres 29462 29461  0 07:41 pts/0    00:00:00 bash
root     29574  1020  0 08:16 ?        00:00:00 sshd: postgres [priv]
postgres 29576 29574  0 08:16 ?        00:00:00 sshd: postgres@notty
postgres 29577 29576  0 08:16 ?        00:00:00 /usr/libexec/openssh/sftp-server
postgres 29601     1  0 08:21 pts/0    00:00:00 /usr/local/pgsql9.5.0/bin/postgres -D /var/postgres/pgdata
postgres 29602 29601  0 08:21 ?        00:00:00 postgres: logger process
postgres 29604 29601  0 08:21 ?        00:00:00 postgres: checkpointer process
postgres 29605 29601  0 08:21 ?        00:00:00 postgres: writer process
postgres 29606 29601  0 08:21 ?        00:00:00 postgres: wal writer process
postgres 29607 29601  0 08:21 ?        00:00:00 postgres: autovacuum launcher process
postgres 29608 29601  0 08:21 ?        00:00:00 postgres: archiver process
postgres 29609 29601  0 08:21 ?        00:00:00 postgres: stats collector process
postgres 29612 29462  0 08:22 pts/0    00:00:00 ps -ef
postgres 29613 29462  0 08:22 pts/0    00:00:00 grep --color=auto postgres

停止数据库

pg_ctl stop -D $PGDATA


重启数据库

pg_ctl restart

//使用pgadmin登录postgressql

去http://www.postgresql.org/ftp/pgadmin3/release/v1.22.0/下载安装程序

需要配置服务器的pg_hba.conf  文件

在结尾处增加允许客户端登录的地址

host    all             all             192.168.1.101/32        md5

重启数据库,使用pgadmin连接即可









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值