dbcrossbar Guide

dbcrossbar is an open source tool that copies large, tabular datasets between many different databases and storage formats. Data can be copied from any source to any destination.

%3csv_inCSVdbcrossbardbcrossbarcsv_in->dbcrossbarcsv_outCSVdbcrossbar->csv_outpostgres_outPostgreSQLdbcrossbar->postgres_outbigquery_outBigQuerydbcrossbar->bigquery_outs3_outS3dbcrossbar->s3_outgs_outCloud Storagedbcrossbar->gs_outredshift_outRedShiftdbcrossbar->redshift_outetc_out...dbcrossbar->etc_outpostgres_inPostgreSQLpostgres_in->dbcrossbarbigquery_inBigQuerybigquery_in->dbcrossbars3_inS3s3_in->dbcrossbargs_inCloud Storagegs_in->dbcrossbarredshift_inRedShiftredshift_in->dbcrossbaretc_in...etc_in->dbcrossbar

An example

If we have a CSV file my_table.csv containing data:

1,Blue widget,10
2,Red widget,50

And a file my_table.sql containing a table definition:

CREATE TABLE my_table (
    id INT NOT NULL,
    name TEXT NOT NULL,
    quantity INT NOT NULL

Then we can use these to create a PostgreSQL table:

dbcrossbar cp \
    --if-exists=overwrite \
    --schema=postgres-sql:my_table.sql \
    csv:my_table.csv \

If we want to use this data to update an existing table in BigQuery, we can upsert into BigQuery using the id column:

dbcrossbar config add temporary gs://$GS_TEMP_BUCKET
dbcrossbar config add temporary bigquery:$GCLOUD_PROJECT:temp_dataset
dbcrossbar cp \
    --if-exists=upsert-on:id \
    'postgres://postgres@' \

This will stream the data out of PostgreSQL, upload it to $GS_TEMP_BUCKET, import it into a temporary BigQuery table, and run an appropriate MERGE command. The config add temporary commands tell dbcrossbar what cloud bucket and BigQuery dataset should be used for temporary files and tables, respectively.

Notice that we don't need to specify --schema, because dbcrossbar will automatically translate the PostgreSQL column types to corresponding BigQuery types.


dbcrossbar is generously supported by Faraday and by open source contributors. Please see the credits for more information.