【问题标题】:Oracle 11gR2: slow insert performance, then fast insert performanceOracle 11gR2:插入性能较慢,然后插入性能较快
【发布时间】:2014-02-14 15:03:59
【问题描述】:

试图找出 Oracle 插入性能缓慢的根本原因。我两次运行完全相同的 SQL - 两次都从 Oracle 表中选择 1000 行并插入回同一个表中。第一个 INSERT 在 76 秒内运行。第二个 INSERT(相同的命令)在

INSERT INTO MY_TABLE SELECT * FROM MY_TABLE WHERE ROWNUM

这不是解析问题,INSERT of 1 row (ROWNUM

如果有任何可以帮助的跟踪数据,请告诉我。

(编辑:Gah!-探索了 meta.stackoverflow,找到了将这些数据从 Excel 格式化为 ASCII-Art 的建议,按照建议将结果放在代码标签之间......并且仍然得到了这个乱七八糟的混乱,所有换行符都被删除了...... .. META-HELP 请有人告诉我如何将其格式化为不删除换行符的可读表格!)

╔════════════════════════════════════════════════╦══════════════╦═══════════════╗
║                    StatName                    ║ First Insert ║ Second Insert ║
╠════════════════════════════════════════════════╬══════════════╬═══════════════╣
║ active txn count during cleanout               ║           17 ║            18 ║
║ buffer is not pinned count                     ║            8 ║             0 ║
║ buffer is pinned count                         ║            0 ║             0 ║
║ bytes received via SQL*Net from client         ║          145 ║           145 ║
║ bytes sent via SQL*Net to client               ║           79 ║            79 ║
║ calls to get snapshot scn: kcmgss              ║            4 ║             1 ║
║ calls to kcmgas                                ║            4 ║            16 ║
║ calls to kcmgcs                                ║           49 ║            50 ║
║ cell physical IO interconnect bytes            ║     16080896 ║        147456 ║
║ change write time                              ║            0 ║             1 ║
║ cleanout - number of ktugct calls              ║           17 ║            18 ║
║ consistent gets                                ║           71 ║            68 ║
║ consistent gets - examination                  ║           17 ║            18 ║
║ consistent gets from cache                     ║           71 ║            68 ║
║ consistent gets from cache (fastpath)          ║           50 ║            50 ║
║ CPU used by this session                       ║           17 ║             3 ║
║ CPU used when call started                     ║            0 ║             0 ║
║ cursor authentications                         ║            0 ║             1 ║
║ db block changes                               ║         2131 ║          2124 ║
║ db block gets                                  ║         5166 ║          5160 ║
║ db block gets from cache                       ║         5166 ║          5160 ║
║ db block gets from cache (fastpath)            ║         1035 ║          1037 ║
║ DB time                                        ║         7787 ║           104 ║
║ deferred (CURRENT) block cleanout applications ║            2 ║             0 ║
║ enqueue releases                               ║           22 ║             0 ║
║ enqueue requests                               ║           25 ║             0 ║
║ execute count                                  ║            3 ║             1 ║
║ file io wait time                              ║     76571222 ║       1010237 ║
║ free buffer inspected                          ║         3026 ║            64 ║
║ free buffer requested                          ║         1979 ║            34 ║
║ Heap Segment Array Inserts                     ║           35 ║            35 ║
║ hot buffers moved to head of LRU               ║          631 ║             2 ║
║ HSC Heap Segment Block Changes                 ║           35 ║            35 ║
║ IMU Flushes                                    ║            1 ║             0 ║
║ index scans kdiixs1                            ║            0 ║             0 ║
║ logical read bytes from cache                  ║     42901504 ║      42827776 ║
║ logons cumulative                              ║            0 ║             0 ║
║ logons current                                 ║            0 ║             0 ║
║ no work - consistent read gets                 ║           22 ║            18 ║
║ non-idle wait count                            ║         1732 ║            19 ║
║ non-idle wait time                             ║         7776 ║           101 ║
║ opened cursors cumulative                      ║            3 ║             1 ║
║ opened cursors current                         ║            0 ║             0 ║
║ parse count (hard)                             ║            1 ║             0 ║
║ parse count (total)                            ║            2 ║             1 ║
║ physical read bytes                            ║     16080896 ║        147456 ║
║ physical read IO requests                      ║         1836 ║            18 ║
║ physical read total bytes                      ║     16080896 ║        147456 ║
║ physical read total IO requests                ║         1836 ║            18 ║
║ physical read total multi block requests       ║            1 ║             0 ║
║ physical reads                                 ║         1963 ║            18 ║
║ physical reads cache                           ║         1963 ║            18 ║
║ physical reads cache prefetch                  ║          253 ║             0 ║
║ prefetch clients - default                     ║            1 ║             1 ║
║ process last non-idle time                     ║            0 ║             0 ║
║ recursive calls                                ║           15 ║             0 ║
║ recursive cpu usage                            ║            0 ║             0 ║
║ redo entries                                   ║         1079 ║          1073 ║
║ redo ordering marks                            ║            4 ║            16 ║
║ redo size                                      ║       463216 ║        453624 ║
║ redo subscn max counts                         ║           18 ║            16 ║
║ Requests to/from client                        ║            1 ║             1 ║
║ session connect time                           ║            0 ║             0 ║
║ session cursor cache count                     ║            2 ║             0 ║
║ session cursor cache hits                      ║            1 ║             0 ║
║ session logical reads                          ║         5237 ║          5228 ║
║ session pga memory                             ║       393216 ║             0 ║
║ session pga memory max                         ║       393216 ║             0 ║
║ session uga memory                             ║            0 ║             0 ║
║ session uga memory max                         ║            0 ║             0 ║
║ shared hash latch upgrades - no wait           ║            0 ║             0 ║
║ sorts (memory)                                 ║            0 ║             0 ║
║ sorts (rows)                                   ║            0 ║             0 ║
║ SQL*Net roundtrips to/from client              ║            1 ║             1 ║
║ table fetch by rowid                           ║            4 ║             0 ║
║ table scan blocks gotten                       ║           18 ║            18 ║
║ table scan rows gotten                         ║         1017 ║          1017 ║
║ table scans (long tables)                      ║            1 ║             1 ║
║ table scans (short tables)                     ║            0 ║             0 ║
║ undo change vector size                        ║       127384 ║        126740 ║
║ user calls                                     ║            2 ║             2 ║
║ user I/O wait time                             ║         7776 ║           101 ║
║ workarea executions - optimal                  ║            0 ║             0 ║
╚════════════════════════════════════════════════╩══════════════╩═══════════════╝`

【问题讨论】:

  • 您确定是 INSERT 需要时间,而不是第一次运行的 SELECT 吗?你试过只运行 SELECT 部分,看看发生了什么
  • 是的——绝对是 INSERT。能够通过 2 步重现效果:1)将 1k 行推送到边表 2)将行从边表推送到主表...确认 #1 非常快,#2 非常非常慢...以下接下来在贾斯汀的回答中,可能有更多细节

标签: sql performance oracle oracle11g


【解决方案1】:

两者之间的差异似乎主要是由于物理读取的差异。这意味着当您运行第一个INSERT 语句时,您需要SELECT 的块不在缓存中,必须从磁盘读取。当您再次运行该语句时,您需要的块仍在缓存中,因此您只需从 RAM 中读取它们。显然,从 RAM 读取比从磁盘读取要快得多。

话虽如此,很难想象从磁盘读取 1000 行数据(总共约 16 MB)真的需要 76 秒(file io wait time 从 76 秒以北到 1 秒以北第二个和physical read bytes 从 16 MB 到 150 kb)。这是一个相当慢的 I/O 速度,这意味着底层磁盘子系统存在某种问题。

【讨论】:

  • 更准确地说,我们将这里的缓存命名为 Exadata Cells。以cell% 开头的统计信息是 Exadata 的
  • 这很有趣 - cell% 的值也跳出来了 - 这不是 Exadata 数据库,我不知道为什么会显示这些互连统计信息。如果它有帮助,这是一个“突然”的发展......数据库没有重大变化,但是有一天,过去需要 2 小时的批量加载运行了 2 天。唯一的祝福是,它是开发盒......但是,在它出现在产品中之前,真的需要深入了解它。对于 I/O,我已经在磁盘设备上进行了一些基本的读/写“dd”测试——那里没有危险信号,但如果推荐更正式的测试,我会全力以赴。
  • @KevinKirkpatrick - 你在处理本地磁盘吗?还是使用 SAN?如果您查看 AWR 报告,您是否看到某些文件或某些表空间的平均读取时间过长?
  • 问题出在底层磁盘阵列上。我犯了一个不幸的错误,即使用“dd”实用程序进行基准测试,但只运行 100MB 测试。过错。数组的缓存很容易处理这个负载,所以我得到的印象是——“磁盘很好”。 3 天后......“嗯,也许我应该尝试 8GB 测试”。果然,前 100MB = 250MB/ps。剩余 7.9GB = 15 MB/秒。经验教训 :-) 这是确认磁盘问题的命令。 Shell1: "#iostat -xtcni 5 120 > /tmp/iostats.txt" Shell2 (cd 到数据库目录后): "# time sh -c "dd if=/dev/zero of=ddfile bs=8k count=1000000 &&同步”
  • 一方面道歉 - 很抱歉把它拖出去 - 因为问题出在开发盒上,必须努力寻找带宽来直接处理它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 2012-04-02
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多