Wednesday, 29 January 2014

ORA-01031: insufficient privileges to sys@standby as sysdba


The ORA-01031 is very generic error and normally users will receive this error when users don’t have appropriate privilege.

$oerr ora 01031
01031, 00000, "insufficient privileges"
// *Cause: An attempt was made to change the current username or password
//         without the appropriate privilege. This error also occurs if
//         attempting to install a database without the necessary operating
//         system privileges.
//         When Trusted Oracle is configure in DBMS MAC, this error may occur
//         if the user was granted the necessary privilege at a higher label
//         than the current login.
// *Action: Ask the database administrator to perform the operation or grant
//          the required privileges.
//          For Trusted Oracle users getting this error although granted the
//          the appropriate privilege at a higher label, ask the database
//          administrator to regrant the privilege at the appropriate label.

On standby
$ sqlplus
Enter user-name: /as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>


From Primary or Standby
$ sqlplus
 

Enter user-name: sys@standby as sysdba
Enter password:
ERROR:
ORA-01031: insufficient privileges


Error in alert log of PRIMARY database

Error 1034 received logging on to the standby
PING[ARC0]: Heartbeat failed to connect to standby 'STANDBY'. Error is 1034.
Error 1034 received logging on to the standby
FAL[server, ARC2]: Error 1034 creating remote archivelog file 'STANDBY'

 Metalink notes for insufficient privileges  as sysdba
OERR: ORA 1031 "insufficient privileges" [ID 18622.1]
Troubleshooting ORA-1031: Insufficient Privileges While Connecting As SYSDBA [ID 730067.1]

But

Original problem in my case  was with listener file. Instance name is crated in small letter but in listener.ora sid given in CAPS it caused the problem. After changing sid in listner.ora it is working fine.

Saturday, 25 January 2014

Creating Redo Log Groups and Members

Create all required groups and members of redo log files during database creation. However, there are situations where you might want to create additional groups or members.

Creating Redo Log Groups
To create new redo log groups and members, you must have the ALTER DATABASE system privilege.
To create a new group of redo log files, use the SQL statement ALTER DATABASE with the ADD LOGFILE clause.

The following statement adds a new group of redo logs to the database:
 ALTER DATABASE
  ADD LOGFILE ('/oracle/dbs/log1c.rdo', '/oracle/dbs/log2c.rdo') SIZE 500K;

You can also specify the number that identifies the group using the GROUP clause:
ALTER DATABASE
  ADD LOGFILE GROUP 10 ('/oracle/dbs/log1c.rdo', '/oracle/dbs/log2c.rdo')
      SIZE 500K;

Using group numbers can make administering redo log groups easier. However, the group number must be between 1 and MAXLOGFILES.

In some cases, it might not be necessary to create a complete group of redo log files. A group could already exist, but not be complete because one or more members of the group were dropped (for example, because of a disk failure). In this case, you can add new members to an existing group.

Creating Redo Log Members
To create new redo log members for an existing group, use the SQL statement ALTER DATABASE with the ADD LOGFILE MEMBER clause.
The following statement adds a new redo log member to redo log group number 2:

ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2b.rdo' TO GROUP 2;

Notice that filenames must be specified, but sizes need not be. The size of the new members is determined from the size of the existing members of the group.
When using the ALTER DATABASE statement, you can alternatively identify the target group by specifying all of the other members of the group in the TO clause, as shown in the following example:

ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2c.rdo'
    TO ('/oracle/dbs/log2a.rdo', '/oracle/dbs/log2b.rdo');

Note:
Fully specify the filenames of new log members to indicate where the operating system files should be created. Otherwise, the files will be created in either the default or current directory of the database server, depending upon your operating system. You may also note that the status of the new log member is shown as INVALID. This is normal and it will change to active (blank) when it is first used.

Multiplex & Move Oracle control files to different directory


1, shutdown database.
shutdown immediate;
2, edit Oracle init.ora file, e.g., C:\Oracle\10g\database\inittest.ora, find the line with control file location, change the location from old directory to new directory, e.g.:

         OLD:
         control_files=("H:\Oradata\test\control01.ctl")

         NEW:
         control_files=("I:\Oradata\test\control01.ctl",  "J:\Oradata\test\control02.ctl", "K:\Oradata\test\control03.ctl")

save init.ora file.

3, create spfile from pfile:
create spfile from pfile;
4, Copy control files from old directory to new directory

    copy H:\Oradata\test\control01.ctl I:\Oradata\test\control01.ctl
    copy H:\Oradata\test\control01.ctl J:\Oradata\test\ control02.ctl
    copy H:\Oradata\test\control01.ctl K:\Oradata\test\control03.ctl

5, startup database.
SQL> startup
ORACLE instance started.

Total System Global Area 1426063360 bytes
Fixed Size 2004264 bytes
Variable Size 352324312 bytes
Database Buffers 1056964608 bytes
Redo Buffers 14770176 bytes
Database mounted.
Database opened.
SQL>

Saturday, 18 January 2014

Automate AWR Report Generation


By default snapshots of the relevant data are taken every hour and retained for 7 days. Most of the times database running in default AWR settings. DBA's generates the awr report when something  happened in their database or periodically to check if anything is wrong in databases

Some times databases are running smooth without any problems. Due to the default retention of AWR snapshot setting we may loose some good information about database.When problem occurs in the database we may need to compare the bad time report (when problem occurred) vs good time report (when db running smooth). In this case we don't have any information about database when running without any problem or we don't have same period snapshot AWR report to compare it with current reports.

To avoid this situation DBA can automate the AWR reports generation using below script.
It automatically generates the awr report of last one hour and no manual intervention is required by DBAs onece it is schedule in cronjob

Crontab Entry

05 * * * * sh /oracle/AWR/generate_awr.sh ORCL  >> /oracle/AWR/awr_rpt.log

Cronjob to be executed every hour at 05 mins on daily basis  and shell output is redirected to log file

SCRIPT STARTS HERE
##############################################################################
1 ) generate_awr.sh

#------------------------------------------------------------------------------
#!/usr/bin/ksh
# File: generate_awr.sh
# Description:
# shell script to run under the UNIX "cron" utility to automatically generate Oracle "AWR" reports in HTML   against the database accessed via passed parameter
# Usage :
# sh generate_awr.sh oracle_sid
# Parameters:
#  One parameter to be  passed. Oracle_sid to be passed as parameter.
#  Environment variables are captured from /etc/oratab entry.

dbSid=${1}
export oraSid=${dbSid}
#echo $oraSid
export ORACLE_SID=`grep "$oraSid:" /etc/oratab|cut -d: -f1 -s`
export ORACLE_HOME=`grep "$oraSid:" /etc/oratab|cut -d: -f2 -s`
export ORAENV_ASK=NO
#. oraenv ${dbSid}
unset TWO_TASK
export PATH=$PATH:$ORACLE_HOME/bin

#echo $ORACLE_SID
#echo $ORACLE_HOME
#echo $PATH

sqlplus -S " / as sysdba" @/oracle/AWR/create_awr_report_for_database.sql

# Finish
#------------------------------------------------------------------------------



2) create_awr_report_for_database.sql

/* ---------------------------------------------------------------------------
Original script byhttp://damir-vadas.blogspot.in/2009/11/automated-awr-reports-in-oracle-10g11g.html

 Filename: create_awr_report_for_database.sql
 Purpose : In directory defined with v_dir, create awr reports for last one hour snapshots, so put in crontab  to run at every hour on daily basis

 Remarks : Run as privileged user

#  If No report generated in report folder (v_dir) create directory manually once before running the script.
 --------------------------------------------------------------------------- */
set serveroutput on
set linesize 166
set pagesize 600
set trimout on

DECLARE
   CURSOR c_instance
   IS
        SELECT   instance_number, instance_name
          FROM   gv$instance
      ORDER BY   1;

   c_dir CONSTANT   VARCHAR2 (256) := 'oracle/AWR';
   v_dir            VARCHAR2 (256) := 'oracle/AWR/daily_awr';
   v_dbid           v$database.dbid%TYPE;
   v_dbname         v$database.name%TYPE;
   v_inst_num       v$instance.instance_number%TYPE := 1;
   v_begin          NUMBER;
   v_end            NUMBER;
   v_start_date     VARCHAR2 (20);
   v_end_date       VARCHAR2 (20);
   v_options        NUMBER := 8;        -- 0=no options, 8=enable addm feature
   v_file           UTL_FILE.file_type;
   v_file_name      VARCHAR (50);
BEGIN
   -- get database id
   SELECT   dbid, name
     INTO   v_dbid, v_dbname
     FROM   v$database;

   -- get end snapshot id
   SELECT   MAX (snap_id)
     INTO   v_end
     FROM   dba_hist_snapshot
     WHERE  TO_CHAR (END_INTERVAL_TIME, 'yyyy/mm/dd hh24') <= to_char(sysdate,'yyyy/mm/dd hh24');

   DBMS_OUTPUT.put_line ('end snap_id ' || v_end);

   -- get start snapshot id
   SELECT   MAX (snap_id)
     INTO   v_begin
     FROM   dba_hist_snapshot
    WHERE   snap_id < v_end;

   DBMS_OUTPUT.put_line ('begin snap_id ' || v_begin);

   SELECT   TO_CHAR (END_INTERVAL_TIME, 'YYMMDD_HH24MI')
     INTO   v_start_date
     FROM   dba_hist_snapshot
    WHERE   snap_id = v_begin AND instance_number = v_inst_num;

   DBMS_OUTPUT.put_line ('v_start_date ' || v_start_date);

   SELECT   TO_CHAR (END_INTERVAL_TIME, 'HH24MI')
     INTO   v_end_date
     FROM   dba_hist_snapshot
    WHERE   snap_id = v_end AND instance_number = v_inst_num;

   DBMS_OUTPUT.put_line ('v_end_date ' || v_end_date);

   -- Thanx to Yu Denis Sun - we must have directory defined as v_dir value!
execute immediate('create or replace directory awrdir as '''||v_dir||'''');

   -- let's go to real work...write awrs to files...
   FOR v_instance IN c_instance
   LOOP
      DBMS_OUTPUT.put_line (
         'v_instance.instance_name:' || v_instance.instance_name
      );
      v_file :=
         UTL_FILE.fopen (
            'AWRDIR',
               'awr_'
            || v_instance.instance_name
            || '_'
            || v_instance.instance_number
            || '_'
            || v_start_date
            || '_'
            || v_end_date
            || '.html',
            'w',
            32767
         );

      FOR c_report
      IN (SELECT   output
            FROM   TABLE(DBMS_WORKLOAD_REPOSITORY.awr_report_html (
                            v_dbid,
                            v_instance.instance_number,
                            v_begin,
                            v_end,
                            v_options
                         )))
      LOOP
         UTL_FILE.PUT_LINE (v_file, c_report.output);
      END LOOP;

      UTL_FILE.fclose (v_file);
   END LOOP;

EXECUTE IMMEDIATE ('drop directory AWRDIR');
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.PUT_LINE (SQLERRM);

      IF UTL_FILE.is_open (v_file)
      THEN
         UTL_FILE.fclose (v_file);
      END IF;

      BEGIN
    EXECUTE IMMEDIATE ('drop directory AWRDIR');
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;
END;
/
exit;

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





Total Pageviews