Oracle 表空间的监控
现在所有业务系统上面都部署了各种类型针对各方面的监控,那么咱们oracle也不例外,也需要做关于oracle方面的监控,比如实例的存
现在所有业务系统上面都部署了各种类型针对各方面的监控,那么咱们Oracle也不例外,也需要做关于oracle方面的监控,比如实例的存活状况,监听器的存活状况,系统的运行情况(包括,磁盘使用率,进程数,登陆系统用户数,系统负载情况,各类型表空间的使用率等等)基于系统运行情况的监控软件很多,比如nagios之类的,在此就不做使用和监控方法。但是要监控oracle实例的运行情况,就得一直观察oracle的告警日志,那么我们可以通过使用脚本来监控oracle实例的运行情况,当告警日志中出现ORA错误时,立即将告警日志中的错误信息提取使用邮件和短信的方式发送给咱们DBA工程师。至于表空间的监控,由于需要了解表空间的使用率,必须使用sql语句查询来看,仅仅依靠脚本是不够的,那么我们就可以通过脚本+sql语句来监控oracle的表空间。下面我分别说下监控oracle告警日志和表空间的方法。
监控oracle告警日志的方法:
1.创建profile文件。
vim /etc/oracle.profile
#######################################################################
## oracle.profile ##
#######################################################################
EDITOR=vi;export EDITOR
ORACLE_BASE=/u01/app/oracle; export
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64; export
LD_LIBRARY_PATH TNS_ADMIN=$ORACLE_HOME/network/admin;export
TNS_ADMIN NLS_LANG='American_China.ZHS16GBK'; export
NLS_LANG NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'; export
NLS_DATE_FORMAT RATAB=/etc/oratab;export
#ORATAB PATH=$PATH:$ORACLE_HOME:$ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/
#sbin:/usr/openwin/bin:/opt/bin:.; export
PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
DBALIST="xujinhua@uniits.com,xujinhua@cbc.cn";export DBALIST
2. 编写检查oracle alter日志脚本(oracle用户)
#!/bin/ksh
source /etc/oracle.profile
#for SID in `cat $ORACLE_HOME/sidlist`
for SID in 'orcl'
do
cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace
if [ -f alert_${SID}.log ]
then
mv alert_${SID}.log alert_work.log
touch alert_${SID}.log
cat alert_work.log >> alert_${SID}.hist
grep ORA- alert_work.log > alert.err
fi
if [ `cat alert.err|wc -l` -gt 0 ]
then
mailx -s "mobile-testdb${SID} ORACLE ALERT ERRORS" $DBALIST fi
rm -f alert.err
rm -f alert_work.log
done
3.oracle用户下使用crontab定期运行检查oracle alter日志的脚本,即可。
监控表空间的方法:
由于现在表空间都使用自动扩展模式,在规划数据库的时候,都是根据业务一段时间运行的数据量作参考规划数据文件的大小,从而决定数据文件的个数以及初始每个数据文件的初始大小和每次扩展的大小。那么咱们要监控表空间的利用率是没意义的,因为运行数据增长一段时间就会达到初始设置的大小,,此时就会触发报警表空间不足,但是事实上它会自动扩展。但是也不能说就不监控了,咱们可以定期了解表空间的使用情况,看跟咱们预估的数据文件的大小有多少,这样也能起到监控表空间的效果。 【Linux公社 】
1)编写如下脚本:
[root@woodpecker oracle]# cat tbs_monitor.sh
#!/bin/sh
#this is a script. of monitor
#login
su - oracle -c "sqlplus / as sysdba"
start /home/oracle/tb_check/spool.sql
exit;
EOF
#out
export ORACLE_SID=orcl
export TODAY=`date '+%Y%m%d'`
MONITOR=monitor$TODAY.lst
#mail for user
mail -s "$ORACLE_SID TABLESPACE $MONITOR" xujinhua@uniits.com
2)编写如下sql:
[root@woodpecker oracle]# cat /home/oracle/tb_check/spool.sql
spool on;
set echo off
set feedback off;
set termout off;
set heading on;
set term off
column dat new_value date;
select to_char(sysdate,'yyyymmdd') dat from dual;
spool monitor&&date;
set linesize 80;
select d.tablespace_name,space sum_space,
space-nvl(free_space,0) used_space,
round((1-nvl(free_space,0)/space)*100,2) used_rate,
free_space free_space
from (select tablespace_name,
round(sum(bytes)/(1024*1024),2) space,
sum(blocks) blocks
from dba_data_files
group by tablespace_name) d,
(select tablespace_name,
round(sum(bytes)/(1024*1024),2) free_space
from dba_free_space
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name(+);
spool off;
exit;
3)通过系统的crontab定时每天调度一次脚本即可每天告诉给dba数据库的所有表空间的使用情况。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.
