Archive for the ‘Uncategorized’ Category
Delete vs Truncate For Inserts….
In my last trip, my friend Abhiranjan asked me a question which I promised him to answer later. The question was that when we do an insert in the table, oracle moves the High Water Mark. This would make the blocks formatted and eventually would be used by Oracle for insert. When this allocation is deleted by the Delete command, it leaves the free space in the table but the used space marker,High Water Mark still points towards the last block of the HWM list. So when we insert, why does Oracle doesn’t go and insert in the pre-allocated blocks and it would allocate new blocks?This was the question that was asked by Abhi.
The answer is that whether the pre-formatted blocks,which are below the HWM will be used or not will depend upon the nature of the Insert. if it would be normal insert than certainly depending upon the managment of the table,either FreeList or Bitmaps , Oracle would decide to use the pre-formatted blocks. But if the the insert would be a bulk insert than Oracle would assume that its better to format fresh,clean blocks above HWM and thus would allocate the new blocks.Bulk insert won’t use the blocks below the HWM.
A pretty simple answer of a pretty tough-looking question but I couldn’t answer it properly at that time. I hope it makes things clear now.
Cheers
Aman….
Shared_IO_Pool In SecureFiles Of 11g….
Securefiles in Oracle 11gR1 is a complete reengineered thing. Traditional lobs didn’t present so well themselves in the long run of business due to the limiation of their sizes and other factors which are pretty well documented in Oracle docs. So Oracle has given us in 11g Securefiles, LOBs on steroids if I can say so.
Well this blog post is not about Securefiles. Official docs do a pretty good job in explaining their working and other stuff and there are tons of other web sites which have done that already a good job explaining them eg you can read Tim Hall’s excellent article about the same here . This blog post is about a parameter that Oracle has given for the better working of Securefiles, yup correct, Shared_io_pool.
Shared_io_pool is added in the Oracle architecture to support large IOs. Normally large IO’s and if I can say, sort of like private IOs are best done using PGA with direct path access. When Securefiles are created with the options Cache which is actually borrowed from older cousin Basicfile aka LOBs only , they are read into the Buffer Cache which makes the access of these lobs more faster. This option is not there in Securefiles actually and hence is the reason for the 10g doc link. Using Buffer Cache is a good option but it has couple of issues as well. First and foremost is that due to the large size of lobs, they may go and kick the heck out all other tiny miny buffers from the buffer cache. Now if we are really using Lobs so we won’t mind doing this too I guess. But still, this can be not-so-good issue for the other small lookup table’s buffers which are thrown out. Another issue can be when we actually don’t use the Cache at all and go with plain, Nocache option which means , no buffer cache access. So now zero chance of any memory based access for lobs.
In 11g, for Securefiles, Oracle has tried to remove this issue with the introduction of Shared_IO_Pool parameter. This can be used as a shared region to support cached IOs for Securefiles. This parameter’s default size is mentioned as zero but I couldn’t find it as zero. I found it of actually some size. I guess the benefit is clear cut. As opposed to private memory given for PGA and to be allocated , this is a system level stuff so its more easy to give to everyone.
Lets see this parameter, starting from “normal” views
SQL> select * from V$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
SQL> select pool,name,bytes from V$sgastat where lower(name) like '%shared%';
POOL NAME BYTES
------------ -------------------------- ----------
shared_io_pool 4194304
shared pool SHARED SERVERS INFO 3108
generic process shared st 12
array 2 for shared redo b 96
array 1 for shared redo b 96
ksfd shared pool recovery 24
6 rows selected.
SQL> startup force
ORACLE instance started.
Total System Global Area 188313600 bytes
Fixed Size 1332048 bytes
Variable Size 134220976 bytes
Database Buffers 46137344 bytes
Redo Buffers 6623232 bytes
Database mounted.
Database opened.
SQL> select pool,name,bytes from V$sgastat where lower(name) like '%shared%';
POOL NAME BYTES
------------ -------------------------- ----------
shared_io_pool 4194304
shared pool SHARED SERVERS INFO 3108
generic process shared st 12
array 2 for shared redo b 96
array 1 for shared redo b 96
ksfd shared pool recovery 24
6 rows selected.
SQL>
The default of this parameter’s value in my system is coming out to be 4m. I am not sure that its actually correct or not. I shall install a vanila install of Oracle db and will recheck it. Let’s try to see a little more deeper about this parameter.
I blogged about learning a new trick to find the info about the fixed table structures some time ago. Using the same, let’s see what comes out for this parameter,
SQL> desc v$fixed_view_definition
Name Null? Type
----------------------------------------- -------- ----------------------------
VIEW_NAME VARCHAR2(30)
VIEW_DEFINITION VARCHAR2(4000)
SQL> set long 500000
SQL> select view_definition from V$fixed_view_definition where view_name like 'V$SGASTAT';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select POOL, NAME , BYTES from GV$SGASTAT where inst_id = USERENV('Instance')
SQL> set long 500000000
SQL> select view_definition from V$fixed_view_definition where view_name like 'GV$SGASTAT';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select inst_id,'',ksmssnam,ksmsslen from x$ksmfs where ksmsslen>1 union all se
lect inst_id,'shared pool',ksmssnam, sum(ksmsslen) from x$ksmss where ksmssle
n>1 group by inst_id, 'shared pool', ksmssnam union all select inst_id,'large
pool',ksmssnam, sum(ksmsslen) from x$ksmls where ksmsslen>1 group by inst_id,
'large pool', ksmssnam union all select inst_id,'java pool',ksmssnam, sum(ksm
sslen) from x$ksmjs where ksmsslen>1 group by inst_id, 'java pool', ksmssnam
union all select inst_id,'streams pool',ksmssnam, sum(ksmsslen) from x$ksmstrs
where ksmsslen>1 group by inst_id, 'streams pool', ksmssnam
So there are couple of fixed table structures which are involved here. The structure, X$KSMFS(Kernel Services , Memory Fixed SGA) shows the info of fixed value area in the sga which includes shared_io_pool also,
SQL> select ksmssnam,ksmsslen from x$ksmfs 2 / KSMSSNAM KSMSSLEN -------------------------- ---------- fixed_sga 1332048 buffer_cache 46137344 log_buffer 6623232 shared_io_pool 4194304
So the size shown here is also 4m only.
Let’s see how many other parameters are there related to this?
SQL> select ksppinm,ksppstvl,ksppstdvl 2 from x$ksppcv a,x$ksppi b 3 where a.indx=b.indx and b.ksppinm like '%shared_io%'; KSPPINM KSPPSTVL KSPPSTDVL ------------------------------ ------------------------------ ---------------- __shared_io_pool_size 4194304 4M _shared_io_pool_size 4194304 4M _shared_iop_max_size 536870912 512M _shared_io_pool_buf_size 1048576 1M _shared_io_pool_debug_trc 0 0 _shared_io_set_value FALSE FALSE 6 rows selected. SQL>
So I guess the default size is indeed 4m only. I may be wrong so if you know some thing correct about this, do let me know and I shall correct it. It seems that this parameter can go maximumly to 512m. I am still searching for the other parameter’s description. Though look straight forward, I shall still wait to get the exact details about them before speaking about them.
Reading this article from Arup Nanda, it seems oracle has introduced some thing called Lob Cache specifically. Though I am not actually sure that there is some thing like this but it seems that this shared io pool is going to be lined with that in some way. It may be correct or may be not but this is my best guess about it so far.
It seems that Oracle has done some real thought-process before coming out with Securefiles. Let’s see what else we would see about them in future.
Aman….
Fixed Table’s Definitions, A New Learning….
Whenever I used to find out the info of any fixed table(x$) I used to do this by a workaround. I used to set the trace, run the query and see the table’s name. For example, if we are looking for the V$log’s fixed table name so I would do something like that ,
<code>
SQL> select * from V$log;
Execution Plan
----------------------------------------------------------
Plan hash value: 2536105608
--------------------------------------------------------------------------------
------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time |
--------------------------------------------------------------------------------
------------
| 0 | SELECT STATEMENT | | 1 | 185 | 0 (0)
| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 185 | 0 (0)
| 00:00:01 |
|* 2 | FIXED TABLE FULL | X$KCCLE | 1 | 136 | 0 (0)
| 00:00:01 |
|* 3 | FIXED TABLE FIXED INDEX| X$KCCRT (ind:1) | 1 | 49 | 0 (0)
| 00:00:01 |
--------------------------------------------------------------------------------
------------
Transport Tablespace In The Same Database….
Well this was not supposed to be a post but it was asked over Forums.oracle.com that can we do the transport of the tablespace in the same database after some testing?So the answer is yes. Now I was originally going to post it over there only but thanks to new Jive software, I couldn’t so I had to post it here. Have a read,
C:\Documents and Settings\Administrator>sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Sep 17 09:31:00
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> select name from V$database;
NAME
---------
MUMMYORA
SQL> create tablespace test_tt datafile 'd:\test.dbf' size 2m;
Tablespace created.
SQL> create user test identified by test default tablespace
test_tt
quota un
ted on test_tt;
User created.
SQL> grant create table ,create session to test;
Grant succeeded.
SQL> conn test/test
Connected.
SQL> create table tt_tab(a number);
Table created.
SQL> insert into tt_tab values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> conn / as sysdba
Connected.
SQL> alter tablespace test_tt read only;
Tablespace altered.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0
-
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
C:\Documents and Settings\Administrator>sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Sep 17 09:33:44
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> alter user sys identified by oracle;
User altered.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0
-
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
C:\Documents and Settings\Administrator>sqlplus "sys/oracle as
sysdba"
file=
est_tt.dmp tablespaces=TEST_TT TRANSPORT_TABLESPACE=y
Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
<logon> ::= <username>[/<password>][@<connect_string>] | /
|
/NOLOG
<start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
"-H" displays the SQL*Plus version banner and usage
syntax
"-V" displays the SQL*Plus version banner
"-L" attempts log on just once
"-M <o>" uses HTML markup options <o>
"-R <n>" uses restricted mode <n>
"-S" uses silent mode
C:\Documents and Settings\Administrator>exp "sys/oracle as
sysdba"
file=d:\t
tt.dmp tablespaces=TEST_TT TRANSPORT_TABLESPACE=y
LRM-00108: invalid positional parameter value 'as'
EXP-00019: failed to process parameters, type 'EXP HELP=Y' for
help
EXP-00000: Export terminated unsuccessfully
C:\Documents and Settings\Administrator>exp 'sys/oracle as
sysdba'
file=d:\t
tt.dmp tablespaces=TEST_TT TRANSPORT_TABLESPACE=y
Export: Release 9.2.0.1.0 - Production on Wed Sep 17 09:35:09
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 -
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR
character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace TEST_TT ...
. exporting cluster definitions
. exporting table definitions
. . exporting table TT_TAB
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
C:\Documents and Settings\Administrator>sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Sep 17 09:40:22
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0
-
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
C:\Documents and Settings\Administrator>d:
D:\>mkdir d:\bkup
D:\>copy TEST.DBF d:\bkup
1 file(s) copied.
D:\>sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Sep 17 09:40:50
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> alter tablespace test_tt read write;
Tablespace altered.
SQL> insert into test.tt_tab values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test.tt_tab;
A
----------
1
2
SQL> rem this was after export ;
SQL> drop tablespace test_tt including contents and datafiles;
Tablespace dropped.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0
-
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
D:\>imp 'sys/oracle as sysdba' file=d:\test_tt.dmp
tablespaces=TEST_TT
TRANS
_TABLESPACE=y datafiles='d:\test.dbf'
Import: Release 9.2.0.1.0 - Production on Wed Sep 17 09:43:03
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 -
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR
character set
. importing SYS's objects into SYS
IMP-00017: following statement failed with ORACLE error 1565:
"BEGIN
sys.dbms_plugts.beginImpTablespace('TEST_TT',12,'SYS',1,0,8192,1,3
"710620,1,2147483645,8,128,8,0,1,0,8,1151101578,1,1,35710182,NULL,0,0
,NULL,
"ULL); END;"
IMP-00003: ORACLE error 1565 encountered
ORA-01565: error in identifying file 'd:\test.dbf'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.
ORA-06512: at "SYS.DBMS_PLUGTS", line 1441
ORA-06512: at line 1
IMP-00000: Import terminated unsuccessfully
D:\>copy d:\bkup\TEST.DBF d:\
1 file(s) copied.
D:\>imp 'sys/oracle as sysdba' file=d:\test_tt.dmp
tablespaces=TEST_TT
TRANS
_TABLESPACE=y datafiles='d:\test.dbf'
Import: Release 9.2.0.1.0 - Production on Wed Sep 17 09:43:18
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 -
Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR
character set
. importing SYS's objects into SYS
. importing TEST's objects into TEST
. . importing table "TT_TAB"
Import terminated successfully without warnings.
D:\>sqlplus test/test
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Sep 17 09:43:26
2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights
reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> select * from tt_tab;
A
----------
1
SQL>
What we have done is that we made a user Test owning a tablespace
Test_tt. We put one value in it(our original work) and we exported the ”good time” tablespace. We did some more work,inserted one more
value(can call it changes or testing) and once we finished,we dropped the
tablespace. We didn’t drop the user. We imported back the tablespace
and we were back to value 1 from where we started. More or less,same like tablespace attached and detached.
Aman….