MogDB
Ecological Tools
Doc Menu

Container-based MogDB Installation

This document introduces the installation of single instance and primary/standby instances in a MogDB docker container. MogDB container does not support the MogHA and OM tools, and currently supports at most one primary node and eight standby nodes.

In consideration of narrowing the container image size for quick download and deployment, it is recommended that the x86 and ARM-based OSs depended by MogDB running in a docker container will be Ubuntu and Debian since MogDB 2.0.0.

A MogDB container based on the x86-64 architecture runs in Ubuntu 18.04.

A MogDB container based on the ARM64 architecture runs in Debian 10.


Before You Start

The installation of a MogDB container is independent of the host OS. All OSs that can run a container enginer are supported, such as Linux, Windows, and macOS.

Before installing the MogDB container, you need to prepare the container runnning environment, such as Docker.

Docker is an open source application container engine based on Go and compliant with the Apache 2.0 protocol. Docker allows developers to package their applications and dependency packages into a lightweight, portable container that can then be distributed to any popular Linux machine and virtualized.

Docker Desktop download address: https://www.docker.com/products/docker-desktop


Installation Procedures

  1. Run Docker.
  2. Run the following command to connect to Huawei Cloud SWR.

    docker login -u cn-east-3@MLI3I6DMIETZS9H5N2VI -p c2ebf043f73720aabada13b8a3ae0f7c152bbe32515389a4f60ceede8857ce51 swr.cn-east-3.myhuaweicloud.com
  3. Run one of the following commands according to your system architecture to obtain the latest version of the MogDB image file.

    x86-64:

    docker pull swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd

    ARM64:

    docker pull swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_arm

    Take the x86-64 machine as an example:

    docker pull swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd
    2.0.1_amd: Pulling from enmotech/mogdb
    feac53061382: Pull complete
    3d93ed1381ed: Pull complete
    ff71768be531: Pull complete
    f0e5522ade34: Pull complete
    5bcc54da2fc0: Pull complete
    615274e4a1ad: Pull complete
    14de03ed7a5f: Pull complete
    ec2e6c8ece85: Pull complete
    b5884cae3461: Pull complete
    865b32103ae9: Pull complete
    b183a90e4bf8: Pull complete
    Digest: sha256:75f89b9254d8d6f3e7e95f08b473704f2ba159d44e7a3036286ca1ff5eb5421c
    Status: Downloaded newer image for swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd
    swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd
  4. Run the following command to create a running directory for MogDB, using mymogdb as an example below.

    mkdir /mymogdb
  5. Continue with the following command to create a new container, and name it mymogdb to run a MogDB instance:

    docker run --name mymogdb --privileged=true -d -e GS_PASSWORD=Secretpassword@123  -v /mymogdb:/var/lib/opengauss  -p 15432:5432  swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd

    For Windows OS:

    • If Docker uses Hyper-V as the engine, run the following commands in sequence to create the logical object mogdata of the volume in Hyper-V, and then create the container:

      docker volume create mogdata
      
      docker run --name mymogdb --privileged=true -d -e GS_PASSWORD=Secretpassword@123 -v mogdata:/var/lib/opengauss -p 15453:5432  swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd
    • If Docker uses WSL 2 as the engine, run the following command to create the container:

      docker run --name mymogdb --privileged=true -d -e GS_PASSWORD=Secretpassword@123 -v C:\mymogdb:/var/lib/opengauss -p 15432:5432  swr.cn-east-3.myhuaweicloud.com/enmotech/mogdb:2.0.1_amd

      Note:

      • MogDB uses port 5432 in the container for listening by default. If you want to access the database from outside the container, you need to specify the -p parameter in docker run command. For example, the above command will allow access to the container database using port 15432.
      • Once the container is deleted, all the data and configuration in the container will be lost. After re-running a container from the image, all the data is presented in the initialized state. So for the database container, in order to prevent the loss of data due to the demise of the container or corruption, the operation of persistent storage data is required. This is achieved by specifying the -v parameter in docker run command. For example, the above command will specify that all data files of MogDB will be stored under /mymogdb of the host. In addition, If you use Podman, there will be a target path check. Therefore you need to create the target path in advance (step 4).
  6. Execute bash in the mymogdb container via the exec command:

    docker exec -it mymogdb bash

    Now, the installation of MogDB in the container is complete.


Using MogDB

After the installation is complete and enter the container, switch to omm user by running "su - omm", you can access the database via gsql and use MogDB properly.

root@384ac97543bd:/# su - omm
omm@384ac97543bd:~$ gsql -d postgres
gsql ((MogDB 2.0.1 build f892ccb7) compiled at 2021-07-09 16:12:59 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

postgres=#

Environment Variables

To flexibly use an MogDB image, you can set additional parameters. In the future, more control parameters will be added. The current version supports the setting of the following variables:

GS_PASSWORD

This parameter is mandatory when the MogDB image is used. The value cannot be empty or undefined. This parameter specifies the passwords of superuser omm and test user mogdb of the MogDB database. During the MogDB installation, the superuser omm is created by default. This username cannot be changed. The test user mogdb is created in entrypoint.sh.

The local trust mechanism is configured for the MogDB image. Therefore, no password is required for connecting to the database in the container. However, if you want to connect to the database from other hosts or containers, you need to enter the password.

The password must contain at least eight characters, including uppercase letters, lowercase letters, digits, and special characters ( # ? ! @ $ % ^ & * - ). !$&must be escaped using a backslash (\).

GS_NODENAME

Specifies the database node name. The default value is mogdb.

GS_USERNAME

Specifies the username for connecting to the database. The default value is mogdb.

GS_PORT

Specifies the database port. The default value is 5432.


What's Next

MogDB container does not support MogHA and OM tools. It is only used for testing, and currently supports at most one primary node and eight standby nodes. MogDB Enterprise Edition includes MogHA component. The basic functions of the MogDB container and Enterprise Edition are identical. It is recommended that MogDB Enterprise Edition is used in the production environment.