A method and related apparatus for synchronizing logical replication slots
Patent Information
- Application Number
- CN202310254518.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-16
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2043-03-16
AI Technical Summary
[0003]然而目前在将备用数据库作为新的主数据库时,需要基于新的主数据库重新创建逻辑复制槽建立发布订阅,操作较为繁琐
[0018]另一方面,本申请实施例提供了一种包括计算机程序的计算机程序产品,当其在计算机设备上运行时,使得所述计算机设备执行所述的逻辑复制槽的同步方法。
Smart Images

Figure CN118673078B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and in particular to a synchronization method and related apparatus for a logical replication slot. Background Technology
[0002] Currently, for disaster recovery purposes, a data center can include one primary database and at least one standby database. This allows the standby database to continue providing data services as a new primary database should the primary database fail. When creating a logical subscription, users can create logical replication slots corresponding to the subscribed content. When the relevant content changes, the subscriber can obtain the change information through the logical replication slots.
[0003] However, when using a backup database as a new primary database, it is currently necessary to recreate logical replication slots and establish publish / subscribe based on the new primary database, which is a rather cumbersome operation. Summary of the Invention
[0004] To address the aforementioned technical problems, this application provides a method and related apparatus for synchronizing logical replication slots, which realizes the synchronization of logical replication slots between the primary database and the standby database, simplifying operations after database switchover.
[0005] The embodiments of this application disclose the following technical solutions:
[0006] On one hand, embodiments of this application provide a synchronization method for logical replication slots, the method comprising:
[0007] When the information of the target logical replication slot in the first database is updated, the updated first replication slot information of the target logical replication slot is determined, and the target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot;
[0008] If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information is obtained in the second database through a synchronization operation.
[0009] If the first database malfunctions, the second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information.
[0010] On the other hand, this application provides a synchronization device for a logical replication slot, the device comprising:
[0011] The replication slot information determination unit is used to determine the updated first replication slot information of the target logical replication slot when the information of the target logical replication slot in the first database is updated. The target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot.
[0012] A synchronization unit is used to obtain, through a synchronization operation, the second replication slot information corresponding to the first replication slot information of the target logical replication slot in the second database if the synchronizeable identifier of the target logical replication slot is a first identifier.
[0013] The data service providing unit is configured to provide data services to the subscriber corresponding to the target logical replication slot through the second database based on the second replication slot information if the first database fails.
[0014] On the other hand, this application provides a computer device, the device including a processor and a memory:
[0015] The memory is used to store computer programs and to transfer the computer programs to the processor;
[0016] The processor is configured to execute the synchronization method for the logical copy slots described above, according to instructions in the computer program.
[0017] On the other hand, embodiments of this application provide a computer-readable storage medium for storing a computer program for executing the synchronization method of the logical replication slot described above.
[0018] On the other hand, embodiments of this application provide a computer program product including a computer program that, when run on a computer device, causes the computer device to execute the synchronization method of the logical replication slot.
[0019] As can be seen from the above technical solution, when the information of the target logical replication slot in the first database is updated, the updated first replication slot information of the target logical replication slot is determined. The target logical replication slot is used to provide data services to the subscribers corresponding to the target logical replication slot. If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information of the target logical replication slot is obtained in the second database through synchronization operation. For a specific target logical replication slot, the synchronization of replication slot information between different databases can be realized. Compared with synchronizing replication slot information for each logical replication slot, the resource consumption of the second database is reduced. If the first database fails, since the second database has already synchronized the replication slot information of the target logical replication slot, it can take over the provision of data services to the subscribers corresponding to the target logical replication slot based on the replication slot information. This saves the operation of re-establishing the target logical replication slot in the second database, and can ensure uninterrupted data service, reduce the complexity of operation, and improve the smoothness of data service. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A schematic diagram illustrating an application scenario of a synchronization method for a logical replication slot provided in an embodiment of this application;
[0022] Figure 2 A flowchart illustrating a synchronization method for a logical replication slot provided in an embodiment of this application;
[0023] Figure 3 A schematic diagram of a target logical replication slot creation command provided for an embodiment of this application;
[0024] Figure 4 A schematic diagram illustrating the name lookup of a target logical replication slot provided in an embodiment of this application;
[0025] Figure 5 This is a schematic diagram of the first replication slot information of a target logical replication slot in an embodiment of this application;
[0026] Figure 6 A schematic diagram illustrating a synchronization process based on physical logs, provided for an embodiment of this application;
[0027] Figure 7This application provides a schematic diagram of a process for determining information about a second replication slot.
[0028] Figure 8 A schematic diagram of database switching provided in an embodiment of this application;
[0029] Figure 9 A structural block diagram of a synchronization device for a logical replication slot provided in an embodiment of this application;
[0030] Figure 10 A structural diagram of a terminal device provided in an embodiment of this application;
[0031] Figure 11 This is a structural diagram of a server provided in an embodiment of this application. Detailed Implementation
[0032] The embodiments of this application will now be described with reference to the accompanying drawings.
[0033] Currently, when using a standby database as the new primary database, it is necessary to recreate logical replication slots and establish publish / subscribe mechanisms based on the new primary database, which is a cumbersome process. To address the aforementioned technical issues, this embodiment of the application implements the synchronization of logical replication slots between the primary and standby databases, simplifying the operations after database switchover.
[0034] The synchronization method for logical replication slots provided in this application can be implemented using a computer device, which can be a terminal device or a server. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud computing services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Terminal devices include, but are not limited to, smartphones, tablets, laptops, desktop computers, smart speakers, smartwatches, smart voice interaction devices, smart home appliances, vehicle terminals, and aircraft. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0035] Cloud technology refers to a managed technology that unifies a series of resources such as hardware, software, and networks within a wide area network or local area network to achieve data computing, storage, processing, and sharing.
[0036] Cloud technology is a collective term for network technology, information technology, integration technology, management platform technology, and application technology applied to the cloud computing business model. It can form resource pools, providing flexible and convenient on-demand access. Cloud computing technology will become a crucial support. Backend services of technical network systems require substantial computing and storage resources, such as video websites, image websites, and many portal websites. With the rapid development and application of the internet industry, every item may have its own identification mark in the future, requiring transmission to backend systems for logical processing. Data at different levels will be processed separately, and various industry data will all require robust system support, which can only be achieved through cloud computing.
[0037] A database, simply put, can be viewed as an electronic filing cabinet—a place to store electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, with minimal redundancy, and independent of application programs.
[0038] A Database Management System (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters or mobile devices; or according to the query language used, such as SQL (Structured Query Language) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, supporting multiple query languages simultaneously.
[0039] To facilitate understanding of the technical solutions provided in this application, the following section will introduce a synchronization method for a logical replication slot provided in an embodiment of this application, in conjunction with a practical application scenario.
[0040] Figure 1 The illustration shows an application scenario of a logical replication slot synchronization method provided in this application embodiment. In this scenario, there are a server 10 and a terminal device 20. The terminal device 20 and the server 10 are connected through a network. The server 10 can act as the aforementioned computer device to provide data services to the terminal device and realize the synchronization of the logical replication slot. The terminal device 20 can be equipped with a client that is connected to the server 10 so as to obtain data services from the terminal device 20.
[0041] In server 10, when the information of the target logical replication slot in the first database is updated, the updated information of the first replication slot of the target logical replication slot is determined. The target logical replication slot is used to provide data services to the subscriber corresponding to the target logical replication slot.
[0042] If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information can be obtained in the second database through the synchronization operation. For a specific target logical replication slot, the replication slot information between different databases can be synchronized. Compared with synchronizing the replication slot information for each logical replication slot, the resource consumption of the second database is reduced.
[0043] If the first database fails, since the second database has already synchronized with the replication slot information of the target logical replication slot, it can take over as the primary database based on the replication slot information and provide data services to the subscribers corresponding to the target logical replication slot. This saves the operation of re-establishing the target logical replication slot in the second database, ensures uninterrupted data service, reduces operational complexity, and improves the smoothness of data service.
[0044] Figure 2 A flowchart illustrating a synchronization method for a logical replication slot provided in this application embodiment. In this embodiment, a server is used as the aforementioned computer device for description. The method may include:
[0045] S101, when the information of the target logical replication slot in the first database is updated, determine the updated first replication slot information of the target logical replication slot.
[0046] In this embodiment, the data center may include a primary database and at least one standby database. This allows the standby database to act as a new primary database and continue providing data services when the primary database fails. For example, a PostgreSQL database in the data center may include a primary database and at least one standby database. Specifically, a first database can be used as the primary database, and a second database as the standby database. When the first database is working normally, the second database does not provide data services. However, when the first database fails or experiences an anomaly, such as a physical machine failure, database crash, or code bug preventing it from continuing to provide data services, the second database acts as the new primary database and continues to provide data services. In this case, other databases can act as new standby databases; these other databases can be a third database or the first database that has recovered and is functioning normally.
[0047] When creating a logical subscription, users can create logical replication slots corresponding to the subscribed content. These slots enable logical replication, allowing subscribers to access changes to their subscribed content. However, current data centers do not support logical replication slot synchronization between primary and standby databases. For example, PostgreSQL does not support synchronization between primary and standby instances. This means that logical replication slots created on the primary database are unusable on the standby database. When the standby database becomes the new primary database, it cannot provide data services based on the established logical replication slots. Therefore, it is necessary to recreate the logical replication slots and corresponding publish / subscribe operations on the new primary database, resulting in cumbersome operations and a high risk of data loss or service interruption. Furthermore, after recreating the logical replication slots, a full replication process of the subscribed content often needs to be repeated before logical replication can continue. When the data volume is large, full replication becomes extremely time-consuming.
[0048] In this embodiment, taking a target logical replication slot as an example, the target logical replication slot has a corresponding subscription account used to provide data services to the corresponding subscription account. Specifically, when the target content corresponding to the target logical replication slot in the first database is updated, a second physical log can be generated based on the update information of the target content. The second physical log is used to indicate the update information of the target content, such as the physical location to be updated and the update type of the target content. In this way, when the target content corresponding to the target logical replication slot is updated multiple times, multiple second physical logs can be generated for multiple updates. The physical location to be updated and the update type corresponding to the multiple second physical logs can be different. Since the multiple updates have a time sequence, the log sequence identifiers of the multiple second physical logs are also different, which are used to reflect the time relationship of the multiple physical logs being consumed (i.e., processed). The log sequence identifier can be a log sequence number (LSN), and the type of the second physical log can be a write-ahead log (WAL) type.
[0049] The target logical replication slot indicates the log position that has been consumed in the current logical replication. This consumed log position can indicate the log sequence identifier of the second physical log, which can be represented by `confirmed_flush_lsn`. By updating the consumption point of the log logical replication slot, different second physical logs can be consumed sequentially, allowing the corresponding update information of the second physical logs to be processed sequentially. Of course, the target logical replication slot can also indicate the minimum log identifier (`restart_lsn`) required for logical replication, thus preventing the second physical logs after this minimum log identifier from being cleared. The target logical replication slot can also indicate the logical decoding method, allowing physical logs to be decoded into logical logs using this method. The target logical replication slot can also indicate other logical replication information, which will not be listed here.
[0050] In this way, when the information of the target logical replication slot in the first database is updated, the updated first replication slot information can be determined. The updated first replication slot information indicates the log position that the current logical replication has consumed. Therefore, a target logical log can be generated based on the first replication slot information and the second physical log indicated by the first replication slot information. The second physical log and the target logical log have the same log sequence identifier. A logical log sequence including the target logical log is sent to the subscriber corresponding to the target logical replication slot, thereby providing data services to the subscriber. The subscriber can update its existing full data according to the target logical log to obtain the updated full data. Since the target logical log has a log sequence identifier, the full data can be updated sequentially according to the log sequence identifier. In addition, the first database can also send a physical log sequence including the second physical log to the second database. This enables physical log synchronization in the second database. Based on the second physical log, the full data in the second database can be updated so that data services can be provided to the subscriber when the first database fails.
[0051] Updates to the target logical replication slot's information can include the creation of a new target logical replication slot, giving it initial information; changes to the target logical replication slot's information; or deletion of the target logical replication slot's information. Specifically, after a target logical replication slot is created in the first database using the replication slot creation plugin, its initial information is used as the first replication slot's information. Alternatively, after a target logical replication slot is deleted from the first database using the replication slot plugin, the first replication slot's information is determined to be empty. The replication slot creation plugin can also be used to set the target logical replication slot's synchronization flag and to view its information. Furthermore, changes to the target logical replication slot's information can be implemented through the replication slot creation plugin or automatically updated using preset rules.
[0052] The syncability flag indicates whether the target logical replication slot is a master-slave syncable logical replication slot. The syncability flag is denoted as `is_failover`. When the syncability flag is the first flag, the target logical replication slot is a master-slave syncable logical replication slot. When the syncability flag is the second flag or does not have the first flag, the target logical replication slot is not a master-slave syncable logical replication slot. If the first flag can be true, a master-slave syncable logical replication slot can be denoted as a failover slot. In this case, the replication slot information of this logical replication slot will be synchronized from the master database to the slave database, thus preventing logical subscription disconnection after master-slave failover.
[0053] The replication slot creation plugin can be determined based on the specific scenario of the primary database. Taking Tencent Cloud Database as an example, the replication slot creation plugin could be the `tencentdb_failover_slot` plugin. For instance, the interface of this plugin can create target logical replication slots. The creation of the target logical replication slot can be achieved through the logical replication slot creation function from the terminal device. This function can be represented as `pg_create_logical_failover_slot()`. The name of the target logical replication slot can be specified through this function. (See reference...) Figure 3 The diagram illustrates a command for creating a target logical replication slot according to an embodiment of this application. The `tencentdb_failover_slot` plugin can be created, and then the interface of the `tencentdb_failover_slot` plugin can be used to create a target logical replication slot named "fs". The first database can then use the native `ReplicationSlotCreate` interface to create a failover slot, setting the `is_failover` flag of that slot to true based on the addition indication of the synchronization identifier.
[0054] The replica slot creation plugin can also be used to view information about the target logical replica slot, such as querying the name of the target logical replica slot. (See reference) Figure 4 The diagram shown is a schematic of a target logical replication slot name query provided in an embodiment of this application. The logical replication slot named "fs" that has been created can be queried through the view provided by the tencentdb_failover_slot plugin.
[0055] In this embodiment of the application, the information of the first replication slot can also be queried through the terminal device, for reference. Figure 5 The diagram shown illustrates the first replication slot information of a target logical replication slot in an embodiment of this application. The first replication slot information may include the replication slot name (slot_name), a plugin identifier (plugin) indicating whether a plugin is added to the replication slot, a slot type (slot_type), an empty position of the physical replication slot (datoid), an activity identifier (active) indicating whether the replication slot is currently active, a minimum transaction identifier (xmin) indicating the minimum transaction identifier affecting the database itself (catalog_xmin) indicating the current logical replication consumed log position (confirmed_flush_lsn), a minimum log identifier (restart_lsn) indicating the target logical replication slot's logical replication requirements, a log status identifier (wal_status) indicating the data capture status, and a data size identifier (safe_wal_size) indicating the amount of data that can be written to the slot, etc. The first replication slot information can be obtained when logging into the first database. The second replication slot information can be obtained when logging into the second database. The second replication slot information can be found by referring to... Figure 5 The information of the first replication slot in the database.
[0056] S102, if the synchronous identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot is obtained in the second database through the synchronization operation.
[0057] If the synchronizeable identifier of the target logical replication slot is the first identifier, it indicates that the target logical replication slot requires logical synchronization between databases. This also means that the subscriber has high requirements for the complexity and smoothness of data service operations, thus allowing for the synchronization of replication slot information. Specifically, the second replication slot information of the target logical replication slot can be obtained in the second database. The second replication slot information corresponds to the first replication slot information, and usually, the second replication slot information is the same as the first replication slot information.
[0058] One possible implementation is to achieve logical replication synchronization between the first and second databases by sending physical logs. Specifically, if the synchronizeable identifier of the target logical replication slot is a first identifier, a first physical log corresponding to the first replication slot information can be generated based on the first replication slot information. In the second database, based on the first physical log from the first database, the second replication slot information corresponding to the first replication slot information of the target logical replication slot can be determined. Since the first physical log is generated based on the first replication slot information and can indicate the content of the first replication slot information, the second replication slot information can be determined based on the first physical log, which is equivalent to restoring the replication slot information based on the first physical log to obtain the second replication slot information. This method does not require additional processes for the first and second databases, requires no additional resource consumption or process maintenance, has simple logic, and is not prone to errors. Both the first and second physical logs can belong to a physical log sequence, thus the first database sends a physical log sequence including the first and second physical logs to the second database.
[0059] Specifically, the type of the first physical log can be a preset type within the write-ahead log type. If the synchronizeable identifier of the target logical replication slot is the first identifier, the type of the first physical log can be determined to be a preset type within the write-ahead log type. Then, based on the first replication slot information and the preset type, the first physical log corresponding to the first replication slot information is generated. The preset type can be the info field type within the write-ahead log type, meaning that the existing XLOG log type under the write-ahead log type can be extended to determine the type of the first physical log, rather than introducing a new log type. This preset type enables the first and second databases to achieve binary compatibility with other databases under the same major version.
[0060] refer to Figure 6 The diagram illustrates a process for synchronization based on physical logs, as provided in this embodiment of the application. Based on the requirement to create a synchronizable target logical replication slot, a replication slot creation plugin can create the target logical replication slot using a logical replication slot creation function. In the first database, the synchronizable identifier of the target logical replication slot is marked as a first identifier. When the target logical replication slot is updated based on a subscription task, its information is updated to the first replication slot information. Based on the first replication slot information, a first physical log (WAL) can be generated, and then the first replication slot information can be written to disk. After being sent by the log sending (walsender) process of the first database, the first physical log is received by the log receiving (walreceiver) process of the second database. The second database can then determine the second replication slot information based on the first physical log and perform disk writing processing on the second replication slot information.
[0061] Specifically, the update type of the target logical replication slot can be determined based on the first physical log, thereby determining the second replication slot information. After generating the first physical log, the update type of the target logical replication slot can be determined in the second database based on the first physical log. If the update type is "create," the target logical replication slot is created based on the first physical log, and the second replication slot information of the target logical replication slot in the second database is determined. If the update type is "update," the historical replication slot information of the target logical replication slot in the second database can be modified based on the first physical log to obtain the second replication slot information. If the update type is "drop," the historical replication slot information of the target logical replication slot can be cleared based on the first physical log, making the second replication slot information corresponding to the first replication slot information of the target logical replication slot empty. In this way, by updating the replication slot information under different conditions, the first and second databases can achieve synchronization of replication slot information.
[0062] refer to Figure 7 The diagram illustrates a process for determining second replication slot information according to an embodiment of this application. For the first physical log, if the update type is "create," all slots can be traversed to determine if there are any idle operations. If so, a target logical replication slot is created based on the first physical log, and the second replication slot information of the target logical replication slot in the second database is determined; otherwise, an error is reported and the process exits. If the update type is "update," all operations can be traversed to determine if a target logical replication slot exists. If so, the historical replication slot information of the target logical log in the second database is modified based on the first physical log to obtain the second replication slot information; otherwise, an error is reported and the process exits. If the update type is "drop," all operations can be traversed to determine if a target logical replication slot exists. If so, the historical replication slot information of the target logical replication slot is cleared based on the first physical log, making the second replication slot information corresponding to the first replication slot information of the target logical replication slot empty; otherwise, an error is reported and the process exits.
[0063] As another possible implementation, logical replication synchronization between the first and second databases can be achieved through a synchronization process in the second database. Specifically, if the synchronizeable identifier of the target logical replication slot is a first identifier, the synchronization process in the second database obtains the first replication slot information, and based on the first replication slot information, synchronizes the second replication slot information of the target logical replication slot in the second database. The synchronization process in the second database can be a bgworker process, which can monitor the first replication slot information in the first database in real time. If the first replication slot information is updated, it can obtain the first replication slot information and synchronize the second replication slot information based on it. Because the synchronization process obtains the first replication slot information relatively promptly, the second physical log related to the first replication slot information in the second database will not be optimized and deleted. The second database has the ability to provide data services when it is promoted to the primary database. This can achieve faster synchronization efficiency with less resource consumption, without waiting for the generation and transmission of the first physical log, and without the step of obtaining the second replication slot information based on the first physical log.
[0064] In this embodiment, the first replication slot information can be stored in the first local storage space of the first database, achieving disk-based storage of the first replication slot information. Compared to storing the first replication slot information in memory, the data in the first local storage space has higher reliability. Thus, during the synchronization of replication slot information in the second database, the first replication slot information can be retrieved from the first local storage space through the synchronization process of the second database. This does not affect the operation of the first database and allows for faster data retrieval.
[0065] Furthermore, the second replication slot information can be written to the memory of the second database for fast access. The second database can also store this information in its second local storage space, achieving disk persistence. The data in the second local storage space also boasts high reliability. Specifically, storing the first replication slot information in the first local storage space of the first database can be achieved using the first database's native SaveSlotToPath function, for example, writing the first replication slot information to the file ` / data / pg_replslot / fs / state` within the first database. Similarly, storing the second replication slot information in the second local storage space of the second database can also be achieved using the second database's native SaveSlotToPath function, for example, writing the second replication slot information to the file ` / data / pg_replslot / fs / state` within the second database.
[0066] S103, if the first database fails, the second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information.
[0067] Since the replication slot information of the target logical replication slot has been synchronized from the first database to the second database, if the first database fails, the second database can provide data services to the subscribers corresponding to the target logical replication slot based on the second replication slot information. This ensures the target logical replication slot remains usable, guaranteeing smooth data service provision without requiring additional operations. Of course, providing data services to subscribers through the second database signifies that the second database becomes the new master database; that is, the second database is promoted from a standby database to a master database. This promotion can be achieved using PostgreSQL's native `promote` command.
[0068] Typically, the first database sends logical logs to the subscribers and physical logs to the second database. Physical logs are sent faster than logical logs, so the second database has a sufficient number of physical logs to meet the subscribers' needs. After the second database becomes the primary database, it can use these physical logs to send corresponding logical logs to the subscribers to provide data services.
[0069] In this embodiment, if the first database fails, the sending sequence identifier of the latest sent log in the logical log sequence and the receiving sequence identifier of the latest received log in the physical log sequence obtained by the second database from the first database can be determined. If the sending sequence identifier is earlier than the receiving sequence identifier, or the sending sequence identifier is the same as the receiving sequence identifier, it can be considered that there are enough physical logs in the second database to meet the needs of the subscriber. The second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information and the second physical logs indicated by the second replication slot information in the second database. In this way, even if a database switch occurs, the provision of data services will not be affected.
[0070] In this embodiment, if the first database fails and the sending sequence identifier is later than the receiving sequence identifier, it indicates that the second database does not contain physical logs corresponding to some logical logs that have already been sent to the subscriber. The physical logs in the second database are not comprehensive. When the second database works as the master database, the log sequence identifiers of the newly generated physical logs are generated according to the order of the existing log sequence identifiers, which may be duplicated with the log sequence identifiers of the logical logs that have already been sent to the subscriber. If logical logs are continued to be sent to the subscriber according to the sending sequence identifier, it will result in a batch of logical logs generated by the first database in the subscriber and a batch of physical logs generated by the second database in the second database. These logical logs and physical logs have the same log sequence identifier, but have different contents, that is, there is a problem of data inconsistency between the second database and the subscriber.
[0071] For example, refer to Figure 8 The diagram illustrates a database switching process according to an embodiment of this application. The first database generates target logical logs based on the second physical logs and sends LSN80 and the target logical logs corresponding to the preceding second physical logs to the subscriber, while sending LSN75 and the preceding second physical logs to the second database. Subsequent second physical logs generated by the second database are numbered starting from LSN76. Therefore, the subscriber has a batch of target logical logs from LSN76 to 80 (corresponding to the physical logs from LSN76 to 80 above), and the second database also has a batch of second physical logs from LSN76 to 80 (i.e., the physical logs below). These two batches of logs have the same log sequence identifier but different content. This causes the subscriber to update its data based on the batch of target logical logs from LSN76 to 80, while the second database updates its data based on the batch of second physical logs from LSN76 to 80, resulting in different total data for the subscriber and the second database.
[0072] Therefore, if the sent sequence identifier is later than the received sequence identifier, a logical replication failure alert can be sent to the subscriber so that the user can make a logical replication instruction based on the logical replication failure alert. Then, in response to the logical replication instruction from the subscriber, the third replication slot information of the target logical replication slot can be determined. Through the second database, based on the third replication slot information and the second physical log indicated by the second replication slot information in the second database, data services are provided to the subscriber corresponding to the target logical replication slot. In this way, the third replication slot information can be determined based on different logical replication instructions, which essentially means that different logical replication strategies can be determined based on different logical replication instructions.
[0073] The logical replication instruction may include a replication slot deletion instruction. In response to the logical replication instruction including the replication slot deletion instruction from the subscriber, the target logical replication slot can be deleted. Then, a new logical replication slot associated with the data content corresponding to the target logical replication slot is established in the geothermal database. This new logical replication slot corresponds to the subscriber corresponding to the aforementioned target logical replication slot, or it may correspond to other subscribers. Subsequently, the information of the new logical replication slot can be determined as the third replication slot information. Since there may be other second physical logs before the second physical log indicated by the third replication slot information, and the data update information identified by the other second physical logs will be applied to the data content corresponding to the target logical replication slot, thus updating this data content, before providing data services to the subscriber corresponding to the new logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database, the data content corresponding to the new logical replication slot can be sent to the subscriber corresponding to the new logical replication slot, that is, the updated data content corresponding to the target logical replication slot can be sent. This allows the subscriber corresponding to the new logical replication slot to update all data and obtain data services from the second database based on the updated all data, ensuring data consistency between the second database and the subscriber corresponding to the new logical replication slot.
[0074] For example, the first database generates a target logical log based on the second physical log and sends LSN80 and the target logical log corresponding to the previous second physical log to the subscriber, while sending LSN75 and the previous second physical log to the second database. The third replication slot information can indicate the second physical log of LSN90. Since the full data in the second database has been updated according to the update information of the second physical log before LSN90, after sending this full data to the subscriber, logical replication can start from LSN90, ensuring the consistency of data between the second database and the subscriber account.
[0075] The logical replication instruction can also be a continue logical replication instruction. In response to the logical replication instruction from the subscriber, including the continue logical replication instruction, the third replication information of the target logical replication slot is determined based on the received sequence identifier. This way, it is possible to achieve the goal without creating a new target logical replication slot or sending all data. The difference between the full data on the subscriber and the full data in the second database is only the updated content of the logs sent from the first database to the subscriber but not synchronized to the second database. For scenarios with low requirements for data content precision, the impact is small.
[0076] For example, the first database generates a target logical log based on the second physical log and sends LSN80 and the target logical log corresponding to the previous second physical log to the subscriber, while sending LSN75 and the previous second physical log to the second database. The third replication slot information can indicate the second physical log of LSN76, that is, all data update information available in the second database is pushed to the subscriber. The subscriber's full data is updated based on a batch of target logical logs of LSN76-80 sent by the first database, and also based on a batch of target logical logs of LSN76-80 sent by the second database.
[0077] Based on the synchronization method for logical replication slots provided in the embodiments of this application, the embodiments of this application also provide a synchronization device for logical replication slots, see reference. Figure 9 The diagram shown is a structural block diagram of a synchronization device for a logical replication slot provided in an embodiment of this application. The synchronization device 1300 for the logical replication slot includes:
[0078] The replication slot information determination unit 1301 is used to determine the updated first replication slot information of the target logical replication slot when the information of the target logical replication slot in the first database is updated. The target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot.
[0079] Synchronization unit 1302 is used to obtain the second replication slot information corresponding to the first replication slot information in the second database through a synchronization operation if the synchronizeable identifier of the target logical replication slot is the first identifier.
[0080] The data service providing unit 1303 is used to provide data services to the subscriber corresponding to the target logical replication slot through the second database according to the second replication slot information if the first database fails.
[0081] Optionally, the synchronization unit 1302 includes:
[0082] The first physical log generation unit is used to generate a first physical log corresponding to the first replication slot information based on the first replication slot information if the synchronizeable identifier of the target logical replication slot is a first identifier.
[0083] The synchronization subunit is used to determine, in the second database, the second replication slot information corresponding to the first replication slot information of the target logical replication slot based on the first physical log from the first database.
[0084] Optionally, the first physical log generation unit includes:
[0085] The type determination unit is used to determine the type of the first physical log as a preset type in the write-ahead log type if the synchronizeable identifier of the target logical replication slot is a first identifier.
[0086] The first physical log generation subunit is used to generate the first physical log corresponding to the first replication slot information based on the first replication slot information and the preset type.
[0087] Optionally, the synchronization subunit includes:
[0088] An update type determination unit is used to determine the update type of the target logical replication slot in the second database based on the first physical log;
[0089] The second replication slot information determination unit is configured to: if the update type is "create", create the target logical replication slot according to the first physical log, and determine the second replication slot information of the target logical replication slot in the second database; if the update type is "modify", modify the historical replication slot information of the target logical replication slot in the second database according to the first physical log to obtain the second replication slot information; if the update type is "delete", clear the historical replication slot information of the target logical replication slot according to the first physical log, so that the second replication slot information of the target logical replication slot corresponding to the first replication slot information is empty.
[0090] Optionally, the synchronization unit 1302 includes:
[0091] The process synchronization unit is used to obtain the first replication slot information through the synchronization process of the second database if the synchronizeable identifier of the target logical replication slot is a first identifier, and to synchronize the second replication slot information of the target logical replication slot in the second database according to the first replication slot information.
[0092] Optionally, the device further includes:
[0093] The disk storage unit is used to store the first replication slot information into the first local storage space of the first database through the first database;
[0094] The process synchronization unit is specifically used for:
[0095] If the synchronizeable identifier of the target logical replication slot is a first identifier, the first replication slot information is obtained from the first local storage space through the synchronization process of the second database, and the second replication slot information of the target logical replication slot is obtained synchronously in the second database based on the first replication slot information.
[0096] Optionally, the device further includes:
[0097] The second physical log generation unit is used to generate a second physical log based on the update information of the target content when the target content corresponding to the target logical replication slot in the first database is updated.
[0098] A logical log generation unit is used to generate a target logical log based on the first replication slot information and the second physical log indicated by the first replication slot information, wherein the second physical log and the target logical log have the same log sequence identifier;
[0099] A logical log sending unit is used to send a logical log sequence including the target logical log to the subscriber corresponding to the target logical replication slot, so as to provide data services to the subscriber.
[0100] The physical log sending unit is used to send a physical log sequence, including the second physical log, to the second database through the first database.
[0101] Optionally, the data service providing unit 1303 includes:
[0102] The sequence identifier determination unit is used to determine the sending sequence identifier of the latest sent log in the logical log sequence and the receiving sequence identifier of the latest received log in the physical log sequence obtained by the second database from the first database if the first database fails.
[0103] A data service providing subunit is used to provide data services to the subscriber corresponding to the target logical replication slot through the second database, based on the second replication slot information and the second physical log indicated by the second replication slot information in the second database, if the sending sequence identifier is earlier than the receiving sequence identifier, or the sending sequence identifier is the same as the receiving sequence identifier.
[0104] The device further includes:
[0105] The reminder unit is used to send a logical replication failure reminder to the subscriber if the sending sequence identifier is later than the receiving sequence identifier;
[0106] The third replication slot information determination unit is used to determine the third replication slot information of the target logical replication slot in response to a logical replication instruction from the subscriber.
[0107] Other data service providing units are used to provide data services to the subscribers corresponding to the target logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database.
[0108] Optionally, the third replication slot information determining unit includes:
[0109] A copy slot deletion unit is configured to delete the target logical copy slot in response to a logical copy instruction, including a copy slot deletion instruction, from the subscriber.
[0110] The replication slot creation unit is used to create a new logical replication slot in the second database that is associated with the data content corresponding to the target logical replication slot;
[0111] The third replication slot information determination subunit is used to determine that the information of the newly created logical replication slot is the third replication slot information;
[0112] The device further includes:
[0113] The data content sending unit is used to send the data content corresponding to the newly created logical replication slot to the subscriber corresponding to the newly created logical replication slot before providing data services to the subscriber corresponding to the target logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database.
[0114] Optionally, the third replication slot information determining unit includes:
[0115] The third replication slot information determination subunit is used to determine the third replication slot information of the target logical replication slot based on the received sequence identifier in response to a logical replication indication, including a continue logical replication indication, from the subscriber.
[0116] Optionally, the replication slot information determining unit 1301 is specifically used for:
[0117] After the target logical replication slot is established in the first database through the replication slot establishment plugin, the initial information of the target logical replication slot is determined to be the first replication slot information. The replication slot establishment plugin is also used to set the synchronization identifier of the target logical replication slot.
[0118] Alternatively, after deleting the target logical copy slot from the first database via the copy slot plugin, it is determined that the first copy slot information of the target logical copy slot is empty.
[0119] As can be seen from the above technical solution, when the information of the target logical replication slot in the first database is updated, the updated first replication slot information of the target logical replication slot is determined. The target logical replication slot is used to provide data services to the subscribers corresponding to the target logical replication slot. If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information of the target logical replication slot is obtained in the second database through synchronization operation. For a specific target logical replication slot, the synchronization of replication slot information between different databases can be realized. Compared with synchronizing replication slot information for each logical replication slot, the resource consumption of the second database is reduced. If the first database fails, since the second database has already synchronized the replication slot information of the target logical replication slot, it can take over the provision of data services to the subscribers corresponding to the target logical replication slot based on the replication slot information. This saves the operation of re-establishing the target logical replication slot in the second database, and can ensure uninterrupted data service, reduce the complexity of operation, and improve the smoothness of data service.
[0120] This application also provides a computer device, which is the computer device described above, and may include a terminal device or a server. The synchronization device of the aforementioned logical replication slot may be configured in the computer device. The computer device will now be described in conjunction with the accompanying drawings.
[0121] If the computer device is a terminal device, please refer to Figure 10 As shown, this application provides a terminal device, taking a mobile phone as an example:
[0122] Figure 10 This diagram illustrates a partial structural representation of a mobile phone related to the terminal device provided in this embodiment. (Reference) Figure 10 The mobile phone includes components such as a radio frequency (RF) circuit 1410, a memory 1420, an input unit 1430, a display unit 1440, a sensor 1450, an audio circuit 1460, a Wi-Fi module 1470, a processor 1480, and a power supply 1490. Those skilled in the art will understand that... Figure 10 The mobile phone structure shown does not constitute a limitation on the mobile phone and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0123] The following is combined Figure 10 A detailed introduction to each component of a mobile phone:
[0124] The RF circuit 1410 can be used to receive and transmit signals during information transmission or calls. In particular, it receives downlink information from the base station and processes it with the processor 1480; in addition, it transmits uplink data to the base station.
[0125] The memory 1420 can be used to store software programs and modules. The processor 1480 executes various mobile phone functions and data processing by running the software programs and modules stored in the memory 1420. The memory 1420 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 1420 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0126] The input unit 1430 can be used to receive input numeric or character information, and to generate key signal inputs related to user settings and function control of the mobile phone. Specifically, the input unit 1430 may include a touch panel 1431 and other input devices 1432.
[0127] The display unit 1440 can be used to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 1440 may include a display panel 1441.
[0128] The mobile phone may also include at least one sensor 1450, such as a light sensor, a motion sensor, and other sensors.
[0129] Audio circuitry 1460, speaker 1461, and microphone 1462 provide an audio interface between the user and the mobile phone.
[0130] WiFi is a short-range wireless transmission technology. Through the WiFi module 1470, mobile phones can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access.
[0131] The processor 1480 is the control center of the mobile phone. It connects to various parts of the mobile phone through various interfaces and lines. It performs various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 1420 and calling data stored in the memory 1420.
[0132] The phone also includes a power supply 1490 (such as a battery) that powers the various components.
[0133] In this embodiment, the processor 1480 included in the terminal device also has the following functions:
[0134] When the information of the target logical replication slot in the first database is updated, the updated first replication slot information of the target logical replication slot is determined, and the target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot;
[0135] If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information is obtained in the second database through a synchronization operation.
[0136] If the first database malfunctions, the second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information.
[0137] If the computer device is a server, this application embodiment also provides a server; please refer to [link to relevant documentation]. Figure 11 As shown, Figure 11 This is a structural diagram of a server 1500 provided in an embodiment of this application. The server 1500 can vary significantly due to different configurations or performance. It may include one or more processors 1522, such as a Central Processing Unit (CPU), a memory 1532, and one or more storage media 1530 (e.g., one or more mass storage devices) for storing application programs 1542 or data 1544. The memory 1532 and storage media 1530 can be temporary or persistent storage. The program stored in the storage media 1530 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the processor 1522 may be configured to communicate with the storage media 1530 and execute the series of instruction operations in the storage media 1530 on the server 1500.
[0138] Server 1500 may also include one or more power supplies 1526, one or more wired or wireless network interfaces 1550, one or more input / output interfaces 1558, and / or one or more operating systems 1541, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.
[0139] The steps performed by the server in the above embodiments can be based on Figure 11The server structure shown.
[0140] In addition, this application embodiment also provides a storage medium for storing a computer program for executing the method provided in the above embodiment.
[0141] This application also provides a computer program product including instructions that, when run on a computer, cause the computer to perform the methods provided in the above embodiments.
[0142] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium can be at least one of the following media: read-only memory (ROM), RAM, magnetic disk, or optical disk, etc., and other media capable of storing program code.
[0143] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and 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 to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0144] The above description is merely one specific embodiment of this application, but the scope of protection of this application 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 this application should be included within the scope of protection of this application. Moreover, based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A synchronization method for logical replication slots, characterized in that, The method includes: When the information of the target logical replication slot in the first database is updated, the updated first replication slot information of the target logical replication slot is determined, and the target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot; If the synchronizeable identifier of the target logical replication slot is the first identifier, the second replication slot information corresponding to the first replication slot information is obtained in the second database through the synchronization operation. If the first database fails, the second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information.
2. The method according to claim 1, characterized in that, If the synchronizeable identifier of the target logical replication slot is a first identifier, the second replication slot information corresponding to the first replication slot information is obtained from the second database through a synchronization operation, including: If the synchronizeable identifier of the target logical replication slot is a first identifier, generate a first physical log corresponding to the first replication slot information based on the first replication slot information; Based on the first physical log from the first database, the second database determines the second replication slot information corresponding to the first replication slot information of the target logical replication slot.
3. The method according to claim 2, characterized in that, If the synchronizeable identifier of the target logical replication slot is a first identifier, generating a first physical log corresponding to the first replication slot information based on the first replication slot information includes: If the synchronizeable identifier of the target logical replication slot is the first identifier, the type of the first physical log is determined to be a preset type in the write-ahead log type; Based on the first replication slot information and the preset type, a first physical log corresponding to the first replication slot information is generated.
4. The method according to claim 2, characterized in that, The step of determining the second replication slot information corresponding to the first replication slot information in the target logical replication slot based on the first physical log from the first database in the second database includes: The update type of the target logical replication slot is determined in the second database based on the first physical log; If the update type is new, then the target logical replication slot is created according to the first physical log, and the second replication slot information of the target logical replication slot in the second database is determined; If the update type is modification, then the historical replication slot information of the target logical replication slot in the second database is modified according to the first physical log to obtain the second replication slot information; If the update type is deletion, then the historical replication slot information of the target logical replication slot is cleared according to the first physical log, so that the second replication slot information of the target logical replication slot corresponding to the first replication slot information is empty.
5. The method according to claim 1, characterized in that, If the synchronizeable identifier of the target logical replication slot is a first identifier, the second replication slot information corresponding to the first replication slot information is obtained from the second database through a synchronization operation, including: If the synchronizeable identifier of the target logical replication slot is a first identifier, the first replication slot information is obtained through the synchronization process of the second database, and the second replication slot information of the target logical replication slot is obtained synchronously in the second database based on the first replication slot information.
6. The method according to claim 5, characterized in that, The method further includes: The first replication slot information is stored in the first local storage space of the first database through the first database; The step of obtaining the first replication slot information through the synchronization process of the second database includes: The first replication slot information is obtained from the first local storage space through the synchronization process of the second database.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: When the target content corresponding to the target logical replication slot in the first database is updated, a second physical log is generated based on the update information of the target content; A target logical log is generated based on the first replication slot information and the second physical log indicated by the first replication slot information, wherein the second physical log and the target logical log have the same log sequence identifier; Send a logical log sequence including the target logical log to the subscriber corresponding to the target logical replication slot to provide data services to the subscriber; The first database sends a physical log sequence, including the second physical log, to the second database.
8. The method according to claim 7, characterized in that, If the first database fails, the second database provides data services to the subscriber corresponding to the target logical replication slot based on the second replication slot information, including: If the first database fails, determine the sending sequence identifier of the latest sent log in the logical log sequence, and the receiving sequence identifier of the latest received log in the physical log sequence obtained by the second database from the first database; If the sending sequence identifier is earlier than the receiving sequence identifier, or the sending sequence identifier is the same as the receiving sequence identifier, the second database provides data services to the subscriber corresponding to the target logical replication slot according to the second replication slot information and the second physical log indicated by the second replication slot information in the second database; The method further includes: If the sending sequence identifier is later than the receiving sequence identifier, a logical replication failure alert is sent to the subscriber. In response to a logical replication instruction from the subscriber, the third replication slot information of the target logical replication slot is determined; The second database provides data services to the subscriber corresponding to the target logical replication slot based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database.
9. The method according to claim 8, characterized in that, The step of determining the third replication slot information of the target logical replication slot in response to a logical replication indication from the subscriber includes: In response to a logical replication instruction from the subscriber, including a replication slot deletion instruction, the target logical replication slot is deleted; In the second database, a new logical replication slot is created that is associated with the data content corresponding to the target logical replication slot; The information of the newly created logical replication slot is determined to be the information of the third replication slot; Before providing data services to the subscriber corresponding to the target logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database, the method further includes: Send the data content corresponding to the newly created logical replication slot to the subscriber corresponding to the newly created logical replication slot.
10. The method according to claim 8, characterized in that, The step of determining the third replication slot information of the target logical replication slot in response to a logical replication indication from the subscriber includes: In response to a logical replication instruction from the subscriber, including a continue logical replication instruction, the third replication slot information of the target logical replication slot is determined based on the received sequence identifier.
11. The method according to any one of claims 1-6, characterized in that, When the information of the target logical replication slot in the first database is updated, determining the updated first replication slot information of the target logical replication slot includes: After the target logical replication slot is established in the first database through the replication slot establishment plugin, the initial information of the target logical replication slot is determined to be the first replication slot information. The replication slot establishment plugin is also used to set the synchronization identifier of the target logical replication slot. Alternatively, after deleting the target logical copy slot from the first database via the copy slot plugin, it is determined that the first copy slot information of the target logical copy slot is empty.
12. A synchronization device for a logical replication slot, characterized in that, The device includes: The replication slot information determination unit is used to determine the updated first replication slot information of the target logical replication slot when the information of the target logical replication slot in the first database is updated. The target logical replication slot is used to provide data services to the subscription terminal corresponding to the target logical replication slot. The synchronization unit is used to obtain the second replication slot information corresponding to the first replication slot information in the second database through a synchronization operation if the synchronizeable identifier of the target logical replication slot is the first identifier. The data service providing unit is configured to provide data services to the subscriber corresponding to the target logical replication slot through the second database based on the second replication slot information if the first database fails.
13. The apparatus according to claim 12, characterized in that, The synchronization unit includes: The first physical log generation unit is used to generate a first physical log corresponding to the first replication slot information based on the first replication slot information if the synchronizeable identifier of the target logical replication slot is a first identifier. The synchronization subunit is used to determine, in the second database, the second replication slot information corresponding to the first replication slot information of the target logical replication slot based on the first physical log from the first database.
14. The apparatus according to claim 13, characterized in that, The first physical log generation unit includes: The type determination unit is used to determine the type of the first physical log as a preset type in the write-ahead log type if the synchronizeable identifier of the target logical replication slot is a first identifier. The first physical log generation subunit is used to generate the first physical log corresponding to the first replication slot information based on the first replication slot information and the preset type.
15. The apparatus according to claim 13, characterized in that, The synchronization subunit includes: An update type determination unit is used to determine the update type of the target logical replication slot in the second database based on the first physical log; The second replication slot information determination unit is configured to: if the update type is "create", create the target logical replication slot according to the first physical log, and determine the second replication slot information of the target logical replication slot in the second database; if the update type is "modify", modify the historical replication slot information of the target logical replication slot in the second database according to the first physical log to obtain the second replication slot information; if the update type is "delete", clear the historical replication slot information of the target logical replication slot according to the first physical log, so that the second replication slot information of the target logical replication slot corresponding to the first replication slot information is empty.
16. The apparatus according to claim 12, characterized in that, The synchronization unit includes: The process synchronization unit is used to obtain the first replication slot information through the synchronization process of the second database if the synchronizeable identifier of the target logical replication slot is a first identifier, and to synchronize the second replication slot information of the target logical replication slot in the second database according to the first replication slot information.
17. The apparatus according to claim 16, characterized in that, The device further includes: The disk storage unit is used to store the first replication slot information into the first local storage space of the first database through the first database; The process synchronization unit is specifically used for: If the synchronizeable identifier of the target logical replication slot is a first identifier, the first replication slot information is obtained from the first local storage space through the synchronization process of the second database, and the second replication slot information of the target logical replication slot is obtained synchronously in the second database based on the first replication slot information.
18. The apparatus according to any one of claims 12-17, characterized in that, The device further includes: The second physical log generation unit is used to generate a second physical log based on the update information of the target content when the target content corresponding to the target logical replication slot in the first database is updated. A logical log generation unit is used to generate a target logical log based on the first replication slot information and the second physical log indicated by the first replication slot information, wherein the second physical log and the target logical log have the same log sequence identifier; A logical log sending unit is used to send a logical log sequence including the target logical log to the subscriber corresponding to the target logical replication slot, so as to provide data services to the subscriber. The physical log sending unit is used to send a physical log sequence, including the second physical log, to the second database through the first database.
19. The apparatus according to claim 18, characterized in that, The data service providing unit includes: The sequence identifier determination unit is used to determine the sending sequence identifier of the latest sent log in the logical log sequence and the receiving sequence identifier of the latest received log in the physical log sequence obtained by the second database from the first database if the first database fails. A data service providing subunit is used to provide data services to the subscriber corresponding to the target logical replication slot through the second database, based on the second replication slot information and the second physical log indicated by the second replication slot information in the second database, if the sending sequence identifier is earlier than the receiving sequence identifier, or the sending sequence identifier is the same as the receiving sequence identifier. The device further includes: The reminder unit is used to send a logical replication failure reminder to the subscriber if the sending sequence identifier is later than the receiving sequence identifier; The third replication slot information determination unit is used to determine the third replication slot information of the target logical replication slot in response to a logical replication instruction from the subscriber. Other data service providing units are used to provide data services to the subscribers corresponding to the target logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database.
20. The apparatus according to claim 19, characterized in that, The third replication slot information determination unit includes: A copy slot deletion unit is configured to delete the target logical copy slot in response to a logical copy instruction, including a copy slot deletion instruction, from the subscriber. The replication slot creation unit is used to create a new logical replication slot in the second database that is associated with the data content corresponding to the target logical replication slot; The third replication slot information determination subunit is used to determine that the information of the newly created logical replication slot is the third replication slot information; The device further includes: The data content sending unit is used to send the data content corresponding to the newly created logical replication slot to the subscriber corresponding to the newly created logical replication slot before providing data services to the subscriber corresponding to the target logical replication slot through the second database based on the third replication slot information and the second physical log indicated by the third replication slot information in the second database.
21. The apparatus according to claim 19, characterized in that, The third replication slot information determination unit includes: The third replication slot information determination subunit is used to determine the third replication slot information of the target logical replication slot based on the received sequence identifier in response to a logical replication indication, including a continue logical replication indication, from the subscriber.
22. The apparatus according to any one of claims 12-17, characterized in that, The replication slot information determination unit is specifically used for: After the target logical replication slot is established in the first database through the replication slot establishment plugin, the initial information of the target logical replication slot is determined to be the first replication slot information. The replication slot establishment plugin is also used to set the synchronization identifier of the target logical replication slot. Alternatively, after deleting the target logical copy slot from the first database via the copy slot plugin, it is determined that the first copy slot information of the target logical copy slot is empty.
23. A computer device, characterized in that, The computer device includes a processor and memory: The memory is used to store computer programs and to transfer the computer programs to the processor; The processor is configured to execute the synchronization method of the logical replication slot according to any one of claims 1-11, based on instructions in the computer program.
24. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program for performing the synchronization method of the logical replication slot as described in any one of claims 1-11.
25. A computer program product comprising a computer program, characterized in that, When it is run on a computer device, it causes the computer device to perform the synchronization method of the logical replication slot as described in any one of claims 1-11.
Citation Information
Patent Citations
Data synchronization method and system between databases, electronic equipment and storage medium
CN115329007A
Transaction consistency query support for replicated data from recovery log to external data stores
US20170351585A1
