How to trace a running process?

Using strace one can trace the system calls being executed by a running process. To stop the strace press control-C

To display the system calls being executed
$ strace -p <pid>

or

To display a summary of system calls being executed
$ strace -cfo <logfile> -p <pid>

Example: In this example smon process was being traced
$ strace -p 1234
Process 1234 attached – interrupt to quit
getrusage(RUSAGE_SELF, (ru….
getrusage(RUSAGE_SELF, (ru….
Pressed <control-C>

$ strace -cfo smon_strace.log -p 1234
Process 1234 attached – interrupt to quit
Process 1234 detached
Pressed <control-C> to detach.

$ cat smon_strace.log
% time seconds usecs/call calls errors syscall
—— ———– ———– ——— ——— —————-
nan 0.000000 0 22 getrusage
—— ———– ———– ——— ——— —————-
100.00 0.000000 22 total

List of all system privileges

Using the view “system_privilege_map” one can list all the system privileges or search for a specific privilege.

Example: List all privilege that have “TABLE” keyword in it.
SQL> select * from system_privilege_map where NAME like ‘%TABLE%’;

PRIVILEGE NAME PROPERTY
———- —————————————- ———-
-10 CREATE TABLESPACE 0
-11 ALTER TABLESPACE 0
-12 MANAGE TABLESPACE 0
-13 DROP TABLESPACE 0
-15 UNLIMITED TABLESPACE 0
-40 CREATE TABLE 0
-41 CREATE ANY TABLE 0
-42 ALTER ANY TABLE 0
-43 BACKUP ANY TABLE 0
-44 DROP ANY TABLE 0
-45 LOCK ANY TABLE 0
-46 COMMENT ANY TABLE 0
-47 SELECT ANY TABLE 0
-48 INSERT ANY TABLE 0
-49 UPDATE ANY TABLE 0
-50 DELETE ANY TABLE 0
-213 UNDER ANY TABLE 0
-243 FLASHBACK ANY TABLE 0

Monitoring AIX

On AIX – nmon on AIX can be used to monitoring a machine (CPU, Memory, Network traffic, I/O, top processes, etc). Here is the link to download nmon http://www.ibm.com/developerworks/wikis/display/WikiPtype/nmon

Example to collect nmon data and extract output to a file:
$ nmon_aix53 -fTNWLA -I 0.001 -s 300 -c 288 -m /home/nmon_data
This collects the data once a day in the directory /home/nmon_data at once every 5 minutes and with 288 snapshot which makes a excellent graph detail level. It also collects top processes and user command lines (T), NFS stats (N), Workload Manager but no Subclasses (W), Large page stats (L) and Asynchronous I/O details. The reporting threshold is 0.001 percent of a CPU.

The output from nmon can be graphed using nmon analyzer it reads output from nmon and it can be loaded into excel that graphs to aid in analysis and reports to analyze nmon.
http://www.ibm.com/developerworks/wikis/display/Wikiptype/nmonanalyser

Script to change date on a computer

'
' script to change computer date
'
DIM objShell

strComputer = "." ' current host
' get current time
Set objWMIService = GetObject("winmgmts:{(Systemtime)}\\" & strComputer & "\root\cimv2")
Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Primary=True")

For Each objOS In colOS
Exit For
Next
Wscript.Echo "Current Date: " & strDate
strNow = objOS.LocalDateTime

' loop through to get last 5 date
FOR counter=1 TO 5
' get current system date – 1
dtPrev = DateAdd("d", -1, Date)
' get month
dtMonth = Month(dtPrev)
If dtMonth < 10 Then
dtMonth = "0" & dtMonth
End If

' get day
dtDay = Day(dtPrev)
If dtDay < 10 Then
dtDay = "0" & dtDay
End If

dtStrPrev = Year(dtPrev) & dtMonth & dtDay ' set previous date string
strDate = dtStrPrev & Right(strNow, Len(strNow) – 8) ' set date
Wscript.Echo "Setting Date to: " & dtStrPrev
objOS.SetDateTime strDate ' set new date
' perform task with new date
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run("cmd.exe /C set var=hello", 1, TRUE)
Next

objOS.SetDateTime strNow ' Set the date back to what it was before
Wscript.Echo "Date Reset: " & Date

Output:
C:\temp>cscript c.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Current Date: 20100929221421.174000-360
Setting Date to: 20100928
Setting Date to: 20100927
Setting Date to: 20100926
Setting Date to: 20100925
Setting Date to: 20100924
Date Reset: 9/29/2010

How to delete/reset a parameter in spfile using ALTER SYSTEM?

Using ALTER SYSTEM RESET one can delete parameter from spfile if the parameter is in the spfile.

Example:
— shows the parameter is in the spfile
$ pwd
/u01/oracle/product/10.2.0/db_1/dbs
$ strings spfileTEST.ora | grep open
*.open_cursors=100

— Login to SQL*Plus, scope has to spfile and sid has to be supplied. When '*' is specified it applies to all instances if it is a cluster
SQL> alter system reset open_cursors scope=spfile sid='*';

System altered.

# check spfile after running reset command grep no longer finds the parameter in the spfile
$ strings spfileTEST.ora | grep open
$ echo $?
1

Note: If the parameter is not found in the spfile oracle will return “ORA-32010: cannot find entry to delete in SPFILE”, and if the scope is set to both oracle will return “ORA-32009: cannot reset the memory value for instance * from instance TESTDB”

How to tell if a parameter can be modified in a session/system?

By querying V$parameter one can find if the parameter can be modified in session and/or system.

If isses_modifiable is true then value can be modified in session, if FALSE then it can’t be modified using ALTER SESSION SET..

If issys_modifiable = DEFERRED, the value can be changed with scope=spfile specified (if spfile is used) and the change will take into effect into subsequent sessions.

If issys_modifiable =FALSE, the value can be changed using ALTER SYSTEM only if spfile is used and the change will take into effect after instance restart.

If issys_modifiable = IMMEDIATE, the value can be changed with scope=[memory|both|spfile]

To find out if the database is using spfile is being used refer to the following link https://oraclespin.wordpress.com/2008/06/22/how-to-tell-if-the-database-was-started-with-spfile-or-pfile/

Eg:

SELECT  isses_modifiable, issys_modifiable FROM V$parameter WHERE name = ‘shared_pool_size’;

ISSES   ISSYS_MOD

—– ———
FALSE  IMMEDIATE