tag:blogger.com,1999:blog-29177231986821183642024-02-18T23:47:22.393-08:00afzalAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comBlogger36125tag:blogger.com,1999:blog-2917723198682118364.post-64654310330958552432011-09-22T01:51:00.001-07:002011-09-22T01:51:21.488-07:00SMON - How it will handle instance recovery
Instance recovery occurs in two steps:<br>
1.Cache Recovery <br>
2.Transaction Recovery<br>
Cache recovery:<br>
Changes being made to a database are recorded in the database buffer cache. These changes are also recorded in online redo log files simultaneously. <br>
When there are enough data in the database buffer cache, they are written to data files. <br>
If an Oracle instance fails before the data in the database buffer cache are written to data files, Oracle uses the data recorded in the online redo log files to recover the lost data when the associated database is re-started. This process is called cache recovery. <br>
<br>
Transaction recovery: <br>
When a transaction modifies data in a database, the before image of the modified data is stored in an undo segment.The data stored in the undo segment is used to restore the original values in case a transaction is rolled back. At the time of an instance failure, the database may have uncommitted transactions. It is possible that changes made by these uncommitted transactions have gotten saved in data files.(We don't have any mechanism to track this) <br>
To maintain read consistency, Oracle rolls back all uncommitted transactions when the associated database is re-started. Oracle uses the undo data stored in undo segments to accomplish this. This process is called transaction recovery.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-57155214168510931192011-09-22T01:49:00.001-07:002011-09-22T01:49:40.421-07:00ORA-01565ORA-01565: error in identifying file /dbs/spfile@.ora
<br>
When we’re going to create pfile from spfile while spfile running on ASM instance, We can face the below errors,
<br>
SQL> create pfile=’/u01/inittest.ora’ from spfile;<br>
create pfile=’/u01/inittest.ora’ from spfile<br>
*<br>
ERROR at line 1:<br>
ORA-01565: error in identifying file ‘?/dbs/spfile@.ora’<br>
ORA-27037: unable to obtain file status<br>
Linux Error: 2: No such file or directory<br>
Additional information: 3<br>
<br>
Solution :<br>
We need to give ASM path of SPFILE.<br>
SQL> create pfile=’/u01/inittest.ora’ from spfile=’+DATA/dbasm/spfiledbasm.ora’;<br>
File created.<br>Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-49413436003083385272011-09-22T01:46:00.001-07:002011-09-22T01:48:55.437-07:00ORA-01031Could not validate asmsnmp password due to following error ora-01031:insufficent privileges
<br>
[oracle@db1 ~]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid
<br>
[oracle@db1 ~]$ export PATH=/u01/app/oracle/product/11.2.0/grid/bin
<br>
[oracle@db1 ~]$ export ORACLE_SID=+ASM
<br>
[oracle@db1 ~]$ sqlplus sys/sys as sysasm
<br>
SQL> create user asmsnmp identified by asmsnmp;
<br>
User created.
<br>
SQL> grant sysdba to asmsnmp;
<br>
Grant succeeded.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-64191877602405552652011-09-22T00:34:00.000-07:002011-09-22T00:36:05.465-07:00Encryption for RMAN BackupRAM backups are unencrypted.<br /><br />we can encrypt any rman backup in the form of a backup set.<br /><br />we can encrypt in two ways ie transport and password encryption<br /><br />Password Encryption:<br /><br /><br />$export ORACLE_SID=TEMP<br /><br />$rlwrap rman target sys/oracle<br /><br />rman>set encryption on identified <pwd> only;<br /><br /><br />Here i am choosing encryption on tablespace ie users<br /><br />rman>configure encryption for tablespace users on;<br /><br />rman>sql'alter tablespace users offline';<br /><br />rman>restore tablespace users;<br /><br />failed we need to <br /><br />Rman>set decryption identified by <pwd>;<br /><br />Rman>restore tablespace users;<br /><br />rman> recover tablespace users;<br /><br />rman>sql'alter tablespace users online';Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-41683962949463804442011-09-21T23:51:00.000-07:002011-09-21T23:52:21.997-07:00Duplicate Database Using RMANYou want to use RMAN to create a duplicate database on the same server by using RMAN backups.<br /><br />My Source Database Name is MYTEST<br /><br />Target (duplicate) Database name is MYDB <br /><br />Step 1: Configure Listener.ora and tnsnames.ora files<br /><br />tnsnames.ora file<br /><br />MYTEST =<br />(DESCRIPTION =<br />(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))<br />(CONNECT_DATA =<br />(SERVER = DEDICATED)<br />(SERVICE_NAME = mytest)<br />)<br />)<br /><br />MYDB =<br />(DESCRIPTION =<br />(ADDRESS_LIST =<br />(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))<br />)<br />(CONNECT_DATA =<br />(SERVICE_NAME = mydb)<br />)<br />)<br /><br />listener.ora file<br /><br />SID_LIST_LISTENER =<br />(SID_LIST =<br />(SID_DESC =<br />(GLOBAL_DBNAME = mytest)<br />(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_1)<br />(SID_NAME = mytest)<br />)<br />(SID_DESC =<br />(GLOBAL_DBNAME= mydb)<br />(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_1)<br />(SID_NAME = mydb)<br />)<br />)<br /><br />LISTENER =<br />(DESCRIPTION_LIST =<br />(DESCRIPTION =<br />(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))<br />)<br />)<br /><br />Step 2: create pfile for target database from source database<br /><br />SQL> create pfile from spfile;<br /><br />File created.<br /><br />Step 3: modified parameter file for target database (duplicate) here log_file_name_convert and db_file_name_convert and control file location is important, further your choice.<br /><br />*.audit_file_dest=’/home/oracle/oracle/product/10.2.0/db_1/admin/mydb/adump’<br />*.compatible=’10.2.0.1.0′<br />*.db_block_size=8192<br />*.db_domain=”<br />*.db_file_multiblock_read_count=16<br />*.db_name=’mydb’<br />*.control_files=’/home/oracle/oracle/product/10.2.0/oradata/mydb/control01.ctl’,'/home/oracle/oracle/product/10.2.0/oradata/mydb/control02.ctl’,'/home/oracle/oracle/product/10.2.0/oradata/mydb/control03.ctl’<br />*.db_file_name_convert=’/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest’,'/home/oracle/oracle/product/10.2.0/oradata/mydb’<br />*.log_file_name_convert=’/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest’,'/home/oracle/oracle/product/10.2.0/oradata/mydb’<br />*.db_recovery_file_dest=’/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area’<br />*.db_recovery_file_dest_size=2147483648<br />*.dispatchers=’(PROTOCOL=TCP) (SERVICE=mydbXDB)’<br />*.job_queue_processes=10<br />*.open_cursors=300<br />*.pga_aggregate_target=94371840<br />*.processes=150<br />*.remote_login_passwordfile=’EXCLUSIVE’<br />*.sga_target=285212672<br />*.undo_management=’AUTO’<br />*.undo_tablespace=’UNDOTBS1′<br /><br />Step 4: Create password file<br /><br />[oracle@localhost ~]$orapwd file=orapwmydb password=oracle entries=5<br /><br />Step 5: start your target database nomount stage<br /><br />[oracle@localhost ~]$ export ORACLE_SID=mydb<br />[oracle@localhost ~]$ rlwrap sqlplus<br /><br />SQL*Plus: Release 10.2.0.1.0 – Production on Tue May 25 18:22:09 2010<br /><br />Copyright (c) 1982, 2005, Oracle. All rights reserved.<br /><br />Enter user-name: sys/oracle@mydb as sysdba<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL> startup nomount pfile=/home/oracle/oracle/product/10.2.0/db_1/dbs/initmydb.ora<br />ORACLE instance started.<br /><br />Total System Global Area 285212672 bytes<br />Fixed Size 1218992 bytes<br />Variable Size 92276304 bytes<br />Database Buffers 188743680 bytes<br />Redo Buffers 2973696 bytes<br />SQL> exit<br /><br />Step 6: From source database<br /><br />SQL> alter system switch logfile;<br /><br />System altered.<br /><br />SQL><br /><br />Step 7: Backup database and archivelog Source database<br /><br />[oracle@localhost root]$ rlwrap rman target sys/azar@mytest<br /><br />Recovery Manager: Release 10.2.0.1.0 – Production on Tue May 25 19:56:10 2010<br /><br />Copyright (c) 1982, 2005, Oracle. All rights reserved.<br /><br />connected to target database: MYTEST (DBID=2419076664)<br /><br />RMAN> backup database plus archivelog;<br /><br />Starting backup at 25-MAY-10<br />current log archived<br /><br />input datafile fno=00001 name=/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest/system01.dbf<br />input datafile fno=00003 name=/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest/sysaux01.dbf<br />input datafile fno=00002 name=/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest/undotbs01.dbf<br />input datafile fno=00004 name=/home/oracle/oracle/product/10.2.0/db_1/oradata/mytest/users01.dbf<br />channel ORA_DISK_1: starting piece 1 at 25-MAY-10<br />channel ORA_DISK_1: finished piece 1 at 25-MAY-10<br /><br />(skipped)<br /><br />Starting Control File and SPFILE Autobackup at 25-MAY-10<br />piece handle=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/autobackup/2010_05_25/o1_mf_s_719956316_5zr01f85_.bkp comment=NONE<br />Finished Control File and SPFILE Autobackup at 25-MAY-10<br /><br />Step 8: Connect auxiliary database<br /><br />RMAN> connect auxiliary sys/oracle@mydb;<br /><br />connected to auxiliary database: MYDB (not mounted)<br /><br />Step 9: Create duplicate database.<br /><br />RMAN> duplicate target database to mydb;<br /><br />Starting Duplicate Db at 25-MAY-10<br />using target database control file instead of recovery catalog<br />allocated channel: ORA_AUX_DISK_1<br />channel ORA_AUX_DISK_1: sid=156 devtype=DISK<br /><br />contents of Memory Script:<br />{<br />set until scn 470310;<br />set newname for datafile 1 to<br />“/home/oracle/oracle/product/10.2.0/oradata/mydb/system01.dbf”;<br />set newname for datafile 2 to<br />“/home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf”;<br />set newname for datafile 3 to<br />“/home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf”;<br />set newname for datafile 4 to<br />“/home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf”;<br />restore<br />check readonly<br />clone database<br />;<br />}<br />executing Memory Script<br /><br />executing command: SET until clause<br /><br />executing command: SET NEWNAME<br /><br />executing command: SET NEWNAME<br /><br />executing command: SET NEWNAME<br /><br />executing command: SET NEWNAME<br /><br />Starting restore at 25-MAY-10<br />using channel ORA_AUX_DISK_1<br /><br />skipping datafile 1; already restored to file /home/oracle/oracle/product/10.2.0/oradata/mydb/system01.dbf<br />skipping datafile 2; already restored to file /home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf<br />skipping datafile 3; already restored to file /home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf<br />skipping datafile 4; already restored to file /home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf<br />restore not done; all files readonly, offline, or already restored<br />Finished restore at 25-MAY-10<br />sql statement: CREATE CONTROLFILE REUSE SET DATABASE “MYDB” RESETLOGS ARCHIVELOG<br />MAXLOGFILES 16<br />MAXLOGMEMBERS 3<br />MAXDATAFILES 100<br />MAXINSTANCES 8<br />MAXLOGHISTORY 292<br />LOGFILE<br />GROUP 1 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo01.log’ ) SIZE 50 M REUSE,<br />GROUP 2 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo02.log’ ) SIZE 50 M REUSE,<br />GROUP 3 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo03.log’ ) SIZE 50 M REUSE<br />DATAFILE<br />‘/home/oracle/oracle/product/10.2.0/oradata/mydb/system01.dbf’<br />CHARACTER SET WE8ISO8859P1<br /><br />contents of Memory Script:<br />{<br />switch clone datafile all;<br />}<br />executing Memory Script<br /><br />released channel: ORA_AUX_DISK_1<br />datafile 2 switched to datafile copy<br />input datafile copy recid=1 stamp=719956582 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf<br />datafile 3 switched to datafile copy<br />input datafile copy recid=2 stamp=719956582 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf<br />datafile 4 switched to datafile copy<br />input datafile copy recid=3 stamp=719956582 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf<br /><br />contents of Memory Script:<br />{<br />set until scn 470310;<br />recover<br />clone database<br />delete archivelog<br />;<br />}<br />executing Memory Script<br /><br />executing command: SET until clause<br /><br />Starting recover at 25-MAY-10<br />allocated channel: ORA_AUX_DISK_1<br />channel ORA_AUX_DISK_1: sid=156 devtype=DISK<br /><br />starting media recovery<br /><br />archive log thread 1 sequence 9 is already on disk as file /home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_25/o1_mf_1_9_5zr01bl8_.arc<br />archive log filename=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_25/o1_mf_1_9_5zr01bl8_.arc thread=1 sequence=9<br />media recovery complete, elapsed time: 00:00:02<br />Finished recover at 25-MAY-10<br /><br />contents of Memory Script:<br />{<br />shutdown clone;<br />startup clone nomount ;<br />}<br />executing Memory Script<br /><br />database dismounted<br />Oracle instance shut down<br /><br />connected to auxiliary database (not started)<br />Oracle instance started<br /><br />Total System Global Area 285212672 bytes<br /><br />Fixed Size 1218992 bytes<br />Variable Size 92276304 bytes<br />Database Buffers 188743680 bytes<br />Redo Buffers 2973696 bytes<br />sql statement: CREATE CONTROLFILE REUSE SET DATABASE “MYDB” RESETLOGS ARCHIVELOG<br />MAXLOGFILES 16<br />MAXLOGMEMBERS 3<br />MAXDATAFILES 100<br />MAXINSTANCES 8<br />MAXLOGHISTORY 292<br />LOGFILE<br />GROUP 1 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo01.log’ ) SIZE 50 M REUSE,<br />GROUP 2 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo02.log’ ) SIZE 50 M REUSE,<br />GROUP 3 ( ‘/home/oracle/oracle/product/10.2.0/oradata/mydb/redo03.log’ ) SIZE 50 M REUSE<br />DATAFILE<br />‘/home/oracle/oracle/product/10.2.0/oradata/mydb/system01.dbf’<br />CHARACTER SET WE8ISO8859P1<br /><br />contents of Memory Script:<br />{<br />set newname for tempfile 1 to<br />“/home/oracle/oracle/product/10.2.0/oradata/mydb/temp01.dbf”;<br />switch clone tempfile all;<br />catalog clone datafilecopy “/home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf”;<br />catalog clone datafilecopy “/home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf”;<br />catalog clone datafilecopy “/home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf”;<br />switch clone datafile all;<br />}<br />executing Memory Script<br /><br />executing command: SET NEWNAME<br /><br />renamed temporary file 1 to /home/oracle/oracle/product/10.2.0/oradata/mydb/temp01.dbf in control file<br /><br />cataloged datafile copy<br />datafile copy filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf recid=1 stamp=719956593<br /><br />cataloged datafile copy<br />datafile copy filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf recid=2 stamp=719956593<br /><br />cataloged datafile copy<br />datafile copy filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf recid=3 stamp=719956593<br /><br />datafile 2 switched to datafile copy<br />input datafile copy recid=1 stamp=719956593 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/undotbs01.dbf<br />datafile 3 switched to datafile copy<br />input datafile copy recid=2 stamp=719956593 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/sysaux01.dbf<br />datafile 4 switched to datafile copy<br />input datafile copy recid=3 stamp=719956593 filename=/home/oracle/oracle/product/10.2.0/oradata/mydb/users01.dbf<br /><br />contents of Memory Script:<br />{<br />Alter clone database open resetlogs;<br />}<br />executing Memory Script<br /><br />database opened<br />Finished Duplicate Db at 25-MAY-10<br /><br />RMAN><br /><br />Step 10: My duplicate database succesfully created.<br /><br />Enter user-name: sys/oracle@mydb as sysdba<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL> select status from v$instance;<br /><br />STATUS<br />————<br />OPEN<br /><br />SQL> select name from V$database;<br /><br />NAME<br />———<br />MYDB<br /><br />SQL>Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-11891249846654174362011-08-28T01:59:00.000-07:002011-08-28T02:10:20.666-07:00ScriptsAdministration - Status
<br />
<br />Startup time
<br />
<br />SQL> select to_char(startup_time, 'HH24:MI DD-MON-YY') "Startup time" from v$instance;
<br />
<br />Startup time
<br />---------------
<br />13:13 28-AUG-11
<br />
<br />
<br />How large is the database
<br />
<br />col "Database Size" format a20
<br />col "Free space" format a20
<br />col "Used space" format a20
<br />select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size"
<br />, round(sum(used.bytes) / 1024 / 1024 / 1024 ) -
<br /> round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space"
<br />, round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"
<br />from (select bytes
<br /> from v$datafile
<br /> union all
<br /> select bytes
<br /> from v$tempfile
<br /> union all
<br /> select bytes
<br /> from v$log) used
<br />, (select sum(bytes) as p
<br /> from dba_free_space) free
<br />group by free.p;
<br />
<br />
<br />Database Size Used space Free space
<br />-------------------- -------------------- --------------------
<br />1 GB 1 GB 0 GB
<br />
<br />
<br />
<br />
<br />Distribution of objects and data
<br />
<br />set pages 999
<br />col "size MB" format 999,999,999
<br />col "Objects" format 999,999,999
<br />select obj.owner "Owner"
<br />, obj_cnt "Objects"
<br />, decode(seg_size, NULL, 0, seg_size) "size MB"
<br />from (select owner, count(*) obj_cnt from dba_objects group by owner) obj
<br />, (select owner, ceil(sum(bytes)/1024/1024) seg_size
<br /> from dba_segments group by owner) seg
<br />where obj.owner = seg.owner(+)
<br />order by 3 desc ,2 desc, 1
<br />/
<br />
<br />Owner Objects size MB
<br />------------------------------ ------------ ------------
<br />SYS 22,904 531
<br />SYSMAN 1,321 51
<br />XDB 680 49
<br />MDSYS 885 33
<br />SYSTEM 454 23
<br />OLAPSYS 720 16
<br />WMSYS 242 7
<br />CTXSYS 339 5
<br />EXFSYS 281 4
<br />DBSNMP 46 2
<br />ORDSYS 1,669 1
<br />DMSYS 189 1
<br />SCOTT 9 1
<br />OUTLN 8 1
<br />TSMSYS 3 1
<br />PUBLIC 19,981 0
<br />ORDPLUGINS 10 0
<br />SI_INFORMTN_SCHEMA 8 0
<br />
<br />
<br />Show the ten largest objects in the database
<br />
<br />col owner format a15
<br />col segment_name format a30
<br />col segment_type format a15
<br />col mb format 999,999,999
<br />select owner
<br />, segment_name
<br />, segment_type
<br />, mb
<br />from (
<br /> select owner
<br /> , segment_name
<br /> , segment_type
<br /> , bytes / 1024 / 1024 "MB"
<br /> from dba_segments
<br /> order by bytes desc
<br /> )
<br />where rownum < 11
<br />/
<br />
<br />OWNER SEGMENT_NAME SEGMENT_TYPE MB
<br />--------------- ------------------------------ --------------- ------------
<br />SYS IDL_UB1$ TABLE 167
<br />SYS SOURCE$ TABLE 41
<br />MDSYS SYS_LOB0000046123C00006$$ LOBSEGMENT 18
<br />SYS IDL_UB2$ TABLE 16
<br />SYS C_TOID_VERSION# CLUSTER 16
<br />SYS PK_C0 INDEX 10
<br />SYS PK_CS INDEX 10
<br />SYS PK_O INDEX 10
<br />SYS PK_CT INDEX 10
<br />SYS SYS_LOB0000046606C00004$$ LOBSEGMENT 9
<br />
<br />10 rows selected.
<br />
<br />
<br />
<br />Is java installed in the database?
<br />
<br />select count(*) from all_objects where object_type like '%JAVA%'and owner = 'SYS';
<br />
<br /> COUNT(*)
<br />----------
<br /> 15741
<br />
<br />Display character set information
<br />
<br />PARAMETER VALUE
<br />------------------------------ ----------------------------------------
<br />NLS_LANGUAGE AMERICAN
<br />NLS_TERRITORY AMERICA
<br />NLS_CURRENCY $
<br />NLS_ISO_CURRENCY AMERICA
<br />NLS_NUMERIC_CHARACTERS .,
<br />NLS_CHARACTERSET WE8ISO8859P1
<br />NLS_CALENDAR GREGORIAN
<br />NLS_DATE_FORMAT DD-MON-RR
<br />NLS_DATE_LANGUAGE AMERICAN
<br />NLS_SORT BINARY
<br />NLS_TIME_FORMAT HH.MI.SSXFF AM
<br />NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
<br />NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
<br />NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
<br />NLS_DUAL_CURRENCY $
<br />NLS_COMP BINARY
<br />NLS_LENGTH_SEMANTICS BYTE
<br />NLS_NCHAR_CONV_EXCP FALSE
<br />NLS_NCHAR_CHARACTERSET AL16UTF16
<br />NLS_RDBMS_VERSION 10.2.0.1.0
<br />
<br />
<br />Show all used features
<br />
<br />NAME DETECTED_USAGES
<br />-------------------------------------------------- ---------------
<br />Partitioning (system) 1
<br />Protection Mode - Maximum Performance 1
<br />Streams (system) 1
<br />Streams (user) 1
<br />Virtual Private Database (VPD) 1
<br />Automatic Segment Space Management (system) 1
<br />Automatic Segment Space Management (user) 1
<br />Automatic SQL Execution Memory 1
<br />Automatic Undo Management 1
<br />Character Set 1
<br />Dynamic SGA 1
<br />Locally Managed Tablespaces (system) 1
<br />Locally Managed Tablespaces (user) 1
<br />
<br />
<br />Administration - Session
<br />
<br />Show all connected users
<br />
<br />set lines 100 pages 999
<br />col ID format a15
<br />select username
<br />, sid || ',' || serial# "ID"
<br />, status
<br />, last_call_et "Last Activity"
<br />from v$session
<br />where username is not null
<br />order by status desc
<br />, last_call_et desc
<br />/
<br />
<br />USERNAME ID STATUS Last Activity
<br />------------------------------ --------------- -------- -------------
<br />WEBUSER 116,18996 INACTIVE 1766
<br />WEBUSER 132,33364 INACTIVE 1727
<br />WEBUSER 127,4392 INACTIVE 1709
<br />WEBUSER 124,20787 INACTIVE 1682
<br />SYS 143,10 INACTIVE 436
<br />ORA_BLA 126,37072 INACTIVE 3
<br />ORA_BLA 115,6676 INACTIVE 3
<br />ORA_BLA 139,5349 INACTIVE 3
<br />REP_USER 141,3881 ACTIVE 0
<br />REP_USER 144,17898 ACTIVE 0
<br />
<br />Time since last user activity
<br />
<br />
<br />set lines 100 pages 999
<br />select username
<br />, floor(last_call_et / 60) "Minutes"
<br />, status
<br />from v$session
<br />where username is not null
<br />order by last_call_et
<br />/
<br />
<br />USERNAME Minutes STATUS
<br />------------------------------ ---------- --------
<br />SYS 0 ACTIVE
<br />ORA_BLA 1 INACTIVE
<br />ORA_BLA 1 INACTIVE
<br />ORA_BLA 1 INACTIVE
<br />SYS 8 INACTIVE
<br />WEBUSER 29 INACTIVE
<br />WEBUSER 29 INACTIVE
<br />WEBUSER 30 INACTIVE
<br />WEBUSER 30 INACTIVE
<br />REP_USER 34734 INACTIVE
<br />
<br />
<br />Sessions sorted by logon time
<br />
<br />set lines 100 pages 999
<br />col ID format a15
<br />col osuser format a15
<br />col login_time format a14
<br />select username
<br />, osuser
<br />, sid || ',' || serial# "ID"
<br />, status
<br />, to_char(logon_time, 'hh24:mi dd/mm/yy') login_time
<br />, last_call_et
<br />from v$session
<br />where username is not null
<br />order by login_time
<br />/
<br />
<br />USERNAME OSUSER ID STATUS LOGIN_TIME LAST_CALL_ET
<br />--------------- --------------- ---------- -------- -------------- ------------
<br />ORA_BLA 115,6676 INACTIVE 06:51 19/05/08 181
<br />REP_USER oracle 141,3881 ACTIVE 08:17 19/05/08 0
<br />REP_USER oracle 144,17898 ACTIVE 08:18 19/05/08 0
<br />REP_USER oracle 129,8407 ACTIVE 08:23 19/05/08 0
<br />REP_USER oracle 145,19887 ACTIVE 08:28 19/05/08 0
<br />ORA_BLA 139,5349 INACTIVE 09:51 19/05/08 181
<br />ORA_BLA 126,37072 INACTIVE 09:51 19/05/08 181
<br />WEBUSER oracle 116,18996 INACTIVE 10:51 19/05/08 1944
<br />WEBUSER oracle 127,4392 INACTIVE 10:52 19/05/08 1887
<br />WEBUSER oracle 124,20787 INACTIVE 10:52 19/05/08 1860
<br />WEBUSER oracle 132,33364 INACTIVE 10:52 19/05/08 1905
<br />SYS oracle 131,34710 ACTIVE 10:56 19/05/08 0
<br />SYS oracle 143,10 INACTIVE 14:13 16/04/08 614
<br />
<br />Show user info including os pid
<br />
<br />col "SID/SERIAL" format a10
<br />col username format a15
<br />col osuser format a15
<br />col program format a40
<br />select s.sid || ',' || s.serial# "SID/SERIAL"
<br />, s.username
<br />, s.osuser
<br />, p.spid "OS PID"
<br />, s.program
<br />from v$session s
<br />, v$process p
<br />Where s.paddr = p.addr
<br />order by to_number(p.spid)
<br />/
<br />
<br />SID/SERIAL USERNAME OSUSER OS PID PROGRAM
<br />---------- --------------- --------------- ------------ ----------------------------------------
<br />170,1 oracle 8339 oracle@dg1.ecsme.com (PMON)
<br />169,1 oracle 8341 oracle@dg1.ecsme.com (PSP0)
<br />168,1 oracle 8343 oracle@dg1.ecsme.com (MMAN)
<br />166,1 oracle 8345 oracle@dg1.ecsme.com (DBW0)
<br />167,1 oracle 8347 oracle@dg1.ecsme.com (LGWR)
<br />162,1 oracle 8349 oracle@dg1.ecsme.com (CKPT)
<br />165,1 oracle 8351 oracle@dg1.ecsme.com (SMON)
<br />163,1 oracle 8353 oracle@dg1.ecsme.com (RECO)
<br />164,1 oracle 8355 oracle@dg1.ecsme.com (CJQ0)
<br />161,1 oracle 8357 oracle@dg1.ecsme.com (MMON)
<br />160,1 oracle 8359 oracle@dg1.ecsme.com (MMNL)
<br />154,1 oracle 8382 oracle@dg1.ecsme.com (QMNC)
<br />150,1 oracle 8400 oracle@dg1.ecsme.com (q000)
<br />146,1 oracle 8404 oracle@dg1.ecsme.com (q001)
<br />159,16 SYS oracle 9791 sqlplus@dg1.ecsme.com (TNS V1-V3)
<br />148,195 oracle 9888 oracle@dg1.ecsme.com (J000)
<br />
<br />
<br />Show a users current sql
<br />
<br />Select sql_text
<br />from v$sqlarea
<br />where (address, hash_value) in
<br />(select sql_address, sql_hash_value
<br /> from v$session
<br /> where username like '&username')
<br />/
<br />
<br />Enter value for username: SYS
<br />old 6: where username like '&username')
<br />new 6: where username like 'SYS')
<br />
<br />SQL_TEXT
<br />----------------------------------------------------------------------------------------------------
<br />Select sql_text from v$sqlarea where (address, hash_value) in (select sql_address, sql_hash_value
<br /> from v$session where username like 'SYS')
<br />
<br />
<br />Session status associated with the specified os process id
<br />
<br />
<br />select s.username
<br />, s.sid
<br />, s.serial#
<br />, p.spid
<br />, last_call_et
<br />, status
<br />from V$SESSION s
<br />, V$PROCESS p
<br />where s.PADDR = p.ADDR
<br />and p.spid='&pid'
<br />/
<br />
<br />
<br />USERNAME SID SERIAL# SPID LAST_CALL_ET STATUS
<br />--------------- ---------- ---------- ------------ ------------ --------
<br />SYS 159 16 9791 0 ACTIVE
<br />
<br />
<br />
<br />All active sql
<br />
<br />
<br />set feedback off
<br />set serveroutput on size 9999
<br />column username format a20
<br />column sql_text format a55 word_wrapped
<br />begin
<br /> for x in
<br /> (select username||'('||sid||','||serial#||') ospid = '|| process ||
<br /> ' program = ' || program username,
<br /> to_char(LOGON_TIME,' Day HH24:MI') logon_time,
<br /> to_char(sysdate,' Day HH24:MI') current_time,
<br /> sql_address,
<br /> sql_hash_value
<br /> from v$session
<br /> where status = 'ACTIVE'
<br /> and rawtohex(sql_address) <> '00'
<br /> and username is not null ) loop
<br /> for y in (select sql_text
<br /> from v$sqlarea
<br /> where address = x.sql_address ) loop
<br /> if ( y.sql_text not like '%listener.get_cmd%' and
<br /> y.sql_text not like '%RAWTOHEX(SQL_ADDRESS)%' ) then
<br /> dbms_output.put_line( '--------------------' );
<br /> dbms_output.put_line( x.username );
<br /> dbms_output.put_line( x.logon_time || ' ' || x.current_time || ' SQL#=' || x.sql_hash_value);
<br /> dbms_output.put_line( substr( y.sql_text, 1, 250 ) );
<br /> end if;
<br /> end loop;
<br /> end loop;
<br />end;
<br />/
<br />
<br />
<br />
<br />Display any long operations
<br />
<br />set lines 100 pages 999
<br />col username format a15
<br />col message format a40
<br />col remaining format 9999
<br />select username
<br />, to_char(start_time, 'hh24:mi:ss dd/mm/yy') started
<br />, time_remaining remaining
<br />, message
<br />from v$session_longops
<br />where time_remaining = 0
<br />order by time_remaining desc
<br />/
<br />
<br />
<br />
<br />
<br />
<br />List open cursors per user
<br />
<br />set pages 999
<br />select sess.username
<br />, sess.sid
<br />, sess.serial#
<br />, stat.value cursors
<br />from v$sesstat stat
<br />, v$statname sn
<br />, v$session sess
<br />where sess.username is not null
<br />and sess.sid = stat.sid
<br />and stat.statistic# = sn.statistic#
<br />and sn.name = 'opened cursors current'
<br />order by value
<br />/
<br />
<br />USERNAME SID SERIAL# CURSORS
<br />--------------- ---------- ---------- ----------
<br />SYS 152 122 1
<br />SYS 159 16 4
<br />
<br />or
<br />
<br />
<br />set lines 100 pages 999
<br />select count(hash_value) cursors
<br />, sid
<br />, user_name
<br />from v$open_cursor
<br />group by
<br /> sid
<br />, user_name
<br />order by
<br /> cursors
<br />/
<br />
<br /> CURSORS SID USER_NAME
<br />---------- ---------- ------------------------------
<br /> 1 150 SYS
<br /> 1 148 SYS
<br /> 1 156 SYS
<br /> 2 149 SYS
<br /> 5 164 SYS
<br /> 5 145 SYS
<br /> 7 147 SYS
<br /> 7 155 SYS
<br /> 7 159 SYS
<br /> 8 143 SYS
<br /> 15 161 SYS
<br /> 17 153 SYS
<br /> 22 158 SYS
<br /> 38 152 SYS
<br />
<br />Administration - Init Parameters
<br />
<br />Show latent parameter changes
<br />
<br />select name,value from v$parameter where ismodified != 'FALSE';
<br />
<br />
<br />Show non-default parameters
<br />
<br />set pages 999 lines 100
<br />col name format a30
<br />col value format a50
<br />select name,value from v$parameter where isdefault = 'FALSE' and value is not null order by name;
<br />
<br />
<br />or for name='parameter' style...
<br />
<br />set pages 999 lines 100
<br />select name || '=' || decode(type, 2, '''') || value || decode(type, 2, '''') parameter from v$parameter where isdefault = 'FALSE'
<br />and value is not null order by name;
<br />
<br />
<br />Reset/Unset a spfile parameter
<br />Setting a parameter to =' ' often isn't enough. Do this instead...
<br />
<br />alter system reset <parameter> scope=spfile sid='*'
<br />/
<br />
<br />The sid='*' bit is always necessary, even in non RAC database.
<br />
<br />Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-13789563042209024542011-05-05T02:25:00.000-07:002011-05-05T02:29:03.984-07:00Configure VNC Server on Solarisroot# ./vncserver<br />vncserver: couldn't find "Xvnc" on your PATH.<br /><br /><br />root# cd /usr/X11/bin<br /><br />root# ls<br />Xvnc ......<br /><br />root# pwd<br />/usr/X11/bin<br /><br />root# export PATH=$PATH:/usr/X11/bin:/usr/openwin/bin<br /><br />root# vncserver<br /><br />You will require a password to access your desktops.<br /><br />Password:<br />Verify:<br /><br />New 'hostname:1 (root)' desktop is hostname:1<br /><br />Creating default startup script //.vnc/xstartup<br />Starting applications specified in //.vnc/xstartup<br />Log file is //.vnc/hostnames:1.logAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-26147575766265875142011-02-08T23:42:00.000-08:002011-02-08T23:43:34.089-08:00how to add a swap file LinuxProcedure to add a swap file<br /><br />You need to use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.<br /><br />a) Login as the root user<br /><br />b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):<br /># dd if=/dev/zero of=/swapfile1 bs=1024 count=524288<br /><br />c) Set up a Linux swap area:<br /># mkswap /swapfile1<br /><br />d) Activate /swapfile1 swap space immediately:<br /># swapon /swapfile1<br /><br />e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:<br /># vi /etc/fstab<br /><br />Append following line:<br />/swapfile1 swap swap defaults 0 0<br /><br />So next time Linux comes up after reboot, it enables the new swap file for you automatically.<br /><br />g) How do I verify swap is activated or not?<br />Simply use free command:<br />$ free -mAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-22992376718832503512011-01-25T21:58:00.001-08:002011-01-25T21:59:16.374-08:00Recreate the OraInventoryIn cases where the OraInventory is missing or otherwise corrupt, recreate the oraInventory directory on UNIX systems, using the following steps. In a normal installation, there is a Global Inventory (OraInventory) and a Local Inventory ($ORACLE_HOME/inventory). <br /><br />Locate the oraInst.loc file, which may be in different locations, depending on your system:<br /><br /> /var/opt/oracle/oraInst.loc file<br /> or<br /> /etc/oraInst.loc<br />Modify the file oraInst.loc file: <br /><br /> cp /var/opt/oracle/oraInst.loc /var/opt/oracle/oraInst.loc.bak<br /> mkdir /u01/oracle/oraInventory<br /><br /> ---file contents---<br /> inventory_loc=/u01/oracle/oraInventory<br /> inst_group=oinstall<br /> ---file contents---<br />Important:<br />Theses example uses a typical directory, considered an $ORACLE_BASE, and a typical UNIX group which installed the Oracle products. Ensure that the correct values are used for your system. <br /><br />The oraInventory directory is usually a directory under the $ORACLE_HOME. For example, if the $ORACLE_HOME is equal to "/u01/oracle/product/10g", then the OraInventory could be "/u01/oracle/OraInventory".<br />Change the permissions to be appropriate, (using your directory location):<br /><br /> chmod 644 /var/opt/oracle/oraInst.loc<br />For consistency, copy the file to Oracle home directory, (using your directory location):<br /><br />cp $ORACLE_HOME/oraInst.loc $ORACLE_HOME/oraInst.loc.bak<br />cp /var/opt/oracle/oraInst.loc $ORACLE_HOME/oraInst.loc<br />Run Oracle Universal Installer from your Oracle home as below, (using your site specific directory location and Oracle home name):<br /><br />cd $ORACLE_HOME/oui/bin<br />./runInstaller -silent -attachHome <br />ORACLE_HOME="/u01/oracle/product/10.2" ORACLE_HOME_NAME="Ora10gHome"<br />Check the inventory output is correct for your Oracle home:<br /><br /> $ORACLE_HOME/OPatch/opatch lsinventory -detail<br />If the table at the beginning of the output is showing the proper directories, and the Oracle home components are properly reflected in the details, then the Global Inventory has been successfully created from the Local Inventory. At this time, you may patch an maintain your Oracle home, as normal.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-51134069717143920552011-01-25T21:56:00.001-08:002011-01-25T21:56:28.798-08:00SQL*Plus command line history completionThe rlwrap (readline wrapper) utility provides a command history and editing of keyboard input<br /><br />for any other command. This is a really handy addition to SQL*Plus and RMAN .<br /><br /><br />Download the latest rlwrap software from the following URL.<br />http://utopia.knoware.nl/~hlub/uck/rlwrap/<br /><br />Unzip and install the software using the following commands.<br /><br />gunzip rlwrap*.gz<br />tar -xvf rlwrap*.tar<br />cd rlwrap*<br />./configure<br />make<br />make check<br />make install<br /><br />Run the following commands, or better still append then to the ".bash_profile" of the<br /><br /><br />oracle software owner.<br /><br /><br />alias sqlplus='rlwrap ${ORACLE_HOME}/bin/sqlplus'<br />alias rman='rlwrap ${ORACLE_HOME}/bin/rman' <br />alias expdp='rlwrap ${ORACLE_HOME}/bin/expdp'<br /><br />You can now start SQL*Plus or RMAN using "sqlplus" and "rman" respectively, and you will have<br /><br /><br />a basic command history and the current line will be editable using the arrow and delete keys.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-23410834078345069032011-01-24T00:05:00.001-08:002011-01-24T00:05:32.179-08:00Redhat Package Management (RPM)Features:<br /> 1. Provides package management<br /> a. Query<br /> b. Install<br /> c. Uninstall<br /> d. Upgrade<br /> e. Verify<br /> 2. Auto-verifies packages using GPG, MD5, SHA1SUMs<br /> 3. Automatically reports on unresolved dependencies<br /><br /><br /><br /><br />Install (Does NOT overwrite previous package):<br />Note: Use this method to install a new version of the kernel<br /> 1. rpm -ivh *.rpm<br /> 2. rpm -ivh http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm<br /><br /><br /><br />Upgrade (Installs or overwrites existing package):<br /> 1. rpm -Uvh *.rpm<br /> 2. rpm -Uvh http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm<br /><br />Freshen (Updates an existing package):<br />Note: Will NOT install the package, if it doesn't exist locally<br /><br /> 1. rpm -Fvh *.rpm - freshens the current version of a package<br /><br /><br />Removal:<br /> 1. rpm -ev *.rpm - removes a pacakge<br />Note: removal process considers dependencies and will complain if the removal will break 1 or more packages. To get around this, use '--nodeps' option with 'rpm -ev --nodeps *.rpm'<br /><br /> 2. rpm -ev gftp<br /><br /><br />Query:<br /><br /><br /> 1. rpm -qa - shows all installed packages<br /> 2. rpm -qa | wc -l - this dumps all packages and provides a count<br /> 3. rpm -qa | grep -i sendmail<br /> 4. rpm -qi nano - dumps info. about the 'sendmail' package as it's recorded in the local RPM database<br /> 5. rpm -qf /usr/bin/nano - dumps package membership info. for the 'nano' file<br /> 6. rpm -qpi http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm - dumps info. about the uninstalled 'dhcp' package, which resides on the repository<br /> 7. rpm -ql package_name - returns all included files<br /><br /><br />Verify:<br /> 1. rpm -Va - verifies ALL packages on the system, returning info. only if there are discrepancies from the original installation<br /><br /> 2. rpm -Vf /usr/bin/nano<br /><br />Task: Change '/usr/bin/nano' then verify<br /><br />SM5....T /usr/bin/nano<br /><br />S(file size), M(mode or permissions), 5(MD5), T(mod time)<br /> 3. rpm -Vp nanoAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-47875968908078953802011-01-24T00:03:00.001-08:002011-01-24T00:03:28.408-08:00IPTables in LinuxFeatures:<br /> 1. Firewall for Linux<br /> 2. Interface to Netfilter, which is loaded by the kernel<br /> 3. Operates primarily @ layers 3 & 4 of the OSI model<br /> 4. Modular<br /> 5. Provides Network Address Translation (NAT)<br /> 6. IPTables can also access other layers (2, 5-7), with modules<br /><br />1. grep -i config_netfilter /boot/config*<br /><br />Note: Save rules in: /etc/sysconfig/iptables so that when IPTables is restarted, the rules will be applied OR, update /etc/sysconfig/iptables-config to save the rules automatically<br /><br />/sbin/iptables - primary ACL modifier utility<br />/sbin/iptables-restore - restores rules to current IPTables instance<br />/sbin/iptables-save - saves rules to STDOUT, by default, or to a file<br /><br /><br />IPTables includes 3 default tables, which you cannot remove:<br /> 1. NAT<br /> 2. Mangle<br /> 3. Filter (Default) - filters inbound/outbound traffic<br /><br />Note: Each table, includes chains, which include Access Control Entries (ACEs)<br /><br />Usage:<br /> 1. iptables -L<br /><br />Note: The Filter table includes 3 chains:<br /> 1. INPUT - applies to traffic destined to a service that our system is bound to<br /><br /> 2. FORWARD - applies to traffic being routed through the system<br /><br /> 3. OUTPUT - applies to traffic sourced from our system, heading outbound<br /><br /><br />Examples:<br /> 1. Filter inbound traffic to remote RH5 system to SSH<br /> a. iptables -A INPUT -p tcp --dport 22 -j ACCEPT<br /> b. iptables -A INPUT -j DROP<br /><br /> 2. Filter outbound traffic to ANY remote SSH port<br /> a. iptables -A OUTPUT -p tcp --dport 22 -j DROP<br /><br /> 3. Flush ALL rules from OUTPUT chain of the Filter table<br /> a. iptables -F OUTPUT<br /><br /> 4. Save rules to file, then flush rules<br /> a. iptables-save > iptables.rules.1<br /><br /> 5. Reinstate flushed rules<br /> a. iptables-restore iptables.rules.1Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-19662834003311955982011-01-23T23:51:00.001-08:002011-01-23T23:51:40.087-08:00Server Status & Health Check in LinuxTop :<br /><br />Top Command can provide the top processes, CPU Load, Memory Utilization, Swap Utilization<br /><br />Running/Zombie Process, Uptime, etc..<br /><br />iostat:<br /><br />This command will provide the information about the disk utilization, Read/Write rate, etc..<br /><br />vmstat:<br /><br />vmstat command provides the swap memory utilization report<br /><br />sar (System Activity Reporter)<br /><br />sar tool can provide the report about CPU Load, iowait and other useful info at specified intervals.<br /><br />dmesg<br /><br />dmesg command displays all the server errors including Hardware, booting, network errors<br /><br />This command will retrieve the information from log files which located in /var/log<br /><br />Other Useful commands to collect some info about the server :<br /><br />runlevel - To Know the Current Run Level<br /><br />netstat –a - To see the Network sessions<br /><br />netstat –rn - To View the gateways configured<br /><br />who / finger - To View the Users logged in detail<br /><br />ps –ef - To view all the running process and its related files<br /><br />sestatus - To check SELINUX status<br /><br />service iptables status - To check firewall status<br /><br />ifconfig –a - To View the Network cards and IP Address configuredAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-67477182876391466062011-01-23T23:36:00.003-08:002011-01-23T23:36:54.366-08:00Linux Booting Process SequenceWhen the computer is switched on, it automatically invokes BIOS [a ROM chip embedded in the motherboard].<br />The BIOS will start the processor and perform a POST [power on self test] to check whether the connected device are ready to use and are working properly.<br />Once the POST is completes BIOS will jump to a specified location in the RAM and check for the booting device. The boot sector is always the first sector of the hard disk and BIOS will load the MBR into the memory.<br />Here the boot loader takes the control of the booting process.<br />LILO or GRUB is the boot loaders commonly available. It will help the user to select various boot options.<br />Depending on the boot option selected the kernel is loaded.<br />After kernel is loaded the kernel will take the control of the booting process<br />initrd will be loaded which contains drivers to detect hardware (Initialization of RAM Disk)<br />Then it will initialize all the hardware including I/O processors etc.<br />Kernel then mounts the root partition as read-only<br />INIT is loaded.<br />INIT will mount the root partition and other partitions as read/write and checks for file system errors.<br />Sets the System Clock, hostname etc..<br />Based on the Runlevel, it will load the services and runs the startup scripts (Network, cups, nfs, etc.)<br />Finally it runs the rc.local script.<br />Now the login prompt will appear.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-10725223098846302792011-01-23T23:36:00.001-08:002011-01-23T23:36:27.247-08:00Disable SSH root loginProviding direct login access to root via SSH is not a good practice. Administrators should use sudo to switch to root after logged in as themselves. this will helpful in auditing in terms of security.<br /><br />Here is the step by step procedure to disable/deny direct root login via SSH<br /><br />1. Login to the server as Root<br /><br />2. Edit /etc/ssh/sshd_config<br /><br /> Look for the line,<br /><br /> PermitRootLogin=Yes<br /> <br />and then change the value of it to,<br /><br /> PermitRootLogin=No <br /><br />3. Restart the sshd service and make sure its turned on<br /><br /> service sshd restart or /etc/init.d/sshd restart<br /> <br /> service sshd statusAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-49500331900264000282011-01-23T23:35:00.001-08:002011-01-23T23:35:47.610-08:00Delete old log files in LinuxTo find files modified more than 5 days use -mtime +5 and files modified less than 5 days use -mtime -5<br /><br /><br />Use -ctime parameter to find out the created time <br /><br /><br /><br />To List and Delete log files older than 10 days, execute the following commands <br /><br /> <br />find /var/log/ -name *.log -mtime +10 -exec ls -tl {} \; <br /><br />find /var/log/ -name *.log -mtime +10 -exec rm -f {} \;Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-14649291477406308842011-01-23T23:30:00.000-08:002011-01-23T23:31:01.201-08:00Reinstall Grub in LinuxBoot the server using the Linux CD and Type "linux rescue" on the boot prompt.<br /><br />Once you get the Shell Prompt, Now follow the steps:<br /><br /> # chroot /mnt/sysimage<br /><br />Now issue the command "grub-install <your_primary_drive>"<br /> <br />For Example:<br /> <br /> # grub-install /dev/sda<br /><br />Now the grub will be reinstalled in the primary hard disk.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-16468037245482974002011-01-23T06:59:00.001-08:002011-01-23T06:59:55.633-08:00Changing hostname without rebooting Linux serverHere the steps for changing the hostname in Linux (Redhat / CentOS / Fedora) without rebooting the server <br /><br /><br />First you need to find out your current hostname:<br /><br /># hostname<br />server1.mydomain.com<br /><br />Now, Edit /etc/hosts<br /><br />For example, I need to assign it hostname as ftpsrv.mydomain.com. <br /><br /><br />To do this, I have edited /etc/hosts as follows.<br /># Do not remove the following line, or various programs<br /># that require network functionality will fail.<br />127.0.0.1 localhost.localdomain localhost<br />192.168.2.100 ftpsrv.mydomain.com ftpsrv<br /><br /><br />Edit /etc/sysconfig/network<br /><br />To change servers hostname to ftpsrv.mydomain.com, change the file as follows.<br /><br /># cat /etc/sysconfig/network<br /><br /><br />NETWORKING=yes<br />HOSTNAME=ftpsrv.mydomain.com <br />Now Type the following command in Terminal, <br /><br /><br /># hostname ftpsrv.mydomain.com<br /><br /><br />#service syslog restart<br /><br />Now, You should logout and login back to see the changesAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-8500107703489960832011-01-23T06:55:00.001-08:002011-01-23T06:55:28.236-08:00Backup and Recovery in Linux using dd commandCREATING A HARD DISK IMAGE FILE<br /><br />It is better to creating an image file of the hard disk and save it in other storage devices for future recovery. The following command will create an image file "appdisk.img" in your home directory from /dev/sda:<br /><br /><br />dd if=/dev/sda of=~/appdisk.img<br /><br />Since you have created an image file, you can compress it with "gzip" or "bzip2":<br /><br /><br />gzip appdisk.img #generates appdisk.img.gz<br /><br />It might take very long time.<br /><br /><br />CREATING A PARTITION IMAGE <br /><br /><br />Backing up a hard disk partition is much similar to backing up a whole hard disk. <br /><br /><br />For example, if you want to create an image file from the first partition of /dev/sda, use "dd" like this:<br /><br /><br />dd if=/dev/sda1 of=~/disk2.img<br /><br />Also, you can compress the image file:<br /><br /><br />gzip disk2.img<br /><br />By the way, you can copy a partition to another partition completely, just set "of" to the partition's device name. For example:<br /><br /><br />dd if=/dev/sda1 of=/dev/sdb5<br /><br />This command will copy all the contents from /dev/sda1 to /dev/sdb5.<br /><br /><br />You must be sure that the capacity of /dev/sdb5 is larger than /dev/sda1.<br /><br /><br />RESTORING FROM AN IMAGE FILE<br /><br />To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of".<br /><br /><br />For example, restore the whole hard disk from the image file "disk1.img":<br /><br /><br />dd if=disk1.img of=/dev/sda<br /><br />Restore the first partition of /dev/sda from the image file "disk2.img":<br /><br /><br />dd if=disk2.img of=/dev/sda1Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-51714545702696952692011-01-23T06:48:00.001-08:002011-01-23T06:49:38.386-08:00Enable cron for a locked account in LinuxIn some environments, there are times when locked application/databases accounts need to run some cron jobs. In linux, by default, a locked account can not run the cron job.<br /><br />We can enable this by editing a specific setting is disabled in /etc/pam.d/crond file. <br /><br />Here is the details:<br /><br /><br /># cat /etc/pam.d/crond <br /><br /><br />#<br /># The PAM configuration file for the cron daemon<br />#<br />auth sufficient pam_rootok.so<br />auth required pam_stack.so service=system-auth<br />auth required pam_env.so<br />account required pam_stack.so service=system-auth<br /># account required pam_access.so<br />session required pam_limits.so<br />session required pam_loginuid.so<br /><br />This example is working in Redhat Linux. In the /etc/pam.d/crond file, if we disable "account required pam_access.so" line the cron started working again for the locked account as well.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-43308660090673326532011-01-23T06:47:00.000-08:002011-01-23T06:50:42.466-08:00Finding BIOS version in Linux ServersCommand : dmidecode --type 0<br /><br /><br /># dmidecode 2.9<br />SMBIOS 2.6 present.<br /><br />Handle 0x0000, DMI type 0, 24 bytes<br />BIOS Information<br /> Vendor: HP<br /> Version: I24<br /> Release Date: 03/30/2010<br /> Address: 0xF0000<br /> Runtime Size: 64 kB<br /> ROM Size: 8192 kB<br /> Characteristics:<br /> PCI is supported<br /> PNP is supported<br /> BIOS is upgradeable<br /> BIOS shadowing is allowed<br /> ESCD support is available<br /> Boot from CD is supported<br /> Selectable boot is supported<br /> EDD is supported<br /> 5.25"/360 KB floppy services are supported (int 13h)<br /> 5.25"/1.2 MB floppy services are supported (int 13h)<br /> 3.5"/720 KB floppy services are supported (int 13h)<br /> Print screen service is supported (int 5h)<br /> 8042 keyboard services are supported (int 9h)<br /> Serial services are supported (int 14h)<br /> Printer services are supported (int 17h)<br /> CGA/mono video services are supported (int 10h)<br /> ACPI is supported<br /> USB legacy is supported<br /> BIOS boot specification is supported<br /> Function key-initiated network boot is supported<br /> Targeted content distribution is supported<br /> Firmware Revision: 2.1<br />Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-16175740391534340662011-01-23T06:46:00.000-08:002011-01-23T06:50:42.473-08:00NOHUP : Run command continiously even if session closedNohup command is used to run any command continiously even if you close your session from the server.<br /><br /><br />If nohup added in front of any command will continue running that command or process, even if you exit your terminal or close your session in that server<br /><br /><br />Syntax:<br /><br /><br />nohup command-to-run &<br /><br /><br />Where,<br /><br /><br />command-to-run : is name of command or script which you want to run. You can pass argument to that command or script.<br />& : nohup does not automatically runs the command in the background. you must do that explicitly, by ending the command line with an & symbol.<br /><br /><br /><br />example:<br /><br /><br /># nohup /root/backup-script.sh error.log 2>&1 &Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-77490045514328496272011-01-23T06:32:00.003-08:002011-01-23T06:50:42.483-08:00Moving volume group to another Server in Linux<br />Moving a VG to another server:<br /><br />To do this we use the vgexport and vgimport commands.<br /><br />vgexport and vgimport is not necessary to move disk drives from one server to another. It is an administrative policy tool to prevent access to volumes in the time it takes to move them.<br /><br />1. Unmount the file system<br />First, make sure that no users are accessing files on the active volume, then unmount it<br /><br /># unmount /appdata<br /><br />2.Mark the volume group inactive<br />Marking the volume group inactive removes it from the kernel and prevents any further activity on it.<br /><br /># vgchange -an appvg<br />vgchange -- volume group "appvg" successfully deactivate<br /><br /><br /><br />3. Export the volume group<br /><br />It is now must to export the volume group. This prevents it from being accessed on the old server and prepares it to be removed.<br /><br /># vgexport appvg<br />vgexport -- volume group "appvg" successfully exported<br /><br />Now, When the machine is next shut down, the disk can be unplugged and then connected to it's new machine<br /><br />4. Import the volume group<br /><br />When it plugged into the new server, it becomes /dev/sdc (depends).<br /><br />so an initial pvscan shows:<br /><br /># pvscan<br />pvscan -- reading all physical volumes (this may take a while...)<br />pvscan -- inactive PV "/dev/sdc1" is in EXPORTED VG "appvg" [996 MB / 996 MB free]<br />pvscan -- inactive PV "/dev/sdc2" is in EXPORTED VG "appvg" [996 MB / 244 MB free]<br />pvscan -- total: 2 [1.95 GB] / in use: 2 [1.95 GB] / in no VG: 0 [0]<br /><br />We can now import the volume group (which also activates it) and mount the file system.<br /><br />If you are importing on an LVM 2 system, run:<br /><br /># vgimport appvg<br />Volume group "vg" successfully imported<br /><br />5. Activate the volume group<br /><br />You must activate the volume group before you can access it.<br /><br /># vgchange -ay appvg<br /><br />Mount the file system<br /><br /># mkdir -p /appdata<br /># mount /dev/appvg/appdata /appdata<br /><br />The file system is now available for use.Afzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-7279571335137790832011-01-23T06:30:00.001-08:002011-01-23T06:31:01.958-08:00CLEANING UP THE LINUX BUFFER CACHEWhen you write data, it doesn’t necessarily get written to disk right then. The kernel maintains caches of many things, and disk data is something where a lot of work is done to keep everything fast and efficient.<br /><br />That’s great for performance, but sometimes you want to know that data really has gotten to the disk drive. This could be because you want to test the performance of the drive, but could also be when you suspect a drive is malfunctioning: if you just write and read back, you’ll be reading from cache, not from actual disk platters.<br /><br /><br />Obviously the first thing you need to do is get the data in the cache sent on its way to the disk. That’s “sync”, which tells the kernel that you want the data written. But that doesn’t mean that a subsequent read comes from disk: if the requested data is still in cache, that’s where it will be fetched from. It also doesn’t necessarily mean that the kernel actually has sent the data along to the disk controller: a “sync” command is a request, not a command that says “stop everything else you are doing and write your whole buffer cache to disk right now!”. No, “sync” just means that the cache will be written, as and when the kernel has time to do so.<br /><br />Note that you really didn’t even need the “sync” if this is what you are doing: the overwrite forces the sync itself.<br /><br />Modern Linux kernels make this a bit easier: in /proc/sys/vm/ you’ll find “drop_caches”.<br /><br />You can simply echo a number to that to free caches.<br /><br />To free pagecache:<br />echo 1 > /proc/sys/vm/drop_caches<br /><br />To free dentries and inodes:<br />echo 2 > /proc/sys/vm/drop_caches<br /><br />To free pagecache, dentries and inodes:<br />echo 3 > /proc/sys/vm/drop_cachesAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.comtag:blogger.com,1999:blog-2917723198682118364.post-41558472846904372522011-01-23T06:24:00.001-08:002011-01-23T06:25:49.814-08:00Clear Swap Space in LinuxThere have been times where it has been necessary for UNIX Admins to clear out the swap space on a Linux system. In order to do this, you must first make sure that you have enough free memory to hold what is being used by swap.<br /><br /><br />First we want to see what is currently being used.<br /><br />free<br /><br />Then I run the actual commands that empty the swap:<br /><br />swapoff -a <br /><br />free<br /><br />swapon -a<br /><br />Then I check what is being used after doing this.<br /><br />freeAfzalhttp://www.blogger.com/profile/10394105474128051667noreply@blogger.com