The WbCopy
is essentially the command line version of the
the DataPumper. For a more detailed explanation
of the copy process, please refer to that section. It bascially chains a WbExport and a
WbImport
statement without the need of an intermediate data file.
The WbCopy
command requires that a connection to the source and target
database can be made at the same time.
WbCopy
command.Parameter | Description |
---|---|
-sourceProfile |
The name of the connection profile to use as the source connection. If -sourceprofile is not specified, the current connection is used as the source. If the profile name contains spaces or dashes, it has to be quoted. |
-sourceGroup |
If the name of your source profile is not unique across all profiles, you will need to specify the group in which the profile is located with this parameter. If the group name contains spaces or dashes, it has to be quoted. |
-targetProfile |
The name of the connection profile to use as the target connection. If
If the profile name contains spaces or dashes, it has to be quoted. |
-targetGroup |
If the name of your target profile is not unique across all profiles, you will need to specify the group in which the profile is located with this parameter. If the group name contains spaces or dashes, it has to be quoted. |
-commitEvery |
The number of rows after which a commit is sent to the target database. This parameter
is ignored if JDBC batching (-batchSize ) is used.
|
-deleteTarget |
Possible values: If this parameter is set to true, all rows are deleted from the target table before copying the data. |
-mode |
Defines how the data should be sent to the database. Possible
values are |
-syncDelete |
If this option is enabled
Combined with an
If more than one table is copied, the delete process is started after
all inserts and updates have been processed. It is recommended to use the
To only generate the SQL statements that would synchronize two databases, you can use the command WbDataDiff |
-keyColumns |
Defines the key columns for the target table. This parameter
is only necessary if import is running in |
-batchSize |
Enable the use of the JDBC batch update feature, by setting the size of the batch queue. Any value greater than 1 will enable batch modee. If the JDBC driver supports this, the INSERT (or UPDATE) performance can be increased.
This parameter will be ignored if the driver does not support batch updates or if
the mode is not UPDATE or INSERT (i.e. if |
-commitBatch |
Valid values: When using the |
-continueOnError |
Defines the behaviour if an error occurs in one of the statements.
If this is set to
With PostgreSQL |
-useSavepoint |
Possible values:
Controls if SQL Workbench/J guards every insert or update statement
with a savepoint to recover from individual error during import,
when Using a savepoint for each DML statement can drastically reduce the performance of the import. |
-showProgress |
Valid values: true, false, <numeric value>
Control the update frequence in the statusbar (when running in
GUI mode). The default is every 10th row is reported. To disable
the display of the progress specifiy a value of 0 (zero) or the
value |
Parameter | Description |
---|---|
-sourceTable |
The name of the table(s) to be copied. You can either specifiy a
list of tables: -sourceTable=table1,table2 . Or select
the tables using a wildcard: -sourceTable=* will copy
all tables accessible to the user. If more than one table is specified
using this parameter, the -targetTable parameter is
ignored.
|
-checkDependencies |
When copying more than one file into tables with foreign key constraints,
this switch can be used to import the files in the correct order (child tables first).
When |
-sourceWhere |
A WHERE condition that is applied to the source table.
|
-targetTable | The name of the table into which the data should be written. This parameter is ignored if more than one table is copied. |
-createTarget |
If this parameter is set to When using this option with different source and target DBMS, the information about the datatypes to be used in the target database are retrieved from the JDBC driver. In some cases this information might not be accurate or complete. You can enhance the information from the driver by configuring your own mappings in workbench.settings. Please see the section Customizing data type mapping for details. |
-tableType |
When
When using the auto-completion for this parameter, all defined "create types" that
are configured in workbench.settings (or are part of the default settings) are displayed
together with the name of the DBMS they are used for. The list is not
limited to definitions for the target database! The specified type must nonetheless match a type
defined for the target connection. If you specify a type that does not exist, the default
For details on how to configure a CREATE TABLE template for this parameter, please refer to the chapter Settings related to SQL statement generation |
-skipTargetCheck |
Normally WbCopy will check if the specified target table does exist. However, some JDBC drivers
do not always return all table information correctly (e.g. temporary tables). If you know that the
target table exists, the parameter |
-dropTarget |
If this parameter is set to true the target table
will be dropped before it is created.
|
-columns |
Defines the columns to be copied. If this parameter is not specified, then all matching columns are copied from source to target. Matching is done on name and data type. You can either specify a list of columns or a column mapping.
When supplying a list of columns, the data from
each column in the source table will be copied into the corresponding column (i.e.
one with the same name) in the target table.
If
A column mapping defines which column from the source table maps to which column
of the target table (if the column names do not match)
If This parameter is ignored if more than one table is copied. When using a SQL query as the data source a mapping cannot be specified. Please check Copying data based on a SQL query for details. |
-preTableStatement -postTableStatement |
This parameter defines a SQL statement that should be executed before the import
process starts inserting data into the target table. The name of the current
table (when e.g. importing a whole directory) can be referenced using
To define a statement that should be executed after all rows have been
inserted and have been committed, you can use the These parameters can e.g. be used to enable identity insert for MS SQL Server: -preTableStatement="set identity_insert ${table.name} on" -postTableStatement="set identity_insert ${table.name} off"Errors resulting from executing these statements will be ignored. If you want to abort the import in that case you can specify -ignorePrePostErrors=false
and -continueOnError=false .
|
-ignorePrePostErrors=false |
Controls handling of errors for the |
Parameter | Description |
---|---|
-sourceQuery | The SQL query to be used as the source data (instead of a table). |
-columns |
The list of columns from the target table, in the order in which they appear in the source query. If the column names in the query match the column names in the target table, this parameter is not necessary. If you do specify this parameter, note that this is not a column mapping. It only lists the columns in the correct order . |
The WbCopy
command understands the same update mode
parameter as the WbImport
command. For a discussion on
the different update modes, please refer to the WbImport
command.
Using -mode=update,insert
ensures that all rows that are present in
the source table do exist in the target table and that all values for non-key columns
are identical.
When you need to keep two tables completely in sync, rows that are present in the
target table that do not exist in the source table need to be deleted. This is what the
parameter -syncDelete
is for. If this is enabled (-syncDelete=true
)
then SQL Workbench/J will check every row from the target table if it is present in the
source table. This check is based on the primary keys of the target table and
assumes that the source table as the same primary key.
Testing if each row in the target table exists in the source table is a substantial overhead,
so you should enable this option only when really needed. DELETE
s in the
target table are batched according to the -batchSize
setting of the
WbCopy
command. To increase performance, you should enable batching
for the whole process.
Internally the rows from the source table are checked in chunks, which means that
SQL Workbench/J will generate a SELECT
statement that contains
a WHERE
condition for each row retrieved from the target table.
The default chunk size is relatively small to avoid problems with large SQL statements.
This approach was taken to minimize the number of statements sent to the server.
The automatic fallback from update,insert
or insert,update
mode to insert
mode applies for synchronizing tables using WbCopy
as well.
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceTable=the_table -targetTable=the_other_table;
This example will copy the data from the tables in the source database to the corresponding tables in the target database. Rows that are not available in the source tables are deleted from the target tables.
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceTable=* -mode=update,insert -syncDelete=true;
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceTable=the_table -sourceWhere="lastname LIKE 'D%'" -targetTable=the_other_table;
This example will run the statement SELECT * FROM the_table WHERE lastname like 'D%'
and copy all corresponding columns to the target table the_other_table
.
This example copies only selected columns from the source table. The column names in the two tables do not match and a column mapping is defined. Before the copy is started all rows are deleted from the target table.
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceTable=person -targetTable=contacts -deleteTarget=true -columns=firstname/surname, lastname/name, birthday/dob;
When using a query as the source for the WbCopy
command, the column
mapping is specified by simply supplying the order of the target columns as they appear
in the SELECT
statement.
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceQuery="SELECT firstname, lastname, birthday FROM person" -targetTable=contacts -deleteTarget=true -columns=surname, name, dob;
This copies the data based on the SELECT statement into the table CONTACTS
of the target database. The -columns
parameter defines that the first column
of the SELECT (firstname) is copied into the target column with the name surname
,
the second result column (lastname) is copied into the target column name
and the
last source column (birthday) is copied into the target column dob
.
This example could also be written as:
WbCopy -sourceProfile=ProfileA -targetProfile=ProfileB -sourceQuery="SELECT firstname as surname, lastname as name, birthday as dob FROM person" -targetTable=contacts -deleteTarget=true