Nov 09 2011

Customize/Personalize Oracle APEX Workspace Environment

Category: 11g,APEX,Browser,Tool,URLittichai @ 4:06 pm

When you have multiple Oracle APEX environments, e.g., development, test, UAT and production, and for multiple groups, one of the confusing things is that sometimes developers are lost on which environment they’re working on. Most of technically proficient developers can make a distinction easily from the URLs they’re currently using. However, most of less technically proficient (e.g., business users) sometimes cannot.

A quick and simple solution here is to make a visual distinction on the APEX workspace pages especially on the logo area. Instead of using plain vanilla logo images, they are replaced with more distinct and informative images.

This is the default APEX workspace logon page.

Default Workspace Logon Image

This is a sample of the personalized workspace logon page with a company logo and it is showing that this is the development environment.

Customized APEX workspace logon page

This is the main workspace page after logon showing the default logo image.

Default Workspace Page

You can change it to be like this.

Customized APEX workspace development page

With just this minor change, our users feel more comfortable knowing that they’re working the right environment.

How to change it?

With a quick investigation, you can easily find the paths of those image files as follows:

Workspace logon page:

Image path: /i/apex/builder/apex-logo-white.gif
Image size: 300px x 30px
Transparent background

Image path:/i/apex/builder/apex-db-apps.png
Image size: 240px x 200px
Transparent background

Workspace main page after logon:
Image path: /i/htmldb/apex_logo.gif
Image size: 300px x 30px
White background

  • Use Photoshop or any image editing tools to recreate those image files.
  • Copy and replace those image files on the web server. Please make the backup of those files before replacing them.

Note that this approach will NOT work if you’re using a shared web server for multiple APEX database environments because they’re using the same image files.

Update: Using ApexLib script in the login message (under Manage Instance) as mentioned by Peter in the comment section is another solution for customization. I like this approach as not only you can customize the logo, but you can also change the description text on the workspace logon page. In addition, since the change is on the APEX instance itself, it can definitely be used on a shared web server.


Aug 15 2011

Book Review: Oracle 11g R1/R2 Real Application Clusters Essentials by Ben Prusinski and Syed Jaffer Hussain (Packt Publishing)

Category: 11g,Databaseittichai @ 9:31 pm

Oracle 11g R1/R2 Real Application Clusters EssentialsOracle Real Application Cluster (RAC)  becomes the technology of choice for highly available and highly scalable deployment of enterprise Oracle database environment. With its innovative technology it comes with no surprise its complexity. The complexity is not only with the underlying database technology itself, but also how well you design and implement it to work with other components including operating system, storage subsystem, etc. In order to setup and maintain a successful RAC environment, it not only requires technical knowledge of database administrator (DBA), but also well collaboration and extended planning between all IT and business partners.

Few years back, there has been a movement of DBA 2.0 which says that, in addition to database knowledge,  an extended understanding of operating system, storage and/or networking is encouraged due to more tightly integrated of Oracle database technologies such as Clusterware, RAC, ASM with the underlying subsystems. I agree with this notion but not to the extent that DBAs should perform all works in those areas. (Yes, I’m aware that some DBAs do it all.) However, I think at least they should have enough understandings of all-related technologies to collaborate with those who are responsible for in order to achieve the desired setup. In many cases especially in the large companies where traditional organization division of the job description of administrators is clear cut and no overlapping, being well-rounded with all-related technologies will allow DBA to better discuss the requirements and designs and even assist with the implementation details.

Most Oracle RAC books in the market today tend to focus only on the detailed technical aspects of this database technology. This mainly is good for those Oracle professionals who at least have worked with RAC before. Few books really provide a good foundation for those who are new to this technology. One of those few which I’ve just read recently is Oracle 11g R1/R2 Real Application Clusters Essentials authored by Ben Prusinski and Syed Jaffer Hussain published by Packt Publishing.

What I really like about this book is the fact that it does not jump into the nuts and bolts of this Oracle technology right away but instead it is trying to build up good foundation starting from concept (especially high availability), architecture (of all components not just of database), design, implementation and then even some of the real-world samples. This stepping-stone approach helps readers to understand what is involved and how they should deploy this technology for the high available database.

In the chapter 1, the emphasis of the high availability concept is crucial. The authors precisely points out that high availability should be looked from users’ perspective. Many DBAs or system administrators especially novice ones have a tendency to focus solely on their respective areas. The provided sample of the availability percentage in the “high availability interpretations” section is a good reminder for a need to have an end-to-end high availability design to avoid a single point of failure (SPOF). The chapter goes on to give the definitions of many acronyms (BIA, BCP, DRP, etc.) commonly-used during the planning phase. It is quite useful to be aware of them especially when discussing with business end-users. The chapter ends with providing a whole picture of the high availability solutions (RAC, Data Guard, Streams, Application Server Clustering) from Oracle as a part of the Maximum Availability Architecture (MAA). It is worth to point out that RAC is just one (not the only) of key components for a complete high availability solution.

Chapter 2 looks into the hardware components of Oracle RAC architecture including network, storage, etc. Again, I think the authors reinforce a need to understand all these underlying technologies (at least at high level) even though DBAs might not involve in the actual implementation. But it is crucial to have this knowledge under their belts in order to have the productive discussions of the requirements and design with system administrators.

Chapter 3 goes into the clusterware installation of 11g R1/R2. Even though readers may to be able to find similar information on many web sites and blogs, this book has some extra information which makes an attempt to explain what each action does, for example, what happen when the orainstRoot.sh and root.sh run?

Chapter 4 dedicates to the Automatic Storage Management (ASM) which becomes the only clear choice for storage management in the 11g deployment. The chapter covers all aspects of ASM in both R1 and R2 including new features, configurations, management, etc.

Chapter 5 covers Clusterware management and (some) troubleshooting samples. Instead of showing all possible troubleshooting scenarios (which is impossible to include everything in a chapter or even in a book), the authors did an excellent job of giving an overview of all necessary Clusterware utilities in order to troubleshoot the issues.

Chapter 6 turns our attention to RAC database administration. The structure is similar to that of Clusterware in the chapter 3. The latter part of the chapter also covers the automatic workload management including the topic of the service which is highly recommended to utilize it (not using the default database service.)

Chapter 7 covers all aspects of backup and recovery of Oracle database including the best practices. In addition, new features of RMAN in Oracle 11g R1 and 11g R2 along with OCR and voting disk backup and recovery are discussed.

Chapter 8 tries to give an overview of performance tuning. The intention here seems to just give an overview of the concept and methods of performance tuning as well as new 11g performance features, for example, Real Application Testing (RAT) which has the Database Replay and SQL Performance Analyzer (SPA). This high-level overview focus is understandable because the scope of performance tuning is generally vast. Some of tuning metrics especially relate to the wait events are explained here.

Chapter 9 focuses on the upgrade scenarios. As we all know it is impossible to cover all possible scenarios. But the authors gives sufficient information about overall upgrade processes from 10g R2 to 11g R1 and then to 11g R2 in this chapter. Definitely consulting with Oracle support for more details on individual upgrade case is still highly recommended.

Chapter 10 is very informative on the node addition and removal. The chapter steam-lines the steps pretty well (comparing to the official Oracle document which is very confusing at the first read with the flow of information). (We just went through adding two nodes into the existing two nodes of Oracle 11g R1 two months ago. That’s why I can say that.)

Chapter 11 shows the readers the importance of the end-to-end high availability implementation. The high availability should not stop at the Oracle RAC database, but it must extend to application layer on top of it. In addition to an overview of Oracle EBS (E-Business Suite), this chapter shows the readers how to take full advantage of high availability and performance features in Oracle RAC database.

The last chapter wraps up nicely with information about other tools in the MAA tool suite namely Streams and Data Guard. It covers all various topics of thes tools including concepts, new features, best practices, and overview configuration.

The last section of this book on the additional resources and tools is a nice read and very informative. It is just like a nice dessert at the end of a good meal.

In conclusion, if you’re new to Oracle RAC technology, this is THE book for you. It should give the readers enough understanding to jump on Oracle RAC bandwagon. Advanced DBAs may find that most of the contents in the book are too familiar, but they might be attracted to the new features, comparisons between R1 and R1 as well as some of real-world samples mentioned in this book. Overall I appreciate a very well effort of Ben ad Syed for one of the most complete informative books on Oracle RAC in the market today. Well-deserved kudos to them.

Thanks to Packt Publishing for the opportunity to review this book.

Tags: , , , , , , , , , , ,


Mar 21 2011

Differences between Native and Interpreted Compilations in Oracle 11g? Why Performance Is Improved in the Native Compilation?

Category: 11g,Databaseittichai @ 2:38 pm

Quick bullet points from reading the Transparent Performance Improvement: Real Native Compilation from the PL/SQL Enhancements in Oracle Database 11g white paper:

  • The PL/SQL is an interpreted language but it is not just like other interpreted languages , e.g. BASIC, where the code is processed statement by statement at the run time. The PL/SQL code is compiled into machine code called M-Code with a target virtual machine called PL/SQL Virtual Machine (PVM), just like Java to Java Virtual Machine (JVM).
  • The PVM is implemented as a set of subroutines in Oracle executables, and scans the M-Code at run time.
  • The scanning detects each successive OPCODE and its OPERANDS, then calls the subroutine that implements this OPCODE with actual arguments.
  • This run-time scanning of the M-Code takes some resources. This is where the PL/SQL native compilation will help with improvement.
  • Compilations of both follow the same path:
    • In the interpreted mode, the M-Code is produced.
    • In the native mode, a platform-specific dynamically linkable library (DDL) (similar to .dll in Windows or .so in Unix) is produced.
      • This platform-specific DLL, at run time, calls exactly the same PVM subroutines with same arguments as would have been called by scanning the M-Code.
  • In short, the performance improvement is due to the fact that the scanning effort has been moved from run time (when in interpreted mode) to compile time (when in native mode).
  • Since exactly the same PVM subroutines are called with exactly the same arguments in both interpreted and native modes, the native mode is guaranteed to have exactly the same semantics as the interpreted mode.

Tags: , , , , ,


Mar 20 2011

Oracle 11g SQL Error Logging

Category: 11g,Database,SQLPlus,Toolittichai @ 8:00 am

We’re working on the installation scripts for an internal PL/SQL applications. Multiple scripts are called from the main one. To capture errors from script execution, normally the spool syntax will be used in the scripts to pipe out all executions into log files, and then later the deployment team members will examine them using find/search ORA- for any errors. This would work fine if there are only a few scripts but it becomes cumbersome when multiple scripts are involved. In addition we’d like to be able to run the scripts on either Windows and Unix platforms, handling OS file paths for multiple platforms using spool adds unnecessary layer.

The SQL Error Logging is a new feature in 11g. This simplifies the way we capture and locate error messages as information now will be stored in database table instead of OS files.

To check whether or not the Error Logging is enabled.

SQL> show errorlogging

errorlogging is OFF

To enable the Error Logging. The default table SPERRORLOG is created.

SQL> set errorlogging on

By default, the SPERRORLOG will be created under current user. In this sample, the current schema is TEST1_USER.

SQL> show errorlogging

errorlogging is ON TABLE TEST1_USER.SPERRORLOG

Here is the structure of this table SPERRORLOG.

SQL> desc SPERRORLOG
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
USERNAME                                           VARCHAR2(256)
TIMESTAMP                                          TIMESTAMP(6)
SCRIPT                                             VARCHAR2(1024)
IDENTIFIER                                         VARCHAR2(256)
MESSAGE                                            CLOB
STATEMENT                                          CLOB

To enable the Error Logging to an user defined table instead of the default SPERRORLOG table.

SQL> set errorlogging on table [schema].[table]

If non-default, the table has to be created in advance, otherwise you will get an error.

SQL> set errorlogging on table my_sperrorlog;

SP2-1507: Errorlogging table, role or privilege is missing or not accessible

Here is the syntax to create an user-defined table. If this table is created on a different schema, an insert grant to is needed for the current user.

SQL> CREATE TABLE my_sperrorlog (
username     VARCHAR(256),
timestamp    TIMESTAMP,
script       VARCHAR(1024),
identifier   VARCHAR(256),
message      CLOB,
statement    CLOB
);
SQL> set errorlogging on table my_sperrorlog

SQL> show errorlogging
errorlogging is ON TABLE TEST1_USER.my_sperrorlog

Demo
Generate error #1.

SQL> SELECT 1/0 FROM DUAL;
SELECT 1/0 FROM DUAL
*
ERROR at line 1:
ORA-01476: divisor is equal to zero

Generate error #2.

SQL> alter table EMP add new_column VARCHR2(1);
alter table EMP add new_column VARCHR2(1)
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option

Check the SQL Error Logging.

SQL> column username format A10
SQL> column message format A30 wrap
SQL> column statement format A30 wrap

SQL> SELECT username, STATEMENT, message FROM sperrorlog;

USERNAME   STATEMENT                      MESSAGE
---------- ------------------------------ ------------------------------
TEST1_USER SELECT 1/0 FROM DUAL           ORA-01476: divisor is equal to
zero

TEST1_USER alter table EMP add new_column ORA-01735: invalid ALTER TABLE
VARCHR2(1)                     option

Without commit, other sessions won’t see this information.

SQL> commit;

Commit complete.

Set an unique identifier to make it easier to identify the logging record. In sample here, the identifier is set to REL1.

SQL> set errorlogging on identifier 'REL1'

Generate error #3.

SQL> alter table EMP modify ABC NOT NULL;
alter table EMP modify ABC NOT NULL
*
ERROR at line 1:
ORA-00904: "ABC": invalid identifier

Check the SQL Error Logging with the identifier=’REL1′.

SQL> SELECT username, statement, message, IDENTIFIER
FROM sperrorlog where IDENTIFIER='REL1';

USERNAME   STATEMENT                      MESSAGE                        IDENT
---------- ------------------------------ ------------------------------ -----
TEST1_USER alter table EMP modify ABC NOT ORA-00904: "ABC": invalid iden REL1
NULL                          tifier

Truncate the Error Logging to clear all existing rows in the error log table. This will clear out all records regardless of who creates them.

SQL> set errorlogging on truncate

SQL> SELECT * FROM sperrorlog;
No rows selected

There is no set errorlogging truncate only a specified identifier. Doing below is the same set errorlogging on truncate. So basically the identifier is ignored.

SQL> set errorlogging on truncate identifier 'REL1'

But you can just delete records as the regular table.

SQL> delete sperrorlog where IDENTIFIER='REL1';

SQL> commit;

Disable Error Logging. (Log off will automatically disable it.)

SQL> set errorlogging OFF

SQL> show errorlogging
errorlogging is OFF

Will it work with previous versions of Oracle database?

Since the SQL Error Logging is the feature on client, I have no reason to believe that it would not work with pre-11g databases.

The 11g SQL Plus Client to 10.2.0.1 Database

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Solaris: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL> show errorlogging
errorlogging is OFF

SQL> set errorlogging ON

SQL> show errorlogging
errorlogging is ON TEST1_USER.SPERRORLOG

SQL> select username, TIMESTAMP from  sperrorlog;

no rows selected

SQL> SELECT 1/0 FROM DUAL;
SELECT 1/0 FROM DUAL
*
ERROR at line 1:
ORA-01476: divisor is equal to zero

SQL> SELECT username, STATEMENT, message FROM sperrorlog;

USERNAME   STATEMENT                      MESSAGE
---------- ------------------------------ ------------------------------
TEST1_USER SELECT 1/0 FROM DUAL           ORA-01476: divisor is equal to
zero

The 11g SQL Plus Client to 10.1.0.4 Database

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - 64bi
PL/SQL Release 10.1.0.4.0 - Production
CORE    10.1.0.4.0      Production
TNS for Solaris: Version 10.1.0.4.0 - Production
NLSRTL Version 10.1.0.4.0 - Production

SQL> show errorlogging
errorlogging is OFF

SQL> set errorlogging ON

SQL> show errorlogging
errorlogging is ON TABLE TEST1_USER.SPERRORLOG

SQL> select username, TIMESTAMP from  sperrorlog;

no rows selected

SQL> SELECT 1/0 FROM DUAL;
SELECT 1/0 FROM DUAL
*
ERROR at line 1:
ORA-01476: divisor is equal to zero

SQL> SELECT username, STATEMENT, message FROM sperrorlog;

USERNAME   STATEMENT                      MESSAGE
---------- ------------------------------ ------------------------------
TEST1_USER SELECT 1/0 FROM DUAL           ORA-01476: divisor is equal to
zero

The 11g SQL Plus Client to 9i Database
Unfortunately I don’t have any Oracle 9i databases.  :-)

The 11g SQL Plus Client to 8i Database

Surprisingly, I still have one 8i database left. But, well, the 11g client no longer supports the 8i database.

ERROR:
ORA-03134: Connections to this server version are no longer supported.

Related topics:

Tags: , , , , , ,


Feb 14 2011

Easy Connect (EZCONNECT) Naming Method with Instance Name

Category: 11g,Network,SQLPlusittichai @ 7:11 pm

Oftentimes I use the Easy Connect (EZCONNECT) to connect to a new database just to quickly verify database connectivity. The syntax I usually use is as follows:

CONNECT username/password@[//]host[:port][/service_name]
CONNECT scott/tiger@host1-vip:1522/RACDB

In RAC, this will connect to whatever instance based on the service’s load balancing goal.

I just learned that with the 11g net services client software, you can also specify the instance name to connect to. This may be useful especially for RAC setup if you have the need to connect to a specific instance.

CONNECT username@[//]host[:port][/[service_name][:server]][/instance_name]]

-- Connect to the instance name RACDB1
CONNECT scott/tiger@host1-vip:1522/RACDB/RACDB1

-- Connect to the instance name RACDB2
CONNECT scott/tiger@host1-vip:1522/RACDB/RACDB2

Also, the optional [:server] is either dedicated or shared.

CONNECT scott/tiger@host1-vip:1522/RACDB:dedicated/RACDB1

Reference: http://download.oracle.com/docs/cd/B28359_01/network.111/b28316/naming.htm#NETAG255

Tags: , , , , , , , , ,


Jan 11 2011

RMAN Duplicate Failed – Need to Format Corrupt Block Not Part of Any Segment

Category: 11g,Database,RMANittichai @ 9:56 pm

When I tried to duplicate one of the databases using the RMAN duplicate, I’ve encountered the block corruption errors on the SYSAUX tablespace. The root cause of corruptions is still unknown to me. With further investigation, I’ve learned that the corrupt blocks do not belong to any objects. (The query used to identify them will be shown later.) This post is just following the article from MOS on How to Format Corrupted Block Not Part of Any Segment (Doc ID 336133.1) to resolve the issue.

Since this article lists the step-by-step instructions very clearly, I will just follow it as written and add my inputs if any.

However, before we start, please make sure that you read the article. The important note here is, as the document warns us, that these steps are just one of many possible ways to fix this particular problem when the corrupt block does not belong to any object . And there is no guarantee to work.

Step 1 – Identify corrupt datafile.

Check the ORA-19566 message to identify the corrupt datafile.

The corrupt datafile in this case is file 2 which belongs to the SYSAUX tablespace.

The alert log shows as follows:

Corrupt block relative dba: 0x009499e5 (file 2, block 1350117)
Bad header found during validation
Data in bad block:
type: 40 format: 2 rdba: 0x0093abe5
last change scn: 0x09f1.e2a690d1 seq: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x90d12802
check value in block header: 0xeacf
computed block checksum: 0x0
Reread of blocknum=1350117, file=+DEDW_DG1/dedw/datafile/sysaux.261.673617071. found same corrupt data
Reread of blocknum=1350117, file=+DEDW_DG1/dedw/datafile/sysaux.261.673617071. found same corrupt data

Running RMAN validate on the data file, we’ve seen multiple corrupt block numbers.

RMAN> backup validate datafile 2;
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    FAILED 0              90642        1360196         11667810197595
File Name: +DEDW_DG1/dedw/datafile/sysaux.261.673617071
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data       16             46391
Index      4              24256
Other      6730           1198907

The v$database_block_corruption shows the block numbers and how many of them.

SQL> select * from v$database_block_corruption;
FILE# BLOCK#  BLOCKS    CORRUPTION_CHANGE# CORRUPTION_TYPE
----  ------- --------- ------------------ ---------------
2     1350117 1         0                  CORRUPT
2     1350053 1         0                  CORRUPT
2     1349989 1         0                  CORRUPT
2     1349925 1         0                  CORRUPT
2     1349861 1         0                  CORRUPT
2     1349797 1         0                  CORRUPT
2     1341568 4         0                  CORRUPT
2     1341440 84        0                  CORRUPT
2     1337344 512       0                  CORRUPT
2     1333248 512       0                  CORRUPT
2     1329152 512       0                  CORRUPT
2     1325056 512       0                  CORRUPT
2     1320960 512       0                  CORRUPT
2     1316864 512       0                  CORRUPT
2     1312768 512       0                  CORRUPT
2     1308672 512       0                  CORRUPT
2     1304576 512       0                  CORRUPT
2     1300480 512       0                  CORRUPT
2     1296384 512       0                  CORRUPT
2     1288192 512       0                  CORRUPT
2     1284096 512       0                  CORRUPT

Note that there are multiple corrupt blocks in multiple ranges. Some ranges have just only one corrupt block while others have more, e.g., 512 blocks. The highest corrupt block number in this case is 1350117. We will use this number in the later step.

Step 2 – Run DBVERIFY (Database Verification Utility) on affected datafile and check for corrupt block.

Run dbv on the datafile which reports corrupt block.

$ dbv file=+DEDW_DG1/dedw/datafile/sysaux.261.673617071 userid=sys logfile=/tmp/dbv_sysaux.log

You can also specify start and end for the utility to run. But here, we will run for the whole data file.

Part of the output:

DBVERIFY: Release 11.1.0.7.0 - Production on Mon Jan 6 12:27:33 2010
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
DBVERIFY - Verification starting : FILE = +DEDW_DG1/dedw/datafile/sysaux.261.673617071
Page 1284096 is marked corrupt
Corrupt block relative dba: 0x00939800 (file 2, block 1284096)
Bad header found during dbv:
Data in bad block:
type: 40 format: 2 rdba: 0x00938a00
last change scn: 0x09f1.e2a6199c seq: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x199c2802
check value in block header: 0x482a
computed block checksum: 0x0

Page 1284097 is marked corrupt
Corrupt block relative dba: 0x00939801 (file 2, block 1284097)
Bad header found during dbv:
Data in bad block:
type: 40 format: 2 rdba: 0x00938a01
last change scn: 0x09f1.e2a619af seq: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x19af2802
check value in block header: 0x4809
computed block checksum: 0x0
:
:
[the rest is omitted]

Step 3 – Check whether blocks are part of any object.

Query the dba_extents and  cross check that the block does not belong to any object.

SQL> select segment_name, segment_type, owner
from dba_extents
where file_id = <Absolute file number>
and <corrupted block number> between block_id
and block_id + blocks -1;

The <Absolute file number> is 2 (SYSAUX). The <corrupted block number> is the corrupt block number.

Sample here:

select segment_name, segment_type, owner
from dba_extents
where file_id = 2
and 1284096 between block_id and block_id + blocks -1;
no rows selected

If there are multiple blocks to check, this query might not be an efficient way to verify.

The other way to confirm is to use Jonathan Lewis’s query from this post to list all the used extents and free space in a tablespace.

The output of this query gives you a visual of the block ranges which makes it easy to confirm that the affected blocks are not part of any objects.

Visual of the block ranges of interest

Step 4 – Create a dummy table as user other than SYS and SYSTEM.

SQL> connect scott/password

Create a dummy table in the tablespace containing datafile which has the corrupt block. Use nologging option to prevent redo records from being generated.

SQL> create table s (
        n number,
        c varchar2(4000)
     ) nologging tablespace SYSMAN;

Step 5 – Create a trigger on the dummy table which throws exception once the corrupt block is reused.

Note that this trigger is fired when the last (highest) block number is reused.

In our case, we will supply 2 for “filenumber” and 1350117 from the step 1 for the “blocknumber”.

Connect as sys and create the following trigger:

CREATE OR REPLACE TRIGGER corrupt_trigger
   AFTER INSERT ON scott.s
   REFERENCING OLD AS p_old NEW AS new_p
   FOR EACH ROW
DECLARE
   corrupt EXCEPTION;
BEGIN
   IF (dbms_rowid.rowid_block_number(:new_p.rowid)=&blocknumber)
   and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=&filenumber) THEN
      RAISE corrupt;
   END IF;
EXCEPTION
WHEN corrupt THEN
   RAISE_APPLICATION_ERROR(-20000, 'Corrupt block has been formatted');
END;
/

Step 6- Allocate space to the table from the affected datafile.

First, find the extent size by querying the dba_free_space.

SQL> select bytes
from dba_free_space
where file_id=2 and 1284096 between block_id and block_id + blocks -1;
BYTES
----------
4160749568
ALTER table scott.s
  allocate extent (DATAFILE '+DEDW_DG1/dedw/datafile/sysaux.261.673617071' SIZE 4160749568);

Keep allocating until the corrupt block is part of the scott.s table – check this with the following query:

SQL> select segment_name, segment_type, owner
from dba_extents
where file_id = <Absolute file number>
and <corrupt block number> between block_id
and block_id + blocks -1 ;

It is advisable to ensure that AUTOEXTEND is OFF for the datafile to prevent it from growing.

Step 7 -  Insert data into dummy table To format the block.

You can use either one of the three scripts the document provided.

This is the one I used:

BEGIN
FOR i IN 1..1000000000 LOOP
   INSERT INTO scott.s VALUES(i,'x');
END LOOP;
END;
/

The trigger will be fired for every row inserted into the table, and an exception with ORA-20000 will be produced as soon as it inserts row into the last corrupt block.

Step 8 – Verify for any corruption in datafile by running DBV and RMAN backup

Run dbv again on the corrupt datafile.  Hopefully, it will not show any more corruptions.

RMAN backup will not report any errors on these blocks.

RMAN> backup validate datafile 2;
:
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=+DEDW_DG1/dedw/datafile/sysaux.261.673617071
channel ORA_DISK_1: backup set complete, elapsed time: 00:06:06
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    OK     0              259802       1638400         11669581253505
File Name: +DEDW_DG1/dedw/datafile/sysaux.261.673617071
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data       0              1335585
Index      0              17394
Other      0              25619
SQL> select * from v$database_block_corruption;
no rows selected

Step 9 – Drop the dummy table created in step 4.

SQL> drop table scott.s;

Tags: , , , , , , , , ,


Oct 24 2010

Migration of the 11g R1 OCR and Voting disks to different paths when Cluster Ready Service (CRS) is off-line

Category: 11g,Database,Multipathing,Solarisittichai @ 5:15 pm

During a new setup of our 11g R1 (11.1.0.7) on Solaris platform, initially the system is provided with only single path to disks (LUNs) on SAN. Later the sys admins would like to enable the multipathing. :-( Obviously, it is expected that the disk paths will be changed. This will not only affect the ASM disk groups, but also the OCR and Vote disks.

The path that is, for example, c4t50060E80045C5930d17s6, after multipathing, will become something like this c4t60060E80056FB30000006FB300001019d17s6.

The disk path change for the ASM disk groups is not a major concern due to the fact that all needed information is already stored in the disk header  (so the disk path name is irrelevant here). Merely, update the ASM’s disk discovery path parameter (asm_diskstring) to the new path, everything should be fine. (Reference: Metalink Doc ID 466231.1 – ASM Survive Change Of Disc Path?)

The main concern is with cluster registry information stored in the OCR and Voting disks which obviously their paths will not be the same after multipathing. It is expected that CRS won’t start up because the ocr.loc still contains the old paths which will no longer exist after reboot.

We could not run ocrconfig -replace ocr and ocrconfig -replace ocrmirror before multipathing as the  new disk paths are not there yet, or after that as CRS will not be available. Note that to move the OCR location for Oracle RAC 10gR2 or later, use “ocrconfig -replace” command. Manual edit of the ocr.loc at /var/opt/oracle is not recommended.

Fortunately there is a way to perform disk path change while CRS is off-line.

Before multipating
Backup all OCR and Voting disks.

For OCR, use:

# ocrconfig -manualbackup

For Voting disks, use:

# dd if={VOTING_PATH} of={VOTING_BACKUP_PATH}

After multipathing (and server reboot), the CRS is not available.

1. Even with CRS down, ensure that there is no other CRS-related processes (evmd or cssd) running.

Some processes will be restarted automatically even they’re terminated manually with using kill -9.

To ensure that no process running, backup and comment the last three line of the /etc/inittab.

#h1:3:respawn:/etc/init.d/init.evmd run >/dev/null 2>&1 </dev/null
#h2:3:respawn:/etc/init.d/init.cssd fatal >/dev/null 2>&1 </dev/null
#h3:3:respawn:/etc/init.d/init.crsd run >/dev/null 2>&1 </dev/null

Run init q to take change into effect.

Don’t forget to un-comment them when all tasks are completed.

2. On all nodes, run the following commands as root to point to the new disk paths for the master and the mirror:

# ocrconfig -repair ocr /dev/rdsk/c5t60060E80045C590000005C5900000C03d0s6

# ocrconfig -repair ocrmirror /dev/rdsk/c5t60060E80045C590000005C5900000C04d0s6

3. As root, on one node, run:

# ocrconfig -overwrite

4. Run ocrcheck on all nodes to verify new paths:

# ocrcheck
Status of Oracle Cluster Registry is as follows :
Version                  :          2
Total space (kbytes)     :    1036532
Used space (kbytes)      :       5408
Available space (kbytes) :    1031124
ID                       :  582752590
Device/File Name         : /dev/rdsk/c5t60060E80045C590000005C5900000C03d0s6
Device/File integrity check succeeded
Device/File Name         : /dev/rdsk/c5t60060E80045C590000005C5900000C04d0s6
Device/File integrity check succeeded

Cluster registry integrity check succeeded

5. Next, we’ll also change the paths for voting disk.

Delete the old paths and add new ones in the order to ensure that at least one disk is available. The option -force will be required in this case.

# crsctl delete css votedisk /dev/rdsk/c3t50060E80045C5920d15s6 -force
# crsctl add css votedisk /dev/rdsk/c5t60060E80045C590000005C5900000C05d0s6 -force
# crsctl delete css votedisk /dev/rdsk/c3t50060E80045C5920d16s6 -force
# crsctl delete css votedisk /dev/rdsk/c3t50060E80045C5920d17s6 -force
# crsctl add css votedisk /dev/rdsk/c5t60060E80045C590000005C5900000C06d0s6 -force
# crsctl add css votedisk /dev/rdsk/c5t60060E80045C590000005C5900000C07d0s6 –force

Now we should be able to start CRS.

Reference: Method 2 (Offline) in Note 428681.1 :OCR / Vote disk Maintenance Operations: (ADD/REMOVE/REPLACE/MOVE)

Tags: , , , , , , , , , , , , , ,


Apr 26 2010

Install 11g Release 2 Grid Infrastructure for Standalone Server on Windows 7 for Sandbox

Category: 11g,Databaseittichai @ 9:08 pm

Oracle 11g Release 2 for Windows was just released this month. With the availability of the grid infrastructure in this version, I plan to install it on my Windows 7 desktop to see what it can do even if it is just on stand alone environment.

In order for database to use Automatic Storage Management (ASM), it requires the Grid Infrastructure. In addition to ASM, Grid Infrastructure will also provide Oracle Restart to manage the Oracle processes (database, listener, and ASM).

One of the first issues I’ve encountered is the new requirement that the clusterware files (OCR & Voting) must be on ASM. I have to admit even though I’ve done ASM on Solaris and Linux before, but never on Windows. Since this is mandatory, I will give it a try. And since I will use ASM for clusterware files, I plan to use it for database data files as well.

In order to use ASM, I’m required to provide the unformatted (raw) basic disks. I plan to use the existing disks without adding new physical ones. Fortunately in Windows 7, I can use the disk management (diskmgmt.msc) tool to shrink volume and create a new logical disk from claimed space. Note that you may have multiple physical disks on your machine, but ASM supports and recognizes only logical drives on the Basic disk (not Dynamic disk). Click here if you’re interested in differences between Basic and Dynamic disks.

Once data volume is shrunk, I can create a new volume and then a logical drive. The new drive must not be formatted or having a drive letter assigned to it. Here is the guidelines from Oracle document on “create disk partitions”.

To use ASM with direct attached storage or SAN, the disks must be stamped with a header. This can be accomplished by using either asmtool (command-line version) or asmtoolg (GUI version). Since we will install Oracle grid infrastructure in interactive mode, the asmtoolg will be called during the configuration. Somehow, if I tried to launch the asmtoolg outside Oracle grid infrastructure installation, I always encountered error with no disks found. However, within the Oracle grid infrastructure installation, there is no issue.

In general, the installation went well. I’ve encountered few issues which I’ve documented them in the documents below. The snapshots of steps here are for educational purpose only.

Windows 7 – Disk Preparation for ASM

Oracle 11g R2 Grid Infrastructure for Standalone Server Installation on Windows

Oracle 11g R2 Software Installation for Single Instance Database on Windows

Oracle 11g R2 Database Creation using ASM on Windows

Tags: , , , , , , , , , ,


Feb 20 2010

Oracle 11g Network Access Denied by Access Control List (ACL) when using UTL_INADDR

Category: 11g,Database,Networkittichai @ 12:10 pm

I wrote in my previous post about the Access Control Lists to Network Services (e.g., UTL_HTTP, UTL_SMTP, UTL_TCP, etc.) in Oracle 11g. However, it did not cover another PL/SQL network utility package named UTL_INADDR which retrieves host names and IP addresses of local and remote hosts.

You can read some usage samples of the UTL_INADDR from Eddie Awad’s blog.

Similar to those UTL_ packages, in 11g, you will be required to configure the access control list in order to use the UTL_INADDR. Otherwise, by default, you will receive errors as follows:

TEST_USER @DB11> SELECT utl_inaddr.get_host_name FROM dual;
SELECT utl_inaddr.get_host_name FROM dual
*
ERROR at line 1:
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1

Two simple steps to configure are:

1. Create an access control list and its privilege definition.

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;
/

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

You can add more users or roles using DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE.

To verify a newly-created ACL.

SQL> SELECT any_path
FROM resource_view
WHERE any_path like '/sys/acls/Resolve%.xml';

ANY_PATH
--------------------------------------------------------------------------------
/sys/acls/Resolve_Access.xml

2. Assign the the access control list to one or more network hosts.

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;
/
TEST_USER @DB11> SELECT utl_inaddr.get_host_name FROM dual;

GET_HOST_NAME
--------------------------------------------------------------------------------
hostname1

Reference: Oracle document on Managing Fine-Grained Access to External Network Services

Related topics:

 

Tags: , , , , , , ,


Nov 12 2009

11.2.0.1 on Solaris is now available

Category: 11g,Databaseittichai @ 10:35 am

Oracle Database 11g Release 2 (11.2.0.1.0) for Solaris (SPARC) (64-bit) platform is now available for download.

11gr2 solaris

Tags: , ,


Next Page »