MySQL 數據遷移Postgresql(openGuass) 之 pg_chameleon

1 pg_chameleon 介紹
pgchameleon 是一款MySQL 到 PostgreSQL/openGuass 的復制工具。


pg_chameleon 使用場景:
1)分析
2)遷移
3)對多個MySQL 數據庫進行數據聚合?


操作系統信息
(myenv) root@u24-pg-60:~# cat /etc/issue
Ubuntu 24.04.2 LTS \n \l

2 主機列表
192.168.254.50 ? #mysql源庫
192.168.254.60 ? #Postgresql 目標數據庫
192.168.254.61 ? #安裝pg_chameleon


3 mysql 數據庫環境準備(192.168.254.50)
vi /etc/my.cnf
binlog_format = ROW ? ? ? ??
binlog_rows_query_log_events = on
binlog_row_image = full
binlog_row_metadata = full
binlog_row_image = full
autocommit = on


使用pg_chameleon創建用于配置復制的用戶,并使用以下步驟為用戶提供適當的權限.
$ mysql -uroot -p123456
create user 'repuser'@'%' identified by 'repuser123';
GRANT ALL ON *.* TO 'repuser'@'%';
GRANT RELOAD,REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repuser'@'%';
FLUSH PRIVILEGES;

#源數據準備
mysql> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| itpux ? ? ? ? ? ? ?|
| itpux01 ? ? ? ? ? ?|
| itpux02 ? ? ? ? ? ?|
| itpux03 ? ? ? ? ? ?|
| mydb ? ? ? ? ? ? ? |
| mysql ? ? ? ? ? ? ?|
| performance_schema |
| sys ? ? ? ? ? ? ? ?|
+--------------------+


4 Postgresql 環境準備(192.168.254.60)
在PostgreSQL中創建一個用戶,pg_Chameleon可以使用該用戶將更改的數據寫入PostgreSQL.還要創建目標數據庫.
$psql -U postgres?
CREATE USER repuser WITH ENCRYPTED PASSWORD 'repuser123';
CREATE DATABASE mydb WITH OWNER repuser;


5 安裝pg_chameleon(192.168.254.61)
#apt install python3-pip -y

#root 用戶無法啟動pg_chameleon
su - postgres ? ?
python3 -m venv myenv
source myenv/bin/activate
pip install --upgrade setuptools
pip install pg_chameleon

將示例配置文件復制到另一個文件,例如default.yml
cd .pg_chameleon/configuration
cp config-example.yml default.yml

修改default.yml

# postgres ?destination connection
pg_conn:
? host: "192.168.254.60" ?
? port: "5432"
? user: "repuser"
? password: "repuser123"
? database: "mydb"
? charset: "utf8"

sources:
? mysql:
? ? db_conn:
? ? ? host: "192.168.254.50"
? ? ? port: "3306"
? ? ? user: "repuser"
? ? ? password: "repuser123"
? ? ? charset: 'utf8'
? ? ? connect_timeout: 10
? ? schema_mappings:
? ? ? itpux: public
? ? ? itpux01: itpux01
? ? ? itpux02: itpux02
? ? ? itpux03: itpux03
? ? limit_tables:
? ? ? - delphis_mediterranea.foo
? ? skip_tables:
? ? ? - delphis_mediterranea.bar
? ? grant_select_to:
? ? ? - usr_readonly
? ? lock_timeout: "120s"
? ? my_server_id: 100
? ? replica_batch_size: 10000
? ? replay_max_rows: 10000
? ? batch_retention: '1 day'
? ? copy_max_memory: "300M"
? ? copy_mode: 'file'
? ? out_dir: /tmp
? ? sleep_loop: 1
? ? on_error_replay: continue
? ? on_error_read: continue
? ? auto_maintenance: "disabled"
? ? gtid_enable: false
? ? type: mysql
? ? skip_events:
? ? ? insert:
? ? ? ? - delphis_mediterranea.foo ?# skips inserts on delphis_mediterranea.foo
? ? ? delete:
? ? ? ? - delphis_mediterranea ?# skips deletes on schema delphis_mediterranea
? ? ? update:
? ? keep_existing_schema: No
? ? net_read_timeout: 600


參數說明:

#目標Postgresql數據庫配置(192.168.254.61)
pg_conn:
? host: "192.168.254.60" ? #主機
? port: "5432" ? ? ? ? ? ? #端口
? user: "repuser"?? ??? ? ? #用戶
? password: "repuser123" ? #密碼
? database: "mydb"?? ??? ? ? #數據庫
? charset: "utf8"?? ??? ? ? #編碼


#源數MySQL據庫(192.168.254.50)

sources:
? mysql:
? ? db_conn:
? ? ? host: "192.168.254.50" ? #主機
? ? ? port: "3306"?? ??? ??? ? ? #端口
? ? ? user: "repuser"?? ??? ? ? #用戶
? ? ? password: "repuser123" ? #密碼
? ? ? charset: 'utf8'?? ??? ? ? #編碼?? ??? ?
? ? ? connect_timeout: 10 ? ? ?#連接超時
? ? schema_mappings: ? ? ? ? ??
? ? ? itpux: public ? ? ? ? ? ?#mysql的itpux庫 對應Postgresql的mydb庫public schema
? ? ? itpux01: itpux01?? ??? ? ? #mysql的itpux01庫 對應Postgresql的mydb庫itpux01 schema
? ? ? itpux02: itpux02?? ??? ? ? #mysql的itpux02庫 對應Postgresql的mydb庫itpux02 schema
? ? ? itpux03: itpux03?? ??? ? ? #mysql的itpux03庫 對應Postgresql的mydb庫itpux03 schema

#開始數據庫遷移操作步驟
1 初始化副本(在192.168.254.61 ? #安裝pg_chameleon)
命令:
chameleon create_replica_schema --debug


在Postgresql目標庫查看(192.168.254.60)
上面的命令在.pg_chameleon/configuration/default.yml文件中指定的PostgreSQL數據庫中創建一個模式和13個表,
需要這些表來管理從源到目標的復制.在以下日志中可以觀察到相同的情況.

$psql
\dt sch_chameleon.t_*
mydb=# \dt sch_chameleon.*
? ? ? ? ? ? ? ? ? ? List of relations
? ? Schema ? ? | ? ? ? ? Name ? ? ? ? ?| Type ?| ?Owner ?
---------------+-----------------------+-------+---------
?sch_chameleon | t_batch_events ? ? ? ?| table | repuser
?sch_chameleon | t_discarded_rows ? ? ?| table | repuser
?sch_chameleon | t_error_log ? ? ? ? ? | table | repuser
?sch_chameleon | t_fkeys ? ? ? ? ? ? ? | table | repuser
?sch_chameleon | t_indexes ? ? ? ? ? ? | table | repuser
?sch_chameleon | t_last_received ? ? ? | table | repuser
?sch_chameleon | t_last_replayed ? ? ? | table | repuser
?sch_chameleon | t_log_replica ? ? ? ? | table | repuser
?sch_chameleon | t_log_replica_mysql_1 | table | repuser
?sch_chameleon | t_log_replica_mysql_2 | table | repuser
?sch_chameleon | t_pkeys ? ? ? ? ? ? ? | table | repuser
?sch_chameleon | t_replica_batch ? ? ? | table | repuser
?sch_chameleon | t_replica_tables ? ? ?| table | repuser
?sch_chameleon | t_sources ? ? ? ? ? ? | table | repuser
?sch_chameleon | t_ukeys ? ? ? ? ? ? ? | table | repuser
(15 rows)


2 指定源詳細信息(在192.168.254.61 ? #安裝pg_chameleon)
使用以下命令將源詳細信息添加到pg_chameleon.提供配置文件中指定的源名稱。
在此示例中,源名稱為mysql,目標是在pg_conn下定義的postgreSQL數據庫.
命令:
chameleon add_source --config default --source mysql --debug
chameleon show_status --config default


在Postgresql目標庫查看(192.168.254.60)
運行完上述命令后,查看表t_sources即可看到源詳細信息已添加到表t_sources中.
\x
select * from sch_chameleon.t_sources;
mydb=# select * from sch_chameleon.t_sources;
-[ RECORD 1 ]-------+--------------------------------------------------------------------------------------
i_id_source ? ? ? ? | 1
t_source ? ? ? ? ? ?| mysql
jsb_schema_mappings | {"itpux": "public", "itpux01": "itpux01", "itpux02": "itpux02", "itpux03": "itpux03"}
enm_status ? ? ? ? ?| initialised
t_binlog_name ? ? ? | mysql-bin.000008
i_binlog_position ? | 14868456
b_consistent ? ? ? ?| f
b_paused ? ? ? ? ? ?| f
b_maintenance ? ? ? | f
ts_last_maintenance |?
enm_source_type ? ? | mysql
v_log_table ? ? ? ? | {t_log_replica_mysql_2,t_log_replica_mysql_1}


3 初始化目標庫
命令:
chameleon init_replica --config default --source mysql --debug

#一下日志表示完成遷移
2025-05-28 20:39:27 MainProcess INFO pg_lib.py (3464): Set high watermark for source: mysql
2025-05-28 20:39:27 MainProcess INFO mysql_lib.py (1590): init replica for source mysql is complete

在Postgresql目標庫查看(192.168.254.60)
檢查數據是否已經遷移
mydb=# \dn
? ? ?List of schemas
? ? ?Name ? ? ?| ?Owner ?
---------------+---------
?itpux01 ? ? ? | repuser
?itpux02 ? ? ? | repuser
?itpux03 ? ? ? | repuser
?public ? ? ? ?| repuser
?sch_chameleon | repuser
(5 rows)


mydb=# \dt public.*
? ? ? ? ?List of relations
?Schema | ?Name ? | Type ?| ?Owner ?
--------+---------+-------+---------
?public | itpux01 | table | repuser
?public | itpux02 | table | repuser
?public | itpux03 | table | repuser
?public | test ? ?| table | repuser

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/82812.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/82812.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/82812.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spark 中,map和foreach的區別

在 Spark 中,map和foreach是兩種不同用途的轉換操作,主要區別在于: 1. 操作類型與返回值 map:是轉換操作(Transformation),返回一個新的 RDD。foreach:是行動操作(Acti…

More SQL(Focus Subqueries、Join)

目錄 Subqueries Subqueries That Return One Tuple Subqueries and Self Connection The IN Operator The Exists Operator The Operator ANY The Operator ALL Union, Intersection, and Difference(交并差) Bag Semantics Controlling Dupl…

OpenGL Chan視頻學習-4 Vertex Buffers and Drawing a Triangle in OpenGL

一、視頻鏈接 【最好的OpenGL教程之一】https://www.bilibili.com/video/BV1MJ411u7Bc?p5&vd_source44b77bde056381262ee55e448b9b1973 二、相關網站 docs.gl 三、代碼整理 c #include <GL/glew.h> #include <GLFW/glfw3.h>#include<iostream>int…

WSL中ubuntu通過Windows帶代理訪問github

WSL中ubuntu通過Windows帶代理訪問github 前言: WSL是Windows下的ubuntu訪問工具&#xff0c;目前無法訪問外網&#xff0c;因此需要配置一下。 步驟一 代理中進行如下設置: 步驟二 ubuntu22.04中修改配置 使用如下命令獲取IP地址&#xff1a; ip route | grep default | aw…

為(FramePack)的視頻生成添加首尾幀功能

文章目錄 &#xff08;一&#xff09;前言&#xff08;二&#xff09;可選的尾幀&#xff08;三&#xff09;測試&#xff08;四&#xff09;例子 &#xff08;一&#xff09;前言 前提是這個&#xff1a;《筆記本6GB本地可跑的圖生視頻項目&#xff08;FramePack&#xff09;…

C語言中:遞歸問題的深入研究

C語言中&#xff1a;遞歸問題的深入研究 函數的遞歸有兩個限制條件&#xff1a; 1.遞歸存在限制條件&#xff0c;當滿?這個限制條件的時候&#xff0c;遞歸便不再繼續。 2.每次遞歸調?之后越來越接近這個限制條件。 例子&#xff1a; #include <stdio.h> int main…

《C++20新特性全解析:模塊、協程與概念(Concepts)》

引言&#xff1a;C20——現代C的里程碑 C20是繼C11之后最具革命性的版本&#xff0c;它通過模塊&#xff08;Modules&#xff09;、協程&#xff08;Coroutines&#xff09;和概念&#xff08;Concepts&#xff09;三大核心特性&#xff0c;徹底改變了C的代碼組織方式、并發模…

xcode卡死問題,無論打開什么程序xcode總是在轉菊花,重啟電腦,卸載重裝都不行

很可能是因為我們上次沒有正常關閉Xcode&#xff0c;而Xcode保留了上次錯誤的一些記錄&#xff0c;而這次打開Xcode依然去加載錯誤的記錄&#xff0c;所以必須完全刪除這些記錄Xcode才能加載正常的項目。 那么也就是說&#xff0c;我們是不是只需要刪除這部分錯誤記錄文件就可以…

華為云Flexus+DeepSeek征文|華為云Flexus云服務器X實例上部署Dify:打造高效的開源大語言模型應用開發平臺

目錄 前言 1 Dify與華為云部署概述 1.1 什么是 Dify 1.2 華為云與 Flexus 云服務器的優勢 2 云服務器部署 Dify 的步驟詳解 2.1 模板選擇 2.2 參數配置 2.3 資源棧設置 2.4 確認部署信息并執行 3 部署成功后的操作與平臺使用指南 3.1 訪問平臺 3.2 設置管理員賬號 …

物流項目第九期(MongoDB的應用之作業范圍)

本項目專欄&#xff1a; 物流項目_Auc23的博客-CSDN博客 建議先看這期&#xff1a; MongoDB入門之Java的使用-CSDN博客 需求分析 在項目中&#xff0c;會有兩個作業范圍&#xff0c;分別是機構作業范圍和快遞員作業范圍&#xff0c;這兩個作業范圍的邏輯是一致的&#xf…

網絡拓撲如何跨網段訪問

最近領導讓研究下跟甲方合同里的&#xff0c;跨網段訪問怎么實現&#xff0c;之前不都是運維網工干的活么&#xff0c;看來裁員裁到動脈上了碰到用人的時候找不到人了&#xff0c; 只能趕鴨子上架讓我來搞 IP 網絡中&#xff0c;不同網段之間的通信需要通過路由器&#xff0c;…

【前端】PWA

目錄 概述實戰vue項目問題匯總 PWA&#xff08;漸進式 Web 應用&#xff0c;Progressive Web App&#xff09; 2015提出 概述 PWA 是一種提升 Web 應用體驗的技術&#xff0c;使其具備與原生應用相似的功能和性能。PWA不僅能夠在網頁上運行&#xff0c;還能在手機或桌面上像傳…

湖北理元理律師事務所:從法律合規到心靈契合的服務升維

債務優化不僅是數字游戲&#xff0c;更是信任重建的過程。湖北理元理律師事務所在實踐中發現&#xff1a;68%的債務糾紛中存在溝通斷裂。為此&#xff0c;機構構建了“三維信任修復機制”。 維度一&#xff1a;信息透明的技術實現 區塊鏈存證艙&#xff1a;客戶手機實時查看律…

香橙派3B學習筆記2:Vscode遠程SSH登錄香橙派_權限問題連接失敗解決

Vscode下載插件&#xff0c;ssh遠程登錄香橙派。 ssh &#xff1a; orangepi本地ip 密碼 &#xff1a; orangepi 安裝 Remote - SSH 擴展SSH插件&#xff1a; SSH遠程連接&#xff1a; ssh usernameremote_host ssh -p port_number usernameremote_host默認22端口號就用第一行…

VMware安裝Ubuntu實戰分享大綱

深入解析快速排序 一、分治策略分解 分解階段&#xff1a; 選擇基準元素 $pivot$將數組劃分為三個子集&#xff1a; $$ left {x | x < pivot} $$ $$ equal {x | x pivot} $$ $$ right {x | x > pivot} $$ 遞歸排序&#xff1a; 對 left 和 right 子集遞歸調用快速排…

AI 讓無人機跟蹤更精準——從視覺感知到智能預測

AI 讓無人機跟蹤更精準——從視覺感知到智能預測 無人機跟蹤技術正在經歷一場前所未有的變革。曾經,我們只能依靠 GPS 或簡單的視覺識別來跟蹤無人機,但如今,人工智能(AI)結合深度學習和高級視覺算法,正讓無人機的跟蹤變得更加智能化、精準化。 尤其是在自動駕駛、安防監…

GATED DELTA NETWORKS : IMPROVING MAMBA 2 WITH DELTA RULE

TL;DR 2024 年 Nvidia MIT 提出的線性Transformer 方法 Gated DeltaNet&#xff0c;融合了自適應內存控制的門控機制&#xff08;gating&#xff09;和用于精確內存修改的delta更新規則&#xff08;delta update rule&#xff09;&#xff0c;在多個基準測試中始終超越了現有…

Laravel單元測試使用示例

Date: 2025-05-28 17:35:46 author: lijianzhan 在 Laravel 框架中&#xff0c;單元測試是一種常用的測試方法&#xff0c;它是允許你測試應用程序中的最小可測試單元&#xff0c;通常是方法或函數。Laravel 提供了內置的測試工具PHPUnit&#xff0c;實踐中進行單元測試是保障代…

【FastAPI】--3.進階教程(二)

【FastAPI】--進階教程1-CSDN博客 【FastAPI】--基礎教程-CSDN博客 目錄 1.FastAPI - CORS ?2.FastAPI - CRUD 操作 2.1.Create 2.2.Read 2.3.Update 2.4.Delete 3.FastAPI - 使用 GraphQL 4.FastAPI - Websockets 5.FastAPI - 事件處理程序 6.FastAPI - 安裝 Fla…

FEMFAT許可的更新與升級流程

隨著工程仿真技術的不斷發展&#xff0c;FEMFAT作為一款領先的疲勞分析軟件&#xff0c;持續為用戶提供卓越的性能和創新的功能。為了保持軟件的最新性和高效性&#xff0c;了解FEMFAT許可的更新與升級流程至關重要。本文將為您詳細介紹FEMFAT許可的更新與升級流程&#xff0c;…