CN-121979745-A - Parameter set abnormal rollback method and device of PostgreSQL database
Abstract
The application relates to the technical field of databases and discloses a parameter set abnormal rollback method and device of a PostgreSQL database, wherein after receiving an SQL execution request containing parameters, the method and device carry out real-time analysis and feature extraction on a parameter set to be bound before parameter coding and transmission to generate a parameter scale identifier; after establishing the connection of the PostgreSQL database, actively detecting and acquiring protocol support characteristics of a target database, constructing a database capacity description model based on the protocol support characteristics, selecting a target transmission strategy from a plurality of preset transmission strategies according to the parameter scale identification and the database capacity description model, dynamically constructing and sending a corresponding protocol message sequence according to the target transmission strategy to finish the transmission and query execution of parameter data, carrying out real-time anomaly monitoring in the whole process of parameter transmission and execution, determining anomaly types when anomalies are detected, and automatically triggering corresponding rollback processing operation according to the anomaly types.
Inventors
- MIAO JIAN
- CHEN YINGYING
- ZHANG YUANCHAO
- LV XINJIE
Assignees
- 瀚高基础软件股份有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20260402
Claims (10)
- 1. A method for parameter set exception rollback of a PostgreSQL database, the method comprising: after receiving an SQL execution request containing parameters, carrying out real-time analysis and feature extraction on a parameter set to be bound before parameter coding and transmission to generate a parameter scale identifier; After establishing the PostgreSQL database connection, actively detecting and acquiring protocol support characteristics of a target database, and constructing a database capacity description model based on the protocol support characteristics; selecting a target transmission strategy from a plurality of preset transmission strategies according to the parameter scale identification and the database capacity description model; Dynamically constructing and sending a corresponding protocol message sequence according to the target transmission strategy so as to complete the transmission and query execution of parameter data; Real-time anomaly monitoring is carried out in the whole process of parameter transmission and execution; when an abnormality is detected, determining an abnormality type, and automatically triggering corresponding rollback processing operation according to the abnormality type.
- 2. The method of claim 1, wherein the performing real-time analysis and feature extraction on the set of parameters to be bound to generate the parameter scale identifier comprises: Counting the total number of parameters of the parameters to be bound in the parameter set to be bound; Acquiring the data type of each parameter to be bound, and calculating the single parameter coded length of each parameter to be bound in a database communication protocol; calculating the predicted total data length of all parameters in the binding message based on the single parameter coded length; And comparing the total number of parameters and the expected total data length with a preset threshold value to obtain a comparison result, and generating the parameter scale identification based on the comparison result.
- 3. The method of claim 1, wherein actively probing and acquiring protocol support features of a target database comprises: And obtaining the protocol support characteristics of the target database by inquiring a database system table, executing a probe statement or analyzing a handshake protocol, wherein the protocol support characteristics at least comprise one or more of maximum length of single message, maximum parameter number of single statement, whether array type parameter binding is supported and whether replication protocol is supported.
- 4. A method according to claim 1 or 3, wherein actively probing and acquiring protocol support features of a target database, constructing a database capability description model based on the protocol support features, comprises: obtaining the product type and version information of the PostgreSQL database; actively detecting and acquiring protocol support characteristics of a target database, and constructing the database capacity description model based on the protocol support characteristics, the product types and the version information.
- 5. The method of claim 1, wherein if the target transmission policy is a parameter intelligent fragmentation transmission policy, dynamically constructing and transmitting a corresponding protocol message sequence according to the target transmission policy to complete transmission and query execution of parameter data, comprising: in the context of atomic transactions, dynamically determining the fragmentation granularity according to the parameter types and the data distribution characteristics, and splitting the parameter set to be bound into a plurality of parameter subsets; and respectively constructing and sending a corresponding protocol message sequence for each parameter subset according to the target transmission strategy, completing transmission and execution in a slicing mode, and ensuring that the semantics of the multiple execution results are consistent with the semantics of the original single execution.
- 6. The method of claim 1, wherein if the target transmission policy is a group parameter aggregation transmission policy, When it is detected that parameters in the SQL statement have an array semantic aggregation mode, and the database capability description model indicates that array type parameter binding is supported, selecting the array parameter aggregation transmission policy, the method further comprising: identifying a scalar parameter that is polymerizable in the set of parameters to be bound; combining a plurality of the scalar parameters into a single array type parameter; and constructing and transmitting an analysis message supporting the array type parameters.
- 7. The method of claim 1, wherein when the database capability description model indicates that replication protocols are supported and semantics are performed matching a bulk data write, selecting the bulk data streaming policy, the method further comprising: converting the parameter set to be bound into a standard data stream format; and transmitting data through the batch import channels corresponding to the replication protocol.
- 8. The method of claim 1, wherein the automatically triggering a corresponding rollback processing operation based on the exception type comprises at least one of: protocol layer anomaly monitoring, which is used for monitoring message format anomaly, protocol version compatibility anomaly, parameter number field overflow anomaly and message length overrun anomaly; the transmission layer anomaly monitoring is used for monitoring network connection interruption anomaly, data transmission overtime anomaly and buffer overflow anomaly; and the database layer anomaly monitoring is used for monitoring SQL grammar analysis anomaly, parameter type matching anomaly and resource limitation anomaly.
- 9. The method of claim 1, wherein automatically triggering the corresponding rollback processing operation based on the exception type comprises: first-stage rollback, including intra-strategy retry and parameter adjustment for temporary anomalies; secondary rollback, including performing a degraded handoff between multiple transmission strategies; Three-stage rollback, including intelligent splitting and retrying of parameters; four-stage rollback, including safely suspending the current transmission operation and performing state recovery and resource cleaning.
- 10. A parameter set exception rollback apparatus of a PostgreSQL database, comprising: At least one processor and a bus, and A memory communicatively coupled to the at least one processor, wherein, The memory stores instructions executable by the at least one processor, the instructions are executable by the at least one processor to enable the at least one processor to: after receiving an SQL execution request containing parameters, carrying out real-time analysis and feature extraction on a parameter set to be bound before parameter coding and transmission to generate a parameter scale identifier; After establishing the PostgreSQL database connection, actively detecting and acquiring protocol support characteristics of a target database, and constructing a database capacity description model based on the protocol support characteristics; selecting a target transmission strategy from a plurality of preset transmission strategies according to the parameter scale identification and the database capacity description model; Dynamically constructing and sending a corresponding protocol message sequence according to the target transmission strategy so as to complete the transmission and query execution of parameter data; Real-time anomaly monitoring is carried out in the whole process of parameter transmission and execution; when an abnormality is detected, determining an abnormality type, and automatically triggering corresponding rollback processing operation according to the abnormality type.
Description
Parameter set abnormal rollback method and device of PostgreSQL database Technical Field The application relates to the technical field of databases, in particular to a parameter set exception rollback method and device of a PostgreSQL database. Background The PostgreSQL database is a powerful open-source relational database system, where clients and servers interact through a tightly defined front-end/back-end communication Protocol (Frontend/background Protocol). Under the protocol framework, when an application program executes a parameterized SQL statement through driving as JDBC (Java Database Connectivity), the standard flow comprises that the driver program firstly constructs Parse (parsing) message to send SQL text and parameter type information, then constructs Bind message to binary code and transmit the actual value of the parameter, and finally is executed by a server and returns the result. The core of this process, the Bind message, is a format with explicit coding restrictions on key fields such as the number of parameters (e.g., using a 16-bit integer to represent the number of parameters). In the prior art, when a large-scale parameter set is processed, the problems of high transmission failure risk and the like exist, and a solution capable of realizing abnormal rollback of the parameter set on a database driving level is needed. Disclosure of Invention One or more embodiments of the present disclosure provide a method and apparatus for abnormal rollback of a parameter set of a PostgreSQL database, which are used to solve the technical problems set forth in the background art. One or more embodiments of the present disclosure adopt the following technical solutions: one or more embodiments of the present disclosure provide a method for parameter set exception rollback of a PostgreSQL database, where the method includes: after receiving an SQL execution request containing parameters, carrying out real-time analysis and feature extraction on a parameter set to be bound before parameter coding and transmission to generate a parameter scale identifier; After establishing the PostgreSQL database connection, actively detecting and acquiring protocol support characteristics of a target database, and constructing a database capacity description model based on the protocol support characteristics; selecting a target transmission strategy from a plurality of preset transmission strategies according to the parameter scale identification and the database capacity description model; Dynamically constructing and sending a corresponding protocol message sequence according to the target transmission strategy so as to complete the transmission and query execution of parameter data; Real-time anomaly monitoring is carried out in the whole process of parameter transmission and execution; when an abnormality is detected, determining an abnormality type, and automatically triggering corresponding rollback processing operation according to the abnormality type. One or more embodiments of the present specification provide a parameter set exception rollback apparatus of a PostgreSQL database, including: At least one processor and a bus, and A memory communicatively coupled to the at least one processor, wherein, The memory stores instructions executable by the at least one processor, the instructions are executable by the at least one processor to enable the at least one processor to: after receiving an SQL execution request containing parameters, carrying out real-time analysis and feature extraction on a parameter set to be bound before parameter coding and transmission to generate a parameter scale identifier; After establishing the PostgreSQL database connection, actively detecting and acquiring protocol support characteristics of a target database, and constructing a database capacity description model based on the protocol support characteristics; selecting a target transmission strategy from a plurality of preset transmission strategies according to the parameter scale identification and the database capacity description model; Dynamically constructing and sending a corresponding protocol message sequence according to the target transmission strategy so as to complete the transmission and query execution of parameter data; Real-time anomaly monitoring is carried out in the whole process of parameter transmission and execution; when an abnormality is detected, determining an abnormality type, and automatically triggering corresponding rollback processing operation according to the abnormality type. The above-mentioned at least one technical scheme that this description embodiment adopted can reach following beneficial effect: The method provided by the invention provides a set of system solutions for solving the problems of high transmission failure risk, poor compatibility, system weakness and the like caused by the fact that a single transmission strategy is adopted in a stiff way and an abnormality handl