Saturday, December 28, 2013

quickly view reserved words for both SQL and PL/SQL


SQL> help reserved RESERVED

 WORDS (PL/SQL)

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

 PL/SQL Reserved Words have special meaning in PL/SQL, and may not be used

 for identifier names (unless enclosed in "quotes").

 An asterisk (*) indicates words are also SQL Reserved Words.

 ALL*            DESC*           JAVA            PACKAGE         SUBTYPE

 ALTER*          DISTINCT*       LEVEL*          PARTITION       SUCCESSFUL

 * AND*            DO              LIKE*           PCTFREE*        SUM

 ANY*            DROP*           LIMITED         PLS_INTEGER     SYNONYM*

 ARRAY           ELSE*           LOCK*           POSITIVE        SYSDATE*

 AS*             ELSIF           LONG*           POSITIVEN       TABLE*

 ASC*            END             LOOP            PRAGMA          THEN*

 AT              EXCEPTION       MAX             PRIOR*          TIME

 AUTHID          EXCLUSIVE*      MIN             PRIVATE         TIMESTAMP

 AVG             EXECUTE         MINUS*          PROCEDURE       TIMEZONE_ABBR

 BEGIN           EXISTS*         MINUTE          PUBLIC*         TIMEZONE_HOUR

 BETWEEN*        EXIT            MLSLABEL*       RAISE           TIMEZONE_MINUTE

 BINARY_INTEGER  EXTENDS         MOD             RANGE           TIMEZONE_REGION

 BODY            EXTRACT         MODE*           RAW*            TO*

 BOOLEAN         FALSE           MONTH           REAL            TRIGGER*

 BULK            FETCH           NATURAL         RECORD          TRUE

 BY*             FLOAT*          NATURALN        REF             TYPE

CHAR*           FOR*            NEW             RELEASE         UI CHAR_BASE    

FORALL          NEXTVAL         RETURN          UNION* CHECK*          FROM*        

NOCOPY          REVERSE         UNIQUE* CLOSE           FUNCTION        NOT*         

ROLLBACK        UPDATE* CLUSTER*        GOTO            NOWAIT*         ROW*         

USE COALESCE        GROUP*          NULL*           ROWID*          USER*

COLLECT         HAVING*         NULLIF          ROWNUM*         VALIDATE*

COMMENT*        HEAP            NUMBER*         ROWTYPE         VALUES*

COMMIT          HOUR            NUMBER_BASE     SAVEPOINT       VARCHAR*

COMPRESS*       IF              OCIROWID        SECOND          VARCHAR2*

CONNECT*        IMMEDIATE*      OF*             SELECT*         VARIANCE

CONSTANT        IN*             ON*             SEPERATE        VIEW*

CREATE*         INDEX*          OPAQUE          SET*            WHEN

CURRENT*        INDICATOR       OPEN            SHARE*          WHENEVER*

CURRVAL         INSERT*         OPERATOR        SMALLINT*       WHERE*

CURSOR          INTEGER*        OPTION*         SPACE           WHILE

DATE*           INTERFACE       OR*             SQL             WITH*

DAY             INTERSECT*      ORDER*          SQLCODE         WORK

DECIMAL*        INTERVAL        ORGANIZATION    SQLERRM         WRITE

DECLARE         INTO*           OTHERS          START*          YEAR

DEFAULT*        IS*             OUT             STDDEV          ZONE

DELETE*         ISOLATION

Database Link password Change in 11gR2

Before 11gR2 for changing  database link we have  to be drop and recreated db link  with an updated password.

Sample here is on the database where database link is located:

The password of the database link’s account has just been changed.

SQL> select count(*) from PUMP@DB_LiNK_CUST;
select count(*) from PUMP@DB_LiNK_CUST
*
ERROR at line 1:
ORA-01017: invalid username/password; logon denied
ORA-02063: preceding line from DB_LiNK_CUST

SQL> alter database link DB_LiNK_CUST connect to dblink_source identified by dblink_source;

Database link altered.

SQL> select count(*) from PUMP@DB_LiNK_CUST;

COUNT(1)
----------
18762

This option is not available in the pre-11gR2.

ORA-24247: network access denied by access control list (ACL)

Last month we just migrated an application from 10G to 11g. During a test of the send mail package using UTL_SMTP, we got this error, “ORA-24247: network access denied by access control list (ACL).” After a quick search, found below way to setup ALC in 11G.


1. The send mail package which executes the UTL_SMTP failed.

TEST_USER SQL> exec pkg_mails.SendMail('user@.com', 'Test Subject', 'Hello World');

ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_TCP", line 17
ORA-06512: at "SYS.UTL_TCP", line 246
ORA-06512: at "SYS.UTL_SMTP", line 115
ORA-06512: at "SYS.UTL_SMTP", line 138
ORA-06512: at "pkg_mails", line 283
ORA-06512: at line 3

2. To fix it, an ACL has to be created.

The principal is the user or role to be added into this ACL. In this case, the TEST_USER account is added during the ACL creation. This field is case sensitive.

SQL> connect / as sysdba

begin
dbms_network_acl_admin.create_acl (
acl             => 'Resolve_Access.xml',      -- Name of the access control list XML file
description     => 'Resolve Network Access using UTL_INADDR',  -- Brief description
principal       => 'TEST_USER',               -- First user account or role being granted or denied permission
                                              --   this is case sensitive,
                                              --   but typically user names and roles are stored in upper-case letters
is_grant        => TRUE,                      -- TRUE = granted, FALSE = denied
privilege       => 'resolve',                 -- connect or resolve, this setting is case sensitive,
                                              --   so always enter it in lowercase
                                              --    connect if user uses the UTL_TCP, UTL_HTTP, UTL_SMTP, and UTL_MAIL
                                              --    resolve if user uses the UTL_INADDR
start_date      => null,                      -- optional, null is the default
                                              --   in format of timestamp_with_time_zone (YYYY-MM-DD HH:MI:SS.FF TZR)
                                              --   for example, '2008-02-28 06:30:00.00 US/Pacific'
end_date        => null                       -- optional, null is the default
);

commit;
end;
/
http://download.oracle.com/docs/cd/B28359_01/network.111/b28531/authorization.htm#insertedID11

Note that the privilege used for UTL_INADDR is resolve in lowecase.


The description of each variable is clearly described in the Oracle-Base’s article.

3. Verify a newly-created ACL.

SQL> SELECT any_path
     FROM resource_view
     WHERE any_path like '%.xml';

ANY_PATH
--------------------------------------------------------------------------------
/sys/acls/all_owner_acl.xml
/sys/acls/bootstrap_acl.xml
/sys/acls/ro_all_acl.xml
/sys/acls/ro_anonymous_acl.xml

4. Optionally you can add more users or roles into this ACL by using the add_privilege procedure. This is similar to the create_acl procedure except no description. Sample shown here is to add ADMIN_ADMIN_ROLE role.

begin
dbms_network_acl_admin.add_privilege (
acl           => 'Mail_UTL_Access.xml',
principal     => 'APP_ADMIN_ROLE',
is_grant      => TRUE,
privilege     => 'connect',
start_date    => null,
end_date      => null);

commit;
end;
/

5. Add a host and port range allowed.

begin dbms_network_acl_admin.assign_acl (
acl           => 'Resolve_Access.xml', -- Name of the access control list XML file to be modified
host          => '*',                   -- Network host to which this access control list will be assigned
-- This a host name or IP address or wild card name
lower_port    => null,                  -- (optional)
upper_port    => null);                 -- (optional)
commit;
end; /

SELECT utl_inaddr.get_host_name FROM dual;
GET_HOST_NAME
--------------------------------------------------------------------------------
hostname1

6. Test the send mail package again. This time there is no error, and the recipient receives email.

TEST_USER SQL> exec pkg_mails.SendMail('user@company.com', 'Test Subject', 'Hello World');

PL/SQL procedure successfully completed

Alter Statement Hangs

I found this tip from Oracle document while looking for a solution for session hung at the SQL prompt after issuing "alter tablespace read only". Usually "alter tablespace read only" executes very quickly. However, the likelihood cause of waiting for tablespace to become read-only is due to existing in-flight transactions started before "alter tablespace read only" are still running.

To identify these transactions that are preventing the read-only tablespace is to first identify the "alter tablespace read only" session.

SELECT SQL_TEXT, SADDR
FROM V$SQLAREA,V$SESSION
WHERE V$SQLAREA.ADDRESS = V$SESSION.SQL_ADDRESS
AND SQL_TEXT LIKE 'alter %';

SQL_TEXT                                 SADDR
---------------------------------------- ----------------
alter tablespace tbs_tts1 read only      0000040634C0D8B8

Based on the identified session address and start SCN number, we can find the earlier executions before the read-only statement by querying the v$TRANSACTION order by ascending start SCN.

SELECT SES_ADDR, START_SCNB
FROM V$TRANSACTION
ORDER BY START_SCNB;

SES_ADDR         START_SCNB
---------------- ----------
0000040634C254F8 2976616884    --> Waiting on this transaction
0000040634C0D8B8 2980274305    --> alter Statement
0000040634C53858 2980283454

From the session address of the blocking transaction, we then can find information about that session.

SELECT T.SES_ADDR, S.USERNAME, S.MACHINE
FROM V$SESSION S,  V$TRANSACTION T
WHERE T.SES_ADDR = S.SADDR
ORDER BY T.SES_ADDR

SES_ADDR          USERNAME              MACHINE
----------------  --------------------  ------------------
0000040634C254F8  RT_ADMIN              test1

Sunday, December 1, 2013

RMAN-06169: could not read file header for datafile 236 error reason 4


Today I got a new problem in one of our 3 node cluster  database .During rman cold backup my job was failing -

RMAN-06169: could not read file header for datafile 236 error reason 4
+ [ -z '' ]
+ page_msg=abended
+ [ -z 'RMAN- or ORA- errors encountered.  Please check audit log' ]
--

Above it's clear that something wrong with datafile numbre  236.


 using v$recover_file checked datafile status.

SQL> select * from v$recover_file where error like '%FILE%';

  FILE# ONLINE  ONLINE_ ERROR                                                                CHANGE# TIME
---------- ------- ------- ----------------------------------------------------------------- ---------- ---------------
       236 OFFLINE OFFLINE FILE NOT FOUND                                                             0


--  Above is the key point "OFFLINE"

SQL> select file#,name from v$datafile where file#=236;

     FILE#
----------
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       236
/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA


SQL> show parameter db_create_file_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      +SHARED_DATA


As  db_create_file_dest define as +SHARED_DATA , it shows something wrong happen during adding this datafile. common cause is while add datafile if we given space between "add datafile ' +vale of db_create_file_dest'  this way datafile will create inside $ORACLE_HOME/dbs'. seem same happen here for this db also .
Let's fix this now .

SQL>  select file#,name from v$datafile where file#=236;

     FILE#
----------
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       236
/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA

alter database create datafile '/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA' as '+SHARED_DATA'

SQL> show parameter db_create_file_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      +SHARED_DATA
SQL>

SQL> alter database create datafile '/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA' as '+SHARED_DATA'
  2  ;
alter database create datafile '/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA' as '+SHARED_DATA'
*
ERROR at line 1:
ORA-01136: specified size of file 236 (12800 blocks) is less than original size of 131072 blocks
ORA-01110: data file 236: '/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA'

No problem .

SQL> alter database create datafile '/d001/product/oracle/11.2.0.2/db/dbs/SHARED_DATA' as new;

Database altered.

SQL> select file#,name from v$datafile where file#=236;

     FILE#
----------
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       236
+SHARED_DATA/XXXX/datafile/otd.1475.832988265