PolarDB for PostgreSQL (PolarFlex) is deployed using the PolarFlex software stack. Based on your business requirements, you can perform a one-click deployment of a single-node, a primary/standby, or a primary with multiple standbys cluster.
Prerequisites
Purchase a commercial service to obtain the software packages for PolarDB for PostgreSQL (PolarFlex).
You can contact us for a free 30-day trial of the single-node version of PolarDB for PostgreSQL (PolarFlex) without a license. After the trial period, the service is automatically rate-limited.
Environment requirements
Hardware requirements
Before installing PolarDB for PostgreSQL (PolarFlex), ensure your hardware meets the following minimum requirements. Plan your final hardware configuration based on your business needs, data volume, and expected database performance.
|
Item |
Configuration requirements |
|
Server architecture |
x86 and ARM architectures are supported. |
|
Disk |
|
|
CPU |
2 cores or more. |
|
Memory |
8 GB or more. |
|
Network |
Gigabit Ethernet or faster. |
Software requirements
|
Item |
Configuration requirements |
|
Operating system |
Linux CentOS 7.2 or later; Red Hat-based distributions, such as Kylin and Anolis; and Debian-based distributions, such as UOS. Note
We recommend setting the character set to |
|
File system |
The local disk file system must be Ext4. |
|
Glibc version |
glibc version 2.15 or later. Note
Run the following command to list the current glibc versions. The output must include
|
Install the pdbcli tool
pdbcli is a client component that is installed during deployment and serves as the management client for the entire PolarDB for PostgreSQL (PolarFlex) cluster. You can use the command line to perform operations such as cluster deployment, cluster restart, failover, version upgrade, and cluster status check. For detailed information on using pdbcli, see pdbcli Usage Guide and pdbcli Configuration Guide.
-
Obtain the installation package for your target version, polarflex-${version}-${build-date}.tar.gz, and transfer it to the client host.
-
Log on to the client host and set the version variable to match your software version. For example:
version=2.2.2.3 -
Create a working directory and extract the installation files.
mkdir -p polarflex-${version}/ tar -C polarflex-${version}/ -xf polarflex-${version}-${build-date}.tar.gz -
Change to the working directory and run ./scripts/install.sh to start the installation. This command requires
rootpermissions.cd polarflex-${version}/ ./scripts/install.sh -
After installation, run the following command to verify the version. The correct version number confirms a successful installation.
pdbcli version
Install and deploy PolarDB for PostgreSQL (PolarFlex)
Pre-configure the operating system
Disable the Transparent Huge Pages feature on your operating system. Run the following command to check the current configuration:
cat /sys/kernel/mm/transparent_hugepage/enabled
If the output is always madvise [never], Transparent Huge Pages is already disabled. Otherwise, run the following command to disable it:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
Prepare the configuration file
The pdbcli configuration file defines essential settings for the database installation, such as host storage, port configurations, and database parameters. The default configuration file is config.yaml, located in the polarflex-${version}/ directory.
To help you configure config.yaml, templates for different scenarios are provided in the same directory. For more information about parameter settings, see the pdbcli configuration guide.
|
Template file |
Description |
|
|
Template for a primary with multiple standbys cluster. This topology provides high availability with a recovery time objective (RTO) of less than 60 seconds and a recovery point objective (RPO) of 0. |
|
|
Template for a primary/standby cluster. This topology provides high availability with an RTO of less than 60 seconds, but it cannot guarantee an RPO of 0. |
|
|
Template for a single-node cluster. |
If you use the polarflex-deploy.sh one-click deployment script to set up the service, you must modify the parameters in the corresponding configuration file template. The polarflex-deploy.sh script automatically generates config.yaml from the template during runtime.
Note that the following two parameters must be configured before you create the cluster and cannot be modified after creation.
-
Compatibility mode
PolarDB for PostgreSQL (PolarFlex) offers two compatibility modes: Postgres-compatible and Oracle-compatible.
The default is the Postgres-compatible mode. To enable the Oracle-compatible mode, you must set
compatibility_mode: oraat the end of the configuration file template. -
File directory
By default, the database files are located in a subdirectory of
/var/lib/thirdDB. You can change this path by using thepolardb_data_root_dirparameter in the configuration file. Because the default directory might have limited disk space, we strongly recommend choosing a suitable directory based on your host's disk capacity and the expected volume of database files.
Configuration file example
Adjust the contents of the configuration file to match your deployment environment. After making changes, you can run pdbcli validate to verify the configuration.
The configuration file must conform to the YAML format and must not contain tab characters (⇥).
# This example shows how to configure a three-host cluster with the IP addresses 10.XX.XX.1,
# 10.XX.XX.2, and 10.XX.XX.3. Modify the settings according to your actual environment.
all:
children:
cm:
hosts:
host01: null
host02: null
host03: null
var: null
db:
hosts:
host01:
polardb_polar_hostid: 1
host02:
polardb_polar_hostid: 2
polardb_node_type: standby
host03:
polardb_polar_hostid: 3
polardb_node_type: standby
vars:
polardb_custom_params:
- max_standby_streaming_delay = 900000
- max_connections = 3300
- superuser_reserved_connections = 15
- polar_max_super_conns = 1500
polardb_service_restart_sec: 5
hugepage_enabled: off
proxy:
hosts:
host01: null
host02: null
var: null
hosts:
host01:
ansible_host: 10.XX.XX.1 # HOST01_IP
host02:
ansible_host: 10.XX.XX.2 # HOST02_IP
host03:
ansible_host: 10.XX.XX.3 # HOST03_IP
vars:
ansible_group_priority: 99
ansible_python_interpreter: /usr/bin/{{python}}
cluster_id: polardb1
cm_consensus_port: 7001
cm_service_port: 5001
cm_tls_service_port: 6001
cm_db_sync_mode: SYNC
polardb_data_root_dir: /var/lib/thirdDB
polardb_enable_direct_io: false
polardb_multi_instance_per_host: true
polardb_polar_enable_pfs_mode: false
polardb_port: 1523 # Direct connection port for the database
polardb_proxy_port: 12369 # Proxy port for strong consistency
polardb_proxy_port_rwlb: 12370 # Proxy port for read/write splitting
polardb_proxy_admin_port: 12371
polardb_storage_mode: local_filesystem_mode
polardb_user: polar1
primary_db_host: host01
ue_node_driver_service_port: 12355
compatibility_mode: pg # To use the Oracle-compatible mode, change pg to ora before installation.
Install and create the cluster
The polarflex directory contains the polarflex-deploy.sh one-click installation script. Run the command that corresponds to your desired number of cluster nodes:
-
To create a cluster with one primary and two standby nodes (default configuration:
config_template.yaml):bash polarflex-deploy.sh -m "10.XX.XX.1" -p 'password' -m "10.XX.XX.2" -p 'password' -m "10.XX.XX.3" -p 'password' -
To create a primary/standby cluster (default configuration:
config_master_slave.yaml):bash polarflex-deploy.sh -m "10.XX.XX.1" -p 'password' -m "10.XX.XX.2" -p 'password' -
To create a single-node cluster (default configuration:
config_single_node.yaml):bash polarflex-deploy.sh -m "10.XX.XX.1" -p 'password'
The -m parameter specifies the server host address, and -p specifies the root password for the corresponding server host. You can add the -w parameter to deploy prometheus and grafana with a single command. To view cluster monitoring, access port 3000 on the machine where you ran the polarflex-deploy.sh script.
bash polarflex-deploy.sh -m "10.XX.XX.1" -p 'password' -m "10.XX.XX.2" -p 'password' -m "10.XX.XX.3" -p 'password' -w
The script performs the following steps:
-
Configures passwordless SSH login based on the specified server host IP addresses and their
rootpasswords. -
Generates the
config.yamlconfiguration file from a template file such asconfig_template.yaml. -
Runs
pdbcli install clusterto install the required dependencies for the cluster. -
Runs
pdbcli create clusterto create the database cluster.
The current one-click deployment solution requires the root password for the hosts. For environments where this is not possible, a manual installation method is provided in the Appendix.
Verify the deployment
After installing and deploying the database, verify the deployment by checking the cluster's health.
Check the cluster status
Run pdbcli status to check the cluster status. The installation is successful if the statuses of the cluster_manager, master, standby, and proxy nodes are all RUNNING, and the work_path matches the directory specified in the configuration file.
Check the database connection
After the cluster starts, you can use the built-in psql client from the PolarDB for PostgreSQL (PolarFlex) kernel binary package to test the connection.
The following resources are created by default during cluster creation:
-
A user named
adminwith the passwordpostgres. -
A database named
admin_db.
The default access port for the cluster is 1523. Run the following command to check cluster connectivity:
PGPASSWORD=postgres /u01/polardb_pg/bin/psql -h localhost -p1523 -U admin -d admin_db -c 'SHOW polardb_version'
If the command returns the minor kernel version number of the PolarDB for PostgreSQL (PolarFlex) cluster, such as PolarDB V2.0.14.13.26.0, the database is installed correctly and the kernel version is correct.
Check the compatibility mode
After the cluster starts, you can use the built-in psql client from the PolarDB for PostgreSQL (PolarFlex) kernel binary package to query the current engine compatibility mode.
PGPASSWORD=postgres /u01/polardb_pg/bin/psql -h localhost -p1523 -U admin -d admin_db -c 'SHOW polar_compatibility_mode'
The possible results are:
-
pg: Indicates the Postgres-compatible mode. -
ora: Indicates the Oracle-compatible mode.
Check the processes
When a PolarDB for PostgreSQL (PolarFlex) cluster starts successfully, it creates a file named postmaster.pid in the database directory. The first line of this file contains the process ID (PID) of the PolarDB engine daemon process. You can run the command ps -ef | grep <pid> to view all PolarDB for PostgreSQL (PolarFlex) cluster processes. Common auxiliary processes include:
-
postgres: logger: The PolarDB logging process. -
postgres: checkpointer: The PolarDB periodic checkpoint process. -
postgres: background writer: The PolarDB periodic dirty page flushing process. -
postgres: walwriter: The PolarDB periodic WAL log flushing process. -
postgres: autovacuum launcher: The PolarDB automatic cleanup scheduling process. -
postgres: stats collector: The PolarDB statistics collection process.
Uninstall the cluster
If the installation of PolarDB for PostgreSQL (PolarFlex) fails and you need to clean up residual files, run the following command to delete the cluster and uninstall the software stack before reinstalling.
pdbcli delete cluster && pdbcli uninstall cluster
Appendix
After you install the pdbcli cluster management tool and pre-configure the operating system, you can follow these manual steps to deploy a PolarDB for PostgreSQL (PolarFlex) cluster if you cannot obtain the root password for the server hosts.
-
Configure passwordless SSH login between the
pdbcliclient host and the server hosts.# Generate an SSH key. ssh-keygen -t rsa # Copy the public key to all deployment machines. ssh-copy-id -i ~/.ssh/id_rsa.pub <target_user>@$HOST -
Prepare the
config.yamlconfiguration file. Modify theconfig.yamlfile in thepolarflex-${version}/directory to match your deployment environment. After making the changes, you can run pdbcli validate to verify the configuration. -
Install the PolarFlex software stack.
pdbcli install cluster -
Install the PolarDB for PostgreSQL (PolarFlex) cluster and components.
pdbcli create cluster
After a successful installation, verify the deployment to confirm the cluster's running status.