Sunday, August 2, 2015

Password change and locking/unlocking user accounts in Unix system

*** To change your own password, enter:
   $ passwd

To change other users password, you must login as root:
   $ passwd userName
   $ passwd vivek


To lock user account, enter (must be root user to type the following):
   $ passwd -l username

To unlock the account password, enter:
   $ passwd -u username

Saturday, August 1, 2015

Database is RAC or Single instance?

sql>show parameter CLUSTER_DATABASE

--In a non rac environment this parameter is false.

NAME                                       TYPE        VALUE
----------------------------------             -------------   --------------------
cluster_database                        boolean     FALSE
cluster_database_instances        integer         1



--In a rac environment cluster_database_instances shows the number of instances.

NAME                                       TYPE        VALUE
------------------------------------           -------------    -----------
cluster_database                        boolean     TRUE
cluster_database_instances        integer         2

Long running queries check

By using this query we can check for queries which are running for long period of time in the database server.

COLUMN percent FORMAT 999.99 

SELECT sid, to_char(start_time,'hh24:mi:ss') stime, 
message,( sofar/totalwork)* 100 percent 
FROM v$session_longops
WHERE sofar/totalwork < 1
/
--OR

SELECT sid,
       opname,
       sofar,
       totalwork,
       units,
       elapsed_seconds,
       time_remaining
FROM v$session_longops
WHERE sofar != totalwork;

Size of oracle database

#Database size is actually the sum of data files, log files, temp files  and control files.
This query will give us the total db size in GB.

select a.data_size+b.temp_size+c.redo_size+d.controlfile_size "Total_DB_Size in GB"
from ( select sum(bytes)/1024/1024/1024 data_size
from dba_data_files) a,
( select nvl(sum(bytes),0)/1024/1024/1024 temp_size
from dba_temp_files ) b,
( select sum(bytes)/1024/1024/1024 redo_size
from sys.v_$log ) c,
( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024/1024 controlfile_size
from v$controlfile) d;

#OR simply(Excluding control files since its very small in size compared to the database size): 

select sum(bytes)/1024/1024/2014 DB_SIZE_GB from
( select sum (bytes) bytes from v$datafile
  union
  select sum (bytes) from v$tempfile
  union
  select sum (bytes * members) from v$log

)