Distributed database backup method and apparatus, and computer device and storage medium

By building a Citus cluster and deploying a synchronization agent on the backup side, full and incremental data synchronization is performed, which solves the problems of missing metadata and inflexible backup in distributed database backup, and achieves data consistency and backup flexibility.

WO2024212613A1PCT designated stage expired Publication Date: 2024-10-17CHINA TELECOM CLOUD TECH CO LTD

Patent Information

Application Number
PCT/CN2023/143165
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-12-14
Filing Date
2023-12-29
Publication Date
2024-10-17

AI Technical Summary

Technical Problem

Existing distributed database backup methods lack metadata during logical backup, and physical backup cannot adapt to node expansion, resulting in inflexible and unreliable backup.

Method used

By building a Citus cluster to be written on the backup side, deploying a database synchronization agent, synchronizing full and incremental data, using the starting point of incremental data synchronization to achieve data consistency, and using sharding instructions to achieve unequal specifications. backup.

Benefits of technology

It solves the problem of missing metadata in logical backup, achieves the consistency of data on multiple nodes, improves the reliability of backup, supports backup of unequal specifications, and improves the flexibility of distributed database backup.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023143165_17102024_PF_FP_ABST
    Figure CN2023143165_17102024_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of database backups. Particularly disclosed are a distributed database backup method and apparatus, and a computer device and a storage medium. In the present application, when a database is backed up, a Citus cluster to be written is constructed on a backup end in advance, thereby solving the problem of missing metadata when logical backup is performed on both a CN node and a DN node; incremental data synchronization is performed by means of a start site for incremental data synchronization, such that the final consistency can be implemented on data of a plurality of nodes from a source end, thereby improving the reliability of a database backup; and a synchronization relationship and a sharding instruction can implement backup between examples of unequal specifications, thereby improving the flexibility of a distributed database backup.
Need to check novelty before this filing date? Find Prior Art

Description

Distributed database backup method, device, computer equipment and storage medium Technical Field

[0001] The present application relates to the technical field of database backup, and in particular to a backup method, apparatus, computer equipment, and storage medium for a distributed database. Background Art

[0002] Citus is distributed middleware for the PostgreSQL database. It extends PostgreSQL's capabilities through an extension, without intrusively modifying the PostgreSQL kernel code, enabling horizontal scalability. Citus primarily consists of Coordinator Nodes (CN) and Worker Nodes (WN or DN). Each node is a single or a group of PostgreSQL instances operating in a master-slave relationship. Using Citus to scale multiple PostgreSQL instances into a distributed database, current backup technologies include logical and physical backups. However, these issues present the following challenges: 1. Logical backups, using the same logical synchronization method for PostgreSQL, logically back up the CN and DN nodes separately, with each node's data being managed by a separate PostgreSQL instance. Because the Citus cluster's metadata is stored in a system schema called pg_catalog, which is maintained by PostgreSQL and is read-only by default, this metadata cannot be written to through logical backups. Therefore, backed-up instances will lack Citus metadata from the cluster's perspective. 2. During logical backups, existing data can be extracted from the CN nodes, while real-time incremental data must be obtained by parsing the DN nodes' write-ahead logs (WALs). This raises the question of how to coordinate these two aspects to achieve data consistency during backups. 3. For physical backups, separate physical backups of the CN and DN nodes using tools like pg_basebackup are performed. This only allows for peer-to-peer backups. If the Citus cluster is scaled out after the backup, the previously backed-up data becomes unusable. Therefore, improving the flexibility and reliability of distributed database backups has become a pressing issue.

[0003] Summary of the Invention

[0004] The present application provides a distributed database backup method, apparatus, computer equipment, and storage medium to improve the flexibility and reliability of distributed database backup.

[0005] In a first aspect, the present application provides a method for backing up a distributed database, the method comprising:

[0006] Build a Citus cluster to be written on the backup side based on the PostgreSQL instance;

[0007] Deploy a database synchronization agent based on the Citus cluster to be written;

[0008] Perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent;

[0009] When the full data synchronization is completed, incremental data synchronization is performed based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup.

[0010] Furthermore, before building the Citus cluster to be written on the backup side based on the PostgreSQL instance, the process further includes:

[0011] Creating at least one PostgreSQL instance based on the first custom script and the preset installation package;

[0012] Based on the second custom script, at least one of the PostgreSQL instances is connected.

[0013] Furthermore, the step of building a Citus cluster to be written on the backup side based on the PostgreSQL instance includes:

[0014] Obtain the IP and port information of the DN node to be written into the Citus cluster based on the PostgreSQL instance;

[0015] Based on the first instruction and the IP and port information, the socket information is specified for the DN node to be written into the Citus cluster, and the Citus cluster to be written is constructed.

[0016] Furthermore, before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the method further includes:

[0017] Based on the node information of the Citus cluster to be backed up on the source side and the node information of the Citus cluster to be written on the backup side, the database synchronization agent is configured to obtain the synchronization relationship.

[0018] Furthermore, when the full data synchronization is completed, the incremental data synchronization is performed based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup, and the following is further included:

[0019] Based on the execution of the second instruction by the database synchronization agent, the latest position of the current write-ahead log of the DN node of the Citus cluster to be backed up is queried and obtained, and the latest position is used as the starting position.

[0020] Furthermore, before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the method further includes:

[0021] Executing a third instruction based on the database synchronization agent to query and obtain the table structure of the table to be synchronized;

[0022] Based on the table structure of the table to be synchronized, a sharding rule of the table to be synchronized is obtained, and the sharding instruction is generated based on the sharding rule.

[0023] Furthermore, the full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent includes:

[0024] Reading the full data in the CN node and the DN node of the Citus cluster to be backed up based on the database synchronization agent, and writing the full data to the CN node of the Citus cluster to be written;

[0025] Based on the sharding instruction and the CN node of the Citus cluster to be written, the Citus cluster to be written is sharded to complete full data synchronization.

[0026] In a second aspect, the present application further provides a distributed database backup device, the device comprising:

[0027] The module for building the Citus cluster to be written is used to build the Citus cluster to be written on the backup side based on the PostgreSQL instance;

[0028] A data synchronization agent deployment module is used to deploy a database synchronization agent based on the Citus cluster to be written;

[0029] A full data synchronization module is used to perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent;

[0030] The incremental data synchronization module is used to perform incremental data synchronization based on the starting point of the incremental data synchronization and the synchronization relationship when the full data synchronization is completed, so as to complete the database backup.

[0031] In a third aspect, the present application also provides a computer device, comprising a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement the distributed database backup method as described above when executing the computer program.

[0032] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the distributed database backup method as described above.

[0033] The present application discloses a backup method, apparatus, computer equipment and storage medium for a distributed database. A Citus cluster to be written is constructed on the backup end based on a PostgreSQL instance; a database synchronization agent is deployed based on the Citus cluster to be written; full data synchronization is performed based on the Citus cluster to be backed up, sharding instructions, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent; when the full data synchronization is completed, incremental data synchronization is performed based on the starting point of incremental data synchronization and the synchronization relationship to complete the database backup. The present application constructs a Citus cluster to be written on the backup end in advance when performing a database backup, which solves the problem of missing metadata when performing logical backups of CN nodes and DN nodes respectively. Incremental data synchronization is performed through the starting point of incremental data synchronization, so that data from multiple nodes on the source end can achieve final consistency, thereby improving the reliability of database backup; the synchronization relationship and sharding instructions can realize backup between unequal specification examples, thereby improving the flexibility of distributed database backup. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0035] FIG1 is a schematic flow chart of a first embodiment of a distributed database backup method provided by an embodiment of the present application;

[0036] FIG2 is an implementation architecture diagram of a distributed database backup method provided in an embodiment of the present application;

[0037] FIG3 is a schematic diagram of an aggregation link of a distributed database backup method provided in an embodiment of the present application;

[0038] FIG4 is a schematic flow chart of a second embodiment of a distributed database backup method provided in an embodiment of the present application;

[0039] FIG5 is a schematic flow chart of a third embodiment of a distributed database backup method provided in an embodiment of the present application;

[0040] FIG6 is a schematic block diagram of a distributed database backup device provided in an embodiment of the present application;

[0041] FIG7 is a schematic block diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0043] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, combined, or partially merged, so the actual execution order may vary depending on the actual situation.

[0044] It should be understood that the terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms unless the context clearly indicates otherwise.

[0045] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0046] Embodiments of the present application provide a distributed database backup method, apparatus, computer device, and storage medium. The distributed database backup method can be applied to a server to back up the distributed database, thereby improving the flexibility and reliability of distributed database backup. The server can be a standalone server or a server cluster.

[0047] The following describes some embodiments of the present application in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features therein may be combined with each other.

[0048] Please refer to Figure 1, which is a schematic flow chart of a distributed database backup method provided by an embodiment of the present application. The distributed database backup method can be applied to a server to back up a distributed database, thereby improving the flexibility and reliability of distributed database backup.

[0049] As shown in FIG1 , the distributed database backup method specifically includes steps S101 to S104 .

[0050] S101. Build a Citus cluster to be written on the backup side based on the PostgreSQL instance.

[0051] Furthermore, before building the Citus cluster to be written on the backup side based on the PostgreSQL instance, it also includes: creating at least one of the PostgreSQL instances based on the first custom script and the preset installation package; and connecting at least one of the PostgreSQL instances based on the second custom script.

[0052] In one embodiment, as shown in FIG2 , FIG2 is an implementation architecture diagram of a distributed database backup method provided in an embodiment of the present application. The method comprises the following parts:

[0053] 1. Management and control platform: includes modules such as agent management, topology management, backup scheduling, and statistical services. It receives status reports from database synchronization agents and has a front-end page for interaction with users.

[0054] 2. Database synchronization agent: The program that actually performs data extraction, data management, and data storage, regularly reports status to the management and control platform, and parses the issued instructions.

[0055] 3. Database cluster: the database cluster to be backed up.

[0056] In one embodiment, for example, the patented method is used in a disaster recovery platform to back up a three-node Citus cluster, including one CN (Coordinator Node) node and two DN (Worker Node) nodes. The CN node's IP address and port number are 172.16.0.10:5432, and the two DN nodes' IP addresses and ports are 172.16.0.20:5432 and 172.16.0.30:5432, respectively.

[0057] In one embodiment, a backup PostgreSQL underlying instance is created by executing a custom script on the server, installing several PostgreSQL instances based on the open-source PostgreSQL binary installation package. The IP address and port number of the installed CN node underlying PostgreSQL instance are 192.168.0.120:5432, and the IP addresses and ports of the two DN node underlying PostgreSQL instances are 192.168.0.130:5432 and 192.168.0.140:5432, respectively.

[0058] In one embodiment, a Citus cluster and metadata are created. A custom script is executed on the server to connect to the database instances created in the previous steps. The SQL statement "create database backup_db" is used. In backup_db, the SQL statement "create extension citus" is executed. The SQL statement "insert into pg_dist_authinfo values(0,'root','password=kd^tGd6672Ko@s')" is then executed. Authentication information for inter-node communication is added. On the CN node, the SQL statements "select * from citus_add_node('192.168.0.130',5432)" and "select * from citus_add_node('192.168.0.140',5432)" are executed. The socket information for the instance where the DN resides is specified to build the Citus cluster. A socket is a socket (interface) for network communication.

[0059] S102: Deploy a database synchronization agent based on the Citus cluster to be written.

[0060] In one embodiment, a database synchronization agent is deployed, and the number of database synchronization agent programs is equal to the number of Citus cluster nodes. The function of the agent is to perform actual data extraction and writing.

[0061] In a specific embodiment, three database synchronization agent programs are deployed. The function of the agent is to perform actual data extraction and writing. Each agent corresponds to a node of the Citus cluster.

[0062] S103: Perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent.

[0063] Furthermore, before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, it also includes: configuring the database synchronization agent based on the node information of the Citus cluster to be backed up on the source side and the node information of the Citus cluster to be written on the backup side to obtain the synchronization relationship.

[0064] In one embodiment, as shown in Figure 3, which is a schematic diagram of a converged link for a distributed database backup method provided by an embodiment of the present application, the database synchronization agent is configured so that the CN / DN nodes on the source side correspond to the CN nodes on the backup side cluster, and connection and synchronization auxiliary information is issued.

[0065] In a specific embodiment, the database synchronization agent is configured according to the node information of the Citus cluster to be backed up on the source side (i.e., the IP and port information of the CN / DN node on the source side) and the node information of the Citus cluster to be written on the backup side (i.e., the IP and port information of the CN node on the backup side). The CN / DN nodes on the source side correspond to the CN nodes of the backup side cluster, and the synchronization relationship is issued: 172.16.0.10:5432->192.168.0.120:5432, 172.16.0.20:5432->192.168.0.120:5432, 172.16.0.30:5432->192.168.0.120:5432.

[0066] Furthermore, the full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent includes: reading the full data in the CN node and DN node of the Citus cluster to be backed up based on the database synchronization agent, and writing the full data into the CN node of the Citus cluster to be written; based on the sharding instruction and the CN node of the Citus cluster to be written, sharding the Citus cluster to be written to complete the full data synchronization.

[0067] In one embodiment, the database agent responsible for synchronizing the CN node performs full data synchronization, during which all database agents responsible for incremental synchronization of the DN node wait for the completion signal of the full data synchronization of the CN node database agent.

[0068] S104: When full data synchronization is completed, incremental data synchronization is performed based on the starting point of incremental data synchronization and the synchronization relationship to complete database backup.

[0069] Furthermore, when the full data synchronization is completed, the incremental data synchronization is performed based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup, which also includes: executing a second instruction based on the database synchronization agent, querying and obtaining the latest position of the current pre-write log of the DN node of the Citus cluster to be backed up, and using the latest position as the starting point.

[0070] In one embodiment, all database agents responsible for synchronizing DN nodes execute select pg_current_wal_lsn() to obtain the latest location of the current WAL (Write Ahead Log). They then set the incremental synchronization starting point to this location and record it locally. DN1 records the location at 7 / 9CDB6260, and DN2 records the location at 1 / 1A3B6440.

[0071] In one embodiment, after the full synchronization of the CN node is completed, the CN node database synchronization agent continues to perform incremental synchronization while notifying all database agents responsible for synchronizing the DN nodes to read the preset location information stored locally in the previous step. The database synchronization agent of the DN1 node starts incremental synchronization from the preset location 7 / 9CDB6260, and the database synchronization agent of the DN2 node starts incremental synchronization from the preset location 1 / 1A3B6440. After the incremental synchronization is balanced, the data of the backup end instance can be regarded as a mirror image of the source end.

[0072] The above embodiment provides a backup method, apparatus, computer equipment and storage medium for a distributed database, which constructs a Citus cluster to be written on the backup end based on a PostgreSQL instance; deploys a database synchronization agent based on the Citus cluster to be written; performs full data synchronization based on the Citus cluster to be backed up, sharding instructions, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent; when the full data synchronization is completed, performs incremental data synchronization based on the starting point of incremental data synchronization and the synchronization relationship to complete the database backup. The present application constructs a Citus cluster to be written on the backup end in advance when performing a database backup, which solves the problem of missing metadata when performing logical backups on CN nodes and DN nodes respectively, and performs incremental data synchronization through the starting point of incremental data synchronization, so that data from multiple nodes on the source end can achieve final consistency, thereby improving the reliability of database backup; the synchronization relationship and sharding instructions can realize backup between unequal specification examples, thereby improving the flexibility of distributed database backup.

[0073] Please refer to Figure 4, which is a schematic flow chart of a distributed database backup method provided by an embodiment of the present application. The distributed database backup method can be applied to a server to back up a distributed database, thereby improving the flexibility and reliability of distributed database backup.

[0074] As shown in FIG4 , the distributed database backup method specifically includes steps S201 to S202 .

[0075] S201. Obtain the IP and port information of the DN node to be written into the Citus cluster based on the PostgreSQL instance.

[0076] S202. Based on the first instruction and the IP and port information, specify socket information for the DN node to be written into the Citus cluster, and build the Citus cluster to be written.

[0077] In one embodiment, a Citus cluster and metadata are created. A custom script is executed on the server to connect to the database instances created in the previous steps and create the database to be backed up. In each database, the create extension citus statement is executed. The pg_dist_authinfo statement is then executed to add authentication information for inter-node communication. On the CN node, the citus_add_node statement is executed to specify the socket information for the instance where the DN resides, thus building the Citus cluster.

[0078] In a specific embodiment, a custom script is executed on the server to connect to the database instances created in the previous step. The SQL statement "create database backup_db" is used. The SQL statement "create extension citus" is executed in backup_db. Then, the SQL statement "insert into pg_dist_authinfo values(0,'root','password=kd^tGd6672Ko@s')" is executed. Authentication information for inter-node communication is added. The SQL statements "select * from citus_add_node('192.168.0.130',5432)" and "select * from citus_add_node('192.168.0.140',5432)" are executed on the CN node. The socket information of the instance where the DN resides is specified to build a Citus cluster. A socket is a socket (interface) for network communication.

[0079] The distributed database backup method provided in the above embodiment directly creates a Citus cluster without business data on the backup end. The metadata changes generated by subsequent logical synchronization writing to the backup end Citus cluster can be maintained by Citus itself, thereby improving the reliability of distributed database backup.

[0080] Please refer to Figure 5, which is a schematic flow chart of a distributed database backup method provided by an embodiment of the present application. The distributed database backup method can be applied to a server to back up a distributed database, thereby improving the flexibility and reliability of distributed database backup.

[0081] As shown in FIG. 5 , before step S103 , the distributed database backup method further includes steps S301 to S304 .

[0082] S301: Execute a third instruction based on the database synchronization agent to query and obtain the table structure of the table to be synchronized.

[0083] S302: Based on the table structure of the table to be synchronized, obtain the sharding rule of the table to be synchronized and generate the sharding instruction based on the sharding rule.

[0084] In one embodiment, table structure migration: the database synchronization agent executes SQL queries on the source side to obtain the table structure to be synchronized, uses JDCB (Java DataBase Connectivity, java database connection) type as an intermediate bridge, creates the same table structure on the target side, and then queries the sharding rules of the source side table, assembles sharding SQL according to the sharding rules, and sends sharding instructions to the backup side CN node.

[0085] In a specific embodiment, the database synchronization agent executes the SQL statement at the source end: SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema' WHEN true THEN CASE WHEN n.nspname = 'pg_catalog' OR n.nspname = 'information_schema' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TABLE' WHEN 'v' THEN 'SYSTEM VIEW' WHEN 'i' THEN 'SYSTEM INDEX' ELSE NULL END WHEN n.nspname = 'pg_toast' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TOAST TABLE' WHEN 'i' THEN 'SYSTEM TOAST INDEX' ELSE NULL END ELSE CASE c.relkind WHEN 'r' THEN 'TEMPORARY TABLE' WHEN 'p' THEN 'TEMPORARY TABLE' WHEN 'i' THEN 'TEMPORARY INDEX' WHEN 'S' THEN 'TEMPORARY SEQUENCE' WHEN 'v' THEN 'TEMPORARY VIEW' ELSE NULL END END WHEN false THEN CASE c.relkind WHEN 'r' THEN 'TABLE' WHEN 'p' THEN 'PARTITIONED TABLE' WHEN 'i' THEN 'INDEX' WHEN 'P' then 'PARTITIONED INDEX' WHEN 'S' THEN 'SEQUENCE' WHEN 'v' THEN 'VIEW' WHEN 'c' THEN 'TYPE' WHEN 'f' THEN 'FOREIGN TABLE' WHEN'm' THEN 'MATERIALIZED VIEW' ELSE NULL END ELSE NULL END AS TABLE_TYPE, d.description AS REMARKS,"as TYPE_CAT,"as TYPE_SCHEM,"as TYPE_NAME,"AS SELF_REFERENCING_COL_NAME,"AS REF_GENERATION FROM pg_catalog.pg_namespace n,pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_description d ON(c.oid=d.objoid AND d.objsubid=0 and d.classoid='pg_class'::regclass)WHERE c.relnamespace=n.oid;.

[0086] Get a list of tables and execute the following SQL statement for a specific table, such as the partner table under the public schema:

[0087] SELECT*FROM(SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR(t.typtype='d'AND t.typnotnull)AS attnotnull,a.atttypmod,a.attlen,t.typtypmod,a.attnum,null as attidentity,null as attgenerated,pg_catalog.pg_get_expr(def.adbin,def.adrelid)AS adsrc,dsc.description,t.typbasetype,t.typtype FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON(c.relnamespace=n.oid)JOIN pg_catalog.pg_attribute a ON(a.attrelid=c.oid)JOIN pg_catalog.pg_type t ON(a.atttypid=t.oid)LEFT JOIN pg_catalog.pg_attrdef def ON(a.attrelid=def.adrelid AND a.attnum=def.adnum)LEFT JOIN pg_catalog.pg_description dsc ON(c.oid=dsc.objoid AND a.attnum=dsc.objsubid)LEFT JOIN pg_catalog.pg_class dc ON(dc.oid=dsc.classoid AND dc.relname='pg_class')LEFT JOIN pg_catalog.pg_namespace dn ON(dc.relnamespace=dn.oid AND dn.nspname='pg_catalog')WHERE c.relkind in('r','p','v','f','m')and a.attnum>0AND NOT a.attisdropped AND n.nspname LIKE'public'AND c.relname LIKE'partner')c;

[0088] Query to obtain the table structure to be synchronized, use JDCB type as an intermediate bridge, create the same table structure on the target side, and then execute the SQL statement

[0089] SELECT * FROM citus_tables;

[0090] Query the sharding rules of the source table, assemble the sharding SQL according to the sharding rules, and send the sharding SQL command to the backup CN node:

[0091] SELECT create_distributed_table('partner','id',shard_count=>4).

[0092] The distributed database backup method provided in the above embodiment obtains data from the source CN / DN node and writes it to the CN node of the backup instance. The sharding work is performed within the backup Citus cluster, which can realize instance backup between unequal specifications and improve the flexibility of distributed database backup.

[0093] Please refer to Figure 6, which is a schematic block diagram of a distributed database backup device provided by an embodiment of the present application, wherein the distributed database backup device is used to execute the aforementioned distributed database backup method.

[0094] As shown in FIG6 , the distributed database backup device 400 includes:

[0095] A Citus cluster to be written to construct module 401 is used to construct a Citus cluster to be written to on the backup side based on a PostgreSQL instance;

[0096] A data synchronization agent deployment module 402 is used to deploy a database synchronization agent based on the Citus cluster to be written;

[0097] Full data synchronization module 403, used to perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent;

[0098] The incremental data synchronization module 404 is used to perform incremental data synchronization based on the starting point of the incremental data synchronization and the synchronization relationship when the full data synchronization is completed, so as to complete the database backup.

[0099] Furthermore, the distributed database backup device 400 further includes: a PostgreSQL instance creation module, the PostgreSQL instance creation module including:

[0100] A PostgreSQL instance creation unit, configured to create at least one PostgreSQL instance based on a first custom script and a preset installation package;

[0101] The PostgreSQL instance connection unit is configured to connect to at least one of the PostgreSQL instances based on a second custom script.

[0102] Furthermore, the to-be-written Citus cluster construction module 401 includes:

[0103] An IP and port information obtaining unit, configured to obtain, based on the PostgreSQL instance, the IP and port information of the DN node to be written into the Citus cluster;

[0104] The Citus cluster to be written is constructed by a unit for specifying socket information for the DN node of the Citus cluster to be written based on the first instruction and the IP and port information, and constructing the Citus cluster to be written.

[0105] Furthermore, the distributed database backup device 400 further includes:

[0106] The synchronization relationship obtaining module is used to configure the database synchronization agent based on the node information of the Citus cluster to be backed up on the source side and the node information of the Citus cluster to be written on the backup side to obtain the synchronization relationship.

[0107] Furthermore, the distributed database backup device 400 further includes:

[0108] The starting position obtaining module is used to execute the second instruction based on the database synchronization agent, query and obtain the latest position of the current pre-write log of the DN node of the Citus cluster to be backed up, and use the latest position as the starting position.

[0109] Furthermore, the distributed database backup device 400 further includes a sharding instruction obtaining module, the sharding instruction obtaining module including:

[0110] A table structure query and acquisition unit, configured to execute a third instruction based on the database synchronization agent to query and acquire the table structure of the table to be synchronized;

[0111] A sharding instruction generating unit is configured to obtain a sharding rule of the table to be synchronized based on the table structure of the table to be synchronized and generate the sharding instruction based on the sharding rule.

[0112] Furthermore, the full data synchronization module 403 includes:

[0113] A full data writing unit, configured to read the full data in the CN node and the DN node of the Citus cluster to be backed up based on the database synchronization agent, and write the full data to the CN node of the Citus cluster to be written;

[0114] The database sharding unit is used to shard the Citus cluster to be written based on the sharding instruction and the CN node of the Citus cluster to be written to complete full data synchronization.

[0115] It should be noted that those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0116] The above-mentioned apparatus may be implemented in the form of a computer program, and the computer program may be run on a computer device as shown in FIG. 7 .

[0117] Please refer to Figure 7, which is a schematic block diagram of the structure of a computer device provided in an embodiment of the present application. The computer device may be a server.

[0118] 7 , the computer device includes a processor, a memory, and a network interface connected via a system bus, wherein the memory may include a non-volatile storage medium and an internal memory.

[0119] The non-volatile storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any distributed database backup method.

[0120] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.

[0121] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor, the processor can execute any distributed database backup method.

[0122] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that the structure shown in FIG7 is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. A specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0123] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.

[0124] In one embodiment, the processor is configured to execute a computer program stored in the memory to implement the following steps:

[0125] Build a Citus cluster to be written on the backup side based on the PostgreSQL instance;

[0126] Deploy a database synchronization agent based on the Citus cluster to be written;

[0127] Perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent;

[0128] When the full data synchronization is completed, incremental data synchronization is performed based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup.

[0129] In one embodiment, before implementing the construction of the Citus cluster to be written on the backup side based on the PostgreSQL instance, the processor is further configured to implement:

[0130] Creating at least one PostgreSQL instance based on the first custom script and the preset installation package;

[0131] Based on the second custom script, at least one of the PostgreSQL instances is connected.

[0132] In one embodiment, when building a Citus cluster to be written on a backup side based on a PostgreSQL instance, the processor is configured to implement:

[0133] Obtain the IP and port information of the DN node to be written into the Citus cluster based on the PostgreSQL instance;

[0134] Based on the first instruction and the IP and port information, the socket information is specified for the DN node to be written into the Citus cluster, and the Citus cluster to be written is constructed.

[0135] In one embodiment, before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the processor is further configured to implement:

[0136] Based on the node information of the Citus cluster to be backed up on the source side and the node information of the Citus cluster to be written on the backup side, the database synchronization agent is configured to obtain the synchronization relationship.

[0137] In one embodiment, the processor is further configured to implement, before performing incremental data synchronization based on the starting point of incremental data synchronization and the synchronization relationship to complete database backup when full data synchronization is completed:

[0138] Based on the execution of the second instruction by the database synchronization agent, the latest position of the current write-ahead log of the DN node of the Citus cluster to be backed up is queried and obtained, and the latest position is used as the starting position.

[0139] In one embodiment, before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the processor is further configured to implement:

[0140] Executing a third instruction based on the database synchronization agent to query and obtain the table structure of the table to be synchronized;

[0141] Based on the table structure of the table to be synchronized, a sharding rule of the table to be synchronized is obtained, and the sharding instruction is generated based on the sharding rule.

[0142] In one embodiment, when the processor performs full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, it is configured to implement:

[0143] Reading the full data in the CN node and the DN node of the Citus cluster to be backed up based on the database synchronization agent, and writing the full data to the CN node of the Citus cluster to be written;

[0144] Based on the sharding instruction and the CN node of the Citus cluster to be written, the Citus cluster to be written is sharded to complete full data synchronization.

[0145] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and the processor executes the program instructions to implement any of the distributed database backup methods provided in the embodiments of the present application.

[0146] The computer-readable storage medium may be an internal storage unit of the computer device described in the aforementioned embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the computer device.

[0147] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A distributed database backup method, characterized in that: include: Build a Citus cluster to be written on the backup side based on the PostgreSQL instance; Deploy a database synchronization agent based on the Citus cluster to be written; Perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent; When the full data synchronization is completed, incremental data synchronization is performed based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup.

2. The distributed database backup method according to claim 1, characterized in that: Before building the Citus cluster to be written on the backup side based on the PostgreSQL instance, the method further includes: Based on the first custom script and the preset installation package, create at least one PostgreSQL instance; Based on the second custom script, at least one of the PostgreSQL instances is connected.

3. The distributed database backup method according to claim 1, characterized in that: The step of building a Citus cluster to be written on the backup end based on the PostgreSQL instance includes: Obtain the IP and port information of the DN node to be written into the Citus cluster based on the PostgreSQL instance; Based on the first instruction and the IP and port information, the socket information is specified for the DN node to be written into the Citus cluster, and the Citus cluster to be written is constructed.

4. The distributed database backup method according to claim 1, characterized in that: Before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the method further includes: Based on the node information of the Citus cluster to be backed up on the source side and the node information of the Citus cluster to be written on the backup side, the database synchronization agent is configured to obtain the synchronization relationship.

5. The distributed database backup method according to claim 1, characterized in that: When the full data synchronization is completed, before performing the incremental data synchronization based on the starting point of the incremental data synchronization and the synchronization relationship to complete the database backup, the method further includes: Based on the execution of the second instruction by the database synchronization agent, the latest position of the current write-ahead log of the DN node of the Citus cluster to be backed up is queried and obtained, and the latest position is used as the starting point.

6. The distributed database backup method according to claim 1, characterized in that: Before performing full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent, the method further includes: Executing a third instruction based on the database synchronization agent to query and obtain a table structure of a table to be synchronized; Based on the table structure of the table to be synchronized, a sharding rule of the table to be synchronized is obtained, and the sharding instruction is generated based on the sharding rule.

7. The distributed database backup method according to any one of claims 1 to 6, characterized in that: The full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent includes: Based on the database synchronization agent, the full amount of data in the CN node and the DN node of the Citus cluster to be backed up is read, and the full amount of data is written to the CN node of the Citus cluster to be written; Based on the sharding instruction and the CN node of the Citus cluster to be written, the Citus cluster to be written is sharded to complete full data synchronization.

8. A distributed database backup device, characterized in that: include: The module for building the Citus cluster to be written is used to build the Citus cluster to be written on the backup side based on the PostgreSQL instance; A data synchronization agent deployment module, used to deploy a database synchronization agent based on the Citus cluster to be written; A full data synchronization module, used to perform full data synchronization based on the Citus cluster to be backed up, the sharding instruction, the synchronization relationship between the Citus cluster to be backed up and the Citus cluster to be written, and the database synchronization agent; The incremental data synchronization module is used to perform incremental data synchronization based on the starting point of the incremental data synchronization and the synchronization relationship when the full data synchronization is completed, so as to complete the database backup.

9. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the distributed database backup method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the distributed database backup method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Database construction method and device applied to distributed scheduling system

    CN114003580A

  • Method, device and equipment for synchronizing main and standby state information of node and storage medium

    CN115604286A

  • Automatic detection and backup of primary database instance in database cluster

    US10936545B1

Cited By

  • Method for synchronizing financial information data in real time in communication system

    CN119854321A

  • Data synchronization method and device, electronic equipment and storage medium

    CN121560990A