Saturday, October 25, 2014

Who is a DBA!!!

Who is a DBA!!!


During my initial phase as a DBA, many times, this questions crossed my mind. Over the years I do have some findings. 

1) Tough life but very satisfying. 

Yes, as a DBA, life is tough. Those endless on-calls, midnight's crisis, n number of alert logs, non-readable trace-files, etc...etc.. but yes at the end of the day your efforts do count which ultimately leads to job satisfaction. 

Being a DBA, you are always considered special. 

2) Continuous Education

DBA is considered as a most important asset of a team which puts more pressure on us to keep ourselves updated with new technologies, enhancements and all those minute little details.  


3) Certifications.

Oracle certification is a great way to gain confidence during your DBA tenure. It does not help technically much as DUMPS being easily accessible but yes, it does make you aware of  all the features Oracle provide and the correct way to use it  syntactically.  

I always recommend to complete at-least one certification every 6 months or 1 year. Preparation should be done in such a way that you go thorough all the topics at least once.

4) Next time you should automate it!!

Yes indeed!! There are many tasks which are quite repetitive as a DBA. So the motto should be to automate whatever you can, as the word "AUTOMATION" makes your client feel really happy and yes it do save a lot of time. 

5) A Complete DBA!!

As a DBA, its very important that you know at-least one Linux OS flavor in terms of architecture,commands and most important scripting. Scripting is very handy for your day-to-day activities. 

Also its very important to have domain and application knowledge your database is supporting as it gives you an end-to-end picture of what is expected from you. Also, it helps you a lot while making schema level or database level changes. 

6) Repository!!

During those unwanted production outages, you don't want to Google  those complex commands. Rather make a small repository which will have all your handy sql's you will need most of the time. 

I would recommended to follow a directory structure, which each topic having a different folder and related information stored in it. That means, post 5-6 years of experience, you would have  your own set of skills developed within each topic and its really quite easy then to find anything you want. 


This is what I have till know. Will keep on adding more points. Your comments will help me to improve more. Thanks for reading!!!

Keep Exploring!! Keep Learning!! 

Friday, September 5, 2014

Datapump between different schemas and different tables in 11g.

Hello everyone.

Feature - Expdp/impdp
DB - 11gr2 (11.2.0.2)
Non-ASM. Non-RAC
OS - AIX, 6.1.8.15

Scenario

Task is to export few tables from Production and import it into Test schema with new names. 

Tables in Production to be Exported

SEND_ASR_MESSAGE
SEND_ASR_CFA
SEND_ASR_SECLOC
RECEIVE_ASR_MESSAGE
RECEIVE_ASR_CFA
RECEIVE_ASR_SECLOC

Schema name - CHGTWY_PROD

Tables to be imported as below names

SEND_ASR_MESSAGE_PROD
SEND_ASR_CFA_PROD
SEND_ASR_SECLOC_PROD
RECEIVE_ASR_MESSAGE_PROD
RECEIVE_ASR_CFA_PROD
RECEIVE_ASR_SECLOC_PROD

Schema name - CHBAGTWY_PERF

Challenge

- Need to use both remap_schema and remap_table. 
- Many bugs have been reported for remap_table in 11g version. 

Step 1 - Create necessary directories and grants. 

CREATE OR REPLACE DIRECTORY DATA_EXP AS '/oraback/EXP';

grant read,write on directory DATA_EXP to system; (since I am using system user). 

Step 2 - Create par file for expdp

vi export_table_backup.par 


USERID=system/L00k_fwd directory=DATA_EXP dumpfile=expdp_REQ0070510_tables_9_3_2014.dmp logfile=expdp_REQ0070510_tables_9_3_2014.log tables=CHBAGTWY_PERF.SEND_ASR_MESSAGE,CHBAGTWY_PERF.SEND_ASR_CFA,CHBAGTWY_PERF.SEND_ASR_SECLOC,CHBAGTWY_PERF.RECEIVE_ASR_MESSAGE,CHBAGTWY_PERF.RECEIVE_ASR_CFA,CHBAGTWY_PERF.RECEIVE_ASR_SECLOC


Step 3 - Execute in nohup. (nohup will make sure your export is completed, although if we exit from the shell)

nohup expdp parfile=export_table_backup.par > nohup_expdp.out &

Step 4 - Copy the dump files to remote server.  

Step 5 - Create par file for impdp .

Vi import_tables.par

USERID=system/L00k_fwd directory=DATA_EXP dumpfile=expdp_REQ0070510_tables_9_3_2014.dmp logfile=impdp_REQ0070510_tables_9_3_2014.log  REMAP_SCHEMA=CHGTWY_PROD:CHBAGTWY_PERF REMAP_TABLE=SEND_ASR_MESSAGE:SEND_ASR_MESSAGE_PROD,SEND_ASR_CFA:SEND_ASR_CFA_PROD,SEND_ASR_SECLOC:SEND_ASR_SECLOC_PROD,RECEIVE_ASR_MESSAGE:RECEIVE_ASR_MESSAGE_PROD,RECEIVE_ASR_CFA:RECEIVE_ASR_CFA_PROD,RECEIVE_ASR_SECLOC:RECEIVE_ASR_SECLOC_PROD

Note - Please note that in remap_table you should not use OWNER.T1:T2, as this will be considered as partition and not table. 

Step 6 - Execute in nohup. 

nohup impdp parfile=import_tables.par > nohup.out &

At this point you will get some very specific errors. 

ORA-31684: Object type TRIGGER:"CHBAGTWY_PERF"."SEND_ASR_MSG_CHG_Q" already exists
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/POST_INSTANCE/PROCDEPOBJ
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.LOAD_MD_TRANSFORMS []
ORA-31604: invalid NAME parameter "MODIFY" for object type PROCDEPOBJ in function ADD_TRANSFORM

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.KUPW$WORKER", line 8353

This is reported as a bug - Bug 16551094

So the workaround is to exclude a parameter. Please refer below DOC ids for the same. 


ORA-39151 Reported By DataPump Import When Using REMAP_TABLE Option (Doc ID 886762.1)





Wednesday, February 5, 2014

RAC useful Commands

1) Check the status of the cluster
-------------------------------
crsctl check crs
crsctl check cluster
crsctl check cluster -all

2) Check the status of the services on the cluster
-----------------------------------------------
crsctl status resource -t

3) Stop crs on all nodes
---------------------

which crsctl
sudo path/crsctl stop cluster -all

4) Stop crs on specifc node
------------------------
sudo path/crsctl stop has

5) Disable CRS from starting on reboot
-----------------------------------
sudo path/crsctl disable has

6) Enable CRS to start on reboot
-----------------------------
sudo path/crsctl enable has

7) Start crs on specifc node
-------------------------
sudo path/crsctl start has

8) Check database status
---------------------
srvctl status database -d REMCORP

9) Stop / Start an instance
------------------------
srvctl stop instance -i REMCORP1 -d REMCORP
srvctl start instance -i REMCORP1 -d REMCORP

10) Stop / Start an Database
------------------------
srvctl stop database -d REMCORP
srvctl start database -d REMCORP

srvctl modify database -d REMCORP -s open,mount

11) Stop/Start listener on a node
-----------------------------
srvctl status listener -n remedy-ebu-db1
srvctl stop listener -n remedy-ebu-db1
srvctl start listener -n remedy-ebu-db1

12) Check the voting disk
---------------------
crsctl query css votedisk

13) Query the network addresses
---------------------------
oifcfg getif

14) Show OCR backup – the voting file (disk) is also backed up with the OCR backup
------------------------------------------------------------------------------
ocrconfig -showbackup

15) Taking a manual backup of the OCR
-------------------------------
ocrconfig -manualbackup



Data Guard Physical Standby Setup in Oracle Database 11g Release 2

1) On Node check if the DB is in archivelog mode or not

SQL> select log_mode from v$database;

LOG_MODE
------------
ARCHIVELOG

2) Enable Force Logging
ALTER DATABASE FORCE LOGGING;

3) Initialization Parameters

Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this case they are both set to "CRAMPBB" on the primary database.

SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      CRAMPBB
SQL> show parameter db_unique_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      CRAMPBB

The DB_NAME of the standby database will be the same as that of the primary, but it must have a different DB_UNIQUE_NAME value. The DB_UNIQUE_NAME values of the primary and standby database should be used in the DG_CONFIG setting of the LOG_ARCHIVE_CONFIG parameter. For this example, the standby database will have the value "CRAMPRD_STBY".

**SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(CRAMPBB,PBBADG)';

Set suitable remote archive log destinations. In this case I'm using the fast recovery area for the local location, but you could specify an location explicitly if you prefer. Notice the SERVICE and the DB_UNIQUE_NAME for the remote location reference the standby location.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=PBBADG NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PBBADG';
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;


ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='archCRAMPBB_%r_%t_%s.arc' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;



**ALTER SYSTEM SET FAL_SERVER=PBBADG;

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO; (on both nodes)

4) Entries for the primary and standby databases are needed in the "$ORACLE_HOME/network/admin/tnsnames.ora" files on both servers

on ADG and PBB
---------------

PBBADG=
(DESCRIPTION =
 (ADDRESS_LIST =
  (LOAD_BALANCE = yes)
  (ADDRESS = (PROTOCOL = TCP)(HOST = cramuatrpt-scan)(PORT = 1527))
  (ADDRESS = (PROTOCOL = TCP)(HOST = inpudicrmrdbdevrpt1v)(PORT = 1527))
  (ADDRESS = (PROTOCOL = TCP)(HOST = inpudicrmrdbdevrpt2v)(PORT = 1527))
 )
 (CONNECT_DATA =
   (SERVICE_NAME = PBBADG)
   (failover_mode=(type=select)(method=basic))
    )
  )

CRAMPBB=
(DESCRIPTION =
 (ADDRESS_LIST =
  (LOAD_BALANCE = yes)
  (failover=on)
  (ADDRESS = (PROTOCOL = TCP)(HOST = crampbb-scan.vsnl.co.in)(PORT = 1527))
  (ADDRESS = (PROTOCOL = TCP)(HOST = inpudicrmrdbuatpbb1v.vsnl.co.in)(PORT = 1527))
  (ADDRESS = (PROTOCOL = TCP)(HOST = inpudicrmrdbuatpbb2v.vsnl.co.in)(PORT = 1527))
 )
 (CONNECT_DATA =
   (SERVICE_NAME = CRAMPBB)
   (failover_mode=(type=select)(method=basic))
    )
  )


5) Backup Primary DB

run
{
allocate channel c1 type disk format '/export/rman_backup_for_standby/rman_db_%T_%U.rman';
backup as compressed backupset full database PLUS ARCHIVELOG;
release channel c1;
}

6) Create standby controlfile

ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/PBBADG.ctl'

7) Create a parameter file for the standby database.

CREATE PFILE='/tmp/PBBADG1.ora' FROM SPFILE;

8) Ammend below parameters in pfile

*.db_unique_name='PBBADG'
*.fal_server='PBBADG'
*.log_archive_dest_2='SERVICE=CRAMPBB NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=CRAMPBB'


STANDby server commands

9) check if all listener are up and running

10) Create the SPFILE form the amended PFILE.

SQL> create spfile from pfile=


run {

set until sequence=35 thread=1;
recover database;
}



11) Create redo logs

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=MANUAL;
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g1_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g1_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g2_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g2_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g3_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g3_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g4_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g4_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g5_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g5_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g6_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g6_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g7_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g7_m02.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g8_m01.dbf';
ALTER DATABASE ADD LOGFILE '+FRA/oradata/crampbb/redo_g8_m02.dbf';
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

12) Create Standby Log file

ALTER DATABASE ADD STANDBY LOGFILE GROUP 9  '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 10 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 11 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 12 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 13 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 14 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 15 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 16 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 16 '+DATA' SIZE 1G;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 18 '+DATA' SIZE 1G;

13) Create password file with orapwd utility.