Compiling the Version

A build.sh script is provided for compiling openGauss and generating the installation package. You can compile openGauss by using the script. You can also configure environment variables and run commands to compile openGauss.

This section describes the prerequisites and procedure for openGauss compilation. The following figure shows the compilation process.

Preparation Before Compiling

Downloading Code

Prerequisites

The git and git-lfs have been installed and configured on the local host.

Procedure

  1. Run the following command to download the code and open-source and third-party software repository. [git ssh address] indicates the actual code download address. You can obtain them from the openGauss community.

    [user@linux sda]$ git clone [git ssh address] openGauss-server
    [user@linux sda]$ git clone [git ssh address] openGauss-third_party
    [user@linux sda]$ # mkdir binarylibs        For details about this comment, see the following note.
    

    NOTE:

    After the download is complete, decompress and rename the package: mv openGauss-third_party_binarylibs binarylibs.

  2. When the progress of each download reaches 100%, the download is successful.

Compiling Open-source Software

Compiling Open-source Software

Before compiling the openGauss, compile and build the open-source and third-party software on which the openGauss depends. These open-source and third-party software is stored in the openGauss-third_party code repository. After downloading the software, you can use git lfs pull to obtain large files from the code repository. Generally, you only need to build the software once. If the open-source software is updated, rebuild the software.

Since this step takes a long time, we have compiled and built binarylibs using openGauss-third_party. You can download the package by referring to [Downloading Code](#Downloading Code).

Table 1 openGauss open-source third-party software required before build

Software

Recommended Version

python3

3.6

python3-devel

3

setuptools

36.6.1

libaio-devel

0.3.109-13

flex

2.5.31 or later

ncurses-devel

5.9-13.20130511

lsb_release

4.1

pam-devel

1.1.8-1.3.1

libffi-devel

3.1

patch

2.7.1-10

golang

1.13.3 or later

autoconf

2.69

automake

1.13.4

cmake

3.18

diffutils

3.7

openssl-devel

1.1.1

libtool

2.4.2 or later

libtool-devel

2.4.2 or later

Prepare GCC 7.3 before building the third-party libraries. You are advised to use the released and built third-party library GCC and configure environment variables.

After installing the software listed in Table 1, point the default Python version to python3.x and perform the following operations:

  1. Run the following commands to go to the directory of the open-source and third-party software on which the kernel depends, compile and build the open-source and third-party software, and generate binary programs or library files. /sda/openGauss-third_party is the directory for downloading open-source third-party software.

    [user@linux sda]$ cd /sda/openGauss-third_party/build
    [user@linux build]$ sh build_all.sh
    
  2. After the preceding commands are executed, the open-source third-party software required for openGauss build is automatically generated. To generate any open-source third-party software independently, go to the corresponding directory and run the build.sh script. For example:

    [user@linux sda]$ cd /sda/openGauss-third_party/dependency/openssl
    [user@linux openssl]$ sh build.sh
    

    The openssl is generated.

  3. NOTE: For error logs, you can view the corresponding log in the build directory and the log in the corresponding module. For example, you can view the OpenSSL compilation and installation logs in the dependency module.

    • /sda/openGauss-third_party/build/dependency_build.log
    • /sda/openGauss-third_party/dependency/build/openssl_build.log
    • /sda/openGauss-third_party/dependency/openssl/build_openssl.log

Compilation and Build Result

After the preceding script is executed, the final compilation and build result is stored in the **output **directory under the openGauss-third_party directory These files will be used during the compilation of openGauss-server.

Introduction to compile script

openGauss-server/build.sh is an important script tool during compilation. It integrates software installation and compilation and product installation package compilation functions to quickly compile and package code.

The following table describes the parameters.

Table 2 build.sh parameters

Option

Default Value

Parameter

Description

-h

Do not use this option.

-

Help menu

-m

release

[debug | release | memcheck]

Selects the target version.

-3rd

${Code directory}/binarylibs

[binarylibs path]

Specifies the path of binarylibs. The path must be an absolute path.

-pkg

Do not use this option.

-

Compresses the code compilation result into an installation package.

-nopt

Do not use this option.

-

If this option is used, the CPU of the Kunpeng platform is not optimized.

![] (public_sys-resources/icon-note.gif) NOTE:

  1. -m [debug | release | memcheck] indicates that three target versions can be selected:
  • release: indicates that the binary program of the release version is generated. During compilation of this version, the GCC high-level optimization option is configured to remove the kernel debugging code. This option is usually used in the production environment or performance test environment.
  • debug: indicates that a binary program of the debug version is generated. During compilation of this version, the kernel code debugging function is added, which is usually used in the development self-test environment.
  • memcheck: indicates that a binary program of the memcheck version is generated. During compilation of this version, the ASAN function is added based on the debug version to locate memory problems.
  1. -3rd [binarylibs path] is the path of binarylibs. By default, binarylibs exists in the current code folder. If binarylibs is moved to openGauss-server or a soft link to binarylibs is created in openGauss-server, you do not need to specify the parameter. However, if you do so, please note that the file is easy to be deleted by the git clean command.
  2. Each option in this script has a default value. The number of options is small and the dependency is simple. Therefore, this script is easy to use. If the required value is different from the default value, set this parameter based on the actual requirements.

Software Compilation and Installation

Software build and installation are to build code to generate software and install the software on a computer. The one-click build script build.sh is provided. You can also manually configure environment variables. The two methods are described below in this section.

Prerequisites

  • The software and hardware have been prepared based on the requirements in Setting up the Compilation Environment, and the code has been downloaded by referring to [Downloading Code](#Downloading Code).
  • Open-source software has been compiled and built. For details, see [Compiling Open-source Software](#Compiling Open-source Software). GCC 7.3 has been placed in the output directory based on the directory structure of the released and compiled third-party library.
  • You are familiar with the parameter options and functions of the [Introduction to build.sh](#Introduction to compile script) script.
  • The code environment is clean, and no file is generated before the current compilation. For details, see FAQ.

Compilation Using the One-click Script

  1. Run the following command to go to the directory where the software code compilation script is stored:

    [user@linux sda]$ cd /sda/openGauss-server
    
  2. Run the following command to compile openGauss:

    [user@linux openGauss-server]$ sh build.sh -m [debug | release | memcheck] -3rd [binarylibs path]
    

    For example:

    sh build.sh      # Compile and install openGauss of the release version. binarylibs or its soft link must exist in the code directory. Otherwise, the operation fails.
    sh build.sh -m debug -3rd /sdc/binarylibs            # Compile and install openGauss of the debug version.
    
  3. If the following information is displayed, the compilation is successful:

    make compile sucessfully!
    
    • The software installation path after compilation is /sda/openGauss-server/mppdb_temp_install.
    • The compiled binary files are stored in /sda/openGauss-server/mppdb_temp_install/bin.
    • Compilation log: ./build/script/makemppdb_pkg.log
  4. Import environment variables to initialize and start the database.

    export CODE_BASE=________     # openGauss-server path
    export GAUSSHOME=$CODE_BASE/mppdb_temp_install/
    export LD_LIBRARY_PATH=$GAUSSHOME/lib::$LD_LIBRARY_PATH
    export PATH=$GAUSSHOME/bin:$PATH
    

Manual Compilation

  1. Run the following command to go to the software code directory:

    [user@linux sda]$ cd /sda/openGauss-server
    
  2. Obtain the third-party library binary file of the corresponding platform.

  3. Configure environment variables, add ____ based on the code download location.

    export CODE_BASE=________     # Path of the openGauss-server file
    export BINARYLIBS=________    # Path of the binarylibs file
    export GAUSSHOME=$CODE_BASE/dest/
    export GCC_PATH=$BINARYLIBS/buildtools/gcc7.3/
    export CC=$GCC_PATH/gcc/bin/gcc
    export CXX=$GCC_PATH/gcc/bin/g++
    export LD_LIBRARY_PATH=$GAUSSHOME/lib:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$LD_LIBRARY_PATH
    export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH
    
  4. Select a version and configure it.

    debug version:

    ./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib
    

    release version:

    ./configure --gcc-version=7.3.0 CC=g++ CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --with-readline --without-zlib
    

    memcheck version:

    ./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib --enable-memory-check
    

    NOTE:

    • [debug | release | memcheck] indicates that three target versions are available. The three target versions are as follows:
      • release: indicates that the binary program of the release version is generated. During this version build, the GCC high-level optimization option is configured to remove the kernel debugging code. This option is usually used in the production environment or performance test environment.
      • debug: indicates that a binary program of the debug version is generated. During this version build, the kernel code debugging function is added, which is usually used in the development self-test environment.
      • memcheck: indicates that a binary program of the memcheck version is generated. During this version build, the ASAN function is added based on the debug version to locate memory problems.
    • On the ARM-based platform, -D__USE_NUMA needs to be added to CFLAGS.
    • On the ARMv8.1 platform or a later version (for example, Kunpeng 920), -D__ARM_LSE needs to be added to CFLAGS.
    • If binarylibs is moved to openGauss-server or a soft link to binarylibs is created in openGauss-server, you do not need to specify the --3rd parameter. However, if you do so, please note that the file is easy to be deleted by the git clean command.
    • To use the MOT, you need to add --enable-mot to the command.
  5. Run the following commands to compile openGauss:

    [user@linux openGauss-server]$ make -sj
    [user@linux openGauss-server]$ make install -sj
    
  6. If the following information is displayed, the compilation and installation are successful:

    openGauss installation complete.
    
    • The software installation path after compilation is $GAUSSHOME.
    • The compiled binary files are stored in $GAUSSHOME**/bin**.

Compiling the Installation Package

To compile the installation package is to compile the code and generate the software installation package. The compilation and packaging process of the installation package is also integrated in build.sh.

Prerequisites

  • TThe software and hardware have been prepared based on the requirements for setting up the compilation environment, and the code has been downloaded by referring to Downloading Code.
  • The open-source software has been compiled and built. For details, see [Compiling Open-source Software](#Compiling Open-source Software).
  • You are familiar with the parameter options and functions of the [Introduction to build.sh](#Introduction to compile script) script.
  • The code environment is clean, and no file is generated before the current compilation. For details, see FAQ.

Procedure

  1. Run the following command to go to the code directory:

    [user@linux sda]$ cd /sda/openGauss-server
    
  2. Run the following command to compile the openGauss installation package:

    [user@linux openGauss-server]$ sh build.sh -m [debug | release | memcheck] -3rd [binarylibs path] -pkg
    

    For example:

    sh build.sh -pkg      # Generate the openGauss installation package of the release version. binarylibs or its soft link must exist in the code directory. Otherwise, the operation fails.
    sh build.sh -m debug -3rd /sdc/binarylibs -pkg            # Generate the openGauss installation package of the debug version.
    

    Compared with Software Compilation and Installation, this operation involves the process of generating software by one-click compilation and the process of encapsulating the software into an installation package. Compared with the build.sh command in Software Compilation and Installation, only the -pkg option is added.

  3. If the following information is displayed, the installation package compilation is successful:

    success!
    
    • The build and packaging log file is stored in ./build/script/makemppdb_pkg.log.

Verification After Build

After the build is complete, perform the following steps to verify openGauss:

  1. Run the following command to create user omm as user root:

    [user@linux sda]# useradd omm -g dbgrp
    [user@linux sda]# passwd omm
    
  2. Add the following environment variables to ~/.bashrc as user omm:

    export GAUSSHOME=/root/openGauss-server/dest/ ## Path of the build result. You can change the path as required.
    export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
    export PATH=$GAUSSHOME/bin:$PATH
    

    Run the following command for environment variables to take effect:

      [user@linux sda]$ source ~/.bashrc
    
  3. Create the data directory and log directory.

    [user@linux sda]$ mkdir ~/data
    [user@linux sda]$ mkdir ~/log
    [user@linux sda]$ chown -R omm:dbgrp /root/openGauss-server
    
  4. Initialize the database.

    [user@linux sda]$ gs_initdb -D /home/omm/data --nodename=db1 
    
  5. Start the database.

    [user@linux sda]$ gs_ctl start -D /home/omm/data -Z single_node -l /home/omm/log/opengauss.log
    

    After the database is started, you can run the ps -ef | grep gaussdb command to check the database process status, run the gs_ctl query -D /home/omm/data command to check the database status, or run the gsql -d postgres command to enter the gsql command line to view database information.

openGauss-OM Build

After the openGauss-server code repository is built using the source code, gs_om does not exist. To use gs_om, you need to compile openGauss-OM separately, copy the built openGauss-xxx-om.tar.gz package to the directory where the openGauss-server installation package is located, and install the openGauss-OM in the same way as the enterprise edition.

Procedure

  1. Run the git clone command to clone the OM code repository:

    [user@linux sda]$ git clone https://gitee.com/opengauss/openGauss-OM.git
    
  2. Run the following build command:

    [user@linux sda]$ cd openGauss-OM
    [user@linux sda]$ chmod +x build.sh
    [user@linux sda]$ export BINARYLIBS_PATH=/root/binarylibs (Enter the directory generated after the third-party software package is decompressed.)
    [user@linux sda]$ ./build.sh -3rd $BINARYLIBS_PATH
    
  3. The Gauss-OM is built successfully if the following information is displayed:

    ROOT_DIR: /root/binarylibs
    Everything is ready.
    success!
    
Feedback
编组 3备份
    openGauss 2024-05-07 00:46:52
    cancel