直接加载数据性能测试的一点总结

直接加载是提高数据效率的好方法,尤其在OLAP系统中使用的非常普遍,
这是根据自己的测试和别人的经验总结的
概念
直接加载优势
直接加载比传统加载效率要高
不扫描原来的空数据块
不需要sql解析,减少系统的负载
不经过SGA
不走DBWR进程,走自己的专属进程,所以速度快
直接加载限制
不能加载簇表
锁定整个表,在表上有活动事务的时候不能加载
直接加载特点
直接加载是在所有数据块后面加载新数据块,修改高水位线,不扫描原来的空数据块。
直接加载只产生一点点的管理redo,因为要修改数据字典(也可以讲不产生redo)。
回滚,如果加载失败把新分配数据块抹掉就行了。
无需SGA,无需SQL解析,无需DBWR进程
实验
现在我们已经定义了test;
SQL> select count(*) from test; 现在表里没有记录数
COUNT(*)
0
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST'; 现在分配了1个区
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
[oracle@secdb1 ~]$ sqlldr userid=ls/ls control=leo_test.ctl data=leo_test.data log=leo_test.log 传统方式加载数据
LS@LEO> select count(*) from test; 已经成功加载了100万条数据
COUNT(*)
1000000
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST'; 100万条数据占用28个区
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
TEST 1 65536
TEST 2 65536
TEST 3 65536
TEST 4 65536
TEST 5 65536
TEST 6 65536
TEST 7 65536
TEST 8 65536
TEST 9 65536
TEST 10 65536
TEST 11 65536
TEST 12 65536
TEST 13 65536
TEST 14 65536
TEST 15 65536
TEST 16 1048576
TEST 17 1048576
TEST 18 1048576
TEST 19 1048576
SEGMENT_NAME EXTENT_ID BYTES
TEST 20 1048576
TEST 21 1048576
TEST 22 1048576
TEST 23 1048576
TEST 24 1048576
TEST 25 1048576
TEST 26 1048576
TEST 27 1048576
28 rows selected
SQL> delete from test; 删除100万条数据
1000000 rows deleted.
SQL> commit; 提交
Commit complete.
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST';
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
TEST 1 65536
TEST 2 65536
TEST 3 65536
TEST 4 65536
TEST 5 65536
TEST 6 65536
TEST 7 65536
TEST 8 65536
TEST 9 65536
TEST 10 65536
TEST 11 65536
TEST 12 65536
TEST 13 65536
TEST 14 65536
TEST 15 65536
TEST 16 1048576
TEST 17 1048576
TEST 18 1048576
TEST 19 1048576
SEGMENT_NAME EXTENT_ID BYTES
TEST 20 1048576
TEST 21 1048576
TEST 22 1048576
TEST 23 1048576
TEST 24 1048576
TEST 25 1048576
TEST 26 1048576
TEST 27 1048576
28 rows selected
把数据都删除了还占用空间,oracle的delete操作不回收空间,只是把自己的记录标记为删除,实际呢还占用的空间不释放
[oracle@secdb1 ~]$ sqlldr userid=ls/ls control=leo_test.ctl data=leo_test.data log=leo_test.log 第二次传统方式加载数据
SQL> select count(*) from test; 已经成功加载了100万条数据
COUNT(*)
1000000
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST';
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
TEST 1 65536
TEST 2 65536
TEST 3 65536
TEST 4 65536
TEST 5 65536
TEST 6 65536
TEST 7 65536
TEST 8 65536
TEST 9 65536
TEST 10 65536
TEST 11 65536
TEST 12 65536
TEST 13 65536
TEST 14 65536
TEST 15 65536
TEST 16 1048576
TEST 17 1048576
TEST 18 1048576
TEST 19 1048576
SEGMENT_NAME EXTENT_ID BYTES
TEST 20 1048576
TEST 21 1048576
TEST 22 1048576
TEST 23 1048576
TEST 24 1048576
TEST 25 1048576
TEST 26 1048576
TEST 27 1048576
28 rows selected
使用传统方式加载数据,会扫描原来的空数据块,会把新加载的数据插入到空数据块内,看我们还是使用原来的28个区
SQL> delete from test; 这是第二次删除100万条数据
1000000 rows deleted.
SQL> commit; 提交
Commit complete.
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST';
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
TEST 1 65536
TEST 2 65536
TEST 3 65536
TEST 4 65536
TEST 5 65536
TEST 6 65536
TEST 7 65536
TEST 8 65536
TEST 9 65536
TEST 10 65536
TEST 11 65536
TEST 12 65536
TEST 13 65536
TEST 14 65536
TEST 15 65536
TEST 16 1048576
TEST 17 1048576
TEST 18 1048576
TEST 19 1048576
SEGMENT_NAME EXTENT_ID BYTES
TEST 20 1048576
TEST 21 1048576
TEST 22 1048576
TEST 23 1048576
TEST 24 1048576
TEST 25 1048576
TEST 26 1048576
TEST 27 1048576
28 rows selected
delete还是不回收空间,我们依然占用着28个区
[oracle@secdb1 ~]$ sqlldr userid=ls/ls control=leo_test.ctl data=leo_test.data log=leo_test.log direct=true 直接方式加载数据
SQL> select segment_name,extent_id,bytes from user_extents where segment_name='TEST';
SEGMENT_NAME EXTENT_ID BYTES
TEST 0 65536
TEST 1 65536
TEST 2 65536
TEST 3 65536
TEST 4 65536
TEST 5 65536
TEST 6 65536
TEST 7 65536
TEST 8 65536
TEST 9 65536
TEST 10 65536
TEST 11 65536
TEST 12 65536
TEST 13 65536
TEST 14 65536
TEST 15 65536
TEST 16 1048576
TEST 17 1048576
TEST 18 1048576
TEST 19 1048576
SEGMENT_NAME EXTENT_ID BYTES
TEST 20 1048576
TEST 21 1048576
TEST 22 1048576
TEST 23 1048576
TEST 24 1048576
TEST 25 1048576
TEST 26 1048576
TEST 27 1048576
TEST 28 1048576
TEST 29 1048576
TEST 30 1048576
TEST 31 1048576
TEST 32 1048576
TEST 33 1048576
TEST 34 1048576
TEST 35 1048576
TEST 36 1048576
TEST 37 1048576
TEST 38 1048576
TEST 39 1048576
TEST 40 1048576
TEST 41 1048576
TEST 42 1048576
TEST 43 1048576
TEST 44 1048576
TEST 45 1048576
TEST 46 1048576
TEST 47 1048576
48 rows selected
发现同样的100万条记录,竟然占用了48个区,传统加载只用了28个,而我们使用直接加载到多了20个数据块,
对了直接加载不扫描原来的空数据块,会在所有数据块之后加载新的数据块插入数据修改高水位线HWM,
当提交事务之后,把高水位线移到新数据之后,其他的用户就可以看见了。
比较直接加载使用conventional 和direct方式产生的redo大小(可以通过/*+ append */模拟直接加载)。
明确:直接加载与logging配合下并不能显著的减少redo日志量
直接加载与nologging配合下可以大幅度的减少redo日志量
SQL> create table leo_t1 as select * from test where 1=2; 创建leo_t1表
Table created.
SQL> alter table leo_t1 logging; 设置leo_t1表logging模式
Table altered.
SQL> set autotrace trace traceonly;
SQL> insert into leo_t1 select * from leo_test_sqlload where rownum <= 20000; 采用传统方式加载2万条记录
20000 rows created.
Statistics 统计信息
1071 recursive calls
2668 db block gets
1860 consistent gets
386 physical reads
1680404 redo size 这是产生的日志量1680404
680 bytes sent via SQL*Net to client
603 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
20000 rows processed
SQL> rollback; 回滚操作,使用undo表空间
Rollback complete.
SQL> insert /*+ append */ into leo_t1 select * from leo_test_sqlload where rownum <= 20000; 使用直接加载方式插入2万条记录
20000 rows created.
Statistics
94 recursive calls
268 db block gets
1294 consistent gets
202 physical reads
1627260 redo size 当leo_t1为logging属性时,直接加载和传统加载产生redo日志差不多
664 bytes sent via SQL*Net to client
617 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
20000 rows processed
小结:这是因为在logging模式下,所有的数据块的改变都会产生redo日志,为以后恢复做准备,这时候直接加载没有多大的优势。
直接加载与nologging配合下可以大幅度的减少redo日志量
重大前提
如果你的数据库开启了force_logging=yes模式,那么不管你是传统加载还是直接加载都不会减少redo产生量
所以要想大幅度减少redo日志就必须满足3个条件
(1)关闭force_logging选项 alter database no force logging; 启动 alter database force logging;
(2)数据对象级别nologging模式 alter table leo_t1 nologging;
(3)直接加载 insert /*+ append */ into
数据库归档与redo日志量关系
数据库处于归档模式
当表模式为logging状态时,无论是否使用append模式,都会生成redo.当表模式为nologging状态时,只有append模式,不会生成redo。
数据库处于非归档模式
无论是在logging还是nologing的模式下,append的模式都不会生成redo,而no append模式下都会生成redo。
SQL> alter database no force logging;
SQL> select force_logging from v$database; 已经关闭force_logging选项
FOR
NO
SQL> alter table leo_t1 nologging; 设置leo_t1表nologging模式
Table altered.
SQL> select logging from user_tables where table_name='LEO_T1';
LOG
NO
SQL> select count(*) from leo_t1; 0条记录
COUNT(*)
0
SQL> select index_name from user_indexes where table_name='LEO_T1'; 表上没有索引
no rows selected
SQL> insert /*+ append */ into leo_t1 select * from leo_test_sqlload where rownum <= 20000; 直接加载
20000 rows created.
Statistics
1443 recursive calls
649 db block gets
1702 consistent gets
1519 physical reads
44900 redo size 直接加载产生的redo日志非常少
658 bytes sent via SQL*Net to client
617 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
9 sorts (memory)
0 sorts (disk)
20000 rows processed
SQL> rollback;
Rollback complete.
LS@LEO> insert into leo_t1 select * from leo_test_sqlload where rownum <= 20000; 传统加载
20000 rows created.
Statistics
4 recursive calls
2207 db block gets
1534 consistent gets
441 physical reads
1634064 redo size 传统加载产生的redo日志非常非常的多
673 bytes sent via SQL*Net to client
603 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
20000 rows processed
小结:直接加载与nologging配合下可以大幅度的减少redo日志量,因为插入的数据不产生redo日志,
所以在插入后要做备份操作,一旦数据损坏,就要使用备份来恢复,不能使用redo来恢复。注意要关闭force_logging选项

谢谢提醒,不好意思,如果你要贴一段很长的日志 亦或者 执行计划,那么为了防止格式乱掉,建议你用code模式
用2个 把你的内容包括在里面即可 我在CODE模式中                                                                                                                                                                                                            

Similar Messages

  • ошибка загрузки

    Не могу установить программы в Creative Cloud пишет ошибка загрузки

    Please refer to :
    Error downloading and installing Creative Cloud application
    Troubleshoot CCM Applet installation and download
    Creative Cloud "Download Error" message
    It should help you.
    Regards
    Rajshree

  • R Entarprise run embedded R

    Hello All.
    I'm install R Enterprise in my ora 11 base. And try execute code.
    From RStudio I run this:
    ## Is the ORE client connected to the ORE server?
    ## The output of this command should be TRUE.
    ore.is.connected() - it's work
    ## List the available database tables
    ore.ls() - It's work too
    ## Push an R dataframe to a database table
    CARS <- ore.push(cars) -OK
    head(CARS) -OK
    ## Run embedded R
    ore.doEval(function() { 123 }) - It's ERROR
    Error in .oci.GetQuery(conn, statement, data = data, prefetch = prefetch, :
      ORA-06520: PL/SQL: Error loading external library
    ORA-06522: Unable to load DLL
    ORA-06512: at "RQSYS.RQEVALIMPL", line 17
    ORA-06512: at "RQSYS.RQEVALIMPL", line 14
    ORA-06512: at line 4
    More, I run this from SQL Developer:
    BEGIN
    sys.rqScriptCreate('myRandomRedDots2',
    'function(divisor = 100, numDots = 100) {
    id <- 1:10
    plot(1:numDots, rnorm(numDots), pch = 21, bg = "red", cex = 2 )
    data.frame(id = id, val = id / divisor)
    END;
    It's correct.
    But it's ERROR:
    "SELECT *
    FROM table(rqEval(NULL, 'SELECT 1 id, 1 val FROM dual', 'myRandomRedDots2'));
    ORA-06520: PL/SQL: Ошибка загрузки внешней библиотеки
    ORA-06522: Unable to load DLL
    ORA-06512: на  "RQSYS.RQEVALIMPL", line 17
    ORA-06512: на  "RQSYS.RQEVALIMPL", line 14
    ORA-06512: на  line 4
    06520. 00000 -  "PL/SQL: Error loading external library"
    *Cause:    An error was detected by PL/SQL trying to load the external
               library dynamically.
    *Action:   Check the stacked error (if any) for more details.
    Please HELP ME. Where solution?

    What platform (Windows, Linux, or other?) are you running?
    Does libR.so exist in $R_HOME/lib and $ORACLE_HOME/lib?
    Regards,
    Sherry

  • Ошибка в функции YtFlv2Mp3.DocOnLoad. TypeError: oDoc.location.href.startsWith is not a function

    When I try to open my web browser or a new webpage then it writes out the next in a pop-up window: Ошибка в функции YtFlv2Mp3.DocOnLoad. TypeError: oDoc.location.href.startsWith is not a function. I hope that the problem can be solved.

    Thank you so much! Arigatou! Danke schön! Köszönöm!

  • ошибка код 205 при установки Creative Cloud на windows 8.1. Что делать?

    ошибка код 205 при установки Creative Cloud на windows 8.1. Что делать?

    ошибка код 205 при установки Creative Cloud на windows 8.1. Что делать?

  • Установил пробную версию Adobe Photoshop Elements v.11, срок действия закончился, я её удалил.. Купил лицензионную программу, а она не устанавливается! В конце загрузки, при установке общих компонентов пишет:"Не удалось установить Shared Technologies" и д

    Установил пробную версию Adobe Photoshop Elements v.11, срок действия закончился, я её удалил.. Купил лицензионную программу, а она не устанавливается! В конце загрузки, при установке общих компонентов пишет:"Не удалось установить Shared Technologies" и делает откат программы. Как мне исправить эту ошибку? Спасибо!!!

  • ошибка при загрузке OS x 10.8.1

    Было утановлено OS X Moutain Lion 10.8. При загрузке обновлдения 10.8.1. возникает ошибка. Как все исправить???????

    My mail application completely failed shortly after the upgrade to Mountain Lion. None of the user advice has repaired it from these forums, so I have now resigned myself to using my ipad and iphone to conduct all my business emails. I was hopeful that this first 10.8.1 update from Apple would restore the my mail application. I can frustratingly report that no, it certainly hasn't. No change in fact. I click on the mail app and the beachball of death continues for about 5 minutes then it comes up with a message 'there is a problem with your mailboxes' with the option to quit or quit and rebuild index. If I choose that latter, the beachball resumes it's rotation forever or until I hard reset the machine as all other programs crash at this point. Apple, please help FAST, this is no way to run a business!!!!

  • Постоянно выскакивает ошибка Buffer overrun detected firefox.exe После этой ошибки закрываю Firefox но процесс firefox остается незавершенным, и приходится его завершать вручную в Диспетчере задач. Что нужно сделать чтобы эта ошибка больше не выскакивала?

    Постоянно выскакивает ошибка Buffer overrun detected firefox.exe После этой ошибки закрываю Firefox но процесс firefox остается незавершенным, и приходится его завершать вручную в Диспетчере задач. После перезагрузки компьютера эта ошибка поначалу не появляется, но затем снова выскакивает, и все чаще и чаще, и так до следующей перезагрузки. Раньше такого не случалось, это началось несколько месяцев назад, невозможно спокойно работать с интернетом. Прошу мне помочь.

  • Не пускает в ICloud ошибка 403

    Не пускает в ICloud ошибка 403  что это может быть в Appstore пускает

    Try сбросить пароль Apple ID.
    Коснитесь Настройки> Магазин> Apple ID> iForgot

  • ERROR: Media DB Error : 12 ошибка при установке illustrator

    ERROR: Media DB Error : 12 ошибка при установке illustrator

    Give full permisson in to below given location also inherite the permission to sub folders and files.
    Windows (64 bit OS) : C:\Program Files (x86)\Common Files\Adobe\caps
    Windows (32 bit OS) : C:\Program Files\Common Files\Adobe\caps
    MAC :  /Llibrary/Application support/Adobe/caps
    Then try to install, if still not work then Rename media_db.db located in above mentioned location to media_db_old.db
    After Renaming try to install the software

  • Ошибка аутентификации PDP

    Не могу войти в мобильный интернет, всё подключено, но пишет: "ОШИБКА АУТЕНТИФИКАЦИИ PDP". Что делать?

    hello, you could try resetting the file in your firefox profile that holds the certificate information, maybe it has become corrupted.
    therefore go to ''firefox > help > troubleshooting information'', click on ''profile folder/show folder'' and close all firefox windows afterwards. a windows explorer window should open up - in there rename or delete the file named '''cert8.db''' (& '''cert_override.txt''' in case it is present) - it will be regenerated again the next time you launch the browser.

  • Ошибка установки

    При установке Adobe Degign Standart на Windows 7 возникла ошибка,
    Exit Code: 20
    -------------------------------------- Summary --------------------------------------
    - 0 fatal error(s), 0 error(s), 0 warning(s)

    You have to provide exact system info. This simply looks like your system does not at all meet the requirements.
    Mylenium

  • Mac выдает: ошибка 4sns/1/40000000:tmop/65.625 что делать и как настраивать? подскажите

    mac выдает: ошибка 4sns/1/40000000:tmop/65.625. Подскажите что делать и как настраивать?

  • Низкая скорость загрузки Appstore

    Good afternoon. Please tell me the answer to the question about the slow download appstore. Phone Iphone 5 6.1.2. Different modes have switched on the router. Download speed is still very low. Program 10 minutes 10 mb swings

    я не знаю, есть ли у wifi адаптеров стационарных компьютеров опция энергосбережения, если есть - попробуйте отключить ее в диспетчере устройств.
    x220 | i5-2520m | Intel ssd 320 series | Gobi 2000 3G GPS | WiFi
    x220 | i5-2520m | hdd 320 | Intel msata ssd 310 series | 3G GPS | WiFi
    Do it well, worse becomes itself
    Русскоязычное Сообщество   English Community   Deutsche Community   Comunidad en Español

  • Метка времени: 20.02.2013 9:29:11 Ошибка: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized Источник: resource://gre/modules/AddonManager.jsm Строка: 17

    After upgrading from 15 to 18 and then to 19 version, all addons turned off.
    When goind to addon manager page, it shows Loadin... and nothing more. Error from console in subj.

    It is possible that there is a problem with the file(s) that store the extensions registry.
    Delete the files extensions.* (e.g. extensions.sqlite, extensions.ini, extensions.cache) and compatibility.ini in the Firefox profile folder to reset the extensions registry.
    *https://support.mozilla.org/kb/Profiles
    New files will be created when required.
    See "Corrupt extension files":
    *http://kb.mozillazine.org/Unable_to_install_themes_or_extensions
    *https://support.mozilla.org/kb/Unable+to+install+add-ons
    If you see disabled, not compatible, extensions in "Tools > Add-ons > Extensions" then click the Tools button at the left side of the Search Bar (or click the "Find Updates" button in older Firefox versions) to check if there is a compatibility update available.
    If this hasn't helped then also try to delete the addons.sqlite file.

  • HT4623 у меня на iPhone 3G стояла прошивка 4.2.1, я хотел обновить, но теперь вылазит ошибка 1015 как вастоновить прошивку

    HELP.. Помогите пожалуйсто починить iPhone

    Ну пожалуйста помогите!!!

Maybe you are looking for