DataWorks provides AnalyticDB for PostgreSQL Reader and AnalyticDB for PostgreSQL Writer for you to read data from and write data to AnalyticDB for PostgreSQL data sources. This topic describes the capabilities of synchronizing data from or to AnalyticDB for PostgreSQL data sources.
Limits
Data of views can be read during batch synchronization.
Supported AnalyticDB for PostgreSQL versions
AnalyticDB for PostgreSQL of V7.0 and earlier versions is supported.
Data type mappings
Batch data read
AnalyticDB for PostgreSQL Reader supports most AnalyticDB for PostgreSQL data types. Make sure that the data types of your database are supported.
The following table lists the data type mappings based on which AnalyticDB for PostgreSQL Reader converts data types.
Category | AnalyticDB for PostgreSQL data type |
Integer | BIGINT, BIGSERIAL, INTEGER, SMALLINT, SERIAL, and GEOMETRY |
Floating point | DOUBLE, PRECISION, MONEY, NUMERIC, and REAL |
String | VARCHAR, CHAR, TEXT, BIT, and INET |
Date and time | DATE, TIME, and TIMESTAMP |
Boolean | BOOL |
Binary | BYTEA |
Batch data write
AnalyticDB for PostgreSQL Writer supports most AnalyticDB for PostgreSQL data types. Make sure that the data types of your database are supported.
The following table lists the data type mappings based on which AnalyticDB for PostgreSQL Writer converts data types.
Category | AnalyticDB for PostgreSQL data type |
LONG | BIGINT, BIGSERIAL, INTEGER, SMALLINT, and SERIAL |
DOUBLE | DOUBLE, PRECISION, MONEY, NUMERIC, and REAL |
STRING | VARCHAR, CHAR, TEXT, BIT, INET, and GEOMETRY |
DATE | DATE, TIME, and TIMESTAMP |
BOOLEAN | BOOL |
BYTES | BYTEA |
The syntax such as a_inet::varchar
is required when AnalyticDB for PostgreSQL Writer converts data to the MONEY, INET, or BIT data type.
Develop a data synchronization task
For information about the entry point for and the procedure of configuring a data synchronization task, see the following sections. For information about the parameter settings, view the infotip of each parameter on the configuration tab of the task.
Add a data source
Before you configure a data synchronization task to synchronize data from or to a specific data source, you must add the data source to DataWorks. For more information, see Add and manage data sources.
Configure a batch synchronization task to synchronize data of a single table
For more information about the configuration procedure, see Configure a batch synchronization task by using the codeless UI and Configure a batch synchronization task by using the code editor.
For information about all parameters that are configured and the code that is run when you use the code editor to configure a batch synchronization task, see Appendix: Code and parameters.
Configure synchronization settings to implement batch synchronization of all data in a database
For more information about the configuration procedure, see Configure a synchronization task in Data Integration.
Appendix: Code and parameters
Appendix: Configure a batch synchronization task by using the code editor
If you use the code editor to configure a batch synchronization task, you must configure parameters for the reader and writer of the related data source based on the format requirements in the code editor. For more information about the format requirements, see Configure a batch synchronization task by using the code editor. The following information describes the configuration details of parameters for the reader and writer in the code editor.
Code for AnalyticDB for PostgreSQL Reader
{
"type": "job",
"steps": [
{
"parameter": {
"datasource": "test_004",// The name of the data source.
"column": [// The names of the columns.
"id",
"name",
"sex",
"salary",
"age"
],
"where": "id=1001",// The WHERE clause.
"splitPk": "id",// The shard key.
"table": "public.person"// The name of the table.
},
"name": "Reader",
"category": "reader"
},
{
"parameter": {},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",// The version number.
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {// The maximum number of dirty data records allowed.
"record": ""
},
"speed": {
"concurrent": 6,// The maximum number of parallel threads.
"throttle": true,// Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"mbps":"12"// The maximum transmission rate. Unit: MB/s.
}
}
}
Parameters in code for AnalyticDB for PostgreSQL Reader
Parameter | Description | Required | Default value |
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
table | The name of the table from which you want to read data. | Yes | No default value |
column | The names of the columns from which you want to read data. Specify the names in a JSON array. The default value is [*], which indicates all the columns in the source table.
| Yes | No default value |
splitPk | The field that is used for data sharding when AnalyticDB for PostgreSQL Reader reads data. If you specify this parameter, the source table is sharded based on the value of this parameter. Data Integration then runs parallel threads to read data. This improves data synchronization efficiency.
| No | No default value |
where | The WHERE clause. AnalyticDB for PostgreSQL Reader generates an SQL statement based on the settings of the table, column, and where parameters and uses the generated statement to read data. For example, when you perform a test, you can set the where parameter to
| No | No default value |
querySql (advanced parameter, which is available only in the code editor) | The SQL statement that is used for refined data filtering. If you specify this parameter, AnalyticDB for PostgreSQL Reader filters data based only on the value of this parameter. For example, if you want to join multiple tables for data synchronization, set this parameter to If you specify this parameter, AnalyticDB for PostgreSQL Reader ignores the settings of the column, table, and where parameters. | No | No default value |
fetchSize | The number of data records to read at a time. This parameter determines the number of interactions between Data Integration and the source database and affects read efficiency. Note If you set this parameter to a value greater than 2048, an out of memory (OOM) error may occur during data synchronization. | No | 512 |
Code for AnalyticDB for PostgreSQL Writer
{
"type": "job",
"steps": [
{
"parameter": {},
"name": "Reader",
"category": "reader"
},
{
"parameter": {
"postSql": [],// The SQL statement that you want to execute after the synchronization task is run.
"datasource": "test_004",// The name of the data source.
"column": [// The names of the columns.
"id",
"name",
"sex",
"salary",
"age"
],
"table": "public.person",// The name of the table.
"preSql": []// The SQL statement that you want to execute before the synchronization task is run.
},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",// The version number.
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {// The maximum number of dirty data records allowed.
"record": ""
},
"speed": {
"throttle":true,// Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"concurrent":6, // The maximum number of parallel threads.
"mbps":"12"// The maximum transmission rate.
}
}
}
Parameters in code for AnalyticDB for PostgreSQL Writer
Parameter | Description | Required | Default value |
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
table | The name of the table to which you want to write data. | Yes | No default value |
writeMode | The write mode. Valid values: insert, copy, and upsert.
| No | insert |
conflictMode | If writeMode is set to upsert and a primary key conflict or unique index conflict occurs when data is written, you can use the following policies to handle the conflict:
Note You can configure this parameter only when you configure a synchronization task by using the code editor. | No | replace |
column | The names of the columns to which you want to write data. Separate the names with commas (,), such as | Yes | No default value |
preSql | The SQL statement that you want to execute before the synchronization task is run. For example, you can set this parameter to the SQL statement that is used to delete outdated data. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. | No | No default value |
postSql | The SQL statement that you want to execute after the synchronization task is run. For example, you can set this parameter to the SQL statement that is used to add a timestamp. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. | No | No default value |
batchSize | The number of data records to write at a time. Set this parameter to an appropriate value based on your business requirements. This greatly reduces the interactions between Data Integration and AnalyticDB for PostgreSQL and increases throughput. If you set this parameter to an excessively large value, an OOM error may occur during data synchronization. | No | 1,024 |