OracleBulkCopy Memory Leak(OutOfMemory Exception)

China☆狼群 提交于 2019-12-06 08:22:04

问题


Below is the code I used to bulkcopy data from a temp table dataTable into a destTable in Oracle Database. The dataTable has about 2 million records.

using (OracleBulkCopy bulkCopy = new OracleBulkCopy(VMSDATAConnectionString))
            {
                try
                {
                    foreach (OracleBulkCopyColumnMapping columnMapping in columnMappings)
                        bulkCopy.ColumnMappings.Add(columnMapping);

                    bulkCopy.DestinationTableName = destTableName;
                    //bulkCopy.BatchSize = dataTable.Rows.Count;
                    //bulkCopy.BulkCopyTimeout = 100;                   
                    int defaultSize = 5000;
                    int.TryParse(ConfigurationManager.AppSettings["OracleBulkCopyBatchSize"], out defaultSize);
                    bulkCopy.BatchSize = defaultSize;
                    int timeOut = 100;
                    int.TryParse(ConfigurationManager.AppSettings["OracleBulkCopyTimeout"], out timeOut);
                    bulkCopy.BulkCopyTimeout = timeOut;
                    Console.WriteLine("Bulk insert from {0} to {1} started at: {2}\r\nBatchSize : {3}, BulkCopyTimeout : {4} ", dataTable.TableName, destTableName, DateTime.Now.ToString("HH:mm:ss"), bulkCopy.BatchSize.ToString(), bulkCopy.BulkCopyTimeout.ToString());
                    bulkCopy.WriteToServer(dataTable);
                    Console.WriteLine("Bulk insert from {0} to {1} finished at: {2}", dataTable.TableName, destTableName, DateTime.Now.ToString("HH:mm:ss"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error happened during bulk copy from {0} to {1}\r\nBatchSize : {2}, BulkCopyTimeout : {3}\r\n Error message {4}", dataTable.TableName, destTableName, bulkCopy.BatchSize.ToString(), bulkCopy.BulkCopyTimeout.ToString(), ex.ToString());
                    bulkCopy.Close();
                    bulkCopy.Dispose();
                }
            }

But it throws following exception:

The server running this data loading process definitely has enough memory, it looks like the database server (linux) does not have enough memory. Below is the database server memory screen shot:

Can anyone help with this issue? Thanks.


回答1:


Found the root cause, the exe is running in 32 bit and it has a 1.5G memory limit. Need to change the target platform and replace Oracle.DataAccess.dll to 64 bit version.

Also there is an alternative solution: load data in batch so it will not exceed 1.5 G memory limit.

Update:

"MEMORY LEAK USING ORACLEBULKCOPY": the oracle bulk copy has some bug that causes memory leak, it happens when the BatchSize is less than datatable size. Need to modify the BatchSize or update ODAC to higher version.

Reference: https://community.oracle.com/message/4593452#4593452



来源:https://stackoverflow.com/questions/30109156/oraclebulkcopy-memory-leakoutofmemory-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!