Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

How to fix problem with ASM not recognizing multipathed disks after a reboot

After installing ASM 11g on Red Hat 5.5 using the Linux multipath software the disk permissions are not set properly by ASMLib when the system is rebooted. This results in the following error in /var/log/oracleasm:

oracleasm-read-label: Unable to open device "/dev/dm-0": No such file or directory

ASM will not mount the disks and of course the database will not start.

I tried the following:
- I checked that all the correct versions of the ASM RPMs were installed.
- I performed the oracleasm configure, which is supposed to properly set the permissions on reboot.
- I tried setting the ORACLEASM_SCANORDER per the documentation about setting up ASM on Linux Multipath disks [Document Id 602952.1].

None of these things worked.

Finally I added these lines to the top of the script /etc/init.d/oracleasm and the problem is solved:

chown grid:oinstall /dev/dm*
chmod 775 /dev/dm*

Ownership and permissions for ASM devices

When preparing devices for ASM set the following ownership and permissions:

chown <asm owner>:<asmdba group> <device>
chmod 660 <device>


Example:

chown grid:oinstall c5t60060E8006CFCC000000CFCC00000204d0s0
chmod 660 c5t60060E8006CFCC000000CFCC00000204d0s0

Configure Yum on Linux to read from a local repository

This has been tested on Red Hat Linux 5.4.
This example assumes you have an ISO image stored on an NFS volume.

Mount the NFS volume
mount -t nfs <Host Name or IP Address>:/<Path to Directory with ISO> <Local Mount Point>
Example:
mount -t nfs MyVolHost:/isodir /mnt

cd /mnt

Mount the ISO image
mount -o loop image-name.iso /mnt2

Create a local repository file and point it to the ISO image
vi /etc/yum.repos.d/local.repo

[local]
name=Red Hat Local Repository
baseurl=file:///mnt2/Server
enabled=1
gpgcheck=0

From here you should be able to use Yum normally with your local repository.

Configure vi so it doesn't clear screen on Linux

When using Linux I noticed that it clears the screen after quitting out of the file you were editing. If you do not like this behavior here is how to avoid it.

Apparently on most distros of Linux vi is an alias of vim.

Create or edit a file named .vimrc in your home directory and add the following line:

set t_ti= t_te=


Now vi will behave the same on Linux as it does on other flavors of UNIX.

This has been tested on Red Hat 5.

Run UNIX shell script from Stored Procedure via DBMS_SCHEDULER

When you try to run a UNIX shell script directly from DBMS_SCHEDULER it runs as the UNIX owner nobody:nobody, which means it will likely have permissions problems and give the error ORA-27369. It is possible to configure DBMS_SCHEDULER so it will run as the oracle user (Metalink Doc ID 389685.1) but if you can't or don't want to do that you can do this:

First you have to give Java permission to access the script:

begin
dbms_java.grant_permission
('SYS',
'java.io.FilePermission',
'[path]/test.sh',
'execute');

dbms_java.grant_permission
('SYS',
'java.lang.RuntimePermission',
'*',
'writeFileDescriptor' );
end;


After that create the Java procedure itself:

create or replace and compile
java source named "Util"
as
import java.io.*;
import java.lang.*;

public class Util extends Object
{
public static int RunThis(String args)
{
Runtime rt = Runtime.getRuntime();
int rc = -1;

try
{
Process p = rt.exec(args);

int bufSize = 4096;
BufferedInputStream bis =
new BufferedInputStream(p.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];

// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);

rc = p.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
rc = -1;
}
finally
{
return rc;
}
}
}
/


Then a function that calls the java procedure:


create or replace
function RUN_CMD(p_cmd in varchar2) return number
as
language java
name 'Util.RunThis(java.lang.String) return integer';
/


And finally the stored procedure:


create or replace procedure RC(p_cmd in varchar2)
as
x number;
begin
x := run_cmd(p_cmd);
end;
/


After that it can be run from DBMS_SCHEDULER like this:


SQL>BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'MyJob',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN rc(''[path]/test.sh''); END;',
start_date => SYSTIMESTAMP,
end_date => NULL,
enabled => TRUE,
comments => 'UNIX shell script run from stored procedure');
END;
/

PL/SQL procedure successfully completed.



Of course it can also be set up with a schedule, etc. like any other stored procedure.

List all ORACLE_SIDs and their home directories on a server (UNIX)

Look in oratab, typically located in /var/opt/oracle or the /etc directories.

$ more /var/opt/oracle/oratab
#
ora9:/oracle/product/10.2.0/db_1:N
EIC:/oracle/product/10.2.0/db_1:N
cmstdev:/oracle/product/10.2.0/db_1:N

Backup and disable crontab

#!/bin/ksh
export CRONTABFILE=crontab.`date +%m%d%y-%H%M%S`

echo Exporting crontab to $CRONTABFILE

crontab -l > $CRONTABFILE

crontab -r

Set prompt to show current directory (ksh)

PS1="[$LOGNAME@`'hostname'`]"' $PWD>: '
export PS1

Locate the Oracle Inventory Directory

Solaris
$ more /var/opt/oracle/oraInst.loc
inventory_loc=/oracle/oraInventory
inst_group=dba
On Linux the file will be under /etc

Set display for X emulation for installation

DISPLAY=[machine-name]:0.0; export DISPLAY


This may vary by server. A good way to determine the correct value is to connect to the server via Xstart and then to check the value of the DISPLAY variable.

(Telnet connection via Xstart)

Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ echo $DISPLAY
10.177.10.137:1.0