I need to import data from Postgres to Oracle. I'm trying to do this with python using psycopg2, pandas, cx_Oracle. Firstly I'm importing data:
sql = '''select * from test'''
conn = psycopg2.connect(dbname='db',user='usr',password='pswd',host='...')
df = pd.read_sql_query(sql,conn)
conn.close()
Then I'm trying to import it to oracle:
dsn = """(DESCRIPTION=(LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=...)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=...)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=...)(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=test)))"""
usr = "usr"
pswd = "user"
engine = create_engine('oracle+cx_oracle://%s:%s@%s' % (usr, pswd, dsn))
conn = engine.connect()
conn.execute("TRUNCATE TABLE test_or")
df.to_sql(name = 'test_or', con = engine, schema = 'sch', index = False, if_exists='append')
It works fast with 3,000,000 rows tables, but it comes harder and laggy to take data from 70,000,000 rows tables.
Is this possible to speed up the process? I wanted to partition query and iterate it. But I can’t think of how to split query