Archive

Archive for September 20, 2008

Input Console . . .

import java.io.*;

public class InputConsole
{
/**Membaca string dari keyboard*/
public static String readString()
{
BufferedReader bfr
= new BufferedReader(new InputStreamReader(System.in), 1);

// Menginisialisasi string
String string = ” “;

// Get the string from the keyboard
try
{
string = bfr.readLine();
}
catch (IOException ex)
{
System.out.println(ex);
}

// Mengembalikan string hasil pembacaan dari keyboard
return string;
}

/**Mengambil nilai int dengan parsing string input dari keyboard*/
public static int readInt()
{
return Integer.parseInt(readString());
}

//Mengambil nilai byte dengan parsing string input dari keyboard
public static byte readByte() { return
Byte.parseByte(readString()); }

//Mengambil nilai short dengan parsing string input dari keyboard
public static short readShort()
{
return Short.parseShort(readString());
}

//Mengambil nilai long dengan parsing string input dari keyboard
public static long readLong()
{
return Long.parseLong(readString());
}

//Mengambil nilai float dengan parsing string input dari keyboard
public static float readFloat()
{
return Float.parseFloat(readString());
}

//Mengambil nilai double dengan parsing string input dari keyboard
public static double readDouble()
{
return Double.parseDouble(readString());
}

}

Categories: Java Programming

Hello World . . .

class Salam
{
/**Main Method*/
public static void main(String[] args)
{
System.out.println(“Hello World “);
}
}

Categories: Java Programming

CLASS Turunan

#include <iostream>

using namespace std;

class INDUK {
public:
virtual TULIS() { }
};

class TURUNAN {
public:
TULIS() {
cout<<”Ini di dalam kelas turunan”<<endl;
}
};

// Fungsi utama
int main() {
// Mendeklarasikan pointer dan melakukan instansiasi
// untuk tipe INDUK
INDUK *PI, Ob_I;

// Mendeklarasikan pointer dan melakukan instansiasi
// untuk tipe TURUNAN
INDUK *PT, Ob_T;

// Memerintahkan pointer PI untuk menunjuk ke alamat objek Ob_T
PI = &Ob_T;

// Melakukan typecasting terhadap pointer PI sebagai pointer
// yang akan menunjuk ke tipe TURUNAN
PT = dynamic_cast <TURUNAN *> (PI);

if (PT) {
cout<<”Typecasting sukses”;
}

return 0;
}

Categories: C++

Display Text . . .

#include <iostream.h>

int main() {
int X;

// Menampilkan teks untuk informasi
cout<<”Masukkan sebuah bilangan bulat : “;

// Membaca nilai dari keyboard dan menyimpannya
// ke dalam variabel X
cin>>X;

// Menampilkan nilai yang telah dimasukkan
cout<<”Bilangan yang telah Anda masukkan adalah “<<X;

return 0;
}

Categories: C++

Display value from keyboard

#include <stdio.h>

int main(void) {
int X;

/* Menampilkan teks untuk informasi */
printf(“Masukkan sebuah bilangan bulat : “);

/* Membaca nilai dari keyboard dan menyimpannya
ke dalam variabel X */
scanf(“%d”, &X);

/* Menampilkan nilai yang telah dimasukkan */
printf(“Bilangan yang telah Anda masukkan adalah %d”, X);

return 0;
}

Categories: C++

RAC Installation for Sun Solaris with SunCluster 3.2

Preparing for Oracle RAC Installation
This section describes how to prepare a system for Oracle RAC installation with Oracle Clusterware
(formerly called CRS for “Cluster Ready Services”). If other clusterware is being used, please follow
the specific documentation for that product. Before proceeding with the installation steps make sure
that the following hardware requirements are satisfied.
Unless otherwise stated, all the commands described here must be executed as root.
1. Clean up OCR and voting devices.
If you are not placing the OCR and voting devices in the QFS file system, do the following in
the raw devices that will be used for this purpose:
# dd if=/dev/zero of=ocr_dev bs=1024k count=120
# dd if=/dev/zero of=voting-dev bs=1024k count=120
# chown -R oracle:dba voting-dev
# chown -R root:dba ocr-dev
# chmod -R 660 voting-dev
# chmod -R 640 ocr-dev
2. Allow Oracle users to use rsh on all systems.
Execute this command as Oracle user on all the servers that will be part of the RAC cluster.
# echo “+ oracle” > /export/home/oracle/.rhosts
3. Confirm that you can use rsh as Oracle.
For all nodes, execute the following command as Oracle user against all other nodes and
confirm that there are no problems reported:
# rsh other-node hostname
9 Installing Oracle Clusterware (CRS)
1. Obtain the Oracle Clusterware tarball (for x86/x64 or SPARC systems) and place it in
/stage/crs.

Installation Guide for Solaris Cluster 3.2 Software and Oracle 10g Release 2 RAC 23
2. For x86/x64 systems, run the rootpre.sh script as root on each node:
# /stage/crs/rootpre/rootpre.sh
2. Run the following command.
# su . oracle
3. Change to the /stage/crs/ directory.
4. Set the display to the system where you want to display the installer GUI.
5. Run the installer.
# ./runInstaller
For x86/64 systems, the installer prompts you for confirmation that the rootpre script has
been executed. Answer yes.
6. Accept the path for the inventory directory and the group (dba), and click Next.
7. Set the name to crs and the path to /export/home/oracle/crs, and click Next.
8. See if there are any failures, and then click Next.
9. Verify that public, virtual, and private names resolve in /etc/hosts, NIS, or Sun Cluster
database, and then click Next.
10. Set the public IP/device to public. Set the private IP/device to private. Select clprivnet0
device for private and leave the ones used by the Sun Cluster software as “do not use.”
11. Set OCR to the device selected in the storage table using the DID identifier (or the QFS file). Use
external redundancy if possible.
12. Set voting to the device selected in the storage table using the DID identifier (or the QFS file). Use
external redundancy of possible.
13. Click Install.
14. Run scripts as root in the order and on the nodes indicated.
15. If VIP fails while running scripts on the last node (known bug), do the following:
a) Set the DISPLAY variable appropriately.
b) Execute # /export/home/oracle/crs/bin/vipca.
c) Fill in again the VIP information, and vipca creates and starts the VIP, GSD (global
services daemon), and ONS (Oracle name server) resources under Oracle Clusterware.
Installation Guide for Solaris Cluster 3.2 Software and Oracle 10g Release 2 RAC 24
10 Installing the Oracle RDBMS Server
1. Obtain the Oracle database 10.2.0.1.
2. Create the directory /stage/10gdb on the database server and place the database installation
software there.
3. Change to the /stage/10gdb directory and unpackage the tarball.
4. Run the following command:
# su . oracle
5. Change to the /stage/10gdb directory.
6. Set the display to the system where you want to display the installer GUI.
7. Run the installer with the following command:
# ./runInstaller

8. Select Enterprise Edition, and click Next.
9. Define Oracle home as /export/home/oracle/db. Clear the check box for “create starter
database,” and click Next.

10. Select all nodes, and click Next.
11. Leave the inventory in /export/home/oracle/oraInventory and leave the operating
system group name as dba. Click Next.

12. Disregard the failure for nonexec_user_stack=1. If there are no other warnings, click Next
and click Yes in the warning popup dialog.
13. Select the option “install database software only” and click Next.
14. Click Install and wait until the installation finishes.
15. As root, execute the two commands presented by the installer, and click OK.
16. Exit the installer.
17. Now it is necessary to install the patchset 2. Obtain the tarball for this patchset. For x86/64 systems,
get Oracle 10.2.0.2 Database Patchset. For SPARC systems, get Oracle 10.2.0.2 Patchset.

18. Create the directory /stage/ps2 and place the tarball in it.
Installation Guide for Solaris Cluster 3.2 Software and Oracle 10g Release 2 RAC 25
19. Unpackage the tarball.
20. Run the following command:
# su . oracle

21. Set the display to the system where you want to display the installer GUI.
22. Change to the /stage/ps2/Disk1 directory.
23. Install the patch on CRS home first, and then install it again on database home.
24. Execute the following command.
# ./runInstaller
25. Click Next.
26. Select CRS or db for the database (first install on Oracle Clusterware and then on database).
27. Click Install.
28. Repeat installation of patch 10.2.0.2 on database home.
29. As Oracle user, add the following entries to the file /export/home/oracle/.cshrc.
setenv ORACLE_BASE $HOME
setenv ORACLE_HOME $ORACLE_BASE/db
setenv CRS_HOME $ORACLE_BASE/crs (if RAC present)
setenv PATH $ORACLE_HOME/bin:$PATH
setenv LD_LIBRARY_PATH $ORACLE_HOME/lib
setenv ORACLE_SID SID_for_your_database
30. (SPARC only) Install patch 5117016 after patch 10.2.0.2 on Oracle home only (mandatory).
31. Apply the workaround described in document ID 363840.1 at the Oracle MetaLink web site
(https://metalink.oracle.com, requires registration), which involves the following:
a) Ensure all instances are shut down.
b) Manually copy library file libknlopt.a from the local node to the same directory on all
remote nodes. On some ports, this library exists in $ORACLE_HOME/rdbms/lib and in
other ports, this library exists in $ORACLE_HOME/lib. It is critical to copy the library file to
the same location on all remote nodes as it exists on the installation node.
c) Relink Oracle on all remote nodes (it is not necessary to relink on the node where the
installation was performed):

cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk rac_on ioracle

Installation Guide for Solaris Cluster 3.2 Software and Oracle 10g Release 2 RAC 26
32. Apply performance patches, which are downloadable from the Oracle MetaLink web site
(https://metalink.oracle.com):
œ For x86 based systems only, apply performance patch 4770693.
œ For SPARC based systems only, apply patch 5559916 to improve the log writer daemon
(LGRWR) performance.
33. Check the Oracle MetaLink web site for any other patches required for your installation.

Recover the Corruption OCR . . .

$ crs_stat -t

CRS-0184: Cannot communicate with the CRS daemon.

$ crsctl check boot
Failure 4 at procr_open_key with status 4.
PROC-4: The cluster registry key to be operated on does not exist.

$ crsctl check crs
Failure 1 contacting CSS daemon
Cannot communicate with CRS
Cannot communicate with EVM

crsd.log

/opt/crs/oracle/product/10.2.0/crs/crs/init/delphi-1.pid
[ clsdmt][52]Listening to (ADDRESS=(PROTOCOL=ipc)(KEY=delphi-1DBG_CRSD))
2006-05-16 18:08:57.021: [ CRSOCR][1]32OCR api procr_open_key failed for key CRS.CUR. OCR
error
code = 4 OCR error msg: PROC-4: The cluster registry key to be operated on does not exist.
2006-05-16 18:08:57.192: [ CRSMAIN][1]32Using Authorizer location:
/opt/crs/oracle/product/10.2.0/crs/crs/auth/
2006-05-16 18:08:57.220: [ OCRSRV][35]th_select_handler: Failed to retrieve procctx from
ht.
constr = [5988488] retval lht [-27] Signal CV.

Cause
OCR got corrupted.
Solution
To resolve this issue need to restore OCR from backup.

Oracle automatically takes backups of the OCR every 4 hours. Oracle also keeps the last 3
backups, up to 4 hours old, one day old, and one week old available. Here are the steps for restoring the OCR.

1. Find out what time the problem that the inconsistency in the OCR occurred.

2. Find an OCR backup from a time prior to when the inconsistency occurred.

To do this cd to $ORA_CRS_HOME/cdata/<cluster name>
[or]
Run $ORA_CRS_HOME/bin/ocrconfig -showbacku p (In this case you may not get any result)

Example:

# pwd
/t02/app/oracle/product/crs/cdata/crs_opcbsol
# ls -ltr
total 46560
-rw-r—– 1 root root 3960832 Apr 12 19:53 week.ocr
-rw-r—– 1 root root 3960832 Apr 13 03:53 day.ocr
-rw-r—– 1 root root 3960832 Apr 14 03:54 backup02.ocr
-rw-r—– 1 root root 3960832 Apr 14 03:54 day_.ocr
-rw-r—– 1 root root 3960832 Apr 14 07:54 backup01.ocr
-rw-r—– 1 root root 3960832 Apr 14 11:54 backup00.ocr

3. If you have a backup of the OCR from prior to the time of the inconsistency,
reboot the nodes in single user mode or runlevel 1. If you are unable to
reboot into single user mode for some reason, you can disable CRS with:

Sun or Linux:

/etc/init.d/init.crs disable
/etc/init.d/init.crs stop

HP-UX or HP Tru64::

/sbin/init.d/init.crs disable
/sbin/init.d/init.crs stop

IBM AIX:

/etc/init.crs disable
/etc/init.crs stop

4. After all nodes are rebooted in single user mode and/or you have verified that
CRS is not running (ps -ef | grep crs), restore the OCR with ocrconfig.

Example:

cd $ORA_CRS_HOME/bin
./ocrconfig -restore /t02/app/oracle/product/crs/cdata/crs_opcbsol/week.ocr

5. Re-enable CRS if it was disabled. Example:

Sun or Linux:

/etc/init.d/init.crs enable

HP-UX or HP Tru64::

/sbin/init.d/init.crs enable

IBM AIX:

/etc/init.crs enable

6. Reboot the nodes.

User Information

Query untuk mendisplay informasi user database

DEFINE B=’&Enter_Username’
DEFINE obj_type=’&Enter_Object_type_4_User’
Prompt ————————————– USER INFORMATION ————————————–

SELECT
‘ User ‘||username||”’S Account Information’,
‘ Account Status => ‘||Account_status,
‘ Default Tablespace => ‘||default_tablespace,
‘ Temp Tablespace => ‘||temporary_tablespace
from dba_users where username=upper(‘&&B’)
/

prompt ————————————– OBJECTS OWNED BY USER ——————————–

select a.username LoginId,
‘User ‘||nvl(b.owner,’Does Not Own any objects..’) ||’ Owns ‘ ||nvl(b.cou,0)|| ‘ Nos Of ‘ ||nvl(b.object_type,’Objects’)
FROM
dba_users a,
(SELECT OWNER,OBJECT_TYPE,COUNT(OBJECT_NAME) cou FROM DBA_OBJECTS GROUP BY OBJECT_TYPE,OWNER ORDER BY OWNER,OBJECT_TYPE) b
where a.username=b.owner (+) and a.username=upper(‘! &&B’) and b.object_type(+)=upper(‘&&obj_type’)
/

Prompt ————————————– SYSTEM PRIVIELGES GRANTED TO THE USER —————-

SELECT
nvl(b.grantee,’No_System_Privileges_Granted’),nvl(b.privilege,’null’)
from
dba_users a,dba_sys_privs b
where a.username =b.grantee(+) and grantee=upper(‘&&B’)
/

Prompt ———————————— ROLES GRANTED TO THE USER ——————————

SELECT
nvl(b.grantee,’No_Roles_Granted’),nvl(b.granted_role,’null’)
from
dba_users a,dba_role_privs b
where a.username =b.grantee(+) and grantee=upper(‘&&B’)
/

Categories: Oracle Admin

Find Full Table scan

Gunakan query ini untuk mencari full table scan yang biasanya menyebabkan turunnya performance

select sp.object_owner,sp.object_name,
(select sql_text from v$sqlarea sa
where sa.address = sp.address
and sa.hash_value =sp.hash_value) sqltext,
(select executions from v$sqlarea sa
where sa.address = sp.address
and sa.hash_value =sp.hash_value) no_of_full_scans,
(select lpad(nvl(trim(to_char(num_rows)),’ ‘),15,’ ‘)||’ | ‘||lpad(nvl(trim(to_char(blocks)),’ ‘),15,’ ‘)||’ | ‘||buffer_pool
from dba_tables where table_name = sp.object_name
and owner = sp.object_owner) “rows|blocks|pool”
from v$sql_plan sp
where operation=’TABLE ACCESS’
and options = ‘FULL’
and object_owner IN ()
order by 1,2;

Categories: Oracle Admin

Log all database error to table

drop trigger log_errors_trig;
drop table   log_errors_tab;

create table log_errors_tab (
error     varchar2(30),
timestamp date,
username  varchar2(30),
osuser    varchar2(30),
machine   varchar2(64),
process   varchar2(8),
program   varchar2(48));

create or replace trigger log_errors_trig
after servererror on database
declare
var_user     varchar2(30);
var_osuser   varchar2(30);
var_machine  varchar2(64);
var_process  varchar2(8);
var_program  varchar2(48);
begin
select username, osuser, machine, process, program
into   var_user, var_osuser, var_machine, var_process, var_program
from   sys.v_$session
where  audsid = userenv(’sessionid’);

insert into log_errors_tab
values(dbms_standard.server_error(1),sysdate,var_user,
var_osuser,var_machine,var_process,var_program);
end;

Categories: Oracle Admin