ITPub博客

首页 > 数据库 > Oracle > [20260318]如何实现.txt

[20260318]如何实现.txt

原创 Oracle 作者:lfree 时间:2026-03-19 20:39:23 0 删除 编辑

[20260318]如何实现.txt

--//昨天在执行alter session set events 'trace[nsmtio]';,分析是否采用直接路径读时,跟踪内容如下:
NSMTIO: kcbcmt1: scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084

--//明显scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc对应8个变量,后面0 17952 0 56782 1053 0 0 201084是其对应的值。
--//不知道为什么其他都是 变量  数字,这里风格发生变化。
--//假如问nbuf对应值,肯定给仔细数才能找到对应值。

--//当然使用vim很快修改如下:
scann     = 0
age_diff  = 17952
adjts     = 0
last_ts   = 56782
nbuf      = 1053
nblk      = 0
has_val   = 0
kcbisdbfc = 201084

--//注:不知道这种是否正确,开始我的理解nblk表示表的块数量,应该是1053.而nbuf=56782。这样就错位了。
--//或许这里具备另外的含义。kimi上提问(适当做了排版):
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|字段      | 全称/含义                                    |说明                                                                                             |
|----------| -------------------------------------------- |------------------------------------------------------------------------------------------------ |
|scann     | Scan Count / Scan Flag                       |**扫描计数或扫描类型标志**:0表示第1扫描、全表扫描或特定扫描类型;非零表示扫描次数或并行扫描标识|
|age_diff  | Age Difference                               |当前时间与对象最后加载时间的差值,用于LRU老化算法计算缓存优先级                                  |
|adjts     | Adjusted Timestamp                           |**调整后的时间戳**:此处为0,表示无时间调整或对象未被缓存过                                      |
|last_ts   | Last Timestamp                               |对象最后加载到缓存的时间戳;或参考缓存总大小(如db_cache_size相关)                                |
|nbuf      | Number of Buffers                            |当前为对象分配的**缓冲区数量**:1053表示已分配较多缓冲区                                         |
|nblk      | Number of Blocks                             |**对象块数**:0表示对象当前无块在缓存中,或统计尚未完成                                          |
|has_val   | Has Valid Value                              |**统计有效性标志**:0表示统计数据不可靠、缺失或对象刚被访问,尚未建立完整统计                    |
|kcbisdbfc | KCB Is DB Flash Cache / Cache Decision Value |**数据库闪存缓存标志或缓存决策值**:此处201084是一个较大的数值,可能表示缓存决策权重、           |
|          |                                              |闪存缓存中的块数,或缓存策略计算结果                                                             |
-------------------------------------------------------------------------------------------------------------------------------------------------------------
--//不知道kimi如何猜测这些信息,是否正确也不知道。

--//直接kimi提问,给出几个答案,仅仅贴出其中一个例子:

$ cat nm.sh
#!/bin/bash

line="NSMTIO: kcbcmt1: scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084"

# 提取字段名和数值
read -ra tokens <<< "$line"

names=()
values=()

for token in "${tokens[@]}"; do
    # 跳过前缀
    [[ "$token" == "NSMTIO:" || "$token" == "kcbcmt1:" ]] && continue

    # 判断是否为数字
    if [[ "$token" =~ ^[0-9]+$ ]]; then
        values+=("$token")
    else
        names+=("$token")
    fi
done

# 计算最大长度
max_len=0
for name in "${names[@]}"; do
    len=${#name}
    (( len > max_len )) && max_len=$len
done

# 格式化输出
for ((i=0; i<${#names[@]}; i++)); do
    printf "%-${max_len}s  %s\n" "${names[$i]}" "${values[$i]}"
done

$ . nm.sh
scann      0
age_diff   17952
adjts      0
last_ts    56782
nbuf       1053
nblk       0
has_val    0
kcbisdbfc  201084

--//仔细看了脚本利用判断是否是数字,分别放入2个数组,然后输出。

--//自己想到一个更简单的写法:

$ line="scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084"
$ paste  -d= <(echo $line | grep -o "[a-z_]\+") <(echo $line | grep -o "[0-9]\+")
scann=0
age_diff=17952
adjts=0
last_ts=56782
nbuf=1053
nblk=0
has_val=0
kcbisdbfc=201084

--//如果 line="NSMTIO: kcbcmt1: scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084"
--//还不好写。这样要过滤掉前2个:

$ line="NSMTIO: kcbcmt1: scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084"
$ paste  -d= <(echo $line | grep -o "[a-zA-Z_]\+"| sed -n '3,$p') <(echo $line | grep -o " [0-9]\+")
scann= 0
age_diff= 17952
adjts= 0
last_ts= 56782
nbuf= 1053
nblk= 0
has_val= 0
kcbisdbfc= 201084

--//利用数字前面存在1个空格,因为kcbcmt1包含1个数字1.
--//噢,可以充分利用每个字母字符串结尾都有1个空格实现:

$ line="NSMTIO: kcbcmt1: scann age_diff adjts last_ts nbuf nblk has_val kcbisdbfc 0 17952 0 56782 1053 0 0 201084"
$ paste  -d= <(echo $line | grep -o "[a-zA-Z_]\+ ") <(echo $line | grep -o " [0-9]\+")
scann = 0
age_diff = 17952
adjts = 0
last_ts = 56782
nbuf = 1053
nblk = 0
has_val = 0
kcbisdbfc = 201084


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3113967/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969542