Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deepening and questioning in the study of PostgreSQL logical replication

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the PostgreSQL logic replication learning in-depth and questions, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

First of all, in the early stage of logical replication, before PG10, its function was realized through plug-ins, and it was merged into the database system by PG10.

The main problem solved by logical replication (is a problem that physical replication cannot or is difficult to solve)

1 table-level replication

2 the structure of the master-slave data table is conditionally inconsistent

(3) filter the copied data and only copy INSERT, or UPATE and other operations.

4 data from different libraries in the same cluster is copied to another library

If physical replication deals with data synchronization, database availability, and read-write separation. Logical replication should address the need to be closer to the business or to satisfy data synchronization in more fine-grained business scenarios.

Logical copy schematic diagram

Before that, there was a text that logically copied and output data in other formats. In the following picture, we found its level and mechanism.

In viewing the document, the following picture, one of which is not quite understood, is generated in the decoding.

What is the meaning between tuplebuf * oldtuple and tuplebuf * newtuple

What is the other BDR in the figure? here we dig again. BDR is an asynchronous multi-host logical replication function provided by 2quadrant.

He defines the following four concepts

Mulit-master, asynchronous, logical, replication

They define replication as the process of copying data from one place to another. In BDR, BDR is not a shared storage architecture; each node has its own copy of the database, including all related indexes, and so on. Nodes can satisfy queries without communicating with other nodes, but there must also be enough storage space to hold all the data in the database

Logical replication (row-based) is replicated using a single row value. It contrasts with physical (block-based) replication that sends block changes.

Changes made to one BDR node are not copied to other nodes until they are committed locally. Therefore, the data on all nodes is not exactly the same at any given time; some nodes will have data that has not yet reached other nodes. PostgreSQL's block-based replication solution also defaults to asynchronous replication.

From what we have learned and learned above, there are two modules of logical replication at some level.

DBR + decode + decode send + external receive several parts.

We already know where DBR came from and what happened to decording. Let's talk about it.

The whole process of decording starts with the transaction corresponding to the LSN number after the last reading. If there is no log in the cache, the log will be read in the log segment on disk and stored in the structure xlogrecord. Then decode will be performed in the logicaldecodingprocess record module, and then the log will be parsed in a loop.

LogicalDecodingProcessRecord is the key to parsing the log, in which a hash table is maintained in memory to store the transaction information being processed. In processing each log record, if a begin operation is encountered, the corresponding transaction will be inserted in the hash table. In the event of commit, all statements of the whole transaction will be parsed, and each transaction will have a snapshot. Update the snapshot every time the transaction is done, and wait until the transaction commit to get the latest snapshot. F according to the post system table, get the relationship information between relation node id and relation name, so as to complete the Decode. After completing the Decode, it will call the RecorderBuffercommit function, through which the apply_change function will print the log information into the exportable content, and finally complete the whole Decode process.

Thank you for reading this article carefully. I hope the article "in-depth and questions in PostgreSQL Logic replication Learning" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report