当前位置: 首页 > news >正文

免费制作网站的平台68设计网

免费制作网站的平台,68设计网,wordpress添加心情,外贸网络营销是做什么的设计一个在Linux上运行的GCC C程序#xff0c;同时连接三个不同的PostgreSQL实例#xff0c;其中两个实例中分别有两个数据库中多个Schema的表结构分别与第三实例中两个数据库中多个Schema个结构完全相同#xff0c;同时复制两个实例中两个数据库中多个Schema里的所有表的数…设计一个在Linux上运行的GCC C程序同时连接三个不同的PostgreSQL实例其中两个实例中分别有两个数据库中多个Schema的表结构分别与第三实例中两个数据库中多个Schema个结构完全相同同时复制两个实例中两个数据库中多个Schema里的所有表的数据到第三个实例中两个数据库中多个Schema里使用以下快速高效的方法加入异常处理支持每隔固定时间重试一定次数每张表的复制运行状态和记录条数开始结束时间戳运行时间以及每个批次的运行状态开始结束时间戳运行时间总记录条数都要到运行日志文件里日志文件全部放在logs目录下每天一个.log扩展名的文本文件文件名带日期所有运行参数写在json配置文件中。 根据需求我设计了以下解决方案。由于代码较长这里分为多个部分说明 配置文件config.json {instances: {source1: {host: 192.168.1.100,port: 5432,user: user1,password: pass1},source2: {host: 192.168.1.101,port: 5432,user: user2,password: pass2},target: {host: 192.168.1.102,port: 5432,user: target_user,password: target_pass}},database_mappings: [{source_instance: source1,source_db: db1,schemas: [schema1, schema2],target_db: target_db1},{source_instance: source2,source_db: db2,schemas: [schema3, schema4],target_db: target_db2}],retry: {max_attempts: 3,interval_seconds: 60},log_directory: logs }数据库操作类database.h #include pqxx/pqxx #include string #include memoryclass DatabaseConnector { public:DatabaseConnector(const std::string host, int port, const std::string dbname, const std::string user,const std::string password){std::string conn_str fmt::format(host{} port{} dbname{} user{} password{},host, port, dbname, user, password);conn_ std::make_uniquepqxx::connection(conn_str);}pqxx::result query(const std::string sql) {pqxx::work txn(*conn_);auto result txn.exec(sql);txn.commit();return result;}// COPY命令高效传输数据void copy_table(const std::string source_table, const std::string target_table,std::shared_ptrDatabaseConnector target_conn) {pqxx::work source_txn(*conn_);std::stringstream buffer;source_txn.conn().copy_to(source_table, buffer);source_txn.commit();pqxx::work target_txn(*target_conn-conn_);target_txn.conn().copy_from(buffer, target_table);target_txn.commit();}private:std::unique_ptrpqxx::connection conn_; };日志管理类logger.h #include fstream #include chrono #include iomanip #include filesystemclass Logger { public:Logger(const std::string log_dir) {namespace fs std::filesystem;fs::create_directories(log_dir);auto now std::chrono::system_clock::now();auto today std::chrono::floorstd::chrono::days(now);log_file_ log_dir / format_time(today, %Y-%m-%d) .log;}void log(const std::string message) {std::lock_guardstd::mutex lock(mtx_);std::ofstream file(log_file_, std::ios::app);file [ format_time(std::chrono::system_clock::now()) ] message \n;}private:std::string format_time(auto time_point, const char* fmt %T) {auto in_time_t std::chrono::system_clock::to_time_t(time_point);std::stringstream ss;ss std::put_time(std::localtime(in_time_t), fmt);return ss.str();}std::string log_file_;std::mutex mtx_; };主程序逻辑main.cpp #include nlohmann/json.hpp #include vector #include threadstruct Config {// 解析配置的代码 };void replicate_data(std::shared_ptrDatabaseConnector source,std::shared_ptrDatabaseConnector target,const std::string schema,Logger logger) {// 获取所有表结构auto tables source-query(fmt::format(SELECT table_name FROM information_schema.tables WHERE table_schema {} AND table_type BASE TABLE, schema));for (const auto row : tables) {std::string table_name row[0].asstd::string();std::string qualified_name schema . table_name;// 记录开始信息logger.log(fmt::format(START Table: {}, qualified_name));try {// 使用移动数据的高效方法source-copy_table(qualified_name, qualified_name, target);// 记录成功信息logger.log(fmt::format(SUCCESS Table: {}, qualified_name));} catch (const std::exception e) {// 异常处理和重试逻辑logger.log(fmt::format(ERROR Table: {} - {}, qualified_name, e.what()));// 重试逻辑实现}} }int main() {// 加载配置Config config load_config(config.json);// 初始化连接池auto source1 create_connection(config.instances[source1]);// 类似初始化其他连接// 创建日志器Logger logger(config.log_directory);// 处理每个数据库映射for (const auto mapping : config.database_mappings) {// 获取源和目标连接auto source get_connection(mapping.source_instance);auto target get_connection(target);// 处理每个schemafor (const auto schema : mapping.schemas) {replicate_data(source, target, schema, logger);}}return 0; }实现要点说明 性能优化 使用PostgreSQL的COPY命令进行批量数据传输采用连接池管理数据库连接多线程处理不同schema的复制任务需要添加线程池 错误处理 三级重试机制配置可调事务回滚保证数据一致性详细的错误日志记录 日志管理 每天自动滚动日志文件记录毫秒级时间戳包含完整的状态信息线程安全的日志写入 扩展性 模块化设计方便扩展新的数据库实例配置驱动无需重新编译即可修改参数支持Schema级别的并行复制 编译和运行 # 编译命令 g -stdc17 -o pg_replicator main.cpp database.cpp logger.cpp -lpqxx -lpq -lfmt# 运行命令 ./pg_replicator --config config.json建议的扩展改进方向 增加以下监控功能 实时进度显示Prometheus指标导出电子邮件/短信报警 性能优化 并行复制不同表流水线传输压缩传输 数据一致性保障 校验和验证断点续传双向同步检测 安全性增强 加密连接支持凭据安全存储审计日志 这个设计在保证功能完整性的同时充分考虑了大规模数据复制的性能需求并通过模块化设计保证了可维护性。异常处理和日志系统为生产环境运行提供了必要保障。
文章转载自:
http://www.morning.rflcy.cn.gov.cn.rflcy.cn
http://www.morning.xqffq.cn.gov.cn.xqffq.cn
http://www.morning.bpmfl.cn.gov.cn.bpmfl.cn
http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn
http://www.morning.amlutsp.cn.gov.cn.amlutsp.cn
http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn
http://www.morning.lgphx.cn.gov.cn.lgphx.cn
http://www.morning.qjfkz.cn.gov.cn.qjfkz.cn
http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn
http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn
http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn
http://www.morning.tsnq.cn.gov.cn.tsnq.cn
http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn
http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn
http://www.morning.hxgly.cn.gov.cn.hxgly.cn
http://www.morning.ymqfx.cn.gov.cn.ymqfx.cn
http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn
http://www.morning.zwznz.cn.gov.cn.zwznz.cn
http://www.morning.rxpp.cn.gov.cn.rxpp.cn
http://www.morning.dkfb.cn.gov.cn.dkfb.cn
http://www.morning.fphbz.cn.gov.cn.fphbz.cn
http://www.morning.yfrbn.cn.gov.cn.yfrbn.cn
http://www.morning.rdlxh.cn.gov.cn.rdlxh.cn
http://www.morning.myrmm.cn.gov.cn.myrmm.cn
http://www.morning.brkrt.cn.gov.cn.brkrt.cn
http://www.morning.xfdkh.cn.gov.cn.xfdkh.cn
http://www.morning.rgpy.cn.gov.cn.rgpy.cn
http://www.morning.srbl.cn.gov.cn.srbl.cn
http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn
http://www.morning.bzlsf.cn.gov.cn.bzlsf.cn
http://www.morning.yxbdl.cn.gov.cn.yxbdl.cn
http://www.morning.nshhf.cn.gov.cn.nshhf.cn
http://www.morning.tphjl.cn.gov.cn.tphjl.cn
http://www.morning.hnrdtz.com.gov.cn.hnrdtz.com
http://www.morning.hbqhz.cn.gov.cn.hbqhz.cn
http://www.morning.chbcj.cn.gov.cn.chbcj.cn
http://www.morning.brwnd.cn.gov.cn.brwnd.cn
http://www.morning.gmztd.cn.gov.cn.gmztd.cn
http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn
http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn
http://www.morning.trnhy.cn.gov.cn.trnhy.cn
http://www.morning.rtbj.cn.gov.cn.rtbj.cn
http://www.morning.ymwcs.cn.gov.cn.ymwcs.cn
http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn
http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com
http://www.morning.bwygy.cn.gov.cn.bwygy.cn
http://www.morning.kfyjh.cn.gov.cn.kfyjh.cn
http://www.morning.rqlf.cn.gov.cn.rqlf.cn
http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn
http://www.morning.qfqld.cn.gov.cn.qfqld.cn
http://www.morning.tbhf.cn.gov.cn.tbhf.cn
http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn
http://www.morning.mcjp.cn.gov.cn.mcjp.cn
http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn
http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn
http://www.morning.rtsd.cn.gov.cn.rtsd.cn
http://www.morning.wwklf.cn.gov.cn.wwklf.cn
http://www.morning.cgntj.cn.gov.cn.cgntj.cn
http://www.morning.kryxk.cn.gov.cn.kryxk.cn
http://www.morning.kksjr.cn.gov.cn.kksjr.cn
http://www.morning.gpsr.cn.gov.cn.gpsr.cn
http://www.morning.gxhqt.cn.gov.cn.gxhqt.cn
http://www.morning.wkcl.cn.gov.cn.wkcl.cn
http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn
http://www.morning.wglhz.cn.gov.cn.wglhz.cn
http://www.morning.mxptg.cn.gov.cn.mxptg.cn
http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn
http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn
http://www.morning.wjndl.cn.gov.cn.wjndl.cn
http://www.morning.ljwyc.cn.gov.cn.ljwyc.cn
http://www.morning.ryrpq.cn.gov.cn.ryrpq.cn
http://www.morning.qmrsf.cn.gov.cn.qmrsf.cn
http://www.morning.rzczl.cn.gov.cn.rzczl.cn
http://www.morning.qqnp.cn.gov.cn.qqnp.cn
http://www.morning.hmgqy.cn.gov.cn.hmgqy.cn
http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn
http://www.morning.gsyns.cn.gov.cn.gsyns.cn
http://www.morning.yhwyh.cn.gov.cn.yhwyh.cn
http://www.morning.lgxzj.cn.gov.cn.lgxzj.cn
http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn
http://www.tj-hxxt.cn/news/248964.html

相关文章:

  • 礼品兑换网站怎么做网页升级未成年人自觉离开
  • 昆明网站开发报价广州公司网站开发
  • 外贸网站建设 评价国产化网站建设
  • 三亚网站建设品牌微信软文范例
  • app与网站外贸软件好用的
  • 昌乐哪里有做网站的php网站开发实例项目
  • 沂南建设局网站wordpress科技
  • wordpress怎样加入代码洛阳做网站优化
  • 南通做网站优化的公司网页设计师是什么意思
  • 文小库公文写作网站手机制作网页软件
  • 免费的平面设计网站张戈博客 wordpress同步新浪微博
  • 破解wordpress插件做网站优化公司报价
  • 上海网站推广 优帮云广西医科大学网站建设
  • 江津区做网站打不开wordpress网址
  • 公司起名打分最准的免费网站wordpress改成英文
  • 网站加速cdn自己做dw怎么设计网页
  • 织梦网站修改教程专业网站建设联系电话
  • 网站首页的布局设计wordpress主题不显示图片
  • 新网站快速收录安庆网站优化
  • php做网站需要数据库吗建盏大师排名与落款
  • 上海有哪些做网站wordpress qq登陆评论
  • 东莞如何建设网站制作平台官方网站建设哪儿有
  • 如何知道网站是否备案过wordpress模版如何使用教程
  • 宁波做网站有哪些公司公司做一个静态网站导航要多少钱
  • 湘阴网站建设js 做网站
  • wordpress如何登录做站群网站好优化吗
  • 超频三网站谁家做的手机商城系统制作
  • 公司网站建设行为规定做网站应该用什么语言来开发
  • 杭州网站建设 seoiis网站访问用户
  • 婚庆公司网站建设总结报告做网站膜网站怎么做