Archive for August, 2009
DBMS_UTILITY, A Good Helping Hand For A DBA….
Posted by Aman Sharma in genernal on August 29, 2009
There are couple of stored packages which are not much popular but are immensely popular. If we use them in our daily routine tasks, there are many tasks which would be done very easily. Like this,there is a package called DBMS_UTILITY. I do talk about it a lot in a program of mine which talks about advanced usage of PL/SQL. This is an extremely useful package with many goodies coming along with it which can be handy. Just thought to share this package and some of the procedures that I use,
Port_String
This is a very handy function and answers a question which is asked almost very often that on which operating system, oracle is running. Using this, it comes very easily like follow,
SQL> select dbms_utility.port_string from dual;
PORT_STRING
——————————————————————
IBMPC/WIN_NT-8.1.0
SQL>
So I am running my Oracle 10201 on Windows NT based machine(Windows XP professional).
DB_Version
A very handy procedure to show the current database version and compatibility number. Surely, this can also come from V$version but the option is available from this procedure as well.
SQL>variable a varchar2(4000);
SQL>variable b varchar2(4000);
SQL> declare
2 version varchar2(1000) default ‘Database Version’;
3 compatible varchar2(1000) default ‘DB Compatibility’;
4 begin
5 dbms_utility.db_version(:a,:b);
6 dbms_output.put_line(version||’====’||:a);
7 dbms_output.put_line(compatible||’====’||:a);
8 end;
9 /
Database Version====10.2.0.1.0
DB Compatibility====10.2.0.1.0
PL/SQL procedure successfully completed.
SQL>
Get_Parameter_Value
This shows us the parameter value. Interestingly, this procedure doesn’t need DBA access to be avaiable to see the parameter values. Yuo can run it as a normal user as well and can see the parameter values.Note that this doesn’t apply to all the parameters that are present in the parameter file. So you need to play around a bit with it and check which one works and which doesn’t.Surely, this taks is not supposed to be for a normal user but just in case, if even a normal user needs to see the parameter values,this can come as useful.
SQL> conn new/new
Connected.
SQL> set serveroutput on
SQL> declare
2 intval number;
3 strgval varchar2(400);
4 begin
5 intval:=dbms_utility.get_parameter_value(‘background_dump_dest’,intval,strgval);
6 dbms_output.put_line(‘Value of the parameter Background Dump Dest is ‘||’==== ‘||strgval);
7 end;
8 /
Value of the parameter Session Cached Cursors is ====
E:\ORACLE\PRODUCT\10.2.0\ADMIN\ORCL\BDUMP
PL/SQL procedure successfully completed.
SQL>
Like the above, there are many procedures and functions which can be very useful depending on how and where you use them. Docs have a very good description of each of these so I suggest you refer to docs for the complete description and guidelines. Here is the link for the same(11g),
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_util.htm#i996767
The idea of this blog post was just to give a "bump up" for this package which in my opinion can serve many purposes for a DBA. Hope it helps some where someone
.
Select For Update A DML, Yes It Is….
Posted by Aman Sharma in internals on August 27, 2009
Okay, if you think that what the heck, this guy didn’t know this much even, well, its true. I didn’t know or to save myself, I would say, I did know what Select For Updat does , like it locks the rows and so on, but didn’t relate to the redo part. So when I came to know about it reading this thread(thanks to Mark) today I tested it out, it appears to be true. So before I would forget about it, I thought to store it here. If you already knew, refresh your memories, if not , keep it in memory
.
A Select statement is merely meant to select the data from the table, that’s it, plain and simple. It doesn’t do anything else. It doesn’t generate any undo and redo in normal conditions but for a delayed block cleanout, it may generate redo as well. There are no locks which are acquired by it , there is nothing which gets changed. Yes it may look for the Snapshot Blocks if there are DMLs happening on the data which it is looking for but that’s it. Other than all this, it behaves properly
.
Select for update statement, is a cousin of Select only but it is not that simple as like its sibling. With For Update added , Oracle has to make sure that the candidate rows must be locked. And this means, for all the rows being effected, the lock byte of them would get locked , including the segment also whose row we are going to hit. This means, Select For Update is actually not just a select statement but its a DML which actually would start a transaction, lock the rows, generate redo for changing their lock records and also would require a rollback explicitly given to get those locks released. Have a look,
<code>
SQL> select * from v$version;
BANNER
—————————————————————-
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Prod
PL/SQL Release 10.2.0.1.0 – Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 – Production
NLSRTL Version 10.2.0.1.0 – Production
SQL> create table testredo as select * from all_objects;
Table created.
SQL> set autot trace stat
SQL> select * from testredo;
49714 rows selected.
Statistics
———————————————————-
288 recursive calls
0 db block gets
4041 consistent gets
683 physical reads
0 redo size
5337330 bytes sent via SQL*Net to client
36839 bytes received via SQL*Net from client
3316 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
49714 rows processed
SQL> /
49714 rows selected.
Statistics
———————————————————-
0 recursive calls
0 db block gets
3956 consistent gets
0 physical reads
0 redo size
5337330 bytes sent via SQL*Net to client
36839 bytes received via SQL*Net from client
3316 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
49714 rows processed
</code>
There was no requirement for running the same select twice, I just ran it to ensure me that nothing fishy is going on
.
So there is no redo with the normal select. Let’s try out For Update now,
<code>
SQL> select * from testredo for update;
49714 rows selected.
Statistics
———————————————————-
771 recursive calls
50738 db block gets
4862 consistent gets
1 physical reads
10369188 redo size
4444384 bytes sent via SQL*Net to client
36839 bytes received via SQL*Net from client
3316 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
49714 rows processed
WHOOOAAA! There is a lot of redo. Let’s see if there is some transaction record that we have got,
SQL> select * from V$locked_object;
XIDUSN XIDSLOT XIDSQN OBJECT_ID SESSION_ID
———- ———- ———- ———- ———-
ORACLE_USERNAME OS_USER_NAME PROCESS
—————————— —————————— ————
LOCKED_MODE
———–
9 8 364 52533 159
AMAN oracle 4989
3
SQL> select xidusn,xidslot,xidsqn from V$transaction;
XIDUSN XIDSLOT XIDSQN
———- ———- ———-
9 8 364
SQL>
</code>
So there is indeed a transaction which got recorded and there is surely a lock that’s there on the object also. Let’s finish it off,
<code>
SQL>roll;
Rollback Complete
SQL> select * from V$locked_object;
no rows selected
SQL> select * from V$transaction;
no rows selected
SQL> set autot trace stat
SQL> select * from testredo;
49714 rows selected.
Statistics
———————————————————-
0 recursive calls
0 db block gets
3956 consistent gets
1 physical reads
0 redo size
5337330 bytes sent via SQL*Net to client
36839 bytes received via SQL*Net from client
3316 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
49714 rows processed
SQL>
</code>
So we are back to from where we started.
A small but good learning , at least for me, thanks to Mark and Charles for their explanation over the the original thread.
Conclusion, think more deeply about something. At times, just knowing about the concept is not enough
. And yes, just for the record, select for update is a DML statement, not just a normal select , that’s the actual conclusion right
!
Test Post….
Posted by Aman Sharma in Uncategorized on August 26, 2009
Just posting this post to test whether the psots are being able to come to the blog or not? Issues issues issues are there with the blog
A Small Note About DBCA….
Posted by Aman Sharma in genernal on August 20, 2009
I am asked couple of times by some delegates to write some short notes about couple of topics which they find hard(boring should be right word to use I guess) to read from official oracle documentation. There are couple of topics like these and I finally thought to give a try for one of those. I tried to write a small note about DBCA and some things about it which can be beneficial if one knows about them. Its not an internal note so don’t think it like that way. Its just to understand the tool, its usage and some things related to it. I have mentioned the version of the note as 0.1 as I shall keep on modifying it based on the feedback/corrections that I shall receive ( and the version count will change accordingly ) . I must say thanks to Girish Sharma, Amardeep Sidhu who gave couple of inputs about some points and they were certainly very good. Sidhu even helped me how to make up the pdf file( yes I didn’t know how to do so). Thanks a bunch guys!
So without further wait, download the note from here. Its for the first time that I have attempted to do anything like this so I am part excited , part worried . Anyways, have a happy read and don’t forget the feedback/corrections
.
Update
1) Well, call it silly but today only I was told that the document is not formatted
. One of my friend looked at the document and that was the very first comment of him. Silly me! So now the document is formatted and the new copy is loaded.
2) Amit Bansal gave the feedback about formatting and also about the location of the data files being created using silent mode. According to the feedback, formatting is bit changed(improved I should say) and the note about datafile location is added. Thanks a bunch Amit, it was a really great feedback! Keep them coming
.

Recent Comments