postgresql安装目录:/opt/postgresql/9.6 postgresql数据库目录:/data/postgresql/ 准备包: postgresql: https://www.postgresql.org/ftp/source/ postgresql-9.6.2.tar.gz uuid-ossp:https://launchpad.net/ubuntu/+source/ossp-uuid/1.6.2-1.5build3uuid-1.6.1.tar.gz readline:(推荐yum安装) readinle-devel:https://pkgs.org/download/readline-devel(x86-64)
解压源码包 # tar -zxvf postgresql-9.6.2.tar.gz
进入解压后的目录 # cd postgresql-9.6.2
安装前准备flex bison # yum install flex bison
编译安装 # ./configure --with-libxml --with-ossp-uuid --with-libs=/opt/postgresql/9.6/lib --with-includes=/opt/postgresql/9.6include
报错需要安装readline,那就把readline和readline-devel都装上
# make # make install
设置环境变量 # vi .bash_profile #### 把 PATH=$PATH:$HOME/bin 改成下面内容 ####
# PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin # source .bash_profile
添加用户 # adduser postgres
更改用户目录(可选操作) # vi /etc/passwd
#### 把 postgres:x:528:528::/home/postgres:/bin/bash 改成下面内容 ####
# postgres:x:528:528::/opt/postgresql/9.6:/bin/bash
#### 将.bash_profile 移动到新的用户目录并修改权限 #### # cp /home/postgres/.bash_profile /opt/postgresql/9.6
# chown postgres.postgres .bash_profile
#### 删除用户目录 #### # rm -rf postgres/
新建数据目录 # mkdir /data/postgresql/
# chown postgres /data/postgresql/
切换到postgres 用户 # su - postgres
初始化数据库 # /opt/postgresql/9.6/bin/initdb -D /data/postgresql/ # exit
复制源码目录下的linux文件到/etc/init.d/ # cd cd postgresql-9.6.2
# cp contrib/start-scripts/linux /etc/init.d/postgresql
# vim /etc/init.d/postgresql #### prefix=/usr/local/pgsql 改成以下内容 ###
prefix=/opt/postgresql/9.6 #### PGDATA="/usr/local/pgsql/data" 改成以下内容 ###
PGDATA="/data/postgresql/"
添加权限 # chmod +x /etc/init.d/postgresql
启动数据库 # service postgresql restart
让数据库开机启动 # chkconfig --add postgresql
# chkconfig postgresql on
扩展插件uuid # su - postgres
postgres=# CREATE EXTENSION "uuid-ossp";
源码安装相关问题及解决方案 执行postgresql命令、修改postgresql配置文件(postgresql.conf、pg_hba.conf),文件和目录在哪? # /usr/local/pgsql/data
postgresql默认只允许本机访问,需要远程连接、外网访问,如何配置? 先配置监听地址 # vi /usr/local/pgsql/data/postgresql.conf
#### 取消掉下面一行的前面的#注释,并将值改为* ####
# listen_addresses = '*'
再配置支持远程连接 # vi /usr/local/pgsql/data/pg_hba.conf #### 直接配置为不限制IP,即0.0.0.0,注意:/后面也必须为0!!! #### # 将 127.0.0.1/8 改为 0.0.0.0/0 uuid扩展报错 postgres=# CREATE EXTENSION "uuid-ossp"; ERROR: could not access file "$libdir/uuid-ossp": No such file or directory 回源码目录,安装uuid就可以 # cd postgresql-9.6.2/contrib/uuid-ossp # make && make install
———————————————— 版权声明:本文为博主「dear_Mary」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u010430832/article/details/60142824
