1

I am migrating Informix (11.7) DB to PostgreSQL(9.2). There is only one problem: how to move blob(image) from Informix to PostgreSQL(9.2)? Many thanks in advance.

7
  • Do you need the data type of postgres or do you have any specific problem? The data type you are looking for is bytea in postgres. Commented Oct 21, 2012 at 12:56
  • 4
    How are you migrating the non-blob data to PostgreSQL? What formats does PostgreSQL like for loading blob data? How many tables with blobs are you migrating? How many rows in those tables? How big are the blobs (min, avg, max)? Which of the Informix types TEXT, BYTE, BLOB and CLOB are you dealing with? They're all blob types. Commented Oct 21, 2012 at 15:29
  • @JonathanLeffler: What are the specs for storing Informix TEXT, BYTE, BLOB and CLOB data? Commented Oct 22, 2012 at 0:28
  • What do you mean, @FrankComputer? TEXT and BYTE blobs are older (version 4.00) than the other two types (version 9.00) and can be stored IN TABLE or in a blob space. The BLOB and CLOB types are for 'smart blobs', and are stored in a smart blob space (different). There are complicated rules about how to get the values into the DB and back out again. There's a set of rules about how they're unloaded too if you're using UNLOAD format. And so the list of unanswered questions grows... Commented Oct 22, 2012 at 0:36
  • 1
    @FrankComputer: They're stored internally in opaque formats that are obscure beyond belief. Large tranches of the disk space are simply the data, of course, but the control information is complex — and some is in the blob descriptor in the row of the table while some is in the blob space or smart blob space where the blob is stored (except when it is stored IN TABLE). There's no external documentation (stuff you can see) on how to get at the raw blob data. Commented Oct 24, 2012 at 14:39

2 Answers 2

1

I did some such conversions between various databases using Jython and JDBC.

All you need is Informix and PostgreSQL JDBC drivers in CLASSPATH.

I have Informix table with BYTE column, and PostgreSQL table with BYTEA column:

-- Informix
CREATE TABLE _blob_test (
  id integer PRIMARY KEY,
  image BYTE
)

-- PostgreSQL
CREATE TABLE _blob_test (
  id integer PRIMARY KEY,
  image BYTEA
)

Then you can use JDBC getObject()/setObject() methods to copy data:

#!/usr/bin/env jython
# -*- coding: utf8 -*-

from java.sql import DriverManager
from java.lang import Class

Class.forName("com.informix.jdbc.IfxDriver")
Class.forName('org.postgresql.Driver')

def copy_table(db_from, db_to):
    col_count = 2
    insert_stmt = db_to.prepareStatement('INSERT INTO _blob_test (id, image) VALUES (?, ?)')
    pstm2 = db_from.createStatement()
    pstm2.setFetchSize(10000)
    rs_in = pstm2.executeQuery('SELECT * FROM _blob_test')
    try:
        batch_buffer = 0
        batch_size = 100
        while (rs_in.next()):
            for i in range(1, col_count + 1):
                insert_stmt.setObject(i, rs_in.getObject(i))
            insert_stmt.addBatch()
            batch_buffer += 1
            if (batch_buffer % batch_size == 0):
                insert_stmt.executeBatch()
                batch_buffer = 0
        if (batch_buffer > 0):
            insert_stmt.executeBatch()
    finally:
        rs_in.close()
        pstm2.close()


db_from = DriverManager.getConnection('jdbc:informix-sqli://informix-test:9088/infdb:informixserver=ol_testifx;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'informix', '12345')
db_to   = DriverManager.getConnection('jdbc:postgresql://pg-test:5490/pg_test?stringtype=unspecified', 'postgres', '12345')

copy_table(db_from, db_to)
0

I know the answer is late but this could help other persons looking for a solution.
We have done a similar migration in our company.
To migrate binaries we used a tool called SQL-workbench, we used the data pumper (menu tools). Data pumper allows to copy data from a source DB to a target DB. The DBMSs could be different (in this case Informix and Postgres).
You have to register both drivers in "File > Manage Drivers" and create 2 profiles: A source profile targeting your Informix DB and a target profile targeting your Postgres DB. The profiles will then be selected from Data pumper. Data pumper window If you have several tables to copy at once, please read the documentation about using the function Wbcopy (very useful)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.