My crsstat script: Improved Formatting of crs_stat on 10g and 11g
My crsstat shows a tabular format of CRS or HAS resources (i.e. Cluster 10gR2-11gR2 or ASM/Single instance scenario 11gR2). It has been a work in progress for a while. When I first started working with 10gR2 RAC, I quickly discovered that I didn’t quite like the formatting of the default crs_stat -t output, so I wrote my first version of the crsstat script, which consisted of a korn shell script and an awk script (which gave pretty close to the same output as the current version). I enhanced it at some point to show a different color, if the state didn’t match the target state. Then 11gR2 came out and I really didn’t like the output, so I sat down and wrote the awk script to format the 11gR2 output and added a variable at the top to choose which awk script. One of my colleagues saw it and liked the output, so I shared it; however, he asked if I could simplify the installation, as at that time you had to set the location of the script, whether it was 10g or 11g, and the location of the CRS_HOME. Finally, I sat down and decided to make it as universal and easy to use, as I could by adding the awk scripts as variables within the ksh script and adding a section to attempt to determine the CRS or HAS home automatically. It seems to work fairly well and several of my colleagues have been using it, so I thought I would share it more universally. Hope everyone finds it useful!
Read more
Table Functions: 9i Feature Worth Revisiting (Part 2)
In part I of this series I showed a simple example of how table functions can be used to treat PL/SQL collection types as tables in a SQL query. We used a nested table collection type to which we manually added a few entries. In this example, I intend to show a more practical use of table functions using all three PL/SQL collection types: associative arrays, nested tables, and VARRAYs.
Sizing up your environment for backups to tape
So, you just spent many long hours putting together your latest and greatest creation. Hot off the presses, you have a true work of art. Now what? You are being audited on backups? You realize that there was no money for backup gear in the budget, but having this kind of risk over your head can only be viewed as something to offload to an over-taxed shared services IT department at your org or a chance to play russian roullette with your data? No! It’s time to get an accurate assessment of what you need to backup and get your tape requirements sorted out so that you can present a case for your backups and any needed gear to get the job done. Don’t worry, you may not have to spend 2 trillion dollars on gear (unless you work for the government), especially if you already have a working environment to do your existing backups and just need to find/make capacity on the tape SAN. That being said, you still need to know what you’ll need to do or ask for and how can you do that if you just go to upper management and say, ” I just got an Exadata and I need at least 48×365 = 17520 TB of capacity in my tape backup gear to make sure we are covered for the year. Let’s not be greedy. Even the most novice executive will question the costs needed to satisfy that kind of requirement.
Making the assumption that you are using RMAN, you have already configured your backups to run a weekly full on each database to tape once per week, incrementals daily, and a reasonable amount of archivelogs being generated daily to the Fast Recovery Area, we can proceed to estimate your immediate needs.
If you are running Oracle and you are using RMAN, you can get the sizing numbers you need for your tape requirements somewhat easily if you are already taking backups to your Fast Recovery Area. There are a number of different views that can provide information about your backups, but I have found the most beneficial information can be gathered from the views used here. The helpful script that follows can be run to collect data on all the different types of backups you are currently running and the sizes (this script allows you to feed a list of SIDs):
#!/bin/bash
. /home/oracle/.bash_profile
ORAENV_ASK=NO
for DB in `echo “$DB_LIST”`; do
export ORACLE_SID=$DB
. oraenv $DB >/dev/null
echo “Database: $DB”
sqlplus -s \/ as sysdba<<EOF
set serveroutput on
set linesize 150
set pagesize 300
select ctime “Date”,
decode(backup_type, ‘L’, ‘Archive Log’, ‘D’, ‘Full’, ‘Incremental’) backup_type,bsize “Size GB” from (select trunc(bp.completion_time) ctime, backup_type, round(sum(bp.bytes/1024/1024/1024),2) bsize
from v\$backup_set bs,
v\$backup_piece bp where bs.set_stamp = bp.set_stamp and bs.set_count = bp.set_count and bp.status = ‘A’ group by trunc(bp.completion_time), backup_type) order by 1, 2;
exit;
EOF
done
You can then look at the history of your current backups and right-size your tape requirements.
You might also check how many archive logs you are generating in a week under full production load:
col gbytes form 999,999.99
select sum(blocks*block_size)/1024/1024/1024 gbytes
from v$archived_log
where next_time > sysdate-8;
Some things to consider when you decide on your tape solution:
The type of tape drives
Encryption needs
The amount of compression
The number of tape drives
The type of backup software (OSB vs Netbackup vs Tivoli)
Your vaulting schedule (number of available media slots)
How fast can your channel send the data to the tape drives
Assuming you already have a tape SAN and you are not given enough money in your budget or enough lead time to get the gear in place before an audit, you might consider looking at what you have now in place and checking to see if you are doing too many backups, you have tuned your backups incorrectly, or if you have a number of backups that would benefit from VTL or dedup technologies in order to free space on your existing tape infrastructure.
Get Oracle Instant Client Working on Mac OS X Lion
CJ Travis has an excellent and thorough article on installing Oracle Instant Client on Mac OS X 10.7. The gist: you have to install the 32-bit version. As a bonus, he tells you how to download and install the handy rlwrap command line utility, which gives you the ability to navigate the statement history in SQL*Plus in a very bash-like fashion, using the up and down keys.
Table Functions: 9i Feature Worth Revisiting (Part 1)
Yes, they’ve been around for a while, but if you haven’t made use of table functions lately you might want to reacquaint yourself with this old gem. Table functions allow you to query the contents of PL/SQL collection types using SQL’s TABLE operator. Here is a simple example.
Recyclebin
What is the recyclebin?
The Oracle recyclebin has been around since version 10g release 1 as part of a feature called Flashback Drop and in my opinion, continues to be a little-known and little-understood feature. It has saved me from potential data loss on at least one occasion, though, so I think it deserves some consideration.
The recyclebin is actually a data dictionary table containing information about dropped objects. Each named user account has their own recyclebin. Unless a user has the SYSDBA privilege, the only objects that the user has access to in the recyclebin are those that the user owns. A user can view his objects in the recyclebin using the following statement:
Make bash scripts crontab-compatible
When writing shell scripts in bash, consider whether your script can be automated in a batch scheduler like cron. If you reference any external resources in your script relative to the directory in which it resides, those references may break when running your script through cron.
By default, crontab runs scripts in the user’s home directory, as specified in /etc/passwd. For user “Tim” with home directory /home/tim, a sample crontab might look something like the following:
Invalidating Toplink Session Cache To Avoid Stale Data
Toplink is a Java framework that maps objects to database tables. It is the reference implementation for the Java Persistence Architecture, or JPA. Developers use Toplink to manage data persistence (storage), queries, and transactions in an Oracle database. By default, Toplink makes use of a special cache called a Session Cache, maintained on the server, which is meant to speed up performance. Queried data is stored in the Session Cache and used in subsequent queries to reduce or eliminate calls to the database.
One problem with this approach is how to deal with “stale data”. In other words, what happens when data is changing in the database? How does the developer ensure that the cached data is current?
Fixed Object Statistics Benefits in 11g
I wrote recently about fixed object statistics in 10g and used an example to illustrate
their benefit to the optimizer in one particular situation. I recently found a similar situation in an 11g (release 2) database and wanted to see if I could get the same benefit from generating optimizer statistics on the fixed objects. The automatic statistics gathering job in 11g does not collect the fixed object statistics by default, but the fact that a pre-configured optimizer job exists underscores the importance of optimizer statistics.
We will start with a typical query you would execute to find out who is accessing
certain objects in the database: select distinct owner
from v$access;
Our test system: Oracle 11.2.0.1.0 64-bit on Sun SPARC Solaris version 10
Silently removing an old ORACLE_HOME
During a database upgrade, the majority of the focus is on the pre-requisites for the upgrade, the upgrade itself, and post-upgrade tasks. Little focus is given to the downgrade process and none at all to the removal of the Oracle software used by the previous database version. I was at a new client site the other day and they were running tight on space in one particular file system. The file system contained the Oracle software for versions 8i and 10g. The single database had been upgraded from the 8i to the 10g version some years ago, but the 8i software had never been removed. It was my first time working with this environment, so I wanted to make sure I did not remove anything vital when removing the old Oracle software.
Was the tightening of space sudden or gradual?