Measuring SQL Server memory performance with Buffer Cache Hit Ratio

In SQL Server 2008, there is one important performance counters that can be used to monitor memory performance. The SQL Server Hit Ratio shows the ratio of user requests served by data cache im memory. 

Here is the description about Buffer Cache Hit Ratio from MSDN

Percentage of pages found in the buffer cache without having to read from disk. The ratio is the total number of cache hits divided by the total number of cache lookups over the last few thousand page accesses. After a long period of time, the ratio moves very little. Because reading from the cache is much less expensive than reading from disk, you want this ratio to be high. Generally, you can increase the buffer cache hit ratio by increasing the amount of memory available to SQL Server. 

Since accessing data in memory(buffer cache) is much faster than accessing the same information from I/O subsystem, ideally, we always want to data is from memory instead of I/O.A desired value for cache hit ratio should be over 90 percent.

One simple way to get the value of buffer cache hit ratio is by querying the sys.dm_os_performance_counters dynamic management view. You need to get two counters from this view in order to calculate the Buffer cache hit ratio, one is Buffer cache hit ratio and the other one is Buffer cache hit ratio base. We divide Buffer cache hit ratio by Buffer cache hit ratio base and it will give us the Buffer cache hit ratio.

Here is the query to get the value of Buffer Cache Hit Ratio

SELECT ROUND(CAST(A.cntr_value1 AS NUMERIC) / CAST(B.cntr_value2 AS NUMERIC),6) AS Buffer_Cache_Hit_Ratio
FROM (
SELECT cntr_value AS cntr_value1
FROM sys.dm_os_performance_counters
WHERE object_name = 'SQLServer:Buffer Manager'
AND counter_name = 'Buffer cache hit ratio'
) AS A,
(
SELECT cntr_value AS cntr_value2
FROM sys.dm_os_performance_counters
WHERE object_name = 'SQLServer:Buffer Manager'
AND counter_name = 'Buffer cache hit ratio base') AS B;


In addition to running T-SQL, you can get the Buffer Cache Hit Ratio through the Windows Performance Monitor. After you launched the Performance Monitor from the Window Start Menu (Administrative Tools ).

To let the Performance Monitor displays the value of Buffer Cache Hit Ratio, you need to add the counter. In below screen capture, you will see Buffer Cache Hit Ratio is under SQLServer::Buffer Maanger section. After you added the counter, you will see the graphical presentation of the Buffer Cache Hit Ratio like below.






To recap, Buffer Cache Hit Ratio is a commonly used parameter to measure the memory performance of the databases but only in SQL Server, but Oracle and DB2 etc. This value provides us an insight whether the database server has been allocated to memory and read operation are done with memory. 






These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Delete statement will not reduce table size

Create a testing table called test

SQL> create table test  tablespace users as select * from dba_objects;

Table created.


We look at the size of the table test, the table size is around 3MB now
SQL> select owner,segment_name,tablespace_name, sum(bytes)/1024/1024 "Size in MB
" from dba_segments
  2  where segment_name='TEST'
  3  group by owner,segment_name,tablespace_name ;

OWNER                          SEGMENT_NA TABLESPACE Size in MB
------------------------------ ---------- ---------- ----------
SYS                            TEST       USERS               3


We now delete all the rows in the table and commit the statement.
SQL> delete from test;

22906 rows deleted.

SQL> commit;

Commit complete.


If we look at the size of the table now, the table size is still 3MB. This demonstrated that the table didn’t shrink after we delete data from the table.

SQL> select owner,segment_name,tablespace_name, sum(bytes)/1024/1024 "Size in MB
" from dba_segments
  2  where segment_name='TEST'
  3  group by owner,segment_name,tablespace_name ;

OWNER                          SEGMENT_NA TABLESPACE Size in MB
------------------------------ ---------- ---------- ----------
SYS                            TEST       USERS               3


To shrink the table, what I will do now is enable the row movement feature of the table.
SQL> ALTER TABLE test ENABLE ROW MOVEMENT;

Table altered.

SQL> alter table  test shrink space;

Table altered.



SQL> select owner,segment_name,tablespace_name, sum(bytes)/1024/1024 "Size in MB
" from dba_segments
  2  where segment_name='TEST'
  3  group by owner,segment_name,tablespace_name
  4  ;

OWNER                          SEGMENT_NA TABLESPACE Size in MB
------------------------------ ---------- ---------- ----------

SYS                            TEST       USERS           .0625

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Quick reference link for Oracle database patching

Evaluating and rolling out the latest database patches is one of the most common tasks for database administrator. For Oracle products, you will constantly receive the notification from Oracle (at least)quarterly telling you that the patches you need to implement.However, they wont tell which patch you need for your database versions, and you have search through their slow Oracle support portal to the find patch you need.

To save time, normally I go directly to this document, Quick Reference to Patch Numbers for Database PSU, SPU(CPU), Bundle Patches and Patchsets (Doc ID 1454618.1), and in this document I can see all the patches that have been released for different versions of Oracle databases.

This Oracle document certainly worth saving in the bookmark -)

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

List files in a folder

In this post, I will show you how to get and display the list of files in a folder and display them in an Excel spreadsheet. The below picture show the output spreadsheet of this procedure which display the files in a folder named c:\intel.

Note that you may encounter undefined object errors during the execution of below procedure. To fix this, you only need to enable a reference to Microsoft Scripting Runtime in Visual Basic Editor (Select Tools - References )



Sub CallListDir()
ListDir "C:\Intel", True
End Sub


Function ListDir(Folder As String, IncludeSubFolders As Boolean)

Dim FSO As Scripting.FileSystemObject
Dim CurFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim CurItem As Scripting.File
Dim RowNum As Long

Set FSO = New Scripting.FileSystemObject
Set CurFolder = FSO.GetFolder(Folder)
RowNum = Range("A65536").End(xlUp).Row

Cells(RowNum, 1).Formula = "FileName"
Cells(RowNum, 2).Formula = "FileSize"
Cells(RowNum, 3).Formula = "FileType"
Cells(RowNum, 4).Formula = "FileCreatedDate"
Cells(RowNum, 5).Formula = "FileLastAccessedDate"
Cells(RowNum, 6).Formula = "FileDateLastModifiedDate"
Cells(RowNum, 7).Formula = "FileAttributes : (R)eadOnly/(H)idden/(S)ystem/(V)olume/(D)irectory/(A)rchive/(A)lias/(C)ompressed"
RowNum = RowNum + 1

For Each CurItem In CurFolder.Files

Cells(RowNum, 1).Formula = CurItem.Path '& CurItem.Name
Cells(RowNum, 2).Formula = CurItem.Size
Cells(RowNum, 3).Formula = CurItem.Type
Cells(RowNum, 4).Formula = CurItem.DateCreated
Cells(RowNum, 5).Formula = CurItem.DateLastAccessed
Cells(RowNum, 6).Formula = CurItem.DateLastModified
Cells(RowNum, 7).Formula = ListFileAttr(CurItem.Attributes)
RowNum = RowNum + 1
Next CurItem
If IncludeSubFolders Then
For Each SubFolder In CurFolder.SubFolders
ListDir SubFolder.Path, True
Next SubFolder
End If
Columns("A:H").AutoFit
Set CurItem = Nothing
Set CurFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Function


Function ListFileAttr(a As Integer) As String

ListFileAttr = ""
If a And vbReadOnly Then
ListFileAttr = "R"
ElseIf a And vbHidden Then
ListFileAttr = ListFileAttr & "H"
ElseIf a And vbSystem Then
ListFileAttr = ListFileAttr & "S"
ElseIf a And vbVolume Then
ListFileAttr = ListFileAttr & "V"
ElseIf a And vbDirectory Then
ListFileAttr = ListFileAttr & "D"
ElseIf a And vbArchive Then
ListFileAttr = ListFileAttr & "A"
End If

End Function

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

List shared folders on Windows XP/WIN2K3/WIN2K8

Below is a simple but useful VBScript that can be used to list windows shares and their permission. I create this for my wintel admin for audit purpose sometimes ago and has been tested to be workable on XP and WIN2K3/2K3...;-p

Dim strComputer : strComputer = "."

Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                         
Dim colItems : Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalShareSecuritySetting")

Dim objItem, intRtn, wmiSecurityDescriptor

Dim colDACLs, objACE, objUserGroup, strPermission, colShr, objShr, output ,arg

Function Folderpermission(strRunCmd)

'Wscript.Echo strRunCmd

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strRunCmd)

strOut = "Folder permission:"& vbCr & vbLf

Do While Not objExec.StdOut.AtEndOfStream
strOut = strOut & vbCr & vbLf & objExec.StdOut.ReadLine()
Loop

Set objShell = Nothing
Set objExec = Nothing

Folderpermission= strOut
End Function

Set wshShell = CreateObject( "WScript.Shell" )
strRegValue = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname"
strHostName = wshShell.RegRead( strRegValue )
WScript.Echo "Host Name: " & strHostName & vbCr & vbLf
Wscript.Echo "============================================================="


For Each objItem In colItems
  WScript.Echo "Share Name:  " & objItem.Name

  Set colShr = objWMIService.ExecQuery("Select * from win32_share where name='" & objItem.Name & "'")
  For Each objShr in colShr
    WScript.Echo "Share Path:  " &  objShr.Path
' arg = "cacls " & """ & objShr.Path & """
arg = "cacls " & chr(34) & objShr.Path & chr(34)
  Next

  intRtn = objItem.GetSecurityDescriptor(wmiSecurityDescriptor)
   
  colDACLs = wmiSecurityDescriptor.DACL
 
  For Each objACE In colDACLs
    Set objUserGroup = objACE.Trustee
           
    WScript.Echo vbTab & "User/Group that has access:  " & UCase(objUserGroup.Name)
         
    Select Case objACE.AccessMask
      Case 1179817 strPermission = "READ"
      Case 1245631 strPermission = "CHANGE"
      Case 2032127 strPermission = "FULL CONTROL"
    End Select
         
    WScript.Echo vbTab & "Permission:  " & strPermission & VbCrLf

  Next

Wscript.Echo (Folderpermission (arg))

Wscript.Echo "============================================================="
Next


Output of the script looks like this:


Host Name: Test-PC

=============================================================
Share Name:  avaloq
Share Path:  D:\test\avaloq
        User/Group that has access:  EVERYONE
        Permission:  FULL CONTROL

Folder permission:

D:\test\avaloq DomainA\kokei :(OI)(CI)F

=============================================================
Share Name:  test
Share Path:  D:\test
        User/Group that has access:  kokei
        Permission:  READ

Folder permission:

D:\test BUILTIN\Administrators:(OI)(CI)F
        NT AUTHORITY\SYSTEM:(OI)(CI)F
        DomainA\kokei:F
        CREATOR OWNER:(OI)(CI)(IO)F
        BUILTIN\Users:(OI)(CI)R
        BUILTIN\Users:(CI)(special access:)
                          FILE_APPEND_DATA

        BUILTIN\Users:(CI)(special access:)
                          FILE_WRITE_DATA


=============================================================
Share Name:  shares
Share Path:  D:\shares
        User/Group that has access:  EVERYONE
        Permission:  READ

        User/Group that has access:  kokei
        Permission:  FULL CONTROL

Folder permission:

D:\shares DomainA\kokei:(OI)(CI)F
          BUILTIN\Administrators:(OI)(CI)F
          NT AUTHORITY\SYSTEM:(OI)(CI)F
         DomainA\kokei:F
          CREATOR OWNER:(OI)(CI)(IO)F
          BUILTIN\Users:(OI)(CI)R
          BUILTIN\Users:(CI)(special access:)
                            FILE_APPEND_DATA

          BUILTIN\Users:(CI)(special access:)
                            FILE_WRITE_DATA


=============================================================




These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Running BackupExec tasks from command line

BackupExec offers a command line executable which is especially useful when we want to manage the BackupExec tasks through applications or scripts.

Start Service
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o502

Stop Service
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o503

Tape Format
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o114 -d"IBMLTO4" -pr:Medium –w
** IBMLTO4 is device name

Tape Erase
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o111 -s -d"IBMLTO4" -e:1 -pr:Medium –w
** IBMLTO4 is device name

Inventory
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o117 -d"IBMLTO4" -pr:Medium –w
** IBMLTO4 is device name

Start Daily backup
c:\"Program Files\Symantec\Backup Exec"\bemcmd -o1 -jDaily_Backup -pr:Medium -w
** Daily_Backup is the backup job name


These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Create user with SQL Developer


SQL Developer has a very convenient function which allow users to create database users with user interface. Before you can create you need to ensure you have enough privilege. i.e.,CREATE USER, ALTER USER and etc system privileges.























If you don’t have enough privileges to create user, you may find the tablespaces option are blank and you cannot choose the any existing tablespace as default tablespace.


















Before you click apply to create the user, you can also extract the SQL statements for the user options that you have chosen.


















Move the results tab and then click Apply button. The SQL Developer will create user for you and you can see whether the user is created successfully and any error encountered during user creation will be shown as well.






These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Estimate index size with CREATE_INDEX_COST

Creating indexes on big table takes long time. What is even more time consuming is that you get ORA-01654: unable to extend index error while creating indexes. You have to give a emergency call to the storage guys to ask them allocating more space for you. Sometimes you have wait for hours(luckily) or days before extra space is available…and then run the create index statement again...

Therefore, capacity planning becomes essential when you are planning to create indexes.  In Oracle 10g or later, there is a procedure called CREATE_INDEX_COST in DBMS_SPACE package which can help you estimate the size of the index from your create indexes

Here is an example:
--create a testing table named t
SQL> create table t as select * from dba_objects;

Table created.

SQL> declare
begin
for i in 1..10 loop
insert /*+ APPEND */ into t select * from t;
commit;
end loop;
end; 
/

PL/SQL procedure successfully completed.

SQL> select count(*) from t;

  COUNT(*)
----------
  13405184

1 row selected.

--As told by Oracle docs, you have to have updated statistics in order to allow CREATE_INDEX_COST to produce accurate estimation
SQL> exec dbms_stats.gather_table_stats('TEST','T');

PL/SQL procedure successfully completed.

SQL> variable used_bytes number
SQL> variable allocated_bytes number
SQL> set autoprint on
SQL>


SQL> exec dbms_space.create_index_cost( 'create index t_idx on t(object_id,object_name,object_type)', :used_bytes, :allocated_bytes );

PL/SQL procedure successfully completed.


ALLOCATED_BYTES
---------------
      645922816


USED_BYTES
----------
428965888


Verification
SQL> create index t_idx on t(object_id,object_name,object_type);

Index created.


select segment_name ,sum(bytes) from dba_segments where owner='TEST' and segment_name='T_IDX' group by segment_name;

SEGMENT_NAME                                                                      SUM(BYTES)
--------------------------------------------------------------------------------- ----------
T_IDX                                                                              637534208

1 row selected.

We see that the CREATE_INDEX_COST says that the estimated index size is 616MB and the actual size of the index is 608MB.

Conclusions
We are happy that this procedure produce accurate result for our simple b-tree index. However,  I doubt that if procedure can procedure good result for other types of index such as bitmap or function-based index. I tried other types of indexes, but I found I cannot get a sensible from this procedure, my best guess is since this procedure produces result by the computation of average column length and the columns appeared in the create index statement…Anyways, I believe CREATE_INDEX_COST is good enough for the  rough estimation of index size ;-p

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Copy Schema from one machine to another machine using EXP/IMP

Though Oracle 10g provides new tools expdp and impdp for exporting and importing data between databases.
We still see lots of companies using old exp/imp to copy and move data. However, using exp/imp implies that DBA have to do more manual work in order to export and import data successfully. For example, tablespaces must be created before one can import dump to another database, privileges must be granted explicitly after the import and DBA have to create synonyms manually etc. All these are necessary to ensure users can use data on the new database without errors.

Here is a list of high level steps to copy schemas from one database to another.
In the target database (new database):
1).  Create any roles for the user .Grant system/object/role privileges that the user currently have in the source database
2).  Create any database links will be required in the schema.
3).  Create tablespaces. These would be the same tablespace names that the user currently have in the source database.
4). Create profiles that the user currently using in the source database.
5). Create the user who own the schema. Grant the privs/roles to those user as required.
6). Set the correct tablespace quota limit for users
7). Perform schema exports from the source database.
8). Perform schema import into the target database.
9). Create synonym in other schemas that need to reference to objects in the new schema.
10). Create constraints in other schema that need to reference to objects in the new schema. e.g. Foreign key constraints
11).Recompile invalid objects
12). Check if there are still invalid objects and fix them. 

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Determine the environment variables for a running Oracle instance in Solaris and Linux

One of the important steps in troubleshooting Oracle problem is to find out whether environment variables are set correctly. For a running instance, we can use the following methods to determine the environment variables.

1. Find the process id , PID, of the Oracle process
ps -ef |grep smon

2. Get the environment variables of the Oracle process

In Solaris,
pargs -e | grep ORACLE

In Linux,
cat /proc//environ

Example in Solaris
root# ps -ef |grep -i smon |grep -v grep|awk '{print $2}'|xargs pargs -e
2362:   ora_smon_TESTDB
envp[0]: SKGP_HIDDEN_ARGS=
envp[1]: ORACLE_SPAWNED_PROCESS=1
envp[2]: _=/usr/bin/perl
envp[3]: PATH=
envp[4]: LOGNAME=oracle
envp[5]: SHELL=/usr/bin/sh
envp[6]: HOME=/home/oracle
envp[7]: PWD=/home/oracle
envp[8]: TZ=Hongkong
envp[9]: ORAENV_ASK=NO
envp[10]: ORACLE_HOME=/u01/app/oracle/product/11.1.0.7
envp[11]: LD_LIBRARY_PATH=/u01/app/oracle/product/11.1.0.7/lib
envp[12]: LD_LIBRARY_PATH_64=/u01/app/oracle/product/11.1.0.7/lib
envp[13]: LIBPATH=/u01/app/oracle/product/11.1.0.7/lib
envp[14]: TNS_ADMIN=/u01/app/oracle/product/11.1.0.7/network/admin
envp[15]: ORACLE_SID=TESTDB
envp[16]: ORA_NLS10=/u01/app/oracle/product/11.1.0.7/nls/u01/app
envp[17]: DSM_DIR=/opt/tivoli/tsm/client/ba/bin
envp[18]: DSM_CONFIG=/opt/tivoli/tsm/client/ba/bin/dsm.opt
envp[19]: DSM_LOG=/u01/app/oracle/TESTDB/backup/u01/appbase
envp[20]: NLS_LANG=AMERICAN_AMERICA.AL32UTF8
envp[21]: ORA_NET2_DESC=11,14


Example in Linux
[root@test1 ~]# cat /proc/`ps -ef |grep -i smon |grep -v grep|awk '{print $2}'`/environ | tr '\0' '\n'
HOSTNAME=test1
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.1.200 60578 22
SSH_TTY=/dev/pts/5
USER=oracle
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
ORACLE_SID=testdb2
MAIL=/var/spool/mail/oracle
PATH=
INPUTRC=/etc/inputrc
PWD=/u01/app/oracle/oradata
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=1
HOME=/home/oracle
LOGNAME=oracle
CVS_RSH=ssh
SSH_CONNECTION=192.168.1.200 60578 192.168.1.101 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
G_BROKEN_FILENAMES=1
_=/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus
OLDPWD=/home/oracle
ORA_NET2_DESC=9,12
ORACLE_SPAWNED_PROCESS=1
SKGP_SPAWN_DIAG_PRE_FORK_TS=1305737174
SKGP_SPAWN_DIAG_POST_FORK_TS=1305737174
SKGP_HIDDEN_ARGS=
0
SKGP_SPAWN_DIAG_PRE_EXEC_TS=1305737174

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Space is not freed after removing the file in Unix

This situation usually occurs when a file is deleted while it is still opened by some other processes. This is because when open a file opened by a process, the reference count of the file will increment by 1. Removing the file only remove the directory point to that file and it does not remove the underlying file opened by the process.

Only until the offending processes close the file, either explicitly close the file with close() or manually kill the process, the reference to the file returns to zero and space occupied by the file is freed. A common example is Oracle writing to a trace files and these trace files grows to be large. When a DBA try to free the space by removing the trace files, he may found df command does not reflect the correct result. Under most circumstances, the most easiest way to free the space from the trace files is bounce the Oracle instance.

Below is an example performed 0n Solaris 10 to demonstrate how the space allocated to a file is not freed after removing the file. 

First we check the disk usage of the tmp diretory.
testsvr$ df -h|grep -i /tmp
swap                    78G   488K    78G     1%    /tmp

We run dd command to create a file named testfile in /tmp in the background. Since we are creating a 30GB file, it takes some time complete and the background process will keep the file open.
testsvr$ nohup dd if=/dev/zero of=/tmp/testfile bs=1048576 count=307200 &
[3]     17460
testsvr$ Sending output to nohup.out
testsvr$ ls -al /tmp/testfile
-rw-r--r--   1 oracle   dba      1144528896 May 18 23:42 /tmp/testfile
testsvr$ df -h|grep -i /tmp
swap                    78G   1.9G    77G     3%    /tmp

Here we can see that the dd command is still running and the size of the /tmp/testfile is growing
testsvr$ ps -ef |grep dd
  oracle 17841 12384   0 23:42:15 pts/7       0:00 grep dd
  oracle 17460 12384   2 23:42:00 pts/7       0:15 dd if=/dev/zero of=/tmp/testfile bs=1048576 count=307200

Then we delete the file.
testsvr$ rm /tmp/testfile
testsvr$
testsvr$ ls -al /tmp/testfile
/tmp/testfile: No such file or directory

We spotted the process id 17460 is opening a file with no named filename linked to it.
testsvr$ find /proc/*/fd -type f -links 0 \! -size 0 -ls

   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/1328/fd/5
427559811 6944224 --w-------   0 oracle   dba      7110885376 May 18 23:42 /proc/17460/fd/4
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25269/fd/5
   31    8 --w-------   0 oracle   dba          1418 Apr 16 11:03 /proc/25280/fd/2
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25280/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25286/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25297/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25310/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25322/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25326/fd/5
  102    8 --w-------   0 oracle   dba          5015 May 13 14:25 /proc/25332/fd/2
 
testsvr$ df -h|grep -i /tmp
swap                    78G    10G    68G    14%    /tmp

Then we kill the process 17460.
testsvr$ kill -9 17460
testsvr$ find /proc/*/fd -type f -links 0 \! -size 0 -ls

   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/1328/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25269/fd/5
   31    8 --w-------   0 oracle   dba          1418 Apr 16 11:03 /proc/25280/fd/2
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25280/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25286/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25297/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25310/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25322/fd/5
   67    8 --w-------   0 oracle   dba           639 Dec  9 05:16 /proc/25326/fd/5
  102    8 --w-------   0 oracle   dba          5015 May 13 14:25 /proc/25332/fd/2

After killing the dd command process, the space allocated to file /tmp/testfile is freed.
testsvr$  df -h |grep -i /tmp
swap                    84G   488K    84G     1%    /tmp

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

In Oracle 10g/11g, LOCAL_LISTENER is the parameter for specifying a listener and used for dynamic instance registration. This listener enables the listener to connect client to the correct instance. According to the Oracle documents, the default value of LOCAL_LISTENER is (ADDRESS = (PROTOCOL=TCP)(HOST=hostname)(PORT=1521)) where hostname is the network name of the local host.

SQL> startup
ORA-00119: invalid specification for system parameter LOCAL_LISTENER
ORA-00130: invalid listener address '(ADDRESS=(PROTOCOL=TCP)(HOST=yourhostname)(PORT=1521))'

The common causes of this error during the database startup is Oracle cannot find your in the hosts file, probably because you have changed the hostname of the server recently or you have set the  LOCAL_LISTENER incorrectly

If the error is caused by changed hostname, then you need to check the hosts file, that is, /etc/hosts in Uinx platform or \System32\drivers\etc\hosts make sure that you have an entry like this:

xxx.xxx.xxx.xxx  yourhostname

For incorrect LOCAL_LISTENER, you should modify the parameter LOCAL_LISTENER in the init.ora file to appropriate one or set it to null or ''.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Oracle Learning Library

Though I've knew Oracle has a good learning tutorial named Oracle By Example for a long time, only until few days ago I realized they have a cool page called  Oracle Learning Library which is more fruitful than OBE. This library provides an access to different learning learning information such as, tutorial, OBE and demo etc for different Oracle products and, above all, a good documents searching page. Like!

http://apex.oracle.com/pls/apex/f?p=44785:1:0::NO

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Oracle 11g Enterprise Edition and Standard edition features comparison

Knowing the Oracle features are important for people who are constantly working with Oracle database. From time to time, I have been asking about the functions that Oracle can provide and compare the different features between Oracle editions during different phases of database project.

Here is a short lists of important Oracle features that are only available in Oracle 11g Enterprise edition but not Standard/Standard one. Most of this features are used to provide high availability and performance which are useful especially when you are administrating a large and mission-critical databases

1. All dataguard features
-Physical,Logical and Active dataguard(needs extra license) are only available in Enterprise editiion.

2. Online maintenance
-online index rebuild, online IOT rebuild, online table redefinition.

3. RMAN features
-Block tracking incremental backup, block-level media recovery,parallel backup and recovery, tablespace point-in-time recovery, duplexed backup sets, unused block compression.

4. Flashback features
-Flashback Table, Flashback Database, Flashback Transaction, Flashback Transaction Query.

5. Query cache
-Client Side query cache, Query Results cache, PL/SQL Function Result cache

6. Fine-grained auditing

7. Oracle Database Vault (Requires extra license)

8. Advanced Security option(Requires extra license)

9. Partitioning
-Need to pay extra license even under Enterprise Edition

10. Compression
-Basic Table Compression
-Advanced Compression(requires separate license):DML, RMAN, Datadump, SecureFiles and redo log(Dataguard) transport compression.

11. Parallelism
-Parallel query/DML, Parallel statistics gathering, Parallel index build/scans,Parallel DataPump, Parallel in-memory execution.

12. Export Transportable tablespaces
-Standard edition can only perform transportable tablespaces import, not export.

13. Updateable MV
-Standard versions only support readonly materialized view.

14. Multi-master replication

15. Oracle Streams
-Standard cannot perform redo capture

16. Oracle RAC One Node

17. Oracle Diagnostic Pack(Requires extra license)

18. Oracle Tuning Pack(Requires extra license, also requires the Diagnostic Pack

19. Database Resource Manager

20. SQL Plan Management

21. Oracle OLAP(Requires extra license)

22. Oracle Data Mining(Requires extra license)

23. Bitmapped index, bitmapped join index, and bitmap plan conversions


To determine what Oracle features you have used in a Oracle Enterprise Edition databae, you can query dba_feature_usage_statistics


Set linesize 300
Col name             format a50   
Col version          format a10    
Col currently_used   format a10   
Col first_used format a20    
Col last_used  format a20    

Select name, version, detected_usages, currently_used,
       to_char(first_usage_date,'HH24:Mi DD/MM/YYYY') first_used,
       to_char(last_usage_date,'HH24:Mi DD/MM/YYYY') last_used
from dba_feature_usage_statistics
order by 1, 2

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Using ADRCI to view or monitor the content of alert log

In Oracle 11g,  ADRCI tool is the recommended way to view or monitor the alert log. 

To successfully use ADRCI to view the alert log, we need to make sure the ADRCI home are set correctly.We can determine the ADRCI homepath by using the show home or show homepath commands


adrci> show homes

adrci> show homepth

adrci> set homepath

By default, ADRCI displays the alert log in your default editor. You can use the SET EDITOR command to change your default editor. If no editor is set, ADRCI uses the editor specified by the operating system environment variable $EDITOR

adrci> set editor vi

To display all contents of the alert log
adrci> show alert

To display the last 10 entries of the alert log
adrci> show alert -tail

To display the last 30 entries of the alert log
adrci> show alert -tail 30

To display the last 10 entries and  then waits for more messages to arrive in the alert log
SHOW ALERT -TAIL -F

This displays only alert log messages that contain the string 'ORA-600'
SHOW ALERT -P "MESSAGE_TEXT LIKE '%ORA-600%'"

In Oracle 11gR1, there is bug(Bug 7648929) in "show alert" and you may receive "DIA-48216: Field Len Exceeds Max Field Length [5] [0] [20] [20]" due to the corruption of xml format alert log. To avoid this error, you can upgrade the database to 11gR2 or use "show alert -tail" instead.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Changing the GUI language in SQL Developer

By default, SQL Developer uses the default language of the operating system, e.g.
in Windows platform, the language settings in Regional and Language Options.

There are two ways to change the GUI language in SQL Developer.
1. Change the regional settings .
  In Windows go to Control Panel -> Regional and Language Options
(This also affects the language used on your computer and other applications and you may need to restart machine to be effective)

2.  Edit \sqldeveloper\bin\sqldeveloper.conf file
 - Add/modify the following parameters:

AddVMOption -Duser.language=en
AddVMOption -Duser.country=US
AddVMOption -Duser.region=US

Then, restart the SQL Developer

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati