Friday, May 18, 2018

SQL queries for database operations

How many times query executed in a  day.

select s.begin_interval_time, sql.sql_id as sql_id, sql.executions_delta as exe_delta, sql.EXECUTIONS_TOTAL
from dba_hist_sqlstat sql, dba_hist_snapshot s
where sql_id='f3dwn5j209c7y'
and s.snap_id = SQL.snap_id
and s.begin_interval_time> TO_date('16-MAY-2018 00:00', 'dd-mon-yyyy hh24:mi')
and s.begin_interval_time< TO_date('17-MAY-2018 00:00', 'dd-mon-yyyy hh24:mi') order by s.begin_interval_time;

How to find the size of table partitions and sub partitions.

Find the size of Table(DEPARTMENT) with partitions

SELECT * FROM (
  SELECT
    owner, object_name, object_type, table_name, ROUND(bytes)/1024/1024 AS meg,
    tablespace_name, extents, initial_extent,
    ROUND(Sum(bytes/1024/1024) OVER (PARTITION BY table_name)) AS total_table_meg
  FROM (
    -- Tables
    SELECT owner, segment_name AS object_name, 'TABLE' AS object_type,
          segment_name AS table_name, bytes,
          tablespace_name, extents, initial_extent
    FROM   dba_segments
    WHERE 
--segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION') and segment_name='TABLENAME'))
segment_type IN ('TABLE PARTITION') and segment_name='DEPARTMENT'))

Find the size of Table(DEPARTMENT) which is partitioned (has subpartitions)

select
    s.owner,
    s.segment_name,
    sp.partition_name,
    SUM(bytes/1024/1024/1024) "GB"
from dba_segments s
    join dba_tab_subpartitions sp ON sp.subpartition_name = s.partition_name
where  segment_name='DEPARTMENT'
group by s.owner,
    s.segment_name,
    sp.partition_name;

Thursday, May 10, 2018

How to restart OAKD process in ODA X5(Oracle Database Appliance)

Existing configuration:
Server01,Server02 -ODA X5.

Server01-OAKD is in slave mode.
Server02- OAKD is in Master mode

New configuration:
Server02-OAKD is in slave mode.
Server01- OAKD is in Master mode

Login as root to server02.

[ root@server02 : Wed Apr 18, 05:43 PM : /root ]

oakcli show ismaster

OAKD is in Master Mode

[ root@server02 : Wed Apr 18, 05:53 PM : /root ]

$ oakcli restart oak

2018-04-18 18:03:51.467159031:[init.oak]:[Restarting the oakd..]

2018-04-18 18:03:51.638969666:[init.oak]:[Killing the running oakd with pid 18409]

2018-04-18 18:04:01.862710278:[init.oak]:[Successfully re-started the oakd..]

[ root@server02 : Wed Apr 18, 06:04 PM : /root ]

oakcli show ismaster

OAKD is in Slave Mode

[ root@server02 : Wed Apr 18, 06:04 PM : /root ]

$

Login as root to server01.

[ root@server01 : Wed Apr 18, 06:14 PM : /root ]

 oakcli show ismaster


OAKD is in Master Mode

How to drop a database in ODA X5(Oracle Database appliance)

Login as root to master node.

[ root@Server01 : Tue Aug 01, 10:27 AM : /root ]
$ oakcli delete database -db test99sb
INFO: 2017-08-01 10:37:41: Look at the log file '/opt/oracle/oak/log/Server01/tools/12.1.2.11.0/deletedatabase_test99sb_73509.log' for more details

Please enter the 'SYS'  password :
Please re-enter the 'SYS' password:

All the storage volumes created for the database 'test99sb' will be deleted. Do you want to continue [Y|N]:Y
INFO: 2017-08-01 10:38:08: Deleting the database test99sb. It will take few minutes. Please wait...
INFO: 2017-08-01 10:38:12: Setting up SSH
...SUCCESS: Ran /usr/bin/rsync -tarqvz /opt/oracle/oak/onecmd/ root@190.130.13.18:/opt/oracle/oak/onecmd --exclude=*zip --exclude=*gz --exclude=*log --exclude=*trc --exclude=*rpm and it returned: RC=0

.........
SUCCESS: All nodes in /opt/oracle/oak/onecmd/tmp/db_nodes are pingable and alive.
INFO: 2017-08-01 10:39:11: SSH has been successfully established
INFO: 2017-08-01 10:40:02: Successfully deleted the database 'test99sb'

How to create a standalone database in ODA X5 (Oracle Database Appliance)

Login as root to master node.

$ oakcli show dbhomes

Oracle Home Name      Oracle Home version                  Home Location

----------------      -------------------                  ------------

OraDb11204_home1      11.2.0.4.170418(24732075,23054319)  /u01/app/oracle/product/11.2.0.4/dbhome_1

OraDb12102_home1      12.1.0.2.170418(25171037,25942196)  /u01/app/oracle/product/12.1.0.2/dbhome_1

[ root@server01 : Tue Aug 01, 10:09 AM : /root ]

$ oakcli create database -db test99sb -oh OraDb11204_home1

INFO: 2017-08-01 10:10:05: Please check the logfile  '/opt/oracle/oak/log/server01/tools/12.1.2.11.0/createdb_test99sb_64379.log' for more details

INFO: 2017-08-01 10:10:06: Database parameter file is not provided. Will be using default parameters for DB creation



Please enter the 'SYSASM'  password : (During deployment we set the SYSASM password to '*******'):

Please re-enter the 'SYSASM' password:

Please select one of the following for Database type  [1 .. 2] :

1    => OLTP

2    => DSS

1

The selected value is : OLTP

Please select one of the following for Database Deployment  [1 .. 3] :

1    => EE : Enterprise Edition

2    => RACONE

3    => RAC

1

The selected value is : EE

Please select one of the following for Node Number  [1 .. 2] :

1    => server01

2    => server02

2

The selected value is : server02

...Please select one of the following for Database Class  [1 .. 5] :

1    => odb-01s  (   1 cores ,     4 GB memory)

2    =>  odb-01  (   1 cores ,     8 GB memory)

3    =>  odb-02  (   2 cores ,    16 GB memory)

4    =>  odb-04  (   4 cores ,    32 GB memory)

5    =>  odb-06  (   6 cores ,    48 GB memory)

1

The selected value is : odb-01s  (   1 cores ,     4 GB memory)



Do you want to setup the EM DB Console for this database [ Y | N ] ? : N

INFO   : Logging all actions in the file /opt/oracle/oak/log/server01/patch/12.1.2.11.0/server01-20170801101324.log and traces in  the file /opt/oracle/oak/log/server01/patch/12.1.2.11.0/server01-20170801101324.trc

INFO   : Loading the configuration file /opt/oracle/oak/onecmd/create_database.params...

INFO   : Creating the node list files...

INFO   : Setting up ssh for root...

INFO   : Setting up SSH across the Private Network...

...INFO   : Running as root: /usr/bin/ssh -l root 192.168.16.24 /root/DoAllcmds.sh

INFO   : Background process 78589 (node: 192.168.16.24) gets done with the exit code 0

INFO   : Running as root: /usr/bin/ssh -l root 190.130.10.18 /root/DoAllcmds.sh

INFO   : Background process 78614 (node: 190.130.10.18) gets done with the exit code 0

INFO   : Setting up SSH completed successfully

INFO   : Running the command /usr/bin/rsync -tarqvz /opt/oracle/oak/onecmd/ root@190.130.10.18:/opt/oracle/oak/onecmd --exclude=*zip --exclude=*gz --exclude=*log --exclude=*trc --exclude=*rpm to sync directory</opt/oracle/oak/onecmd> on node <190.130.10.18>

SUCCESS: Ran /usr/bin/rsync -tarqvz /opt/oracle/oak/onecmd/ root@190.130.10.18:/opt/oracle/oak/onecmd --exclude=*zip --exclude=*gz --exclude=*log --exclude=*trc --exclude=*rpm and it returned: RC=0



...INFO   : Did not do scp for node : server01

INFO   : Running as root: /usr/bin/ssh -l root server01 /root/DoAllcmds.sh

INFO   : Running as root: /usr/bin/ssh -l root server02 /root/DoAllcmds.sh

INFO   : Background process 80186 (node: server01) gets done with the exit code 0

INFO   : Background process 80209 (node: server02) gets done with the exit code 0

INFO   : Did not do scp for node : server01

INFO   : Running as root: /usr/bin/ssh -l root server01 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101406.sh

INFO   : Running as root: /usr/bin/ssh -l root server02 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101406.sh

INFO   : Background process 80257 (node: server01) gets done with the exit code 0

INFO   : Background process 80280 (node: server02) gets done with the exit code 0

INFO   : Setting up SSH for user oracle...

...INFO   : checking nodes in /opt/oracle/oak/onecmd/tmp/db_nodes...

...

SUCCESS: All nodes in /opt/oracle/oak/onecmd/tmp/db_nodes are pingable and alive.

INFO   : Checking SSH setup for user (oracle) on nodes in /opt/oracle/oak/onecmd/tmp/db_nodes...

INFO   : Did not do scp for node : server01

INFO   : This is root, will become oracle and run: /bin/su oracle -c /usr/bin/ssh -l oracle server01 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101439.sh

INFO   : Running on the local node: /bin/su oracle -c /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101439.sh

INFO   : Background process 82483 (node: server01) gets done with the exit code 0

INFO   : This is root, will become oracle and run: /bin/su oracle -c /usr/bin/ssh -l oracle server02 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101439.sh

INFO   : Background process 82506 (node: server02) gets done with the exit code 0

INFO   : Setting up ACFS storage

INFO   : Did not do scp for node : server01

INFO   : Running as root: /usr/bin/ssh -l root server01 /opt/oracle/oak/onecmd/tmp/acfsm_64379.sh

INFO   : Running as root: /usr/bin/ssh -l root server02 /opt/oracle/oak/onecmd/tmp/acfsm_64379.sh

INFO   : Background process 82813 (node: server01) gets done with the exit code 0

INFO   : Background process 82837 (node: server02) gets done with the exit code 0

INFO: 2017-08-01 10:15:05: Successfully setup the storage structure for the database 'test99sb'

SUCCESS: Successfully setup ACFS storage for the database test99sb

INFO   : Creating Database using DBCA...

INFO   : Did not do scp for node : server01

INFO   : Running as root: /usr/bin/ssh -l root server01 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101505.sh

INFO   : Running as root: /usr/bin/ssh -l root server02 /opt/oracle/oak/onecmd/tmp/DoAllcmds-20170801101505.sh

INFO   : Background process 87128 (node: server01) gets done with the exit code 0

INFO   : Background process 87152 (node: server02) gets done with the exit code 0

INFO   : Running DBCA using /opt/oracle/oak/onecmd/tmp/dbca-test99sb.sh on server02 as oracle...

INFO   : Check output in /opt/oracle/oak/onecmd/tmp/dbca-test99sb-20170801101324.log on server02

...

INFO   : This is root, will become oracle and run: /bin/su oracle -c /usr/bin/ssh -l oracle server02 /opt/oracle/oak/onecmd/tmp/dbca-test99sb.sh

         Instance test99sb is running on node server02

INFO   : One or more Instances running on the cluster nodes.

INFO   : Running export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1;/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/srvctl setenv database -d test99sb -t 'TZ=America/New_York' to set DB timezone

INFO   : Running the command /u01/app/12.1.0.2/grid/bin/crsctl stat resource ora.test99sb.db -p

...

INFO   : This is root, will become oracle and run: /bin/su oracle -c /usr/bin/ssh -l oracle server02 /opt/oracle/oak/onecmd/tmp/dbupdates-test99sb.sh

INFO   : Running export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1;/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/srvctl stop database -d test99sb

INFO   : Running export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1;/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/srvctl start database -d test99sb

INFO: 2017-08-01 10:23:09: Successfully set the RMAN SNAPSHOT control file

SUCCESS: 2017-08-01 10:23:14: Successfully created the Database : test99sb

[ root@server01 : Tue Aug 01, 10:23 AM : /root ]

Thursday, May 3, 2018

Create db storage in ODA X5(oracle database appliance)

Log in as root in matser node,issue below command
$ oakcli create dbstorage -db testqa

Log in as root,issue below command
$ oakcli create dbstorage -db testqa
INFO: 2018-05-03 17:31:33: Please check the logfile  '/opt/oracle/oak/log/dbserver01/tools/12.2.1.2.0/createdbstorage_testqa_51560.log' for more details
INFO: 2018-05-03 17:31:41: Storage for the Database with the name testqa is possible

Please enter the 'SYSASM'  password : (During deployment we set the SYSASM password to 'welcome1'):
Please enter the 'SYSASM'  password :
Please re-enter the 'SYSASM' password:

Specify the  Database Class (1. odb-01 '1 core, 8 GB memory'   2. Others) [1] : 2

Please select one of the following for Database Class [1 .. 7] :
1    => odb-01s  (   1 cores ,     4 GB memory)
2    =>  odb-01  (   1 cores ,     8 GB memory)
3    =>  odb-02  (   2 cores ,    16 GB memory)
4    =>  odb-04  (   4 cores ,    32 GB memory)
5    =>  odb-06  (   6 cores ,    48 GB memory)
6    =>  odb-12  (  12 cores ,    96 GB memory)
7    =>  odb-16  (  16 cores ,   128 GB memory)
3
The selected value is : odb-02  (   2 cores ,    16 GB memory)
...SUCCESS: Ran /usr/bin/rsync -tarqvz /opt/oracle/oak/onecmd/ root@192.168.16.25:/opt/oracle/oak/onecmd --exclude=*zip --exclude=*gz --exclude=*log --exclude=*trc --exclude=*rpm and it returned: RC=0

.........
SUCCESS: All nodes in /opt/oracle/oak/onecmd/tmp/db_nodes are pingable and alive.
INFO: 2018-05-03 17:34:14: Successfully setup the storage structure for the database 'testqa'
INFO: 2018-05-03 17:34:14: Set the following directory structure for the Database testqa
INFO: 2018-05-03 17:34:14: DATA: /u02/app/oracle/oradata/datastore/.ACFS/snaps/testqa
INFO: 2018-05-03 17:34:14: REDO: /u01/app/oracle/oradata/datastore/testqa
INFO: 2018-05-03 17:34:14: RECO: /u01/app/oracle/fast_recovery_area/datastore/testqa
SUCCESS: 2018-05-03 17:34:14: Successfully setup the Storage for the Database : testqa

Change UNDO tablespace from smallfile to bigfile in RAC environment

With below steps UNDO tablespace in RAC can be converted from small file to bigfile.

RAC Database: TESTQA
Instances: TESTQA1,TESTQA2


1.NODE1-(Login to TESTQA1 instance)

create bigfile undo tablespace UNDOTBS3 datafile
size 200m autoextend on next 5m maxsize 32727m
online
retention noguarantee
blocksize 8k
flashback on;

alter system set undo_tablespace= UNDOTBS3 scope=both sid='testqa1';

drop tablespace UNDOTBS1 including contents and datafiles;


create bigfile undo tablespace UNDOTBS1 datafile
size 200m autoextend on next 5m maxsize 32727m
online
retention noguarantee
blocksize 8k
flashback on;

Alter system set undo_tablespace= UNDOTBS1 scope=both sid='testqa1';

Drop tablespace UNDOTBS3 including contents and datafiles;

2.NODE2-(Login to TESTQA2 instance)

Create bigfile undo tablespace UNDOTBS4 datafile
size 200m autoextend on next 5m maxsize 32727m
online
retention noguarantee
blocksize 8k
flashback on;

Alter system set undo_tablespace= UNDOTBS4 scope=both sid='testqa2';
Drop tablespace UNDOTBS2 including contents and datafiles;

Create bigfile undo tablespace UNDOTBS2 datafile
size 200m autoextend on next 5m maxsize 32727m
online
retention noguarantee
blocksize 8k
flashback on;

Alter system set undo_tablespace= UNDOTBS2 scope=both sid='testqa2';
Drop tablespace UNDOTBS4 including contents;