花开不停 花开不停
首页
  • 追忆杂谈
  • 书信往来
  • 旅行记录
  • 文定之喜
  • 黄金屋-颜如玉
  • 程序化广告
  • 禅茶一味
  • 随写编年
  • 家人物语
  • 追忆青春
  • 大千世界
  • Shell
  • Java
  • Spark
  • Hadoop
  • ClickHouse
  • MySQL
  • PostgreSQL
  • MongoDB
  • 调度器
  • Zookeeper
  • Kafka
  • Flume
  • 学习周刊
关于
  • 分类
  • 标签
  • 归档
开往 (opens new window)

花开不停

此心光明,亦复何言
首页
  • 追忆杂谈
  • 书信往来
  • 旅行记录
  • 文定之喜
  • 黄金屋-颜如玉
  • 程序化广告
  • 禅茶一味
  • 随写编年
  • 家人物语
  • 追忆青春
  • 大千世界
  • Shell
  • Java
  • Spark
  • Hadoop
  • ClickHouse
  • MySQL
  • PostgreSQL
  • MongoDB
  • 调度器
  • Zookeeper
  • Kafka
  • Flume
  • 学习周刊
关于
  • 分类
  • 标签
  • 归档
开往 (opens new window)
  • Shell编程

  • Java编程笔记

  • Spark

  • Hadoop

  • ClickHouse

  • MySQL

  • PostgreSQL

    • PostgreSQL安装部署
    • postgreSQL
    • ClickHouse对PG进行数据备份
      • 1. 介绍
      • 2. 备份流程
        • 2.1 ClickHouse创建临时数据表
        • 2.2数据导入
        • 2.3数据查询
  • MongoDB

  • 调度器

  • Zookeeper

  • Kafka

  • Flume

  • 编程世界
  • PostgreSQL
花开不停
2023-12-07
目录

ClickHouse对PG进行数据备份原创

# PostgreSQL数据备份教程

# 1. 介绍

  • 本文为您介绍通过ClickHouse对PostgreSQL数据库进行数据备份(冷备数据存放至COS)

  • 冷备地址:COS对象存储-qianyi-backup:/history_db/{db_name}/{table_name}/{data_time}/data_{timestamp}.csv

# 2. 备份流程

# 2.1 ClickHouse创建临时数据表

  • 每次备份都需要删除历史临时表,创建新临时表;
--临时表删除
drop table IF EXISTS dmp_test.temp_platformdb_creative_tracker_sync_history ON CLUSTER default_cluster ;

--临时表创建
CREATE TABLE IF NOT EXISTS dmp_test.temp_platformdb_creative_tracker_sync_history ON CLUSTER default_cluster
(
    record_id           Nullable(String)  ,
    creative_id         Nullable(String)  ,
    state               Nullable(String)  ,
    logged_on           Nullable(String)  ,
    created_by          Nullable(String)  ,
    created_on          Nullable(String)  ,
    retry_times         Nullable(String)  ,
    identify            Nullable(String)  ,
    trigger_type        Nullable(String)  
) 
ENGINE=S3(concat('http://qianyi-backup-1305502582.cos.ap-shanghai.myqcloud.com/history_db/platformdb/creative_tracker_sync_history/',toString(today()),'/data_',toString(toUnixTimestamp(now())),'.csv'), 'CSV');

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 2.2数据导入

  • 通过ClickHouse表函数postgresql() 连接PostgreSQL 表,进行查询导入;
-- 表函数 postgresql('host:5432', 'db_name', 'table_name', 'user_name', 'password') 
insert into dmp_test.temp_platformdb_creative_tracker_sync_history
select *
from postgresql('10.80.16.9:5432', 'platformdb', 'creative_tracker_sync', 'wayio', 'HsQ9tE3C') limit 100 ;
1
2
3
4

# 2.3数据查询

  • 新建备份数据查询(一次创建,后续有新备份数据可直接检索出来);
-- 新建备份数据表(正式表,一次创建)
CREATE TABLE IF NOT EXISTS dmp_test.platformdb_creative_tracker_sync_history ON CLUSTER default_cluster
(
    record_id           Nullable(String)  ,
    creative_id         Nullable(String)  ,
    state               Nullable(String)  ,
    logged_on           Nullable(String)  ,
    created_by          Nullable(String)  ,
    created_on          Nullable(String)  ,
    retry_times         Nullable(String)  ,
    identify            Nullable(String)  ,
    trigger_type        Nullable(String)  
) 
ENGINE=S3('http://qianyi-backup-1305502582.cos.ap-shanghai.myqcloud.com/history_db/platformdb/creative_tracker_sync_history/*/data_*.csv', 'CSV');

-- 备份数据查询
select * from dmp_test.platformdb_creative_tracker_sync_history limit 100;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
上次更新: 2024/06/28, 14:46:16

← postgreSQL MongoDB数据导出→

最近更新
01
2025-05-26当我意识到我变得自私、暴躁、情绪不受控制 原创
05-26
02
clickhouse版本升级的语法变动21.8.9.1至23.8.9.1 原创
04-22
03
2025-03-28拍婚纱照 原创
04-02
更多文章>
Theme by Vdoing | Copyright © 2023-2025 | 京ICP备2023013437号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式