通过源码安装PostgresSQL

通过源码安装PostgresSQL

通过源码安装PostgresSQL
1.1 下载源码包
环境: Centos6.8 64位
yum -y install bison flex readline-devel zlib-devel
yum -y groupinstall "Development tools"
cd /opt/
wget https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz
tar -xvf postgresql-10.0.tar.gz
cd postgresql-10.0
./configure --prefix=/opt/pg10 --with-pgport=1921

gmake world
gmake install world

# 查看版本
/opt/pg10/bin/postgres --version

1.2 设置一个软连接
    有时候为了方便工作,会自己写一些shell或者python脚本处理一些定时任务,经常会通过类似/opt/pg9.x这样的全路径调用
一些工具,使用环境也会有一些其他的问题存在,如何尽可能地避免这种麻烦?很简单。
    创建一个/opt/pgsql的软连接指向当前版本即可。
    ln -s /opt/pg10 /opt/pgsql
[root@fudao_db_cluster_003 ~]# ll /opt/pgsql/
total 16
drwxrwxr-x 2 root root 4096 Jun 24 17:31 bin
drwxrwxr-x 4 root root 4096 Jun 24 17:31 include
drwxrwxr-x 4 root root 4096 Jun 24 17:31 lib
drwxrwxr-x 3 root root 4096 Jun 24 17:31 share
[root@fudao_db_cluster_003 ~]#
    当版本变更之后,不需要调整大量的脚本,只需要修改这个软连接即可。
    
1.3 客户端程序和服务端程序
    经过上面的安装步骤,已经成功安装了PostgreSQL数据库。
[root@fudao_db_cluster_003 ~]# ll /opt/pgsql/
total 16
drwxrwxr-x 2 root root 4096 Jun 24 17:31 bin
drwxrwxr-x 4 root root 4096 Jun 24 17:31 include
drwxrwxr-x 4 root root 4096 Jun 24 17:31 lib
drwxrwxr-x 3 root root 4096 Jun 24 17:31 share
[root@fudao_db_cluster_003 ~]#

    share目录存放着PostgreSQL的文档、man、示例文件以及一些扩展。
    include目录是PostgreSQL的C、C++的头文件,bin目录就是PistgreSQL的应用程序了。
    PostgreSQL本身就是一个C/S架构的程序,这些应用程序可以分为两类:客户端程序和服务器程序,本章先介绍这些应用程序的功能。
    并讲解其中比较基础的一部分,其他的会在后续章节详细讲解。
1.3.1 客户端程序
    客户端程序也可以分为几大类,下面分别介绍。
    1. 封装SQL命令的客户端程序
    clusterdb
    clusterdb是 SQL CLUSTER命令的一个封装。PostgreSQL是堆表存储的,clusterdb通过索引对数据库基于堆表的物理文件重新排序,
它在一定场景下可以节省磁盘访问,加快查询速度。
    举例如下:
    [root@fudao_db_cluster_003 ~]# /opt/pgsql/bin/clusterdb -h pghost1 -p 1921 -d mydb
    reindexdb
    reindexdb是SQL REINDEX命令的一个封装。在索引物理文件发生损坏或者索引膨胀等情况发生时,可以使用redindex命令对指定的表或者
    数据库重建索引并且删除旧的索引。
    举例如下:
    [root@fudao_db_cluster_003 ~]# /opt/pgsql/bin/reindexdb -e -h pghost1 -p 1921 -d mydb
    vacuumdb
    vacuumdb是PostgreSQL数据库独有的VACUUM、VACUUM FREEZE和VACUUMA FULL, VACUUM ANALYZE 这几个SQL命令的封装。VACUUMA系列命令的主要职责
是对数据库物理文件等的垃圾回收,是PostgreSQL中非常重要的一系列命令。
    举例如下:
    [root@fudao_db_cluster_003 ~]# /opt/pgsql/bin/vacuumdb -h pghost1 -p 1921 mydb

vacuumlo
    vacuumlo用来清理数据库中未引用的大对象。
    举例如下:
    [root@fudao_db_cluster_003 ~]# /opt/pgsql/bin/vacuumlo -h pghost1 -p 1921 mydb  # 笔者没有找到这个命令,可能原因是版本差异
    createdb 和 dropdb
    它们分别是SQL命令 CREATE DATABASE 和 DROP DATABASE的封装。
    例如在名为pghost1的主机,端口为1921的实例中创建一个名为newdb的数据库,并且加上注释,命令如下:
    [root@fudao_db_cluster_003 ~]# /opt/pgsql/bin/createdb -h pghost1 -p 1921 newdb "New database"

猜你喜欢

转载自www.cnblogs.com/bjx2020/p/11078746.html