1

基本上我試圖將數據從postgres的傳輸使用AWS datapipeline並且處理向紅移我下面AWS Datapipeline:從RDS數據庫(postgres的)移動數據使用管道

  1. 寫管道(CopyActivity)到紅移從postgres to s3
  2. 移動數據寫管道(RedShiftCopyActivity)從s3 to redshift
在我的情況

因此,無論與我寫的流水線工作完美移動數據,但問題是數據是DUPLI cating在紅移數據庫

例如下面是從Postgres數據庫表中的數據叫company

enter image description here

s3 to redshift(RedShiftCopyActivity)管道中的數據被複制的成功運行後,但它被複製爲以下

enter image description here

下面

是一些定義部分從RedShiftCopyActivity(S3至Redshif t)的管道

pipeline_definition = [{ 
     "id":"redshift_database_instance_output", 
     "name":"redshift_database_instance_output", 
     "fields":[ 
      { 
      "key" : "database", 
      "refValue" : "RedshiftDatabaseId_S34X5", 
      }, 
      { 
      "key" : "primaryKeys", 
      "stringValue" : "id", 
      }, 
      { 
      "key" : "type", 
      "stringValue" : "RedshiftDataNode", 
      }, 
      { 
      "key" : "tableName", 
      "stringValue" : "company", 
      }, 
      { 
      "key" : "schedule", 
      "refValue" : "DefaultScheduleTime", 
      }, 
      { 
      "key" : "schemaName", 
      "stringValue" : RedShiftSchemaName, 
      }, 
     ] 
    }, 
    { 
     "id":"CopyS3ToRedshift", 
     "name":"CopyS3ToRedshift", 
     "fields":[ 
      { 
      "key" : "output", 
      "refValue" : "redshift_database_instance_output", 
      }, 
      { 
      "key" : "input", 
      "refValue" : "s3_input_data", 
      }, 
      { 
      "key" : "runsOn", 
      "refValue" : "ResourceId_z9RNH", 
      }, 
      { 
      "key" : "type", 
      "stringValue" : "RedshiftCopyActivity", 
      }, 
      { 
      "key" : "insertMode", 
      "stringValue" : "KEEP_EXISTING", 
      }, 
      { 
      "key" : "schedule", 
      "refValue" : "DefaultScheduleTime", 
      }, 
     ] 
    },] 

所以根據RedShitCopyActivity的,我們需要使用insertMode來描述數據應該如何表現(在文檔插入/更新/刪除)複製到數據庫表的時候,如下

insertMode : Determines what AWS Data Pipeline does with pre-existing data in the target table that overlaps with rows in the data to be loaded. Valid values are KEEP_EXISTING, OVERWRITE_EXISTING, TRUNCATE and APPEND. KEEP_EXISTING adds new rows to the table, while leaving any existing rows unmodified. KEEP_EXISTING and OVERWRITE_EXISTING use the primary key, sort, and distribution keys to identify which incoming rows to match with existing rows, according to the information provided in Updating and inserting new data in the Amazon Redshift Database Developer Guide. TRUNCATE deletes all the data in the destination table before writing the new data. APPEND will add all records to the end of the Redshift table. APPEND does not require a primary, distribution key, or sort key so items that may be potential duplicates may be appended.

那麼我的要求是

  1. 當從Postgres的複製(INFACT數據處於S3現在)到紅移數據庫,如果它發現已如果它開創從S3然後在紅移

創造新的紀錄新紀錄的現有行則剛剛更新

  • 但對我來說,即使我已經使用KEEP_EXISTINGOVERWRITE_EXISTING,數據只是在重複一遍又一遍如上圖所示紅移數據庫圖片

    那麼最後如何達到我的要求?是否還有任何調整或設置添加到我的配置?

    編輯

    表(公司)從紅移

    enter image description here

  • +0

    你能用紅移提供你的表格定義嗎? – Maxime

    +0

    @Maxime我已經編輯了我的問題與表定義,請檢查上面。 –

    +0

    由於您定義了主鍵,請嘗試刪除「key」:「primaryKeys」,「stringValue」:「id」。另外,用戶運行復制活動的權限是什麼?它可以創建臨時表嗎? – Maxime

    回答

    0

    定義看看這個AWS文檔,也許你可以找到一個解決方案在那裏。

    https://aws.amazon.com/blogs/aws/fast-easy-free-sync-rds-to-redshift/https://aws.amazon.com/blogs/aws/fast-easy-free-sync-rds-to-redshift/

    它看起來非常複雜和令人沮喪的移動數據從Postgres的到S3,然後從S3使用管道紅移。

    直接從Postgres database to Redshift直接移動數據 會容易得多,而不會冒數據重複的風險。

    今天有很多平臺可以在沒有所有「混亂和頭痛」的情況下傳輸數據。

    出於同樣的原因,我使用名爲Alooma的工具,它可以近乎實時地將Amazon RDS上託管的Postgres數據庫中的表複製到Redshift中。

    1

    如果您想避免重複,則必須在redshift中定義主鍵,並將myInsertMode設置爲「OVERWRITE_EXISTING」。

    相關問題