Tuesday, August 10, 2010

Equivalent 11.2 Clusterware commands for Deprecated commands

Deprecated Command          Equivalent 11.2 Command
crs_stat                    crsctl stat resource
crsctl check cssd           crsctl check css
crsctl check crsd           crsctl check crs
crsctl check evmd           crsctl check crs
crs_register                crsctl add resource
crs_unregister              crsctl delete resource
crs_start                   crsctl start resource
crs_stop                    crsctl stop resource / crsctl stop cluster
crs_getperm                 crsctl getperm resource
crs_profile                 crsctl add resource
crs_relocate                crsctl relocate resource
crs_setperm                 crsctl setperm resource
crsctl debug log            crsctl set log / crsctl set trace
crsctl set css votedisk     crsctl add css votedisk
crsctl start resources      crsctl start resource
crsctl stop resources       crsctl stop resource

Full word resource could be shorten to 'res'

crsctl status res is same as crsctl status resource

expdp and impdp with ASM

ASM supports dump files created with expdp and impdp. Setup is similar to conventional expdp using a OS file systems, except dump file directory must be created inside the diskgroup if "root" diskgroup location is not used the location for the dumpfiles.
Create directory with asmcmd
. oraenv
ORACLE_SID = [clusdb1] ? +ASM1
+ASM1]$ asmcmd
ASMCMD> ls
CLUSTERDG/
DATA/
FLASH/        
mkdir data/dpump
ASMCMD> ls data
CLUSDB/
dpump/
Create a directory object and grant permission to user
SQL> create directory asmdumpdir as '+DATA/dpump';
Directory created.
grant read,write on directory asmdumpdir to asanga;
Grant succeeded. 
Log files created during expdp cannot be stored inside ASM, for log files a directory object that uses OS file system location must be given. If not following error will be thrown
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
Therefore another directory object must be created for logfile location (or nologfile option could be used).
Execute the expdp command as
expdp asanga/*** directory=asmdumpdir dumpfile=asanga.dmp schemas=asanga logfile=logdir:asa.log
Export: Release 11.2.0.1.0 - Production on Tue Aug 10 11:27:25 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Starting "ASANGA"."SYS_EXPORT_SCHEMA_01":  asanga/******** directory=asmdumpdir dumpfile=asanga.dmp schemas=asanga logfile=logdir:asa.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 75.18 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE           
.
.
.

ASMCMD> ls data/dpump
asanga.dmp
View the created dump file in ASM using asmcmd. Similary import could also be done with
impdp asanga/*** directory=asmdumpdir dumpfile=asanga.dmp logfile=logdir:asmlog tables=city

Import: Release 11.2.0.1.0 - Production on Tue Aug 10 11:30:11 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "ASANGA"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "ASANGA"."SYS_IMPORT_TABLE_01":  asanga/******** directory=asmdumpdir dumpfile=asanga.dmp logfile=logdir:asmlog tables=city
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA  
.
.
To transfer a dumpfile created in ASM dbms_file_transfer.copy_file could be used. Code below copies the dump file created in asm to log file directory
exec dbms_file_transfer.copy_file('asmdumpdir','asanga.dmp','logdir','copydumpfile.dmp');
ASM-to-ASM transfer


Monday, August 9, 2010

Using UTL_MAIL in 10g and 11g

UTL_MAIL PL/SQL package provides a much simplified interface to send email using Oracle database. Both on 10g and 11g "UTL_MAIL is not installed by default because of the SMTP_OUT_SERVER configuration requirement and the security exposure this involves. In installing UTL_MAIL, you should take steps to prevent the port defined by SMTP_OUT_SERVER being swamped by data transmissions" (Oracle PL/SQL Guide).
This is true on 10g and 11g. To install
@?/rdbms/admin/utlmail.sql
@?/rdbms/admin/prvtmail.plb
scripts should be run as sys and
smtp_out_server
parameter should be set on the spfile with mail_server_ip:port format. "However, if SMTP_OUT_SERVER is not defined, this invokes a default of DB_DOMAIN which is guaranteed to be defined to perform appropriately" (Oracle PL/SQL Guide) and when utl_mail is invoked without smtp_out_server set
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.UTL_MAIL", line 427
ORA-06512: at "SYS.UTL_MAIL", line 664
ORA-06512: at line 1
There are some differences in the configuration before using of utl_mail in 10g and 11g where 11g's enhanced security features such as access control list (ACL) plays a major part in the configuration.

First sending an email using utl_mail on a 10.2.0.5.0 standard edition databases.
SQL> @?/rdbms/admin/utlmail
Package created.
Synonym created.

SQL> @?/rdbms/admin/prvtmail.plb
Package body created.

SQL> alter system set smtp_out_server='xxx.xxx.xx.xx:25' scope=spfile;
restart the database.
Grant execute on utl_mail to user that will be using the utl_mail to send email. Otherwise following error will be thrown
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'UTL_MAIL' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
It's better not to grant execute on utl_mail to public for the same reasons (mainly security) why execute privilege is revoked on utl_smtp,utl_tcp and utl_file (read metalink notes 247093.1 , 234551.1 and 390225.1). "In installing UTL_MAIL, you should take steps to prevent the port defined by SMTP_OUT_SERVER being swamped by data transmissions" (Oracle PL/SQL Guide). Test the configuration by sending an email with
exec Utl_Mail.Send(
Sender => 'senders email',
Recipients => 'recipients email',
subject => 'subject line',
MESSAGE => 'message' );
On 11g some additional steps are required (This was tested with a 11.1.0.7 and 11.2.0.1 standard edition database) Setting up is same as on 10g, run the installation script and set smtp_out_serer parameter. But even after grant execute on utl_mail to user was executed, following error will be thrown when utl_mail is invoked to send an email.
ERROR at line 1:
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 "SYS.UTL_MAIL", line 386
ORA-06512: at "SYS.UTL_MAIL", line 599
ORA-06512: at line 1
Granting execute on utl_tcp and utl_smtp is not going to solve this, moreover execute privileges has no impact on utl_mail, all that is needed is for user to have execute on utl_mail.
Create a ACL with user who is going to invoke utl_mail as the principle and granting connect privilege
begin
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(
Acl => 'utlmailpkg.xml',
Description => 'Normal Access',
Principal => 'ASANGA',
Is_Grant => True,Privilege => 'connect',
Start_Date => Null,
End_Date => Null);
End;
/
Add privileges to resolve hosts
begin
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'utlmailpkg.xml',
principal => 'ASANGA',
is_grant => true,
privilege => 'resolve');
end;
/
Assign the created ACL to the mail server IP and port
begin
dbms_network_acl_admin.assign_acl (
acl => 'utlmailpkg.xml',
host => '192.168.0.10',
lower_port => 25,
upper_port => NULL);
end;
/
At the end of executing above PL/SQL code run a commit; without it changes are not visible to users and access denied error will be thrown.
View the privilges in the ACL with
SELECT DECODE(
DBMS_NETWORK_ACL_ADMIN.check_privilege('utlmailpkg.xml', 'ASANGA', 'connect'),
1, 'GRANTED', 0, 'DENIED', NULL) as "Connect",
DECODE(
DBMS_NETWORK_ACL_ADMIN.check_privilege('utlmailpkg.xml', 'ASANGA', 'resolve'),
1, 'GRANTED', 0, 'DENIED', NULL) as "Resolve"
FROM dual;
After this users can invoke ult_mail to send emails.