• PostgreSQL10数据库源码安装


    环境:
    centos 7 + pg10.17

    (一)安装包下载
    postgresql数据库一共有2种安装包,一种是rpm包,可以直接使用yum安装,另外一种是源码,需要自己编译安装,可以看到,与MySQL相比,少了二进制的安装包,这里我们使用源码自己编译安装。
    首先下载源码安装包,各版本的下载地址:https://www.postgresql.org/ftp/source


    下载自己需要的版本即可

     

    (二)安装PostgreSQL
    (2.1)解压安装包

    1. [root@pg01 tmp]# pwd
    2. /tmp
    3. [root@pg01 tmp]# ls
    4. postgresql-10.17.tar.gz
    5. [root@pg01 tmp]# tar -xzvf postgresql-10.17.tar.gz
    6. [root@pg01 tmp]# ls
    7. postgresql-10.17
    8. postgresql-10.17.tar.gz

    (2.2)配置

    1. ./configure \
    2. --prefix=/pg \
    3. --exec-prefix=/pg \
    4. --bindir=/pg/bin \
    5. --sysconfdir=/pg/etc \
    6. --libdir=/pg/lib \
    7. --includedir=/pg/include --mandir=/pg/man --docdir=/pg/doc \
    8. --htmldir=/pg/html \
    9. --enable-nls='zh_CN en_US' \
    10. --with-pgport=5432 \
    11. --with-perl \
    12. --with-python \
    13. --with-tcl \
    14. --with-icu \
    15. --with-openssl \
    16. --with-pam \
    17. --with-ldap \
    18. --with-systemd \
    19. --with-readline \
    20. --with-libxml \
    21. --with-libxslt \
    22. --with-segsize=1 \
    23. --with-blocksize=8 \
    24. --with-wal-segsize=16 \
    25. --with-wal-blocksize=8 \
    26. --without-zlib


    配置的过程中,会提示缺少包,需要根据提示,手动安装这些包

    1. # 查找
    2. yum list all|grep readline
    3. # 安装
    4. yum install -y gcc
    5. yum install -y libicu-devel.x86_64
    6. yum install -y perl-ExtUtils-Embed.noarch
    7. yum install -y readline-devel.x86_64
    8. yum -y install openssl-devel
    9. yum -y install pam-devel.x86_64
    10. yum install -y libxml2-devel.x86_64
    11. yum install -y libxslt.x86_64
    12. yum install -y libxslt-devel.x86_64
    13. yum install -y openldap-devel.x86_64
    14. yum install -y systemd-devel.x86_64
    15. yum install -y tcl-devel.x86_64
    16. yum install -y python-devel.x86_64

    (2.3)编译安装
    (2.3.1)编译
    首先进行编译,使用make命令进行编译,如果希望编译所有的东西,包括文档(man、html)和附加模块(contrib),使用

    make world
    

    如果最后1行出现下面的描述,说明编译成功
    PostgreSQL, contrib, and documentation successfully made. Ready to install.


    (2.3.2)安装
    要安装PostgreSQL,输入下面命令进行安装

    make install
    

    当最后1行出现"PostgreSQL installation complete."时,说明安装成功了。

    NOTE:这条命令会把文件安装到2.2指定的路径,需要确保有足够的权限向该区域写入。通常需要使用root权限操作,或者也可以事先创建目录并分配权限给相应的用户

    (2.4)创建pg用户

    1. adduser postgres
    2. passwd postgres
    3. mkdir -p /pg/data
    4. chown -R postgres:postgres /pg/

    (2.5)初始化数据库

    1. su - postgres
    2. # 初始化
    3. /pg/bin/initdb -D /pg/data
    4. # 或者
    5. /pg/bin/pg_ctl -D /pg/data initdb

    (2.6)设置环境变量
    在postgres用户下配置pg数据库的环境变量

    1. [postgres@pg01 ~]$ cat .bash_profile
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/.local/bin:$HOME/bin:/pg/bin
    9. export PATH
    10. export PGHOME=/pg
    11. export PGDATA=/pg/data
    12. export LD_LIBRARY_PATH=/pg/lib
    13. export MANPATH=/pg/man
    14. export PATH=/pg/bin:$PATH
    15. [postgres@pg01 ~]$

    使用source命令生效

    [postgres@pg01 ~]$ source .bash_profile
    

    (三)启动与关闭
    (3.1)在postgresql用户下使用pg_ctl

    1. # 1.启动数据库
    2. /pg/bin/postgres -D /pg/data >logfile 2>&1 &
    3. # 或者可以使用pg_ctl命令
    4. /pg/bin/pg_ctl -D /pg/data -l /tmp/logfile start
    5. # 2.关闭数据库
    6. /pg/bin/pg_ctl -D /pg/data -l /tmp/logfile stop
    7. # 3.查看数据库状态
    8. /pg/bin/pg_ctl -D /pg/data status

    (3.2)使用root配置systemd管理数据库

    1. # 1.使用root用户配置
    2. su - root
    3. vim /etc/systemd/system/postgresql.service
    4. [Unit]
    5. Description=PostgreSQL database server
    6. Documentation=man:postgres(1)
    7. [Service]
    8. Type=notify
    9. User=postgres
    10. ExecStart=/pg/bin/postgres -D /pg/data
    11. ExecReload=/bin/kill -HUP $MAINPID
    12. KillMode=mixed
    13. KillSignal=SIGINT
    14. TimeoutSec=0
    15. [Install]
    16. WantedBy=multi-user.target
    17. # 2.重新加载systemd配置
    18. [root@pg01 pg]# systemctl daemon-reload
    19. # 3.启动、关闭、状态,使用root用户
    20. systemctl start postgresql
    21. systemctl stop postgresql
    22. systemctl status postgresql
    23. # 4.配置开机自启动
    24. systemctl enable postgresql

    【完】

  • 相关阅读:
    动态链接库.dll、.so和静态库.a,cmake指令
    为什么在做微服务设计的时候一定需要DDD?
    Page Cache的产生和释放
    简单认识dubbo中的几种负载均衡算法
    【计算机网络】网络层:路由器的构成
    4-4网络层-IPv6
    【无标题】算法不能盲目刷!!算法修炼手册(持续更新)
    本地存储WebStorage
    基于 Markdown 与 Git 的知识管理系统
    java为什么编译与解释并存
  • 原文地址:https://blog.csdn.net/weixin_30895723/article/details/126204115