October 28, 2009
In Oracle file structure, there is one type of file called redo log file, which record down all the transactions done to the database. There will be a finite number of redo log files, which will keep on reusing the files in a Mary Go Round way. As the database is enabled with archived log, the redo log file will be duplicated into a copy of archived log before it is being reused.
Aside from recovering purpose, archived log can also be served as a transaction tracking material. However the log itself is in binary form, which we need a utility called LogMiner to decode the log file.
- Before you can use LogMiner you need to install the package by executing the following SQL file as SYS user:
$ORACLE_HOME/rdbms/admin/dbmslm.sql
- Then grant necessary privilege to user who can execute LogMiner package (Let’s say user James):
grant execute_catalog_role to james;
- Then create synonym for the LogMiner package:
create public synonym dbms_logmnr for sys.dbms_logmnr;
- You can query the list of archived log:
SELECT distinct member LOGFILENAME FROM V$LOGFILE;
There is 2 ways to read the archived log, one is to read the archived log at the database with the archived log, or move the archived log to another database and read it there. To read the log at the same database:
- Check where is your archived log placed (you may check it from the parameter file
log_archive_dest). Assume that it is /u01/db/archive and the log you want to encode is 123.arc.
- Run statement below to add the archived log to the dictionary:
exec DBMS_LOGMNR.ADD_LOGFILE('/u01/db/archive/123.arc');
- Then run statement below to start the LogMiner:
exec DBMS_LOGMNR.START_LOGMNR(options => dbms_logmnr.dict_from_online_catalog);
To read the log at a different database:
- Move the archived logs to another database server (let’s say you placed in at
/u01/temp)
- Run statement below to build a data dictionary for the archived log (you can change the file and directory):
exec dbms_logmnr.build('logmnr.dat','/u01/temp');
- The run statement below to add the log file into the dictionary:
exec DBMS_LOGMNR.ADD_LOGFILE('/u01/temp/123.arc');
- Start the LogMiner:
exec DBMS_LOGMNR.START_LOGMNR(dictfilename => '/u01/temp/logmnr.dat');
Either way, you can query the log content through this view v$logmnr_contents. However the data in the view will be wiped off after you close the session, which mean you need to add the log file and start the LogMiner again in order to get back the data. Some useful columns include:
- username: database user used
- timestamp: when it is happened
- sql_redo: SQL statement of what actually been done
- sql_undo: SQL statement to undo the transaction
- scn: system change number, the unique id of this transaction
- seg_type_name: object type
- table_space: from which tablespace
- session#
- seg_owner: object owner
- table_name: table name
- operation: update, insert, delete, commit or rollback
- session_info: include info such as from which machine
Leave a Comment » |
Oracle | Tagged: archive log, logminer, Oracle |
Permalink
Posted by vicker313
October 21, 2009
After we setup the Backup Strategy, we need to prepare for recovering. Basically it involves 2 major steps: restore and recover.
Restore database simply means uncompress (such as UNTAR) the full backup from the backup tape:
- Uncompressed the full backup from tape (assume the tape is known as
/dev/st0)
tar xvf /dev/st0
- Don’t try to start the database first before you finish the next step, recovering database.
Different between restore and recover is that: restore is directly extracted from a backup, while recover is rebuilding data of an outdated database (such as from a full backup) to a status of particular moment.
- Remove all the archived log in the archived log directory (assume it is
/u01/oracle/archive)
rm -fv /u01/oracle/archive/*
- Uncompressed the daily backup (which is the archived log) .
tar xvf /dev/st0
- Start SQLPLUS as SYSDBA.
sqlplus / as sysdba
- Start database in mount mode
startup mount;
- In case you have problem in startup the database because of the parameter file is not set, issue the command below and try again:
create spfile from pfile = 'dest_of_your_parameter_file';
- Then issue command below to start recover from archived log:
recover database using backup controlfile until cancel
- It will keep asking for your comfirmation on the name of the archived log to be recovered. Either press Enter, the location of the archived log, or key in cancel to stop the recover.
- After recover open the database by issuing command below, aware that you won’t able the continue recover the archived log after issue this command, or else you need to start all over again from restoring database:
alter database open resetlogs;
- In case you face problem in open the database, add
_allow_resetlogs_corruption=true to the parameter file, issue command below and try again.
create sp file from pfile = 'dest_of_your_parameter_file';
Leave a Comment » |
Oracle | Tagged: archive log, Oracle, recover, tape catridge, untar |
Permalink
Posted by vicker313
October 14, 2009
Below is a backup strategy of Oracle Database with the conditions:
- The database is Archived Log Enabled.
- The database can be shutdown during weekend.
Archived log records down all the transactions that be performed in the database, which can serve as backup or trace log. It can even be backup when the database is up (hot backup). This strategy is using Linux environment, but you may apply the method to other OS. It involves 2 parts: daily backup (the hot backup) and weekend backup (or full backup, cold backup):
Daily Backup: AKA hot backup, which the backup is performed when database is up.
- This will be performed every night of weekday.
- Identify where is your archived log placed (refer to
log_archive_dest parameter in the parameter file).
- Set CRON job to TAR all the archived log into Tape (assume
/dev/st0 is your tape drive and /u01/oracle/archive is your archive log directory):
tar cvf /dev/st0 /u01/oracle/archive
- You may check the status of the Tape using command below:
mt status
Try to install mt-st package in case the command is not installed.
- To verify the content of the tape and save it as a log by using command below:
tar tvf /dev/st0 > dailybackup.log
Weekend Backup: AKA cold backup because it is performed when the database is shutdown.
- This will be performed during weekend.
- Shutdown the database (command might be different depend on your Oracle Environment Setting).
service dbora stop
- TAR the whole database directory (assume
/u01/oracle is where your database placed).
tar cvf /dev/st0 /u01/oracle
- Verify the tape and save it as log.
tar tvf /dev/st0 > fullbackup.log
- Remove the archived log (or the archived log will getting more and more until take out all your spaces).
rm -fv /u01/oracle/archive/*
- Start the database.
service dbora start
Continue to Recover Strategy.
2 Comments |
Oracle | Tagged: archive log, backup, Oracle, tape catridge, tar |
Permalink
Posted by vicker313
October 7, 2009
URL Query String is the string append to the web page URL. For example http://www.google.com/search?q=url+query+string, the string after the question mark (?) is the query string.
Most of the surfers will not care about the URL, which they consider them as alien language. However it would be nice if the URL can be translated into something more friendly to surfers, and most important to the search engine.
If your web server is Apache, you might follow the steps below to rewrite the URL (assume the folder of your website is webdir inside your document root):
- Enable the rewrite module in Apache. To do this, you need to edit the configuration file conf\httpd.conf.
- Find the following line and uncomment it.
LoadModule rewrite_module modules/mod_rewrite.so
- In some scenario, you need to set the AllowOverride parameter to All as well.
<Directory "document roots">
...
AllowOverride All
...
</Directory>
- Then restart the server.
- Create a file called .htaccess at webdir.
- Add the following coding or sample to .htaccess.
RewriteEngine On
RewriteBase /webdir/
RewriteRule index.html$ index.php [NC]
RewriteRule index/([^/]+)$ index.php?a=$1 [NC]
RewriteRule index/([^/]+)/([^/]+)$ index.php?a=$1&b=$2 [NC]
Now when you type:
- index.html, it will translate to index.php
- index/category, it will translate to index.php?a=category
- index/cateogory/linux, it will translate to index.php?a=category&b=linux
Leave a Comment » |
Apache | Tagged: .htaccess, query string |
Permalink
Posted by vicker313
September 8, 2009
In Windows, we can issue the following command to set static IP address in Command Prompt:
netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1
where the 3 IPs are Machine’s IP, Subnet Mask and Gateway
Or to set dynamic IP:
netsh interface ip set address "Local Area Connection" dhcp
Leave a Comment » |
Windows | Tagged: command prompt, netsh, Windows |
Permalink
Posted by vicker313
September 8, 2009
To change file attributes in Windows using Command Prompt:
attrib [+|-][ahsr] filename
Where + means enable the attribute, - means disable the attribute.
a: Archive
h: Hidden
s: System File
r: Read Only
Example:
attrib +sh filename means make the file a hidden system file
attrib -r filename means make the file not read only
Leave a Comment » |
Windows | Tagged: attrib, command prompt, Windows |
Permalink
Posted by vicker313