CentOS 7.2 源码安装 PostgreSQL 9.0

安装PGSQL

PGSQL源码地址:https://ftp.postgresql.org/pub/source/

下载9.0版本源码

[root@localhost soft]# wget https://ftp.postgresql.org/pub/source/v9.0.0/postgresql-9.0.0.tar.gz --no-check-certificate

解压源码并进入解压目录

[root@localhost soft]# tar -zxvf postgresql-9.0.0.tar.gz
[root@localhost soft]# cd postgresql-9.0.0

配置编译安装包含插件

[root@localhost postgresql-9.0.0]# ./configure --prefix /data/programs/PostgreSQL/9.0 CFLAGS="-Wno-aggressive-loop-optimizations"

[root@localhost postgresql-9.0.0]# make world

[root@localhost postgresql-9.0.0]# make install-world

 

进入安装目录

[root@localhost postgresql-9.0.0]# cd /data/programs/PostgreSQL/9.0/

 

添加postgres用户组及用户

[root@localhost 9.0]# groupadd postgres
[root@localhost 9.0]# useradd -g postgres postgres

创建数据存储目录

[root@localhost 9.0]# mkdir /data/programs/PostgreSQL/9.0/data

修改数据存储目录权限

[root@localhost 9.0]# chown postgres:postgres /data/programs/PostgreSQL/9.0/data

中文环境设置

#临时修改(当前终端生效):
export LANG="zh_CN.UTF-8"

#永久修改:
echo "export LANG=zh_CN.UTF-8"  >> /etc/profile
source /etc/profile

切换postgres用户

[root@localhost 9.0]# su postgres
#如果出现 bash: /home/postgres/.bashrc: Permission denied
#使用root用户,设置home目录权限
[root@localhost 9.0]# chmod 77 /home/postgres

初始化data目录

[postgres@localhost 9.0]$ /data/programs/PostgreSQL/9.0/bin/initdb --pgdata /data/programs/PostgreSQL/9.0/data --encoding=UTF8 --lc-collate=zh_CN.utf8 --lc-ctype=zh_CN.utf8 --lc-messages=zh_CN.utf8 --lc-monetary=zh_CN.utf8 --lc-numeric=zh_CN.utf8 --lc-time=zh_CN.utf8

启动pgsql服务

[postgres@localhost 9.0]$ /data/programs/PostgreSQL/9.0/bin/pg_ctl --pgdata /data/programs/PostgreSQL/9.0/data start

停止pgsql服务

[postgres@localhost 9.0]$ /data/programs/PostgreSQL/9.0/bin/pg_ctl --pgdata /data/programs/PostgreSQL/9.0/data stop

使用service启动

拷贝文件

[root@localhost 9.0]# cp /data/soft/postgresql-9.0.0/contrib/start-scripts/linux /etc/init.d/postgresql-9.0

赋予执行权限

[root@localhost 9.0]# chmod +x /etc/init.d/postgresql-9.0

编辑文件

创建log目录

[root@localhost 9.0]# mkdir /data/programs/PostgreSQL/9.0/data/pg_log

启动服务

[root@localhost 9.0]# service postgresql-9.0 start

配置网络访问

[root@localhost 9.0]# vim /data/programs/PostgreSQL/9.0/data/postgresql.conf

配置错误日志

[root@localhost 9.0]# vim /data/programs/PostgreSQL/9.0/data/postgresql.conf

添加密码访问

[root@localhost 9.0]# vim /data/programs/PostgreSQL/9.0/data/pg_hba.conf

修改配置需要重启服务

[root@localhost 9.0]# service postgresql-9.0 restart

修改密码,用户名postgres

[postgres@localhost bin]$ /data/programs/PostgreSQL/9.0/bin/psql

安装过程中的错误处理

错误信息:

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

安装readline

[root@localhost postgresql-9.0.0]# yum install readline readline-devel -y

错误信息:

configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

安装zlib

[root@localhost postgresql-9.0.0]# yum install zlib zlib-devel -y

错误信息:

initializing pg_authid ... FATAL:  wrong number of index expressions
STATEMENT:  REVOKE ALL on pg_authid FROM public;
    
child process exited with exit code 1

gcc版本过高。高版本的gcc采用了更激进的循环上界分析推导算法。但这会导致一些旧的程序运行出错。在数据库编译安装进行configure操作时,添加参数"-Wno-aggressive-loop-optimizations"或"-fno-aggressive-loop-optimizations"。

参考原文:https://blog.csdn.net/pg_hgdb/article/details/95345650 

[root@localhost postgresql-9.0.0]# cd /data/soft/postgresql-9.0.0
[root@localhost postgresql-9.0.0]# make clean
[root@localhost postgresql-9.0.0]# ./configure --prefix /data/programs/PostgreSQL/9.0 CFLAGS="-Wno-aggressive-loop-optimizations"
#重新编译安装

 

posted @ 2022-10-25 12:49  gzhq  阅读(121)  评论(0编辑  收藏  举报