Uploaded image for project: 'Sqoop'
  1. Sqoop
  2. SQOOP-390

PostgreSQL connector for direct export with pg_bulkload



    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4.3
    • Component/s: None
    • Labels:



      • Fast data export into PostgreSQL database with pg_bulkload.
      • User can get benefit of functionality of pg_bulkload such as
        • fast export bypassing shared bufferes and WAL,
        • removing invalid data which cause parse error,
        • ETL feature with filter functions.



      At first, each map tasks create their own staging table with names based on task attempt id because pg_bulkload holds table level lock.
      Arguments of pg_bulkload command can be passed via configuration object.
      The Mapper export data by invoking pg_bulkload command as external process.
      Commnad execution is done in the same way as DirectPostgresqlManager.


      Reducer migrates data from staging tables into destination table.
      Reducer gets the names of staging tables as map output values.
      In order to do migration in a transaction, the number of reducers must be 1. (It is set by ConnectionManager internally).
      Migration is done in same way as Sqoop defalt connectors using "INSERT INTO dst ( SELECT * FROM src )".
      In the cleanup method, staging tables are dropped.
      If exception is raised in the reducer, garbage staging tables are left.
      User can delete them by executing this connector with --clear-staging-table option.


      • pg_bulkload must be installed on DB server and all slave nodes.
      • PostgreSQL JDBC is also required on client node (same as PostgresqlManager).
      • Superuser role of PostgreSQL database is required for execution of pg_bulkload.


      Currently there is no Factory class.
      Specify connection manager class name with --connection-manager option to use.

      $ sqoop export --connect jdbc:postgresql://localhost:5432/test \
                     --connection-manager com.cloudera.sqoop.manager.PGBulkloadManager \
                     --table test --username postgres --export-dir=/test -m 1

      You can also specify pg_bulkload configuration with Hadoop configuration properties.

      $ sqoop export \
          -Dpgbulkload.bin="/usr/local/bin/pg_bulkload" \
          -Dpgbulkload.input.field.delim=$'\t' \
          -Dpgbulkload.check.constraints="YES" \
          -Dpgbulkload.parse.errors="INFINITE" \
          -Dpgbulkload.duplicate.errors="INFINITE" \
          --connect jdbc:postgresql://localhost:5432/test \
          --connection-manager com.cloudera.sqoop.manager.PGBulkloadManager \
          --table test --username postgres --export-dir=/test -m 1


      There is test class named PGBulkloadManagerManualTest extending TestExport.
      This test expects that

      • The major version of PostgreSQL is 9.0,
      • The version of pg_bulkload is 3.1.1,
      • PostgreSQL server is running on localhost:5432 of testing node,
      • there is database named sqooptest,
      • super user role named sqooptest exists,
      • no password is set for the role, or .pgpass file is created.

      Tests can be invoked as below.

      # ant -Dtestcase=PGBulkloadManagerManualTest test

      Test on CentOS 6

      Install JDK and Ant:

      # rpm -ivh jdk-6u29-linux-amd64.rpm
      # yum install ant-junit

      Setup for PostgreSQL:

      # wget http://ftp.postgresql.org/pub/source/v9.0.7/postgresql-9.0.7.tar.bz2
      # tar jxf postgresql-9.0.7.tar.bz2
      # cd postgresql-9.0.7
      # ./configure --prefix=/usr/local
      # make
      # make install
      # useradd postgres
      # mkdir /var/pgdata
      # chown postgres:postgres /var/pgdata
      # chmod 700 /var/pgdata
      # sudo -u postgres /usr/local/bin/initdb  -D /var/pgdata -E utf-8
      # sudo -u postgres /usr/local/bin/pg_ctl start -D /var/pgdata -l /var/pgdata/postgresql.log
      # createuser -U postgres -s sqooptest
      # createdb -U sqooptest sqooptest

      Setup for pg_bulkload and PostgreSQL JDBC Driver:

      # cd ..
      # wget http://pgfoundry.org/frs/download.php/3176/pg_bulkload-3.1.1.tar.gz
      # tar zxf pg_bulkload-3.1.1.tar.gz
      # mv pg_bulkload-3.1.1 postgresql-9.0.7/contrib/
      # cd postgresql-9.0.7/contrib/pg_bulkload-3.1.1
      # make
      # make install
      # psql -U sqooptest -f /usr/local/share/postgresql/contrib/pg_bulkload.sql sqooptest
      # ln -s /usr/local/bin/pg_bulkload /usr/bin/

      Setup for PostgreSQL JDBC Driver:

      # wget http://jdbc.postgresql.org/download/postgresql-9.0-802.jdbc4.jar
      # cp postgresql-9.0-802.jdbc4.jar /usr/local/src/sqoop-trunk/lib/

      run test.

      # cd /usr/local/src/sqoop-trunk
      # ant -Dtestcase=PGBulkloadManagerManualTest test


        1. pgbulkload-connector-r6.patch
          58 kB
          Masatake Iwasaki
        2. SQOOP-390-1.patch
          37 kB
          Masatake Iwasaki

          Issue Links



              • Assignee:
                iwasakims Masatake Iwasaki
                iwasakims Masatake Iwasaki
              • Votes:
                0 Vote for this issue
                9 Start watching this issue


                • Created: