如何在 Oracle 中收集更多的统计信息?

How to collect more statistics in Oracle?

我是 Oracle 的新手,想知道如何在我将在下面描述的情况下获得更多统计信息。我正在使用 SQL 开发人员。

首先,我执行这个:

SET autotrace on;

SELECT NAME
FROM PASSENGER
WHERE ID_PSG IN (
    SELECT ID_PSG
    FROM PASS_IN_TRIP PIT JOIN TRIP T on T.TRIP_NO = PIT.TRIP_NO
    WHERE UPPER(TOWN_FROM) = 'MOSCOW'
    )

在脚本输出中,我可以看到有关来自 PLAN_TABLE table 的查询的信息,然后是文本:

Unable to gather statistics please ensure user has correct access. The statistic feature requires that the user is granted select on v_$sesstat, v_$statname and v_$session.

我已经尝试在这里找到解决方案,有一个 link: SQL Developer : Unable to gather system statistics : insufficient privileges 所以我执行了相同的命令并且 g运行ts 都成功了:

GRANT CREATE session TO PRACTICE;
GRANT GATHER_SYSTEM_STATISTICS TO PRACTICE; 
GRANT CONNECT TO PRACTICE;

然后我断开连接,关闭 SQL dev,打开它,再次连接,如 link、运行

的解决方案中所述
execute dbms_stats.gather_system_stats ('START'); 

得到这个:

PL/SQL procedure successfully completed.

然后我觉得一切都很好,并尝试从头开始执行代码,它的脚本输出仍然和以前一样。 我是否需要 g运行t 其他任何东西,或者可以在其他地方找到此统计信息,或者我只是做错了?

那个错误是关于 sqlplus autotrace,它不是关于收集系统统计数据,就像你链接的 post 似乎是关于。

有一个专门为这些赠款创建的角色,名为 plustrace https://docs.oracle.com/database/121/SQPUG/ch_eight.htm#SQPUG535

To use this feature, you must create a PLAN_TABLE table in your schema and then have the PLUSTRACE role granted to you. DBA privileges are required to grant the PLUSTRACE role. For information on how to grant a role and how to create the PLAN_TABLE table, see the Oracle Database SQL Language Reference.