Wednesday, March 9, 2022

System Performance Commands

 

System Performance Commands

In this blog, I will be sharing some linux commands which might help you to understand the system’s internal activities.

Note: These commands are very safe to run on production environment other than strace.

Command            Usageuptime             Load Averagedmesg | tail       Kernal Errorsvmstat 1           Overall stats by timempstat -P ALL 1    CPU balanceiostat -xz 1       disk i/opidstat 1          process usagefree -m            Memory usagesar -n DEV 1       network i/osar -n TCP,ETCP 1  TCP statstop                check overview

How to monitor certain process only:

top -p 4360,4358ORhtop -p PID

Check Process tree(Useful to identify which parent process):

ps -ef f

show the connections an application is making including the port being used:

netstat -taucp | grep <pid or process name>

show open ports:

netstat -tulpn

Virtual memory Stats:

vmstat -Sm 1

System I/O:

iostat -xmdz 1

System Activity Reporter

sar -n DEV 1sar -n TCP,ETCP,DEV 1

Processor Related Statistics:

mpstat -P ALL 1

Socket Stats:

ss -s

System Call tracer:

strace -tttT -p 333strace -pt PID 2>&1 | head -100Note: Always use head -10 or so to get only first x call output otherwise it will show down system.

Sniff Packets:

tcpdump -i eth0 -w filenametcpdump -nr

Network Stats:

netstat -s

Process Stats:

pidstat -t 1

specify devices on which paging and swapping are to take place:

swapon -s (if swapon enabled)

LOSF:

lsof -iTCP -sTCP:ESTABLISHED

Friday, March 13, 2020

How to find failed connection attempts using listener log?


[oracle@dbhost01 trace]$ awk  '{ if ( $NF != 0 ) print $0 }' listener_scan1.log|head

11-MAR-2020 10:39:20 * (CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=sqlplus.exe)(HOST=apphost01)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=39371)) * establish * ORCL * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
11-MAR-2020 10:39:20 * (CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=sqlplus.exe)(HOST=apphost01)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=43478)) * establish * ORCL * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
11-MAR-2020 10:39:20 * (CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=sqlplus.exe)(HOST=apphost01)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=39377)) * establish * ORCL * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
11-MAR-2020 10:39:20 * (CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=sqlplus.exe)(HOST=apphost01)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=43484)) * establish * ORCL * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
11-MAR-2020 10:39:30 * (CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=sqlplus.exe)(HOST=apphost01)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=50217)) * establish * ORCL * 12505
[oracle@dbhost01 trace]$

Friday, February 21, 2020

Command for counting the ORA- errors in alert log file.

    As a DBA, one of the primary responsibility is morning the alert log and identifying the issues and fixing them. Some times we may need no of ORA errors and each error count. Using below mentioned command we can get the required output easily. Hope this helps someone.

/home/oracle$  grep -oh "\w*ORA-\w*" alert_ORCL.log |sort|uniq -c
      1 ORA-00028
    132 ORA-00060
      5 ORA-00202
      4 ORA-00206
      1 ORA-00221
      5 ORA-00235
      5 ORA-00245
      3 ORA-00272
/home/oracle$

Monday, November 4, 2019

Tablespace Utilization Script

How to check oracle tablespace report 
1. Check the database details.
2. Check the tablespace Utilization.
3. Check the details of the datafiles for a particular TableSpace which needs attention.
4. Resize or Add the datafiles as per the standards of the existing datafiles on the database.

1. Check the database details.
$ sqlplus "/as sysdba"

set pages 9999 lines 300
col OPEN_MODE for a10
col HOST_NAME for a30
select name DB_NAME,HOST_NAME,DATABASE_ROLE from v$database,v$instance;

2. Check the tablespace Utilization.
Tablespace Utilization Script including AUTOEXTEND (IN GB)
----------------------------------------------------------
$ sqlplus "/as sysdba"

set pages 50000 lines 32767
col tablespace_name format a30
col TABLESPACE_NAME heading "Tablespace|Name"
col Allocated_size heading "Allocated|Size(GB)" form 99999999.99
col Current_size heading "Current|Size(GB)" form 99999999.99
col Used_size heading "Used|Size(GB)" form 99999999.99
col Available_size heading "Available|Size(GB)" form 99999999.99
col Pct_used heading "%Used (vs)|(Allocated)" form 99999999.99

select a.tablespace_name
        ,a.alloc_size/1024/1024/1024 Allocated_size
        ,a.cur_size/1024/1024/1024 Current_Size
        ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
        ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
        ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
from     dba_tablespaces t
        ,(select t1.tablespace_name
        ,nvl(sum(s.bytes),0) used
        from  dba_segments s
        ,dba_tablespaces t1
         where t1.tablespace_name=s.tablespace_name(+)
         group by t1.tablespace_name) u
        ,(select d.tablespace_name
        ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
        ,sum(d.bytes) cur_size
        ,count(*) file_count
        from dba_data_files d
        group by d.tablespace_name) a
where t.tablespace_name=u.tablespace_name
and t.tablespace_name=a.tablespace_name
order by t.tablespace_name
/

Tablespace Utilization Script (including AUTOEXTEND) for generating report of more than 80 % used tablespaces (IN GB)
---------------------------------------------------------------------------------------------------------------------
set pages 50000 lines 32767
col tablespace_name format a30
col TABLESPACE_NAME heading "Tablespace|Name"
col Allocated_size heading "Allocated|Size(GB)" form 99999999.99
col Current_size heading "Current|Size(GB)" form 99999999.99
col Used_size heading "Used|Size(GB)" form 99999999.99
col Available_size heading "Available|Size(GB)" form 99999999.99
col Pct_used heading "%Used (vs)|(Allocated)" form 99999999.99

select a.tablespace_name
        ,a.alloc_size/1024/1024/1024 Allocated_size
        ,a.cur_size/1024/1024/1024 Current_Size
        ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
        ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
        ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
from     dba_tablespaces t
        ,(select t1.tablespace_name
        ,nvl(sum(s.bytes),0) used
        from  dba_segments s
        ,dba_tablespaces t1
         where t1.tablespace_name=s.tablespace_name(+)
         group by t1.tablespace_name) u
        ,(select d.tablespace_name
        ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
        ,sum(d.bytes) cur_size
        ,count(*) file_count
        from dba_data_files d
        group by d.tablespace_name) a
where t.tablespace_name=u.tablespace_name
and ((u.used+a.file_count*65536)*100)/a.alloc_size>80
and t.tablespace_name=a.tablespace_name
order by t.tablespace_name
/

3. Check the details of the datafiles for a particular TableSpace which needs attention.
Datafiles of a particular TableSpace:
------------------------------------
set pages 50000 lines 32767
col tablespace_name for a30
col CREATION_TIME for a15
col file_name for a70
select dd.tablespace_name TABLESPACE_NAME,dd.file_name,dd.bytes/1024/1024 Size_MB,dd.autoextensible,dd.maxbytes/1024/1024 MAXSIZE_MB,df.CREATION_TIME
from dba_data_files dd, v$datafile df where df.name=dd.file_name and tablespace_name='&TABLESPACENAME' order by 1,2,6;

Note:- If required, can get the DDL of a tablespace as below.

TABLESPACE DDL
--------------
set pagesize 0
SET LONG 9999999
select dbms_metadata.get_ddl('TABLESPACE','&TABLESPACE_NAME') FROM DUAL;

Monday, September 16, 2019

How to find OSDBA OSASM OSOPER group

How to find OSDBA or OSOPER or OSASM Group

What is OSDBA group

OSDBA or OSASM or OSOPER refers to the operating system groups,which are being assigned with the database privileges. This mapping takes place during the time of the installation.
# The DBA_GROUP is the OS group which is to be granted OSDBA privileges.
# The OPER_GROUP is the OS group which is to be granted OSOPER privileges.
# The OSASM_GROUP is the OS group which is to be granted OSASM privileges.
An important point to be noted is that, only the members or OSDBA group can connect to the database instance with SYSDBA a privilege using operating system authentication

Finding OSDBA group

Most of the time we can easily find out the information from group name of the owner of the Oracle Binaries. But there are chances that the ownership is changed in later point of time mostly accidental. So if we wanted to find out the values set up initially that is during the time of the installation the best method is to look into the configuration file created during the time of installation
#1 go to your $ORACLE_HOME/rdbms/lib
#2 grep for “define SS_” in config.c file
Eg :
[oracle@localhost]$ cd $ORACLE_HOME/rdbms/lib
 [oracle@wysheid12crac60 lib]$ grep “define SS_” config.c
#define SS_DBA_GRP “dba”
#define SS_OPER_GRP “dba”
#define SS_ASM_GRP “”
#define SS_BKP_GRP “dba”
#define SS_DGD_GRP “dba”
#define SS_KMT_GRP “dba”
[oracle@localhost ]$
 In this example we can see that DBA group is assigned with the OSDBA privilege
Alternatively you can find out this information from your installation log files if it is available.In most cases the installation log files will be available in the log directory in Oracle inventory location.
Hope this helps.

Thursday, July 4, 2019

Whats new in Exadata X8 Server 19.2 Exadata Database Machine?

This blog post quickly scan through the new features of Exadata Database Machine in 19.2 and also hardware capacity and change in Exadata X8 server.


  • Exadata Database Machine Software 19.2.0, supports Exadata X8-2 and X8-8 hardware
  • Changes in IORM's flashcachesize and Disk I/O limits attributes
  • To control the cost of Exadata storage, X8 introduced a new configuration, Exadata Storage Extended (XT)
  • The XT model comes with 14TB hard drives with HCC compression capacity
  • The XT model doesn't have flash drive
  • The lower cost storage option comes with one CPU, less memory and without the core feature of SQL offloading
  • Exadata X8 server has the below hardware capacity per rack:
    • Limit of 912 CPU core and 28 TB memory
    • 2-19 database servers
    • 3-18 cell storage
    • 920 TB of RAW flash capacity
    • 3 PB of RAW disk capacity

References:
http://jaffardba.blogspot.com/2019/04/whats-in-exadata-x8-server-192-exadata.html

https://www.oracle.com/a/ocom/docs/engineered-systems/exadata/exadata-x8-2-ds.pdf
https://docs.oracle.com/en/engineered-systems/exadata-database-machine/dbmso/whats-new-oracle-exadata-database-machine-19.2.html#GUID-B2A6BEAD-873A-4524-82EF-CDF53098820B

Sunday, March 25, 2018

Optimizer_mode – ALL_ROWS or FIRST_ROWS?

Out of all Oracle RDBMS modules, optimizer code is actually the most complicated code and different optimizer modes seem like jack while lifting your car in case of a puncture.


    This paper focuses on how optimizer behaves differently when you have optimizer mode set to ALL_ROWS or FIRST_ROWS.
Possible values for optimizer_mode = choose/ all_rows/ first_rows/ first_rows[n]
By default, the value of optimizer_mode is CHOOSE which basically means ALL_ROWS (if statistics on underlying tables exist) else RULE (if there are no statistics on underlying tables). So it is very important to have statistics collected on your tables on regular intervals or else you are living in Stone Age.
FIRST_ROWS and ALL_ROWS are both cost based optimizer features. You may use them according to their requirement.
FIRST_ROWS/ FIRST_ROWS[n]
In simple terms it ensures best response time of first few rows (n rows).
This mode is good for interactive client-server environment where server serves first few rows and by the time user scroll down for more rows, it fetches other. So user feels that he has been served the data he requested, but in reality the request is still pending and query is still fetching the data in background.
Best example for this is toad, if you click on data tab, it instantaneously start showing you data and you feel toad is faster than sqlplus, but the fact is if you scroll down, you will see the query is still running.
Ok, let us simulate this on SQLPLUS
Create a table and index over it:

SQL> create table test as select * from all_objects;

Table created.

SQL> create index test_in on test(object_type);

Index created.

SQL> exec dbms_stats.gather_table_stats(‘SAC’,'TEST')

PL/SQL procedure successfully completed.

SQL> select count(*) from test;

COUNT(*)
----------
37944

SQL> select count(*) from test where object_type='JAVA CLASS';

COUNT(*)
----------
14927

You see out of almost 38k records, 15k are of JAVA class. And now if you select the rows having object_type=’JAVA_CLASS’, it should not use index as almost half of the rows are JAVA_CLASS. It will be foolish of optimizer to read the index first and then go to table.
Check out the Explain plans


SQL> set autotrace traceonly exp
SQL> select * from test where object_type='JAVA CLASS';

Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1001 | 94094 | 10 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1001 | 94094 | 10 (0)| 00:00:01 |
--------------------------------------------------------------------------

As you see above, optimizer has not used Index we created on this table.
Now use FIRST_ROWS hint:

SQL> select /*+ FIRST_ROWS*/ * from test where object_type='JAVA CLASS';

Execution Plan
----------------------------------------------------------
Plan hash value: 3548301374

---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14662 | 1345K| 536 (1)| 00:00:07 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST | 14662 | 1345K| 536 (1)| 00:00:07 |
|* 2 | INDEX RANGE SCAN | TEST_IN | 14662 | | 43 (3)| 00:00:01 |
---------------------------------------------------------------------------------------

In this case, optimizer has used the index.
Q> Why?
Ans> Because you wanted to see first few rows quickly. So, following your instructions oracle delivered you first few rows quickly using index and later delivering the rest.
See the difference in cost, although the response time (partial) of second query was faster but resource consumption was high.
But that does not mean that this optimizer mode is bad. As I said this mode may be good for interactive client-server model. In most of OLTP systems, where users want to see data fast on their screen, this mode of optimizer is very handy.
Important facts about FIRST_ROWS
  1. It gives preference to Index scan Vs Full scan (even when index scan is not good).
  2. It prefers nested loop over hash joins because nested loop returns data as selected (& compared), but hash join hashes one first input in hash table which takes time.
  3. Cost of the query is not the only criteria for choosing the execution plan. It chooses plan which helps in fetching first rows fast.
  4. It may be a good option to use this in an OLTP environment where user wants to see data as early as possible.

ALL_ROWS
In simple terms, it means better throughput
While FIRST_ROWS may be good in returning first few rows, ALL_ROWS ensures the optimum resource consumption and throughput of the query. In other words, ALL_ROWS is better to retrieve the last row first.
In above example while explaining FIRST_ROWS, you have already seen how efficient ALL_ROWS is.
Important facts about ALL_ROWS
  1. ALL_ROWS considers both index scan and full scan and based on their contribution to the overall query, it uses them. If Selectivity of a column is low, optimizer may use index to fetch the data (for example ‘where employee_code=7712’), but if selectivity of column is quite high ('where deptno=10'), optimizer may consider doing Full table scan. With ALL_ROWS, optimizer has more freedom to its job at its best.
  2. Good for OLAP system, where work happens in batches/procedures. (While some of the report may still use FIRST_ROWS depending upon the anxiety level of report reviewers)
  3. Likes hash joins over nested loop for larger data sets.

Conclusion
Cost based optimizer gives you flexibility to choose response time or throughput. So use them based on your business requirement.

Source of this post is: oracle-online-help.blogspot.in