设为首页 收藏本站
查看: 1560|回复: 0

[经验分享] 源码安装PostgreSQL

  [复制链接]

尚未签到

发表于 2017-10-11 09:25:50 | 显示全部楼层 |阅读模式
数据库版本:
PostgreSQL 9.6.3

系统版本:
CentOS release 6.6 (Final)

下载软件(Download software):
[iyunv@Darren2 tools]# wget https://ftp.postgresql.org/pub/source/v9.6.3/postgresql-9.6.3.tar.gz

查看是否已经安装(Check is not instatll):
[iyunv@Darren2 tools]# ps -ef |grep pgsql
root      28590  18695  0 20:24 pts/0    00:00:00 grep pgsql
[postgres@sht-sgmhadoopdn-02 ~]$ rpm -qa |grep postgres
postgresql-libs-8.4.18-1.el6_4.x86_64

解压(Extract software):
[iyunv@Darren2 tools]# tar xf postgresql-9.6.3.tar.gz

编译和安装(Complie):
[iyunv@Darren2 tools]# cd postgresql-9.6.3
[iyunv@Darren2 postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql

编译所有能编译的东西,包括文档(HTML和手册页)以及附加模块(contrib):
[iyunv@Darren2 postgresql-9.6.3]# make world && make install-world
......
make[2]: Leaving directory `/home/tools/postgresql-9.6.3/contrib/vacuumlo'
make[1]: Leaving directory `/home/tools/postgresql-9.6.3/contrib'
PostgreSQL, contrib, and documentation installation complete.

创建用组和用户(Create group and user)
[iyunv@Darren2 ~]# groupadd -g 101 dba
[iyunv@Darren2 ~]# cat /etc/group|grep dba
dba:x:101:
[iyunv@Darren2 ~]# useradd -u 516 -g dba -G root -d /usr/local/pgsql  postgres
[iyunv@Darren2 ~]# id postgres
uid=516(postgres) gid=101(dba) groups=101(dba),0(root)
-u UID
-g 初始用户组
-G次要用户组
-m 创建用户家目录(系统用户默认不创建家目录)
-M 不创建用户家目录(普通用户默认创建家目录)
-s shell 默认是/bin/bash
-d指定家目录

[iyunv@Darren2 home]# groups postgres
postgres : dba root

配置postgres密码
[iyunv@Darren2 home]# passwd postgres

[iyunv@Darren2 skel]# ls -al /etc/skel/
total 20
drwxr-xr-x.  2 root root 4096 Dec 20  2016 .
drwxr-xr-x. 84 root root 4096 Jul 11 22:27 ..
-rw-r--r--.  1 root root   18 Jul 18  2013 .bash_logout
-rw-r--r--.  1 root root  176 Jul 18  2013 .bash_profile
-rw-r--r--.  1 root root  124 Jul 18  2013 .bashrc
[iyunv@Darren2 skel]# cp /etc/skel/.* /usr/local/pgsql/

创建数据目录(Create data folder)
[iyunv@Darren2 ~]# mkdir -p /usr/local/pgsql/data

配置.bash_profile(Configure .bash_profile)
[iyunv@Darren2 pgsql]# cat /usr/local/pgsql/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
export PATH=$PATH:/usr/local/pgsql/bin
set umask to 022
umask 022
PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1

修改文件权限和所有者(Chmod and chown)
[iyunv@Darren2 pgsql]# chmod -R 755 /usr/local/pgsql
[iyunv@Darren2 pgsql]# chown -R postgres:dba /usr/local/pgsql
[iyunv@Darren2 pgsql]# chmod -R 700 /usr/local/pgsql/data

配置postgresql服务启动和设置自启动(Configure postgresql service and boot auto start) --这步可不做
[iyunv@Darren2 start-scripts]# cp /home/tools/postgresql-9.6.3/contrib/start-scripts/linux /etc/init.d/postgresql
[iyunv@Darren2 start-scripts]# chmod +x /etc/init.d/postgresql
[iyunv@Darren2 start-scripts]# chkconfig --list |grep postgresql
[iyunv@Darren2 start-scripts]# chkconfig --add postgresql
[iyunv@Darren2 start-scripts]# chkconfig --list |grep postgresql
postgresql         0:off    1:off    2:on    3:on    4:on    5:on    6:off

初始化数据和启动(Initialize database and start database)
[iyunv@Darren2 start-scripts]# su - postgres
[postgres@Darren2 start-scripts]$ cd
[postgres@Darren2 ~]$ pwd
/usr/local/pgsql
[postgres@Darren2 ~]$ . .bash_profile

#初始化生成数据文件
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

#启动数据库
Darren2:postgres:/usr/local/pgsql:>pg_ctl start
server starting
Darren2:postgres:/usr/local/pgsql:>LOG:  database system was shut down at 2017-07-12 00:49:17 CST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

创建用户和数据库(Create user and database)
psql
psql (9.6.3)
Type "help" for help.
postgres=# create user admin password'admin' login;
CREATE ROLE
postgres=# create database testdb with owner=admin;
CREATE DATABASE

Darren2:postgres:/usr/local/pgsql:>pg_ctl status
pg_ctl: server is running (PID: 51498)
/usr/local/pgsql/bin/postgres

安装过程中常见报错
编译时候报错:
[iyunv@Darren2 postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql --without-zlib
......
configure: error: readline library not found  --提示找不到readline
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:
[iyunv@Darren2 postgresql-9.6.3]# rpm -qa |grep readline
compat-readline5-5.2-17.1.el6.x86_64
readline-6.0-4.el6.x86_64
通过yum search可以发现没有安装readline-devel:
[iyunv@Darren2 postgresql-9.6.3]# yum search readline
......
readline-devel.i686 : Files needed to develop programs which use the readline library
readline-devel.x86_64 : Files needed to develop programs which use the readline library
......
通过yum安装之后,在编译即可通过:
[iyunv@Darren2 postgresql-9.6.3]# yum install -y readline-devel


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-405352-1-1.html 上篇帖子: postgreSQL二进制快速安装 下篇帖子: Postgres 连接数过多 psql: FATAL: sorry, too many clients already
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表