ORA-04031错误的解决

早上刚一上班,突然得到通知A1数据库不能登录了,在登录的时候会抛出ORA-00604,ORA-04031错误,从ORA-04031错误的提示上看,似乎是shared pool大小不够使用了。登录进数据库以后只能做查询表的操作,不能查询系统管理表,想看看shared_pool_size的设定值也不能查询。只能到spfile里去查看一下当前的shared_pool_size大小设置,原设定值是312M,将其修改为512M后,再登录系统,成功登录,无任何报错了。

通过查询各种资料的结果,该问题主要导致的直接原因是shared pool过小或者shared pool中碎片过多,找不到足够大的连续空间可使用,解决方法主要是以下四种:
- Use bind variables in your applications (if they are not used allready)
- Pin larger packages (the ones you actaully use) immediately uppon database startup
- Increase your shared pool (if it's not unreasonably large allready)
- ALTER SYSTEM FLUSH SHARED_POOL; when you encounter ORA-4031 (this is more of a temporary workaround than a real sollution)

第一种方式需要从应用方面去解决,要在应用里绑定参数;第二种是要在数据库启动后马上将大的包pin到shared pool里,强制占用共享池的这部分空间不再释放;第三种是增加shared pool大小,前提是原有大小确实不是很大;第四种就是清除shared pool里的内容,这个操作只是个治标不治本的办法,执行这个语句的结果是将缓存在library cache和data dictionary cache 中的sql,pl/sql和数据字典定义都从共享池中清除了,在负载很重的生产库里执行flush shared_pool无异于自杀,即使执行成功了,也会产生大量的硬解析。

The FLUSH SHARED POOL clause lets you clear all data from the shared pool in the system global area (SGA). The shared pool stores Cached data dictionary information and Shared SQL and PL/SQL areas for SQL statements, stored procedures, function, packages, and triggers.
This statement does not clear shared SQL and PL/SQL areas for items that are currently being executed. You can use this clause regardless of whether your instance has the database dismounted or mounted, open or closed.

pin包到shared pool:
How to do it: To pin a package in the shared pool use the following command: 
execute dbms_shared_pool.keep('SCHEMA.PACKAGE','P') 

发生这种问题以后还是要注意看应用里是不是没有使用bind变量,这种情况导致此问题的可能性很大。

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

转载于:http://blog.itpub.net/10096205/viewspace-697958/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值