以在64位CentOS6.5操作系统上源码安装postgresql-9.6beta1为例

一.进入官网下载代码(postgresql-9.6beta1.tar.gz)

https://www.postgresql.org

二.将源码上传到服务器/home/alian目录下

可以在windows安装ssh或xftp工具,也可以在CentOS安装lrzsz的rpm包(使用rz,sz命令)上传或下载文件。

三.将源码在当前目录下解压

  1. [root@localhost alian]# tar xzvf postgresql-.6beta1.tar.gz

四.进入解压后的目录postgresql-9.6beta1,使用configure工具查看编译帮助

  1. [root@localhost postgresql-.6beta1]# ./configure --help

五.根据帮助中各配置描述选择适合自己的配置选项

如下命令中

--prefix=/opt/pg9.6

pg软件的安装路径

以下4个配置不是必须的,但如果想修改必须要重新initdb

--with-segsize=1

表在操作系统上物理文件大小,单位GB,默认值为1,如果表大于1GB,将在操作系统上分割成多个1GB的文件。

--with-blocksize=32

块大小,单位KB,默认值为8,是表数据I/O和存储的单元,范围1-32,且必须是2的N次方。

--with-wal-segsize=32

WAL在操作系统上物理文件大小,单位MB,默认值16,范围1-64,且必须是2的N次方。

--with-wal-blocksize=64

WAL块大小,单位KB,是WAL I/O和存储的单元,范围1-64,且必须是2的N次方。

  1. [root@localhost postgresql-.6beta1]# ./configure --prefix=/opt/pg9. --with-segsize= --with-blocksize= --with-wal-segsize= --with-wal-blocksize=
  2.  
  3. checking build system type... x86_64-pc-linux-gnu
  4. checking host system type... x86_64-pc-linux-gnu
  5. checking which template to use... linux
  6. checking whether to build with -bit integer date/time support... yes
  7. checking whether NLS is wanted... no
  8. checking for default port number...
  9. checking for block size... 32kB
  10. checking for segment size... 1GB
  11. checking for WAL block size... 64kB
  12. checking for WAL segment size... 32MB
  13. checking for gcc... gcc
  14.  
  15. ..............

configure过程中可能会出现下面的错误,原因是缺少对应的库,安装对应的库即可。

  1. configure: error: readline library not found
  2.  
  3. [root@localhost postgresql-.6beta1]# yum install readline-devel
  4.  
  5. configure: error: zlib library not found
  6.  
  7. [root@localhost postgresql-.6beta1]# yum install zlib-devel

六.configure成功后,可以直接执行make命令进行简单编译,也可以执行make world将contrib目录下的扩展工具一起编译,当然也可以先进行简单编译,然后进入contrib下对某一工具进行单独编译

方法一:简单安装

1.执行命令

  1. [root@localhost postgresql-.6beta1]# make && make install

命令执行完之后,pg软件就被安装到/opt/pg9.6路径下

  1. [root@localhost postgresql-.6beta1]# ls /opt/pg9./
  2. bin include lib share

2.如果想安装contrib下的某一扩展工具,以检测数据库运行的pg_stat_statements为例

进入contrib/pg_stat_statements目录下(前提是已在主目录下执行了configure)

  1. [root@localhost postgresql-.6beta1]# cd contrib/pg_stat_statements/

执行命令

  1. [root@localhost pg_stat_statements]# make && make install

方法二、全部安装(contrib下所有的扩展工具)

  1. [root@localhost postgresql-.6beta1]# make world && make install-world

七、软件安装完成后,进行初始化

1.新建一个用户postgres

  1. [root@localhost postgresql-.6beta1]# groupadd postgres
  2.  
  3. [root@localhost postgresql-.6beta1]# useradd postgres

2.创建PGDATA目录

  1. [root@localhost postgresql-.6beta1]# mkdir -p /mnt/pgdata
  2. [root@localhost postgresql-.6beta1]# chown postgres:postgres /mnt/pgdata/

3.使用postgres用户初始化

  1. [root@localhost postgresql-.6beta1]# su postgres
  2.  
  3. [postgres@localhost postgresql-.6beta1]$ /opt/pg9./bin/initdb -D /mnt/pgdata -E UTF8 --locale=C

4.使用postgres用户启停数据库

  1. [postgres@localhost postgresql-.6beta1]$ /opt/pg9./bin/pg_ctl -D /mnt/pgdata/ start
  2. server starting
  3.  
  4. [postgres@localhost postgresql-.6beta1]$ /opt/pg9./bin/pg_ctl -D /mnt/pgdata/ stop
  5. waiting for server to shut down....LOG: database system is shut down
  6. done
  7. server stopped

5.修改配置文件,使用客户端访问数据库

初始化完成后,会自动为数据库创建一个超级用户postgres(执行initdb的用户),但是数据库还没有给该用户设置访问密码,所以启动数据库后,执行下面的命令,给该用户配置一个密码

  1. [postgres@localhost postgresql-.6beta1]$ /opt/pg9./bin/psql -U postgres
  2. psql (.6beta1)
  3. Type "help" for help.
  4.  
  5. postgres=# alter user postgres with password 'password';
  6. ALTER ROLE
  7. postgres=# \q

另外,在PGDATA目录下生成配置文件pg_hba.conf和postgresql.conf,

postgresql.conf中配置#listen_addresses = 'localhost',表示只监听本地连接,将此配置改成*用来监听所有IP的访问,也可以指定特定的IP(注意前面的注释符#删掉)

  1. listen_addresses = '*'

pg_hba.conf主要内容如下

  1. # "local" is for Unix domain socket connections only
  2. local all all trust
  3. # IPv4 local connections:
  4. host all all 127.0.0.1/ trust
  5. # IPv6 local connections:
  6. host all all ::/ trust

其中trust表示允许无密码访问,这是不安全的,将其改为md5,使用密码访问。

  1. # "local" is for Unix domain socket connections only
  2.  
  3. local all all md5
  4. # IPv4 local connections:
  5. host all all 127.0.0.1/ md5
  6. # IPv6 local connections:
  7. host all all ::/ md5

修改完密码和配置文件后重启服务再次访问数据库时就会提示输入密码

  1. [postgres@localhost postgresql-.6beta1]$ /opt/pg9./bin/psql -U postgres
  2. Password for user postgres:
  3. psql (.6beta1)
  4. Type "help" for help.
  5.  
  6. postgres=#

Postgresql源码安装的更多相关文章

  1. PostgreSQL源码安装文档

    This document describes the installation of PostgreSQL using the source    code distribution. (If yo ...

  2. 国产龙芯服务器源码安装PostgreSQL数据库的方法

    1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等. 2.. 但是差查了下中标麒麟的官网,在龙芯MIPS的操作系统包源里面仅有 postgreSQL 9.2 版本的r ...

  3. [转]PostgreSQL源码结构

    PostgreSQL采用C/S(客户机/服务器)模式结构.应用层通过INET或者Unix Socket利用既定的协议与数据库服务器进行通信. 另外,还有一种‘Standalone Backend’使用 ...

  4. Linux环境PostgreSQL源码编译安装

    Linux环境PostgreSQL源码编译安装 Linux版本: Red Hat 6.4 PostgreSQL版本: postgresql-9.3.2.tar.gz 数据存放目录: /var/post ...

  5. linux下PostgreSQL数据库的源码安装

    实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...

  6. PostGreSQL(1)-源码安装

    目录 简述 一.格式化磁盘 二.源码安装 PostGreSql 1. 安装 readline-devel 2. 安装 PostGresql 3. 设置环境变量 三. 初始化 1. 设置运行用户 2. ...

  7. Linux环境下源码安装PostgreSQL

    1.下载PostgreSQL源码包,并保存到Linux操作系统的一个目录下 2.解压PostgreSQL源码包 :tar zxvf postgresql-9.2.4.tar.gz 或 tar jxvf ...

  8. CentOS7 源码安装 PostgreSQL 12

    PostgreSQL 12 源码安装 Table of Contents 1. 下载 2. 准备环境 3. 编译安装 4. 设置环境变量 5. 初始化数据库 6. 配置参数文件 6.1. postgr ...

  9. windows下源码安装调试postgresql

    环境:windows 10 postgresql版本:postgresql-9.6.5 使用工具:vs2017社区版 辅助工具:perl.diff.flex.bison 相关工具下载地址: perl下 ...

随机推荐

  1. 《FPGA全程进阶---实战演练》第三章之PCB叠层

    1.双面板 在双层板设计layout时,最好不要不成梳状结构,因为这样构成的电路,回路面积较大,但是只要对较重要的信号加以地保护,布线完成之后将空的地方敷上地铜皮,并在多个过孔将两个地连接起来,可以弥 ...

  2. e641. 使一个组件成为拖放目标

    public class DropTargetComponent extends JComponent implements DropTargetListener { public DropTarge ...

  3. (转)RTP协议全解(H264码流和PS流)

    写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...

  4. 下载最新android adt的方法

    作为一名android开发人员,需要经常更新最新版本的 android adt,但是直接到官网去找很难找到下载的链接,通过下面现成的链接,你就能够直接下载最新的android adt了, 网址是:de ...

  5. CentOS7.2内核版本查看简述

    1.uname 命令 [root@bogon /]# uname --help 用法:uname [选项]... 输出一组系统信息.如果不跟随选项,则视为只附加-s 选项.   -a, --all以如 ...

  6. 【Java面试题】14 super.getClass()方法调用

    下面程序的输出结果是多少? import java.util.Date; public class Test extends Date{ public static void main(String[ ...

  7. maven 打包可执行jar的两种方法

    1.修改pom.xml增加如下内容 <build> <pluginManagement> <plugins> <plugin> <groupId& ...

  8. php字符串算术表达式计算

    $aa = "{1}*{2}-{3}"; $farr = array('/\{1\}/','/\{2\}/','/\{3\}/'); $tarr = array(3,4,10); ...

  9. 左侧固定宽度,右侧自适应宽度的CSS布局

    BI上有高手专门讨论了这种布局方法,但他用了较多的hack,还回避了IE6的dtd.我在实际使用中,发现回避掉IE6的dtd定义后,会导致ajax模态框无法居中(VS的一个控件,自动生成的代码,很难修 ...

  10. mysql中参数--init-file的作用是什么呢?

    需求描述: 今天在修改测试环境mysql数据库中root用户密码的时候,用到了--init-file参数, 所以,就在这里说下该参数的作用. 概念解释: 参数:--init-file=file_nam ...