Database query monitoring method and system

By generating a database connection driver on the server side, the client sends connection and operation requests, and the server side monitors and audits database operations, solving the problem that JDBC direct connections cannot be managed and monitored uniformly, and improving the efficiency and security of database operations.

CN118861007APending Publication Date: 2024-10-29BEIJING ZHIZHENYUN INTELLIGENT TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411103157.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-10-29

AI Technical Summary

Technical Problem

The existing database connection method is directly connected through JDBC, which cannot achieve unified control and security monitoring of different databases, and there are operational security risks.

Method used

Generate a database connection driver on the server, install and load the driver on the client, and send connection and operation requests to the server. The server monitors and records operation information in real time, parses SQL statements, determines permissions and risk thresholds, and realizes the unification of the database. Management and security monitoring.

Benefits of technology

It improves the operational efficiency and security of different databases, realizes centralized monitoring and auditing of database operations, and reduces security risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118861007A_ABST
    Figure CN118861007A_ABST
Patent Text Reader

Abstract

The invention discloses a database query monitoring method and system, and relates to the field of databases, the method comprises the following steps: registering a data source at a server, and generating a database connection driving program; the data source comprises a plurality of databases; the database connection driving program is used for establishing connection with a plurality of databases; installing and loading a database connection driving program at the client, and sending a database connection request and a database operation request to the server based on the database connection driving program; the method comprises the following steps: monitoring a database connection request and a database operation request sent by a client in real time through a server, operating a corresponding database based on the database connection request and the database operation request, and recording operation information at the server. According to the method, unified management operation can be carried out on different databases, and the operation efficiency and safety of the different databases are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of databases, and in particular to a database query monitoring method and system. Background Art

[0002] At present, the common database connection method is to directly connect to the database through the Java Database Connectivity (JDBC) method. Directly operating the database is not conducive to the unified management and control of the database, and the existing technology needs to be compatible with different database vendors. In addition, data security is becoming more and more important nowadays. The method of directly connecting to the database through JDBC cannot control the operation of third-party programs on the database, nor can it centrally monitor the operation of Structured Query Language (SQL) statements, resulting in security risks in database operations. Summary of the invention

[0003] The purpose of this application is to provide a database query monitoring method and system, which can uniformly manage and operate different databases and improve the operating efficiency and security of different databases.

[0004] To achieve the above objectives, this application provides the following solutions:

[0005] In a first aspect, the present application provides a database query monitoring method, comprising:

[0006] Register a data source on the server side and generate a database connection driver; the data source includes multiple databases; the database connection driver is used to establish connections with multiple databases;

[0007] The database connection driver is installed and loaded on the client, and based on the database connection driver, a database connection request and a database operation request are sent to the server; the database connection request includes a client identifier and database connection parameters; the database operation request includes a client identifier and a structured query language statement;

[0008] The server monitors the database connection request and the database operation request sent by the client in real time, and operates the corresponding database based on the database connection request and the database operation request, and records the operation information on the server.

[0009] Optionally, register the data source on the server and generate a database connection driver, including:

[0010] For any database, configure the connection parameters and connection pool parameters of the database, and generate a unique identifier for the database; the connection parameters include a uniform resource locator, a user name, a password, and a driver class name; the connection pool parameters include a minimum number of connections, a maximum number of connections, and a connection timeout;

[0011] Test and establish a connection to the database in question to generate a database connection driver.

[0012] Optionally, the database query monitoring method further includes: registering the client on the server, and binding a unique identifier of the database to the client.

[0013] Optionally, monitoring the database connection request and the database operation request sent by the client in real time by the server, and operating the corresponding database based on the database connection request and the database operation request, specifically includes:

[0014] Establish non-blocking IO communication channels, data buffers and thread pools on the server side;

[0015] When the server receives the database connection request sent by the client, it determines whether the database corresponding to the database connection request has reached the maximum number of connections. If so, the database connection request is placed in a queue. Otherwise, a communication channel and a thread are allocated to the database connection request to establish a connection between the client and the database.

[0016] After the client establishes a connection with the database, when the server receives a database operation request sent by the client, the server stores the database operation request in the data buffer and parses the database operation request to operate the database.

[0017] Optionally, parsing the database operation request to operate the database specifically includes:

[0018] Parsing the structured query language statement in the database operation request into an abstract syntax tree to obtain a token sequence;

[0019] Perform a keyword check on the token sequence: if a pre-set banned keyword exists in the token sequence, terminate the operation on the database, return an error message to the client, and record the failure information on the server; if the banned keyword does not exist in the token sequence, operate the database according to the database operation request and the abstract syntax tree, and record the operation information on the server.

[0020] Optionally, operating the database according to the database operation request and the abstract syntax tree specifically includes:

[0021] Assigning operation permissions to the client through the server; the operation permissions include data operation permissions and structure operation permissions;

[0022] Determining the operation authority of the client according to the client identifier in the database operation request;

[0023] Determine the operation type of the database according to the abstract syntax tree;

[0024] According to the operation type of the database, it is determined whether the client has the corresponding operation authority. If so, the database is operated according to the abstract syntax tree. Otherwise, no authority information is returned to the client.

[0025] Optionally, the database query monitoring method further includes:

[0026] Setting a data operation risk threshold on the server;

[0027] The server determines whether the data operated in the database operation request sent by the client exceeds the data operation risk threshold. If so, the server returns the operation rejection information to the client and issues a warning. Otherwise, the server operates the corresponding database based on the database operation request.

[0028] Optionally, the database query monitoring method further includes: synchronizing the operation information recorded by the server to a search server.

[0029] Optionally, the database query monitoring method further includes: generating, by the server, a report on the client's use of the database according to a set time unit.

[0030] In a second aspect, the present application provides a database query monitoring system, which is applied to the above-mentioned database query monitoring method, including: a server and a client;

[0031] The server is used to register a data source, generate a database connection driver, and monitor in real time the database connection request and database operation request sent by the client, operate the corresponding database based on the database connection request and the database operation request, and record the operation information; the data source includes multiple databases; the database connection driver is used to establish connections with multiple databases;

[0032] The client is used to install and load the database connection driver, and based on the database connection driver, sends a database connection request and a database operation request to the server; the database connection request includes a client identifier and database connection parameters; the database operation request includes a client identifier and a structured query language statement.

[0033] According to the specific embodiments provided in this application, this application discloses the following technical effects:

[0034] The present application provides a database query monitoring method and system. By generating a database connection driver program capable of establishing connections with multiple databases on the server side, the client side only needs to install and load the database connection driver program to operate the corresponding database, and can perform unified management operations on different databases, thereby improving the operation efficiency of different databases. The server side operates the corresponding database based on the database connection request and database operation request sent by the client side, and records the operation information on the server side. The server side can further monitor the operation on the database, thereby improving the security of the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0036] Figure 1 A flowchart of a database query monitoring method provided in one embodiment of the present application. DETAILED DESCRIPTION

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

[0038] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0039] In an exemplary embodiment, Figure 1 As shown, the database query monitoring method provided by the present application includes steps 101 to 103.

[0040] Step 101, registering a data source on the server side and generating a database connection driver.

[0041] The data source includes multiple databases, namely, databases from multiple different manufacturers. The database connection driver is used to establish connections with the multiple databases.

[0042] Specifically, for any database, the connection parameters and connection pool parameters of the database are configured, and a unique identifier is generated for the database. The connection with the database is tested and established to generate a database connection driver.

[0043] The connection parameters include uniform resource locator (URL), user name, password and driver class name. The connection pool parameters include minimum number of connections, maximum number of connections, connection timeout and so on.

[0044] Furthermore, the client is registered on the server side, and the unique identifier of the database is bound to the client. Specifically, the client is a third-party application, such as Office Automation (OA), Enterprise Resource Planning (ERP), Customer Relationship Management (CRM), Business Intelligence (BI) and other systems. The process of registering the client on the server side is: log in to the web console of the server, enter the client management page, click Register, enter the client application name, application number, validity period and other information, then bind the database connection unique identifier, and bind the data source to the client application. The binding relationship between the client and the data source is one-to-one or one-to-many.

[0045] Step 102: Install and load the database connection driver on the client, and send a database connection request and a database operation request to the server based on the database connection driver.

[0046] The database connection request includes a client identifier and database connection parameters. The database operation request includes a client identifier and an SQL statement.

[0047] Specifically, the client changes the JDBC connection information driver to the database connection driver provided by the server, and configures the URL, user name, password and other information. The URL contains the server host address port, application number and other information. The user name and password are the user names issued by the server for identity authentication.

[0048] Step 103: monitor the database connection request and database operation request sent by the client in real time through the server, and operate the corresponding database based on the database connection request and the database operation request, and record the operation information on the server.

[0049] In this application, a non-blocking IO communication channel, a data buffer, and a thread pool are first established on the server side.

[0050] When the server receives the database connection request sent by the client, it determines whether the database corresponding to the database connection request has reached the maximum number of connections. If so, the database connection request is placed in a queue. Otherwise, a communication channel and a thread are allocated to the database connection request to establish a connection between the client and the database.

[0051] Specifically, a non-blocking IO communication channel is established through SocketChannel and Selector, a data buffer is established through ByteBuffer, and a thread pool is created through ThreadPoolExecutor and LinkedBlockingQueue. When a database connection request is received, a SocketChannel and a thread are allocated for the database connection request, and the queue is entered when the maximum number of connections is reached.

[0052] After the client establishes a connection with the database, when the server receives a database operation request sent by the client, the server stores the database operation request in the data buffer and parses the database operation request to operate the database.

[0053] In an exemplary embodiment, the server parses the SQL statement in the database operation request into an abstract syntax tree (AST) to obtain a token sequence. Specifically, the server parses the SQL statement into AST through a lexical parser, and specifically, an ANTLR4 series parser can be used.

[0054] Perform a keyword check on the token sequence: if a pre-set banned keyword exists in the token sequence, terminate the operation on the database, return an error message to the client, and record the failure information on the server; if the banned keyword does not exist in the token sequence, operate the database according to the database operation request and the abstract syntax tree, and record the operation information on the server.

[0055] The failure information includes operation time, SQL statement, data table operated, field operated, success or failure, reason for failure, execution time of this operation and other information.

[0056] Specifically, the SQL types that need to be monitored (such as select, insert, update, delete, drop, etc.) are set in advance on the server side for the client, and unsafe or non-compliant keywords are set to be disabled.

[0057] Further, operating the database according to the database operation request and the abstract syntax tree specifically includes:

[0058] (1) The server allocates operation permissions to the client. The operation permissions include data operation permissions and structure operation permissions. Among them, data operation permissions include deletion, modification, addition and query. Structure operation permissions include creation, modification and deletion of tables.

[0059] (2) Determine the operation authority of the client according to the client identifier in the database operation request.

[0060] (3) Determine the operation type of the database according to the abstract syntax tree.

[0061] (4) According to the operation type of the database, determine whether the client has the corresponding operation authority. If so, operate the database according to the abstract syntax tree; otherwise, return no authority information to the client.

[0062] In order to further improve the security of the database, the database query monitoring method also includes:

[0063] Step 104: Setting a data operation risk threshold on the server.

[0064] Step 105, the server determines whether the data operated in the database operation request sent by the client exceeds the data operation risk threshold. If so, the server returns the operation rejection information to the client and issues a warning. Otherwise, the server operates the corresponding database based on the database operation request.

[0065] Step 106: Synchronize the operation information recorded by the server to the search server (ElasticSearch) for other applications to analyze the operation of the third-party application, etc. The operation analysis specifically includes dimensions such as database usage frequency and query efficiency.

[0066] Step 107, the server generates a client's database usage report according to a set time unit. Specifically, the server can generate a client's database usage report according to a time unit such as month, quarter, year, etc. The usage report includes database usage frequency, query efficiency, etc.

[0067] In this application, the business interaction logic between the server and the client (third-party application) includes but is not limited to the following points:

[0068] (1) Communication: After a third-party application loads the database connection driver provided by the server and changes the configuration to the database connection driver provided by the server, when the third-party application operates on the database, it creates a data stream based on the database connection driver and sends it to the server. After processing, the server returns the result to the database connection driver and further feeds it back to the client.

[0069] (2) Keyword review: After the server receives the SQL statement sent by the client, it is parsed into AST through the lexical parser. After the lexical parser successfully parses and obtains the TOKEN sequence, it performs a keyword check. If a forbidden keyword appears, the operation is terminated directly and the relevant error information is returned to the client. At the same time, the server records the failure information. After the keyword check passes, the data table, field, operation type, SQL parameter and other information involved in the operation are parsed and recorded. The relevant information can be viewed at any time by accessing the server management address. The operation types include data definition language (DDL) and data manipulation language (DML).

[0070] (3) Operation review: The abstract syntax tree is used to parse specific operations (such as deleting data, adding data, deleting tables, adjusting table structures, etc.). When the operation is completed, the server records the database, data table, data (only deletion operations are recorded) and third-party application information involved in the operation.

[0071] (4) Access review: The server records the IP address, application number, user name and password each time a third-party application performs an operation. The server checks whether the application number matches the user name and password. If they do not match, access is denied and the connection is immediately disconnected. At the same time, the server automatically detects the commonly used IP addresses of third-party applications and automatically binds them. When an unfamiliar IP address appears, a message warning is issued through the front-end page. At the same time, the server administrator can also manually set the commonly used IP addresses of third-party applications.

[0072] (5) Operation permissions: Operation permissions can be assigned to third-party applications through the server.

[0073] (6) Risk monitoring: The server can set a data operation risk threshold. When the data operated by a third-party application at a time or within a limited time exceeds the data operation risk threshold, the operation is rejected and a warning is issued to the server console. The server console can set other risk items, such as unconditional deletion, unconditional modification, table deletion, database deletion, slow query, etc.

[0074] (7) Record analysis: All information stored on the server can be synchronized to ElasticSearch to allow other applications to analyze SQL operations on third-party applications.

[0075] (8) Generate reports: The server can generate reports on the use of the database by third-party applications based on monthly, quarterly, annual, and other time units.

[0076] In another exemplary embodiment, a database query monitoring system is provided, including: a server and a client.

[0077] The server is used to register a data source, generate a database connection driver, and monitor the database connection request and database operation request sent by the client in real time, operate the corresponding database based on the database connection request and the database operation request, and record the operation information. The data source includes multiple databases; the database connection driver is used to establish connections with multiple databases.

[0078] The server parses the request based on the data stream sent by the database connection driver and responds with the required data.

[0079] The client is used to install and load the database connection driver, and based on the database connection driver, sends a database connection request and a database operation request to the server. The database connection request includes a client identifier and database connection parameters. The database operation request includes a client identifier and an SQL statement.

[0080] Any third-party application can use the corresponding database by simply introducing the database connection driver provided by this application. Different databases from different manufacturers can be dynamically configured on the server side. In addition, the data source connected to the client application can be switched on the server side, and the corresponding management and control rules can be configured.

[0081] This application can accurately manage and monitor the interaction of third-party applications with the database, record the SQL execution records of each third-party application, monitor and analyze the operation of each SQL statement, and determine whether there is a data security risk. It can centrally manage, monitor, and audit every operation of a third-party application on the database.

[0082] The present application also provides an application scenario, which applies the above-mentioned database query monitoring method. Specifically: The database query monitoring method provided in this embodiment can be applied in an enterprise resource management scenario. The enterprise resource management scenario involves multiple databases, such as a personnel information database, an office supplies database, etc. When managing enterprise resources, a database connection driver program that can establish a connection relationship with each database is first generated through the server, and a specific management application loads the database connection driver program, thereby realizing unified management of each database and improving the compatibility of the database.

[0083] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0084] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0085] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.

[0086] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0087] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.

Claims

1. A database query monitoring method, characterized in that: The database query monitoring method comprises: Register a data source on the server side and generate a database connection driver; the data source includes multiple databases; the database connection driver is used to establish connections with multiple databases; The database connection driver is installed and loaded on the client, and based on the database connection driver, a database connection request and a database operation request are sent to the server; the database connection request includes a client identifier and database connection parameters; the database operation request includes a client identifier and a structured query language statement; The server monitors the database connection request and the database operation request sent by the client in real time, and operates the corresponding database based on the database connection request and the database operation request, and records the operation information on the server.

2. The database query monitoring method according to claim 1, characterized in that: Register the data source on the server and generate a database connection driver, including: For any database, configure the connection parameters and connection pool parameters of the database, and generate a unique identifier for the database; the connection parameters include a uniform resource locator, a user name, a password, and a driver class name; the connection pool parameters include a minimum number of connections, a maximum number of connections, and a connection timeout; Test and establish a connection to the database in question to generate a database connection driver.

3. The database query monitoring method according to claim 1, characterized in that: The database query monitoring method also includes: Register the client on the server and bind the unique identifier of the database to the client.

4. The database query monitoring method according to claim 1, characterized in that: The server monitors the database connection request and the database operation request sent by the client in real time, and operates the corresponding database based on the database connection request and the database operation request, specifically including: Establish non-blocking IO communication channels, data buffers and thread pools on the server side; When the server receives the database connection request sent by the client, it determines whether the database corresponding to the database connection request has reached the maximum number of connections. If so, the database connection request is placed in a queue. Otherwise, a communication channel and a thread are allocated to the database connection request to establish a connection between the client and the database. After the client establishes a connection with the database, when the server receives a database operation request sent by the client, the server stores the database operation request in the data buffer and parses the database operation request to operate the database.

5. The database query monitoring method according to claim 4, characterized in that: Parsing the database operation request to operate the database specifically includes: Parsing the structured query language statement in the database operation request into an abstract syntax tree to obtain a token sequence; Perform a keyword check on the token sequence: if a pre-set banned keyword exists in the token sequence, terminate the operation on the database, return an error message to the client, and record the failure information on the server; if the banned keyword does not exist in the token sequence, operate the database according to the database operation request and the abstract syntax tree, and record the operation information on the server.

6. The database query monitoring method according to claim 5, characterized in that: The database is operated according to the database operation request and the abstract syntax tree, specifically comprising: Assigning operation permissions to the client through the server; the operation permissions include data operation permissions and structure operation permissions; Determining the operation authority of the client according to the client identifier in the database operation request; Determine the operation type of the database according to the abstract syntax tree; According to the operation type of the database, it is determined whether the client has the corresponding operation authority. If so, the database is operated according to the abstract syntax tree. Otherwise, no authority information is returned to the client.

7. The database query monitoring method according to claim 1, characterized in that: The database query monitoring method also includes: Setting a data operation risk threshold on the server; The server determines whether the data operated in the database operation request sent by the client exceeds the data operation risk threshold. If so, the server returns the operation rejection information to the client and issues a warning. Otherwise, the server operates the corresponding database based on the database operation request.

8. The database query monitoring method according to claim 1, characterized in that: The database query monitoring method also includes: The operation information recorded by the server is synchronized to the search server.

9. The database query monitoring method according to claim 1, characterized in that: The database query monitoring method also includes: The server generates a report on the use of the database by the client according to the set time unit.

10. A database query monitoring system, applied to the database query monitoring method according to any one of claims 1 to 9, characterized in that: The database query monitoring system comprises: a server and a client; The server is used to register a data source, generate a database connection driver, and monitor in real time the database connection request and database operation request sent by the client, operate the corresponding database based on the database connection request and the database operation request, and record the operation information; the data source includes multiple databases; the database connection driver is used to establish connections with multiple databases; The client is used to install and load the database connection driver, and based on the database connection driver, sends a database connection request and a database operation request to the server; the database connection request includes a client identifier and database connection parameters; the database operation request includes a client identifier and a structured query language statement.

Citation Information

Patent Citations

  • Application program monitoring system and monitoring method

    CN101226497A

  • Method and apparatus for monitoring and managing database connection pool

    CN105426285A

  • Access control method and device, electronic equipment and storage medium

    CN113626870A

  • Multi-database data processing method and related equipment

    CN116127515A

  • Blockchain data storage and query method, apparatus and device, and storage medium

    WO2020233367A1