命令行界面下使用Emca安装配置Oracle Database Contr(2)

3 使用EMCA配置Database Control

3.1 配置数据

使用的命令是: emca -repos create

它的作用是为Database Control在数据库中创建必要的用户(模式)(sysman, dbsnmp等)和模式对象(存储过程,表,索引等等)。emca本身是一个脚本文件,最终调用的是java程序来完成实际的工作。由于在创建对象的过程中,需要以sysman用户身份调用Oracle数据库提供的一些函数或过程,所以必须要确保sysman拥有相关的权限。这也是配置中通常会出问题的地方。

需要注意的是emca首先以sys身份创建sysman账户,然后以sysman账户进行后续对象的创建。然后这两者之间是连续的,没有给我们修改sysman权限的机会。所以我们要在运行emca之前把sysman需要的权限赋予public账户,这样当sysman账户被创建后自动就会有相应的权限了。

那么到底需要赋予sysman那些权限呢?答案是很多。我的方法是,首先运行emca,如果权限有问题emca就会爆粗,然后根据错误日志找到缺少的权限,之后把这个权限赋给public,然后emca -repos recreate。

下面给出一个排错的例子:

[oracle@db001 ~]$ emca -repos recreate;

STARTED EMCA at Jul 10, 2014 4:18:24 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: xgdb
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:
Password for SYSMAN user:
Do you wish to continue? [yes(Y)/no(N)]: y
Jul 10, 2014 4:18:37 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log.
Jul 10, 2014 4:18:37 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) ...
Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig invoke
SEVERE: Error creating the repository
Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_repos_create_<date>.log for more details.
Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMConfig perform
SEVERE: Error creating the repository
Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log for more details.
Could not complete the configuration. Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log for more details.

上面是一个出错的例子,从红色部分看出,创建数据失败,根据提供的信息,查看日志文件:

313 Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
314 CONFIG: Spooling to /oracle/cfgtoollogs/emca/xgdb/emca_repos_create_2014_07_10_16_19_44.log
315 Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
316 INFO: Creating the EM repository (this may take a while) ...
317 Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig createRepository
318 CONFIG: ORA-04063: package body "SYSMAN.MGMT_LOGIN_ASSISTANT" has errors
319 ORA-06508: PL/SQL: could not find program unit being called:

这里已经能看出大概的错误是SYSMAN.MGMT_LOGIN_ASSISTANT这个包编译有问题了,为了获取详细错误,继续查看提示的日志文件。

PL/SQL procedure successfully completed.


Commit complete.

BEGIN
*
ERROR at line 1:
ORA-04063: package body "SYSMAN.MGMT_LOGIN_ASSISTANT" has errors
ORA-06508: PL/SQL: could not find program unit being called:
"SYSMAN.MGMT_LOGIN_ASSISTANT"

这就能确定确实是这个包的问题了,那么究竟为什么这个包编译失败呢?此时,sysman账户已经建立,我们以sysman账户登入sqlplus,然后手动编译这个包,看看错误究竟在哪里。

执行 SQL> alter package mgmt_login_assistant compile body;

此时会报错,继续查看出错原因:

SQL> show errors;

显示 函数ENCRYPT invalid。

这说明magmt_login_assistant这个包依赖ENCRYPT函数,而ENCRYPT函数自身有问题。那么继续看看ENCRYPT函数究竟什么问题。

SQL> alter function encrypt compile;

Warning: Function altered with compilation errors.

SQL> show errors;
Errors for FUNCTION ENCRYPT:
9/5      PL/SQL: Statement ignored
10/22    PLS-00201: identifier 'SYS.UTL_I18N' must be declared

可见错误在于ENCRYPT函数依赖于SYS.UTL_I18N这个包,而这个包没有声明,其实是sysman用户没有执行权限。

找到了错误根源,解决就容易多了,以sys账户登录,然后赋予public角色执行SYS.UTL_I18N这个包的权限。

SQL>  grant execute on UTL_I18N to public;

Grant succeeded.

然后重新以sysman登录,并编译ENCRYPT函数成功,继续编译MGMT_LOGIN_ASSISTANT也成功了,这说明找到了问题所在。总结一下上面的依赖情况:

SYSMAN.MGMT_LOGIN_ASSISTANT包 < SYSMAN.ENCRYPT函数 < SYS.UTL_I18N包。

然后退出sql,重新执行 emca -repos recreate。如果还是报错,请按照上面查找问题的思路解决问题,直到成功。

[oracle@db001 ~]$ emca -repos recreate;

STARTED EMCA at Jul 10, 2014 4:37:11 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: xgdb
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:

Do you wish to continue? [yes(Y)/no(N)]: y
Jul 10, 2014 4:37:24 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_37_11.log.
Jul 10, 2014 4:37:25 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) ...
Jul 10, 2014 4:38:28 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Jul 10, 2014 4:38:29 PM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Jul 10, 2014 4:42:47 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Enterprise Manager configuration completed successfully
FINISHED EMCA at Jul 10, 2014 4:42:47 PM

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/df3028768d9e87344440c025ed322b79.html