Psqlodbc read-write separation method and system of openGauss

By selecting primary and backup machines based on a load balancing strategy in the psqlodbc read/write separation method of openGauss, read/write separation and load balancing are achieved, solving the performance bottleneck problem of the psqlodbc driver in a primary-backup architecture and improving the stability and reliability of the system.

CN120950585APending Publication Date: 2025-11-14BEIJING VASTDATA TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511076310.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-01
Publication Date
2025-11-14

AI Technical Summary

Technical Problem

The existing psqlodbc driver is difficult to implement read-write separation in a master-slave architecture, causing read and write operations to be concentrated on the master, creating a bottleneck, affecting performance and stability, and failing to fully utilize the high availability and automatic failover functions of the openGauss database.

Method used

By parsing configuration information to establish a connection, analyzing statement operation types, selecting primary and backup machines according to the load balancing strategy, and reselecting the execution host in the psqlodbc read-write separation method of openGauss, read and write operations are performed on the same machine, thus achieving read-write separation and load balancing.

Benefits of technology

It significantly improves read and write performance, optimizes resource utilization, enhances system high availability and scalability, simplifies system maintenance and management, and meets the needs of enterprises and government departments for high performance and high availability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120950585A_ABST
    Figure CN120950585A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database management, and provides a psqlodbc read-write separation method and system for openGauss, and the method comprises the steps: in a connection stage, analyzing configuration information, building connection with a main database and a standby database, and recording connection information to a connection handle; in the preparation stage, the operation type of the statement is analyzed, and the corresponding main and standby machines are selected according to the configured load balancing strategy; in the execution stage, an execution host is reselected, it is guaranteed that read-write operations in the preparation stage and the execution stage are on the same machine, and corresponding read-write operations are executed according to the load balancing strategy. According to the psqlodbc read-write separation method and the psqlodbc read-write separation system of openGauss, the read-write performance and the resource utilization rate of the system can be remarkably improved, the high availability and the expandability of the system can be enhanced, and meanwhile, the maintenance and the management of the system can be simplified, so that the application of an openGauss database under a main and standby framework is more efficient, stable and flexible, and the application range of the openGauss database is widened. And the requirements of enterprises and government departments on high-performance and high-availability databases can be better met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database management technology, and in particular to an openGauss psqlodbc read / write separation method and system. Background Technology

[0002] With the rapid development of internet technology, databases, as core components of information storage and processing, are becoming increasingly important. OpenGauss, as a high-performance, highly available database system, is widely used in various business scenarios in enterprises and government departments. In practical applications, to meet requirements such as high availability, automatic failover, data disaster recovery, load balancing, zero-downtime maintenance, and backups that do not affect production, a master-slave architecture has become a common choice. However, existing psqlodbc drivers have significant shortcomings in master-slave architectures, making it difficult to fully leverage the performance advantages of the OpenGauss database and limiting its application in large-scale business scenarios.

[0003] Specifically, the existing psqlodbc driver relies solely on the master node for operations, concentrating read and write operations on the host and creating bottlenecks that impact read and write speeds. This single dependency not only fails to effectively distribute read and write loads but can also lead to performance bottlenecks on the master node under high concurrency scenarios due to excessive load, thus affecting the overall system's responsiveness and stability. Furthermore, the existing psqlodbc driver lacks read / write separation capabilities, failing to allocate read and write operations appropriately across master and backup nodes based on different business needs. This further exacerbates the load on the master node, limiting the overall system performance and scalability. In practical applications, this driver-side bottleneck prevents the openGauss database kernel from fully leveraging its high availability and automatic failover features, making it difficult to meet the stringent requirements of enterprises and government departments for high-performance and high-availability databases.

[0004] Chinese patent CN106126600A discloses a method, apparatus, and system for implementing read-write separation. However, in practical applications, this solution suffers from the following shortcomings: 1. It heavily relies on proxy middleware for read-write separation and load balancing, increasing system complexity and single-point-of-failure risk, and raising management costs; 2. The heartbeat mechanism for detecting write node failures leads to untimely fault detection, affecting the stability of write operations and data consistency; 3. It relies on polling or simple random strategies, lacking intelligent scheduling and unable to dynamically adapt to complex business scenarios; 4. After a write operation is completed, data is synchronized to the read node via binary log files, resulting in synchronization delays and consistency risks, affecting the real-time performance and data integrity of read operations; 5. It is primarily designed for multi-master database architectures and lacks applicability to master-slave architectures and special business scenarios. These shortcomings limit the widespread adoption and efficient operation of this solution in practical applications.

[0005] Therefore, how to provide a method to achieve read / write separation in psqlodbc, while achieving load balancing, improving the system's read / write performance, fully leveraging the high availability and automatic failover advantages of the openGauss database, and enhancing the stability and reliability of the entire system, has become an urgent technical problem to be solved. Summary of the Invention

[0006] In view of this, in order to overcome the shortcomings of the prior art, the present invention aims to provide a psqlodbc read-write separation method and system for openGauss.

[0007] According to a first aspect of the present invention, a psqlodbc read / write separation method for OpenGauss is provided, the method comprising: Step S1: In the connection phase, parse the configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle; Step S2: In the preparation phase, analyze the operation type of the statement and select the corresponding primary and backup machines according to the configured load balancing strategy; Step S3: During the execution phase, select a new execution host to ensure that read and write operations in the preparation and execution phases are performed on the same machine, and execute the corresponding read and write operations according to the load balancing strategy.

[0008] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, step S1 includes: The primary and backup addresses and port numbers in the configuration file are parsed using the get_host_port_arry_by_connfo function to form host and port arrays. The host and port arrays are then constructed into a PgconnArray structure using the iallocPGcrnrry function. Connect to the primary / standby machine corresponding to the PgconnArray structure via the PQconnectdbParams function; The IsStandby function is used to determine the primary / standby status of each connection. The PQ connection handles of the primary and backup connections are placed into the constructed PgconnArray structure using the setPGconnAnrry interface.

[0009] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, step S2 includes: determining whether the statement type is a read operation or a write operation; if the statement type is a read operation, selecting the corresponding primary or backup machine according to the load balancing strategy through the selectActiveAndby function; if the statement type is a write operation, allocating the operation to the primary machine.

[0010] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, in step S3, before the statement is executed, it is determined whether read / write separation can be used, whether to enable random load balancing strategy is determined by IsAutoBalanceRandom function, and whether to enable round-robin load balancing strategy is determined by IsAutoBalancePolling function.

[0011] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, the load balancing strategy in step S2 includes: Read operations are randomly distributed to the primary and backup machines; Distribute read operations in a round-robin fashion to the primary and backup machines; Read operations are randomly distributed to backup machines; Read operations are distributed to backup machines in a round-robin fashion.

[0012] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, in step S2, when the load balancing strategy is to randomly distribute read operations to the primary and backup machines, the GetIndexRandom interface is called to randomly select the primary and backup machines and record the selected machine information on the statement handle.

[0013] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, in step S2, when the load balancing strategy is to distribute read operations to the primary and backup machines in a round-robin fashion, the GetIndexPolling interface is called to select the primary and backup machines in a round-robin fashion, and the selected machine information is recorded on the statement handle.

[0014] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, in step S3, before the statement is executed, it is determined whether read / write separation can be used, whether to enable random load balancing strategy is determined by IsAutoBalanceRandom function, and whether to enable round-robin load balancing strategy is determined by IsAutoBalancePolling function.

[0015] Optionally, in the openGauss psqlodbc read / write separation method of the present invention, in step S3, during the execution phase, the execution host is reselected through the SelectReadHost interface to ensure that the read / write operations of the preparation phase and the execution phase are on the same machine.

[0016] According to a second aspect of the present invention, an openGauss psqlodbc read / write splitting system is provided, the system comprising a read / write splitting server, the read / write splitting server comprising: The connection module is used to parse configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle during the connection phase. The preparation module is used during the preparation phase to analyze the operation type of the SQL statement and select the corresponding primary or backup machine based on the configured load balancing strategy. The execution module is used to reselect the execution host during the execution phase, ensuring that read and write operations in the preparation and execution phases are performed on the same machine, and to execute the corresponding read and write operations according to the load balancing strategy.

[0017] According to a third aspect of the present invention, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect of the present invention.

[0018] This invention relates to an openGauss psqlodbc read / write separation method and system. By implementing read / write separation and load balancing in psqlodbc, it significantly improves the system's read / write performance and resource utilization, enhances the system's high availability and scalability, and simplifies system maintenance and management. This makes the application of openGauss database in a master-slave architecture more efficient, stable, and flexible, and better meets the needs of enterprises and government departments for high-performance, high-availability databases. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is an example architecture diagram of an openGauss psqlodbc read / write separation system according to an embodiment of the present invention. Figure 2 This is an example architecture diagram of a read / write separation server in an openGauss psqlodbc read / write separation system according to an embodiment of the present invention. Figure 3 This is a flowchart illustrating the steps of an openGauss psqlodbc read / write separation method according to an embodiment of the present invention. Figure 4 This is an example diagram illustrating the execution of an openGauss psqlodbc read / write separation method according to an embodiment of the present invention. Figure 5 This is a schematic diagram of the structure of the device provided by the present invention. Detailed Implementation

[0021] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0022] It should be noted that, in the absence of conflict, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0023] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.

[0024] Figure 1 This is an example architecture diagram of an openGauss psqlodbc read / write separation system according to an embodiment of the present invention, as shown below. Figure 1As shown, the system may include a read / write separation server 101, a communication network 102, and / or one or more read / write separation clients 103. Figure 1 The example in the text is 103, which consists of multiple read / write splitting clients.

[0025] The read / write splitting server 101 can be any suitable server used to store information, data, programs, and / or any other suitable type of content. In some embodiments, the read / write splitting server 101 can perform appropriate functions. For example, in some embodiments, the read / write splitting server 101 can be used for psqlodbc read / write splitting in openGauss. As an optional example, in some embodiments, the read / write splitting server 101 can be used to: in the connection phase, parse configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle; in the preparation phase, analyze the operation type of the statement and select the corresponding primary and backup machines according to the configured load balancing strategy; in the execution phase, reselect the execution host to ensure that the read / write operations in the preparation and execution phases are on the same machine, and execute the corresponding read / write operations according to the load balancing strategy.

[0026] Figure 2 This is an example architecture diagram of a read / write splitting server in an openGauss psqlodbc read / write splitting system according to an embodiment of the present invention. Figure 2 As shown, as an optional example, in this embodiment, the read / write separation server includes: The connection module is used to parse configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle during the connection phase. The preparation module is used during the preparation phase to analyze the operation type of the SQL statement and select the corresponding primary or backup machine based on the configured load balancing strategy. The execution module is used to reselect the execution host during the execution phase, ensuring that read and write operations in the preparation and execution phases are performed on the same machine, and to execute the corresponding read and write operations according to the load balancing strategy.

[0027] As another example, in some embodiments, the read / write splitting server 101 may send the openGauss psqlodbc read / write splitting method to the read / write splitting client 103 for user use, based on a request from the read / write splitting client 103.

[0028] As an optional example, in some embodiments, the read / write separation client 103 is used to provide a visual read / write separation interface, which is used to receive a user's openGauss psqlodbc read / write separation selection input operation, and to obtain from the read / write separation server 101 the read / write separation interface corresponding to the option selected by the selection input operation and display the read / write separation interface, which at least displays openGauss psqlodbc read / write separation information and operation options for openGauss psqlodbc read / write separation information.

[0029] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide area network (WAN), a local area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The read / write splitting client 103 can be connected to the communication network 102 via one or more communication links (e.g., communication link 104), which can be linked to the read / write splitting server 101 via one or more communication links (e.g., communication link 105). The communication links can be any communication link suitable for transmitting data between the read / write splitting client 103 and the read / write splitting server 101, such as network links, dial-up links, wireless links, hardwired links, any other suitable communication links, or any suitable combination of such links.

[0030] The read / write splitting client 103 may include any one or more clients that present an interface related to openGauss's psqlodbc read / write splitting in a suitable manner for user use and operation. In some embodiments, the read / write splitting client 103 may include any suitable type of device. For example, in some embodiments, the read / write splitting client 103 may include a mobile device, tablet computer, laptop computer, desktop computer, and / or any other suitable type of client device.

[0031] Although the read / write splitting server 101 is illustrated as a single device, in some embodiments, any suitable number of devices can be used to perform the functions performed by the read / write splitting server 101. For example, in some embodiments, multiple devices can be used to implement the functions performed by the read / write splitting server 101. Alternatively, cloud services can be used to implement the functions of the read / write splitting server 101.

[0032] Based on the above system, this invention provides a psqlodbc read / write separation method for openGauss, which is illustrated in the following embodiments.

[0033] openGauss is a high-performance, highly available, open-source relational database management system suitable for business scenarios involving large-scale data storage and high-concurrency access. Through its optimized storage engine, intelligent query optimizer, robust transaction support, and flexible scaling mechanisms, it provides efficient and reliable data storage and processing solutions for enterprise applications, cloud computing environments, and big data analytics.

[0034] psqlodbc is an ODBC (Open Database Connectivity) driver for connecting to PostgreSQL databases. It allows applications to interact with PostgreSQL databases through the ODBC interface, enabling operations such as querying, updating, inserting, and deleting data. psqlodbc is an open-source project provided by the PostgreSQL community and is widely used in various applications that require interaction with PostgreSQL databases.

[0035] Figure 3 This is a flowchart illustrating the steps of an openGauss psqlodbc read / write separation method according to an embodiment of the present invention. Figure 4 This is an example diagram illustrating the execution of an openGauss psqlodbc read / write separation method according to an embodiment of the present invention.

[0036] like Figure 3 and Figure 4 As shown, the openGauss psqlodbc read / write splitting method of this embodiment can be executed on the read / write splitting server. The openGauss psqlodbc read / write splitting method includes the following steps: Step S1: In the connection phase, parse the configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle.

[0037] In this embodiment, the primary and backup addresses and port numbers in the configuration file are parsed using the get_host_port_arry_by_connfo function to form host and port arrays, and the host and port arrays are constructed into a PgconnArray structure using the iallocPGcrnrry function.

[0038] As an optional example, the configuration information in this embodiment includes: the IP addresses of the primary and backup servers, the port numbers of the primary and backup servers, and the load balancing switch value. For example, in this embodiment, the configuration information is as follows: Servletnate: Configure the primary and backup IP addresses, separated by commas. Port: Configure the primary and backup port numbers, separated by commas. AutoBalance: This value represents the load balancing switch, and its possible values ​​are as follows: 0: Default value, not enabled; 1: Related to cloud databases, not currently used; 2: Read operations are randomly distributed to each primary and backup server; 3: Read operations are distributed to each primary and backup server in a round-robin fashion; 4: Read operations are randomly distributed to each backup device; 5: Read operations are distributed to each backup in a round-robin fashion.

[0039] In this embodiment, the `host` and `port` arrays are used to specify configuration parameters for the addresses and port numbers of multiple database servers. The `host` array contains the hostnames or IP addresses of the multiple database servers. The `port` array contains the port numbers of the database servers corresponding to the `host` array. By configuring multiple `host` and `port` arrays, multiple database nodes can be connected, thereby achieving failover, read / write separation, or load balancing.

[0040] The PQconnectdbParams function connects to the primary and backup machines corresponding to the PgconnArray structure; the IsStandby function determines the primary and backup status of each connection; and the setPGconnAnrry interface puts the PQ connection handles of the primary and backup connections into the constructed PgconnArray structure.

[0041] Step S2: In the preparation phase, analyze the operation type of the statement and select the corresponding primary and backup machines according to the configured load balancing strategy.

[0042] The system determines whether the statement type is a read or write operation. If the statement type is a read operation, the `selectActiveestandby` function selects the corresponding primary / standby machine according to the load balancing strategy. If the statement type is a write operation, the operation is assigned to the primary machine. In this embodiment, before the statement is executed, it is determined whether read / write separation can be used. The `IsAutoBalanceRandom` function determines whether a random load balancing strategy is enabled, and the `IsAutoBalancePolling` function determines whether a round-robin load balancing strategy is enabled.

[0043] This embodiment provides multiple load balancing strategies, including random distribution and round-robin distribution, allowing users to flexibly choose according to actual business needs and system load. The random distribution strategy can quickly distribute read load, suitable for scenarios with many read operations and high response speed requirements; the round-robin distribution strategy can distribute load more evenly, suitable for scenarios with relatively stable loads requiring long-term balancing. This flexibility enables the system to better adapt to different business needs and optimize overall performance.

[0044] As an optional example, in this embodiment, the load balancing strategy includes: Read operations are randomly distributed to the primary and backup machines; Distribute read operations in a round-robin fashion to the primary and backup machines; Read operations are randomly distributed to backup machines; Read operations are distributed to backup machines in a round-robin fashion.

[0045] As an optional example, when the load balancing strategy is to randomly distribute read operations to the primary and backup machines, the GetIndexRandom interface is called to randomly select the primary and backup machines, and the information of the selected machines is recorded in the statement handle. When the load balancing strategy is to distribute read operations to the primary and backup machines in a round-robin fashion, the GetIndexPolling interface is called to select the primary and backup machines in a round-robin fashion, and the information of the selected machines is recorded in the statement handle.

[0046] Step S3: During the execution phase, select a new execution host to ensure that read and write operations in the preparation and execution phases are performed on the same machine, and execute the corresponding read and write operations according to the load balancing strategy.

[0047] As an optional example, in this embodiment, before statement execution, it is determined whether read-write separation can be used. The IsAutoBalanceRandom function is used to determine whether a random load balancing strategy is enabled, and the IsAutoBalancePolling function is used to determine whether a round-robin load balancing strategy is enabled. During the execution phase, the SelectReadHost interface is used to reselect the execution host, ensuring that read and write operations in the preparation and execution phases are performed on the same machine.

[0048] The openGauss psqlodbc read / write separation method and system of this embodiment can achieve read / write separation of psqlodbc to achieve load balancing. By optimizing the psqlodbc driver, it can reasonably distribute read and write operations to the primary and backup nodes according to different strategies. This not only effectively reduces the load on the primary node and improves the read / write performance of the system, but also fully leverages the high availability and automatic failover advantages of the openGauss database, improving the stability and reliability of the entire system. Specifically, the following beneficial technical effects are achieved: 1. Significantly improves read and write performance By separating read and write operations, with write operations concentrated on the master node and read operations flexibly distributed to master and backup nodes according to configuration policies, the read load is effectively distributed, avoiding performance bottlenecks caused by concentrating read and write operations on the master node. This significantly improves the database's read and write speed, especially in high-concurrency read scenarios, where the performance improvement is even more pronounced. When handling a large number of users querying data simultaneously, the system can respond quickly and provide a smoother user experience.

[0049] 2. Optimize resource utilization After implementing read / write separation, the standby node is no longer just a data backup, but can also undertake actual read tasks. This allows the computing resources of both the primary and standby nodes to be fully utilized, avoiding the situation where the standby node is idle or running inefficiently under normal circumstances, thus improving the resource utilization of the entire system. By rationally allocating read and write operations to the primary and standby nodes, the system can dynamically adjust resource allocation according to the actual load, further optimizing performance and cost-effectiveness.

[0050] 3. Enhance system high availability In a primary-backup architecture, the standby node is typically used for failover to ensure high system availability. This embodiment uses read-write separation, allowing the standby node to participate in read operations even under normal circumstances. This not only improves the utilization of the standby node but also further enhances the system's high availability. Even if the primary node fails, the standby node is already active and can seamlessly take over all read and write operations, ensuring continuous system operation and reducing failover time and complexity.

[0051] 4. Simplify system maintenance and management By implementing read / write separation and load balancing at the psqlodbc level, this embodiment shifts the complex load balancing logic from the application layer to the database driver layer, simplifying application layer development and maintenance, and avoiding system problems caused by application layer logic errors. Simultaneously, unified load balancing strategy configuration and management make system maintenance more convenient and reduce operational costs.

[0052] 5. Improve system scalability As business grows, the load on the database system will also increase. This embodiment utilizes read / write separation and load balancing mechanisms to make it easier for the system to expand its read capacity by adding standby nodes without requiring large-scale hardware upgrades or architectural adjustments to the primary node. This scalability provides strong support for the long-term development of the system and better addresses the challenges brought by future business growth.

[0053] like Figure 5As shown, the present invention also provides a device including a processor 210, a communication interface 220, a memory 230 for storing processor-executable computer programs, and a communication bus 240. The processor 210, communication interface 220, and memory 230 communicate with each other via the communication bus 240. The processor 210 implements the aforementioned openGauss psqlodbc read / write separation method by running the executable computer program.

[0054] The computer program in memory 230, when implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0055] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected based on actual needs to achieve the purpose of this embodiment. Those skilled in the art can understand and implement this without any creative effort.

[0056] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.

[0057] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A psqlodbc read / write separation method for OpenGauss, characterized in that, The method includes: Step S1: In the connection phase, parse the configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle; Step S2: In the preparation phase, analyze the operation type of the statement and select the corresponding primary and backup machines according to the configured load balancing strategy; Step S3: During the execution phase, select a new execution host to ensure that read and write operations in the preparation and execution phases are performed on the same machine, and execute the corresponding read and write operations according to the load balancing strategy.

2. The openGauss psqlodbc read / write separation method according to claim 1, characterized in that, Step S1 includes: The primary and backup addresses and port numbers in the configuration file are parsed using the get_host_port_arry_by_connfo function to form host and port arrays. The host and port arrays are then constructed into a PgconnArray structure using the iallocPGcrnrry function. Connect to the primary / standby machine corresponding to the PgconnArray structure via the PQconnectdbParams function; The IsStandby function is used to determine the primary / standby status of each connection. The PQ connection handles of the primary and backup connections are placed into the constructed PgconnArray structure using the setPGconnAnrry interface.

3. The openGauss psqlodbc read / write separation method according to claim 1, characterized in that, Step S2 includes: determining whether the statement type is a read operation or a write operation; if the statement type is a read operation, selecting the corresponding primary or backup machine according to the load balancing strategy using the selectActivestandby function; if the statement type is a write operation, assigning the operation to the primary machine.

4. The openGauss psqlodbc read / write separation method according to claim 3, characterized in that, In step S3, before the statement is executed, it is determined whether read-write separation can be used. The IsAutoBalanceRandom function is used to determine whether a random load balancing strategy is enabled, and the IsAutoBalancePolling function is used to determine whether a round-robin load balancing strategy is enabled.

5. The openGauss psqlodbc read / write separation method according to claim 1, characterized in that, In step S2, the load balancing strategy includes: Read operations are randomly distributed to the primary and backup machines; Distribute read operations in a round-robin fashion to the primary and backup machines; Read operations are randomly distributed to backup machines; Read operations are distributed to backup machines in a round-robin fashion.

6. The openGauss psqlodbc read / write separation method according to claim 5, characterized in that, In step S2, when the load balancing strategy is to randomly distribute read operations to the primary and backup machines, the GetIndexRandom interface is called to randomly select the primary and backup machines and record the selected machine information on the statement handle.

7. The openGauss psqlodbc read / write separation method according to claim 5, characterized in that, In step S2, when the load balancing strategy is to distribute read operations to the primary and backup machines in a round-robin fashion, the GetIndexPolling interface is called to select the primary and backup machines in a round-robin fashion, and the information of the selected machines is recorded on the statement handle.

8. The openGauss psqlodbc read / write separation method according to claim 1, characterized in that, In step S3, before the statement is executed, it is determined whether read-write separation can be used. The IsAutoBalanceRandom function is used to determine whether a random load balancing strategy is enabled, and the IsAutoBalancePolling function is used to determine whether a round-robin load balancing strategy is enabled.

9. The openGauss psqlodbc read / write separation method according to claim 1, characterized in that, In step S3, during the execution phase, the execution host is reselected through the SelectReadHost interface to ensure that the read and write operations in the preparation and execution phases are performed on the same machine.

10. An OpenGauss psqlodbc read / write separation system, characterized in that, The system includes a read / write separation server, which includes: The connection module is used to parse configuration information, establish a connection with the primary and backup databases, and record the connection information on the connection handle during the connection phase. The preparation module is used during the preparation phase to analyze the operation type of the SQL statement and select the corresponding primary or backup machine based on the configured load balancing strategy. The execution module is used to reselect the execution host during the execution phase, ensuring that read and write operations in the preparation and execution phases are performed on the same machine, and to execute the corresponding read and write operations according to the load balancing strategy.

Citation Information

Patent Citations

  • Method, device and system for executing read / write splitting

    CN106126600A

  • Data processing method and device

    CN107665210A

  • Method for realizing read-write separation of database

    CN115098573A

  • Method for realizing load balancing at driving level

    CN118295816A