Chinaunix首页 | 论坛 | 博客
  • 博客访问: 236591
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 533
  • 用 户 组: 普通用户
  • 注册时间: 2015-07-28 21:56
个人简介

活着,寻找生存。

文章分类

全部博文(50)

文章存档

2017年(1)

2016年(20)

2015年(29)

我的朋友

分类: Mysql/postgreSQL

2015-11-23 09:49:29

 编译安装基本流程:
./configure
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

下载源代码:
  
   源代码可以通过官网下载: 。从这里可以下载到你所要的源代码。对于选择源代码版本,尽量选择一个合适的版本,这里我选择v9.2.4版本进行安装。

安装前准备:
  
     检查PostgreSQL编译所需软件包:
 GNU make version 3.80 or newer is required; other make programs or older GNU make versions will not work. GNU make is often installed under the name gmake; this document will always refer to it by that name. (On some systems GNU make is the default tool with the name make.) To test for GNU make enter:
gmake --version
     
按官方的要求make 版本需要是3.80或者更高的版本。
   
  
  • The GNU Readline library is used by default. It allows psql (the PostgreSQL command line SQL interpreter) to remember each command you type, and allows you to use arrow keys to recall and edit previous commands. This is very helpful and is strongly recommended. If you don't want to use it then you must specify the --without-readline option to configure. As an alternative, you can often use the BSD-licensed libedit library, originally developed on NetBSD. The libedit library is GNU Readline-compatible and is used if libreadline is not found, or if --with-libedit-preferred is used as an option to configure. If you are using a package-based Linux distribution, be aware that you need both the readline and readline-devel packages, if those are separate in your distribution.
  
   如果你需要在psql中使用上下键来查看历史命令,那么你必须安装Readline开发包。
  
  •  The zlib compression library is used by default. If you don't want to use it then you must specify the --without-zlib option to configure. Using this option disables support for compressed archives in pg_dump and pg_restore.

    默认情况下,安装会使用到数据库中的压缩功能,而使用这个压缩功能就需要安装zlib开发包,如果你不想使用,你可以在--without-zlib参数来配置。

创建PostgreSQL用户:
   
root># adduser postgres

root># passwd postgres
Changing password for user postgres.
New password: 
BAD PASSWORD: it is based on a dictionary word
Retype new password: 
passwd: all authentication tokens updated successfully.

解压源代码:
  
 root># ls postgresql-9.2.4.tar.bz2
 root># tar xvf postgresql-9.2.4.tar.bz2
 
进行编译安装第一步,执行configure命令:
  
 root># ./configure --prefix=/usr/local/pgsql9.2.4 --with-perl --with-python
  
再看看./configure后面几个参数选项:
   
    >  --prefix :这个参数是指定安装目录,如果不指定默认会安装在 /usr/local/pgsql目录下。
 
  >  --with-perl :加上这个参数选项,才能够使用perl语法的PL/Perl过程语言写自定义函数,对于比较喜欢使用perl人员来说也是一个不错得参数。
 
    >  --with-python :加上这个选项,才能使用python语法的PL/Python过程语言写自定义函数。现在python语言是一门比较火得语言了,会python得人员也是比较多的,所以加上这个选项是很不错得。
  
如果想使用较大的数据块来提高I/O性能,那么可以添加如下几个参数:
    
  > --with-blocksize :指定数据块大小,默认是8kb,可以调整到1 and 32 (kilobytes)。

  > --with-wal-segsize :指定WAL日志文件大小,默认16mb,可以调整到1 and 64 (megabytes)。

 > --with-wal-blocksize :指定WAL日志块大小,默认是8kb,可以调整到1 and 64 (kilobytes)。

更多的参数可以参考官方手册:
  
第二步,执行MAKE命令:

root># make

第三步:执行make install命令:

root># make install

编译完成后,我们进入/usr/local/到为/usr/local/pgsql9.2.4 建立一个/usr/local/pgsql 的链接:
  
postgresql.db.com<2015-11-22 18:08:30=""> 
root># cd /usr/local/

postgresql.db.com<2015-11-22 18:09:45=""> /usr/local
root># ln -sf /usr/local/pgsql9.2.4 /usr/local/pgsql

postgresql.db.com<2015-11-22 18:10:21=""> /usr/local
root># ll -lth

lrwxrwxrwx. 1 root root   21 11月 22 18:10 pgsql -> /usr/local/pgsql9.2.4

安装后的配置:
 
 安装完成后,我们需要设置PostgreSQL执行文件路径:
 
  export PATH=/usr/local/pgsql/bin/:$PATH

  设置共享库的路径:
 
  export LD_LIBRARY=/usr/local/pgsql/lib

 创建数据库簇:
 
 创建数据目录:
  root># mkdir pgdata/ 
  
  root># chown -R postgres:postgres pgdata/
  
   设置数据库中数据目录的环境变量:
   
   export PGDATA=/opt/pgdata

    执行下面命令创建数据库簇:
 
    initdb

   安装contrib目录下的工具:
   
    contrib目录下有一些比较实用的工具,是第三方组织贡献出来得代码工具,一般情况下都会安装上:
      
     postgresql.db.com<2015-11-22 18:41:42=""> ~/pkg/postgresql-9.2.4/contrib
      root># make
      root>#make install

   启动和关闭数据库:
       
   启动数据库:
   postgres>$ pg_ctl start -D /opt/pgdata
   server starting

   关闭数据库:
    postgres>$ pg_ctl stop -D $PGDATA -m fast
     waiting for server to shut down.... done
     server stopped
    
     这里$PGDATA 指向的就是/opt/pgdata目录,所以直接指定目录和$PGDATA都行。
 
    关闭数据库-m 后的几种参数:
  
       > smart :等待所有得连接终止后,才会关闭数据库。
   
       > fast :快速关闭数据库,断开数据库连接,回滚事务,然后正常关闭数据库。类似ORACLE中的shutdown immedaite操作。

       >immediate :立即关闭数据库,断开所有数据库连接,直接退出,待下次启动数据库需进行恢复。相当ORACLE中的shutdown abort操作

在编译安装中所需错误解决:

 1: Python错误
configure: error: header file is required for Python

这个问题通过安装python-devel包解决:

yum install python-devel

2:启动报错:
postgres>$ postgres -D /opt/pgdata
LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for "localhost"
FATAL:  could not create any TCP/IP sockets

这是因为有之前安装了一个postgresql,所以端口被占用,解决:

root># netstat -lnt  --查看5432是否占用

关闭postgresql服务:

root># service postgresql stop
Stopping postgresql service:                               [  OK  ]


参考手册:

阅读(1313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~