Followers

Monday, May 27, 2019

Mamun's DBA Blog: How to Install & Run ORAchk


To run orachk follow the steps below...

Step 1. Download the ORAchk zip from MOS DOC ID 1268927.2 if not have downloaded.
Note: Download the 2nd one.

Step 2. Check if the directory “/opt/oracle.SupportTools/orachk” exists
     a. If the directory does not exist, create it and unzip the zip file to it.
     b. If the directory exists but ORAchk isn't installed, unzip the zip file.

Step 3. After you’ve completed the installation, you’re ready to run ORAchk from the OS command line as root
    ./orachk –a –o verbose

Step 4. Then get the report as zip by following the directed location at the end.

Wednesday, May 15, 2019

Mamun's DBA Blog: How To Check Undo Tablespace Size and Free Size in Oracle

First Connect through SQLPlus then,

SQL> select a.tablespace_name, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) FREEMB
     from (select sum(bytes) / 1024 / 1024 SIZEMB, b.tablespace_name from dba_data_files a,
     dba_tablespaces b where a.tablespace_name = b.tablespace_name and b.contents = 'UNDO'
     group by b.tablespace_name) a, (select c.tablespace_name, sum(bytes) / 1024 / 1024 USAGEMB
     from DBA_UNDO_EXTENTS c where status <> 'EXPIRED'group by c.tablespace_name) b
     where a.tablespace_name = b.tablespace_name;

TABLESPACE_NAME     SIZEMB    USAGEMB        FREEMB
--------------- ---------- ---------- -------------------------------------------------
UNDOTBS1                        15360         50.6875           15309.3125
UNDOTBS2                        15360         40.5625           15319.4375

Mamun's DBA Blog: How To Check Redolog File Size in Oracle

Here we go for fetch the size of all redo logs...
SQL> set linesize 300
SQL> column REDOLOG_FILE_NAME format a45
SQL> SELECT
        a.GROUP#,
        a.THREAD#,
        a.SEQUENCE#,
        a.ARCHIVED,
        a.STATUS,
        b.MEMBER    AS REDOLOG_FILE_NAME,
        (a.BYTES/1024/1024) AS SIZE_MB
    FROM v$log a
    JOIN v$logfile b ON a.Group#=b.Group#
    ORDER BY a.GROUP# ASC;

    GROUP#    THREAD#  SEQUENCE#  ARC           STATUS                    REDOLOG_FILE_NAME                    SIZE_MB
---------- ---------- ---------- --- --------- --------------------------------------------- ---------------------------------------------------------------------
         1               1               17309           NO             CURRENT   +RECO/ieclive/onlinelog/group_1.257.860629021        200
         1               1               17309           NO              CURRENT   +DATA/ieclive/onlinelog/group_1.266.860629021       200
         2               1               17306          YES             INACTIVE  +RECO/ieclive/onlinelog/group_2.259.860629023        200
         2               1               17306          YES             INACTIVE  +DATA/ieclive/onlinelog/group_2.268.860629023        200
         3               2               30917          NO              CURRENT   +DATA/ieclive/onlinelog/group_3.261.860629087        200
         3               2               30917          NO              CURRENT   +RECO/ieclive/onlinelog/group_3.261.860629087        200
         4               2               30914         YES              INACTIVE  +DATA/ieclive/onlinelog/group_4.270.860629089         200
         4               2               30914         YES              INACTIVE  +RECO/ieclive/onlinelog/group_4.262.860629089         200
         5               1               17307         YES              INACTIVE  +RECO/ieclive/onlinelog/group_5.258.860629023         200
         5               1               17307         YES              INACTIVE  +DATA/ieclive/onlinelog/group_5.272.860629023         200
  

Mamun's DBA Blog: Gathering Table Stats in Oracle11g

Hello Visitors!!!


  • When we gather stats we are updating Optimizer to choose optimal execution plan which enhance the performance of the database.
  • We can gather stats at database level,schema level, Table level,Index level.
Table Level Stats :

SQL> Begin DBMS_STATS.GATHER_TABLE_STATS (
         ownname =>'SCOTT',
         tabname =>'EMPLOYEE',
         degree => 2,
         cascade => TRUE,
         METHOD_OPT => 'FOR COLUMNS SIZE AUTO',
         estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE);
         END;
         /


Parameters Defination:-
  • Owner-name = Schema Name which holds the table.
  • Tabname = Table Name
  • Degree  = When you set degree to some value oracle will invoke slave process which speedup the performance.
  • cascade = The cascade option can be used to analyze al the indexes.
  • METHOD_OPT (FOR COLUMNS SIZE AUTO) = Auto is the Oracle default and this option will analyze histograms  on what the optimizer considers to be "important columns". The optimizer does this by examining your current workload when you run the dbms_stats command,interrogating all current SQL in the library cache to see which columns might benefit from a histogram.
  •  estimate_percent = This argument is a new way to allow Oracle's dbms_stats to automatically   estimate  the "best" percentage of a segment to sample when gathering statistics.

Mamun's DBA Blog: How to Check Oracle Database Listener Port Status from Sql & OS Level

Hello Everyone!

You can check listener status in windows environment by using Sql & Os using Netstat.


SQL> select * from gv_$listener_network;


  
C:\Users\oracle> netstat -na |find "1521"

  TCP    0.0.0.0:1521                0.0.0.0:0                       LISTENING
  TCP    10.10.20.244:1521      10.10.20.244:49928     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49929     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49933     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49934     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49939     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49947     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:50037     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.246:50605     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:50613     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:55062     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57671     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57675     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57680     ESTABLISHED



C:\Users\oracle> netstat -a -o -n

Active Connections

  Proto  Local Address    Foreign Address       State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       752
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:1158           0.0.0.0:0              LISTENING       2828
  TCP    0.0.0.0:1521           0.0.0.0:0              LISTENING       1984
  TCP    0.0.0.0:1831           0.0.0.0:0              LISTENING       14504
  TCP    0.0.0.0:3389           0.0.0.0:0              LISTENING       5316

Thursday, April 25, 2019

Mamun's DBA Blog: Manage Tablespace in oracle

What is a tablespace and datafile:

Tablespace is the primary logic structure of the oracle database. It consists of one or more physical datafiles. Datafiles physical stores database data in storage.(DISKS) . So when we create a datafile of 30G in database, it will eat 30G of space from defined storage. All the table or index segment is created in tablespace only.

Types of Tablespace

SYSTEM TABLESPACE:

    Each database contains a SYSTEM tablespace.( It is created by default while creating the database itself) .
    It contains the data dictionary tables of the database.
    All the view,procedures, functions, packages and triggers are stored in SYSTEM tablespace
    It is not recommended to user SYSTEM tablespace for creating any other table or index.

SYSAUX TABLESPACE:    

All the database metadata, that doesnt store in SYSTEM tablespace, will be stored here.

    Many database components datas are stored in this tablespace

PERMANENT TABLESPACE:

    When someone says tablespace, Means they are mostly refering to PERMANENT TABLESPACE
    This tablespace are used for storing the actual schema tables or indexes . i.e it Stores user data.
    It doesnt store any of the data dictionary tables.

    There are two types of PERMANENT TABLESPACE.

    SMALL FILE – (DEFAULT) – This is the common size tablespace, It can contain multiple datafiles with each datafile of size 31G;
    BIG FILE – It can contain only one datafile which can grow upto 128 TB.

    UNDO TABLESPACE:

    This tablespace stores Undo data:
    We can’t create any table or index inside undo tablespace.
    Each instance in the database have one defined UNDO tablespace. i.e for standalone database one assigned undo tablespace, and for multi node rac system, each instance on the node will have one assigned undo tablespace.

    TEMPORARY TABLESPACE:

    This tablespace stores the data temporarily for sessions doing sorting and join operations.
    Sort operations are also generated by SELECT * FROM WHERE CLAUSE that join rows from within tables and between tables. The segments generated during this process will be stored in temp tablespace.
    Each database will have one default temporary tablespace

    Create a NEW tablespace:


   Create tablespace DATA datafile '/u01/app/oracle/oradata/data01.dbf' size 5G autoextend on next 500M;
       
Here, 500M of extent will be added to the datafile automatically, when the space is required.

For creating a tablespace on ASM disk group:

– With OMF file system:

Create tablespace DATA datafile '+DATAG' size 5G autoextend on next 500M;

--- Else we can give the complete path also:

Create tablespace DATA datafile '+DATAG/oradata/datafile/data01.dbf' size 5G autoextend on next 500M;

Adding a datafile:

alter tablespace DATA add datafile '/u01/app/oracle/oradata/data02.dbf' size 2G;

Resize a datafile: ( To increase or decrease the datafile)

alter database datafile '/u01/app/oracle/oradata/data02.dbf' resize 3G;

Change default tablespace:

Every database will have one default tablespace. If any user is created without mentioning any tablespace_name, then that schema objects will be created under default tablespace. – Get the current default tablespace:

SELECT PROPERTY_VALUE
FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE';

ALTER DATABASE DEFAULT TABLESPACE DATATBS;

Rename a tablespace:

set pagesize 200
set lines 200
col file_name for a57

SQL❯ select file_id,file_name,tablespace_name from dba_data_files where file_id=37;

   FILE_ID FILE_NAME                            TABLESPACE_NAME
---------- -------------------------------------------------------- ------------------------------
 37 /u01/app/oracle/oradata/cdb1/test1.dbf        TESTING


--- Rename the tablespace_name from TESTING to PRODUCING;

SQL❯ alter tablespace TESTING rename to PRODUCING;

Tablespace altered.

SQL❯ select file_id,file_name,tablespace_name from dba_data_files where file_id=37;

   FILE_ID FILE_NAME                            TABLESPACE_NAME
---------- -------------------------------------------------------- ------------------------------
 37 /u01/app/oracle/oradata/cdb1/test1.dbf        PRODUCING

 NOTE: SYSTEM and SYSAUX tablespace cannot be renamed.

Drop a tablespace:

-- Drop a tablespace without removing the physical database files.

SQL❯ drop tablespace TESTING;

Tablespace dropped.

SQL❯ select file_name from dba_data_files where tablespace_name='TESTING';

no rows selected

 -- Drop tablespace including the physical datafiles.

SQL❯ drop tablespace TESTING including contents and datafiles;

Tablespace dropped.

Make tablespace Read only:

alter tablespace DATA2 READ ONLY;

alter tablespace DATA2 read write;

Take tablespace offline:

DBAs usually make the tablespace offline, while restoring or recovering any underlying corrupt datafile.
-- To make a tablespace offline

ALTER TABLESPACE DATATS OFFLINE;

-- To make it online

ALTER TABLESPACE DATATS ONLINE;

Create a temporary tablespace:

CREATE TEMPORARY TABLESPACE TEMP1 '/u01/app/oracle/tempfile/temp01.dbf' size 1G autoextend on next 200M;

Adding a tempfile:

alter tablespace TEMP1 add tempfile '/u01/app/oracle/tempfile/temp02.dbf' size 1G autoextend on next 200M;

Resize tempfile:

alter database tempfile '/u01/app/oracle/tempfile/temp02.dbf' resize 2G;

Drop tempfile:

It will drop and remove the tempfile from physical location.

ALTER DATABASE TEMPFILE '/u01/app/oracle/tempfile/temp02.dbf' DROP INCLUDING DATAFILES;

 Change default temporary tablespace:

When we create a new user, we assign a default temporary tablespace. If nothing is assigned, then it will use the default temporary tablespace set a database level.
Get the current default temporary tablespace for the database


SQL❯ SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'DEFAULT_TEMP_TABLESPACE';

PROPERTY_VALUE
--------------------------------------------------------------------------------
TEMP
 
-- Set New default temp tablespace


ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP2;
 
-- Check the new default temp tablespace
SQL❯ SELECT PROPERTY_VALUE FROM  DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'DEFAULT_TEMP_TABLESPACE';

PROPERTY_VALUE
--------------------------------------------------------------------------------
TEMP2

Tuesday, April 23, 2019

Mamun's DBA Blog: DB Link and GLOBAL_NAMES parameter in Oracle

GLOBAL_NAMES is either set to FALSE OR TRUE.

GLOBAL_NAMES specifies whether a database link is required to have the same name as the database to which it connects.

If the value of GLOBAL_NAMES is FALSE, then any name can be given to DB_LINK. If value is TRUE, then database link name should be same as that of the database it is pointing.

Default value is FALSE:

SQL> show parameter global_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
global_names                         boolean     FALSE

1. Lets create a database link with any name:


SQL> create public database link TESTDB  connect to SYSTEM IDENTIFIED BY welcome1 USING 'ORCL';
Database link created.
SQL>  select sysdate from dual@TESTDB;
SYSDATE
---------
01-MAR-19
SQL>drop public database link TESTDB ;
So with GLOBAL_NAME set to FALSE, db_link name is independent of target database name.

2. Update the GLOBAL_NAMES value to TRUE:

SQL> alter system set global_names=TRUE scope=both;
System altered.
SQL> show parameter global_names
NAME                                 TYPE        VALUE
------------------------------------ ----------- ---------------------------
global_names                         boolean     TRUE

3. Create database link as before(with different name)


SQL> create public database link TESTDB  connect to SYSTEM IDENTIFIED BY welcome1 USING 'ORCL';
Database link created
SQL> select sysdate from dual@TESTDB;
select sysdate from dual@TESTDB
                         *
ERROR at line 1:
ORA-02085: database link TESTDB connects to ORCL
We can see, when global_name is TRUE, DB_LINKs with different name as that of database name is not working.

4. Lets create a db_link having same name as target db.

SQL> create public database link ORCLconnect to SYSTEM IDENTIFIED BY welcome1 USING 'ORCL';
Database link created.
SQL>  select sysdate from dual@ORCL;
SYSDATE
---------
01-MAR-19
Hope it Works!!!