通过程序要把1000万的数据插入到数据表中,刚开始每100条数据耗时50ms左右,但是越往后越慢,最慢到了十几秒的都有,真实好坑了.
于是在网上百度了一波,如何进行insert优化.倒是有了一点小小的优化,但是还是有些慢.具体操作如下:
1.关掉表和索引的nologged日志
alter table human_info NOLOGGING;
alter index PK_PERSON_ID NOLOGGING; alter index IDX_NAME NOLOGGING; alter index IDX_ID_NUMBER NOLOGGING;
2.禁用索引,启用,查询索引状态
#禁用 ALTER INDEX PK_PERSON_ID UNUSABLE; ALTER INDEX IDX_NAME UNUSABLE; ALTER INDEX IDX_ID_NUMBER_IDX UNUSABLE; #启用 ALTER INDEX PK_PERSON_ID REBUILD; ALTER INDEX IDX_NAME REBUILD; ALTER INDEX IDX_ID_NUMBER REBUILD; #查看状态 select status from user_indexes where index_name='PK_PERSON_ID '; select status from user_indexes where index_name='IDX_NAME '; select status from user_indexes where index_name='IDX_ID_NUMBER ';
3查看sql执行状况
#监控文件系统的io比例
select substr(a.file#,1,2) "#",substr(a.name,1,30) "name",a.status,a.bytes,b.phyrds,b.phywrts from v$datafile a,v$filestat b where a.file#=b.file#;
#查看sql执行来源 SELECT osuser,username,sql_text from v$session a, v$sqltext b where a.sql_address =b.address order by address, piece; #sql监控器 select * from v$sql_monitor; select * from v$sql_plan_monitor;