Wednesday, October 31, 2012

Using perl modules without root privilege - local libraries

http://stackoverflow.com/questions/2980297/how-can-i-use-cpan-as-a-non-root-user

wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib

echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> .bash_profile

cpanm Module::<module>

Monday, October 29, 2012

How to test any database link for other schema or the whole database?


Even if you have "create any" and "select any" privileges, you still can't directly test or create database links owned by other schemas.
  
SQL> select * from dual@SCHEMA.DBLINK;
select * from dual@
SCHEMA.DBLINK
                   *
ERROR at line 1:
ORA-02019: connection description for remote database not found


But, there are ways to get around it. 

Method 1

By creating an object within the schema like this:

  
SQL> create view SCHEMA.for_dblink_test_only as select * from dual@SCHEMA.DBLINK;

View created.
 

If the database link doesn't work, we'll get the error message, in this example, the database link was pointing to the "old" server:
  
SQL> create view SCHEMA.for_dblink_test_only as select * from dual@SCHEMA.DBLINK_NOWORKING;

ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
 


So, we can generate a script to test all database links:



select 'CREATE VIEW '||owner||'.for_dblink_test_only as select * from dual@'||db_link||';',
'DROP VIEW '||owner||'.for_dblink_test_only;'
from dba_db_links where username is not null;

Or even better, build a procedure to do so.

Method 2: 

If you can get execute privilege on sys.dbms_sys_sql, you can also do it without creating any object:

create procedure execute_sql( p_cmd varchar2, p_user varchar2 )
authid current_user
is
    l_user_id number;
    l_cursor  number;
    l_result  number;
begin
    -- fetch userid
    select user_id into l_user_id
      from dba_users
     where username = p_user;
    -- parse and execute
    l_cursor := sys.dbms_sys_sql.open_cursor;
    sys.dbms_sys_sql.parse_as_user( l_cursor, p_cmd, dbms_sql.native, l_user_id, true );
    l_result := sys.dbms_sys_sql.execute( l_cursor );
    sys.dbms_sys_sql.close_cursor( l_cursor );
end;
/

 


If the database link doesn't work, you'll get:


execute execute_sql('select * from dual@db_link','SCHEMA');


ERROR at line 1:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1306
ORA-06512: at "SYS.EXECUTE_SQL", line 14
ORA-06512: at line 1


If the database link works, you'll get:

execute execute_sql('select * from dual@db_link','SCHEMA');


PL/SQL procedure successfully completed.

Tuesday, October 23, 2012

Network timeout causing ORA-03113: end-of-file on communication channel

If you have this error from your client connections due to network timeout, try to set



SQLNET.EXPIRE_TIME=10

in sqlnet.ora

Basically it "pings" client every 10 minutes, that small packet resets the network timeout clock.

Here's what Oracle says about this parameter:

http://docs.oracle.com/cd/B28359_01/network.111/b28317/sqlnet.htm#BIIEEGJH

5.2.28 SQLNET.EXPIRE_TIME

Purpose
Use parameter SQLNET.EXPIRE_TIME to specify a time interval, in minutes, to send a probe to verify that client/server connections are active. Setting a value greater than 0 ensures that connections are not left open indefinitely, due to an abnormal client termination. If the probe finds a terminated connection, or a connection that is no longer in use, it returns an error, causing the server process to exit. This parameter is primarily intended for the database server, which typically handles multiple connections at any one time.
Limitations on using this terminated connection detection feature are:
  • It is not allowed on bequeathed connections.
  • Though very small, a probe packet generates additional traffic that may downgrade network performance.
  • Depending on which operating system is in use, the server may need to perform additional processing to distinguish the connection probing event from other events that occur. This can also result in degraded network performance.
Default
0
Minimum Value
0
Recommended Value
10
Example
SQLNET.EXPIRE_TIME=10


Tuesday, October 16, 2012

Unix and Dos commands mapping

Not exactly, but sort of, if you need more powerful utilities, using CygWin
Dos commandUnix commandNotes
arparp
assignlnCreate a file link
assignln -sOn Unix, a directory may not have multiple links, so instead a symbolic link must be created with ln -s.
atat, batch,cron
assocfile
attribchown,chmodSets ownership on files and directories
cdcd
cdpwdcd alone prints the current directory.
chkdskfsckChecks filesystem and repairs filesystem corruption on hard drives.
clsclearClear the terminal screen
copycp
datedate
delrm
deltreerm -rRecursively deletes entire directory tree
dirls"dir" also works on some versions of Unix.
doskey /h, F7 keyhistoryThe Unix history is part of the Bash shell.
editvi, emacs, etc.edit brings up a simple text editor in Windows. On Unix, the environment variable EDITOR should be set to the user's preferred editor.
exitexit, Control-DOn Unix, pressing the control key and D simultaneously logs the user out of the shell.
explorernautilus, etc.The command explorer brings up the file browser on Windows.
fcdiff
findgrep
ftpftp
helpman"help" by itself prints all the commands
hostnamehostname
ipconfig /allifconfig -aThe /all option lets you get the MAC address of the Windows PC
mkdirmkdir
memtopShows system status
moremore / less
movemv
net statisticsuptime
nslookupnslookup
pingping
printlprSend a file to a printer.
regeditedit /etc/*The Unix equivalent of the Windows registry are the files under /etc and /usr/local/etc.
rmdirrmdir
rmdir /srm -rWindows has a y/n prompt. To get the prompt with Unix, use rm -i.
setenvPrints a list of all environment variables. For individual environment variables, set <variable> is the same as echo $<variable> on Unix.
set Pathecho $PATHPrint the value of the environment variable using set in Windows.
shutdownshutdownWithout an option, the Windows version produces a help message
reboot, shutdown -rshutdown -r
shutdown -sshutdown -hAlso need -f option to Windows if logged in remotely
sortsort
systeminfouname -a
tasklistps"tasklist" is not available on some versions of Windows. See also this article on getting a list of processes in Windows using Perl



tracerttraceroute
treefind / ls -RUse tree | find "string"
typecat
veruname -a
xcopycp -RRecursively copy a directory tree

Oracle cross platform migration not working as advertised

According Oracle document, you should be able to convert any data file including those for system tablespaces with RMAN, even the ENDIAN format is different,
 
http://docs.oracle.com/cd/E11882_01/backup.112/e10643/rcmsynta012.htm

In Oracle Database 10g and later releases, CONVERT DATAFILE or CONVERT TABLESPACE is required in the following scenarios:
  • Transporting data files between platforms for which the value in V$TRANSPORTABLE_PLATFORM.ENDIAN_FORMAT differs.
  • Transporting tablespaces with undo segments (typically SYSTEM and UNDO tablespaces, but also tablespaces using rollback segments) between platforms, regardless of whether the ENDIAN_FORMAT is the same or different. Typically, the SYSTEM and UNDO tablespaces are converted only when converting the entire database.
  • Other platform specific data files, (like when converting to or from the hp Tru64 operating system), require additional data file conversion .
One use of CONVERT is to transport a tablespace into a database stored in ASM. Native operating system commands such as Linux cp and Windows COPY cannot read from or write to ASM disk groups.


It works well for non-system (actually should say non-undo) files:

RMAN> convert datafile '/dsk01/oradata/TESTDB/users01.dbf'
FROM PLATFORM = 'Solaris[tm] OE (64-bit)'
TO PLATFORM = 'Linux x86 64-bit'
db_file_name_convert '/dsk01/oradata/TESTDB' '/dsk01/oradata/TESTDB_CVT'

Starting conversion at target at 15-OCT-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input file name=/dsk01/oradata/TESTDB/users01.dbf
converted datafile=/dsk01/oradata/TESTDB_CVT/users01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished conversion at target at 15-OCT-12


But not so well for any data files containing undo segments:

RMAN> convert datafile '/dsk01/oradata/TESTDB/system01.dbf'
FROM PLATFORM = 'Solaris[tm] OE (64-bit)'
TO PLATFORM = 'Linux x86 64-bit'
db_file_name_convert '/dsk01/oradata/TESTDB' '/dsk01/oradata/TESTDB_CVT'

Starting conversion at target at 15-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=212 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/dsk01/oradata/TESTDB/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of conversion at target command on ORA_DISK_1 channel at 10/15/2012 15:17:32
ORA-00600: internal error code, arguments: [ktu_format_nr: rbu mgc failed], [640], [32770], [32896], [], [], [], [], [], [], [], []


Oracle has a bug filed about this situation:

Bug 10409625 - ORA-600 [ktu_format_nr: rbu mgc failed] during RMAN convert datafile [ID 10409625.8]    To Bottom   

Description

If an ORA-600 [ktu_format_nr: rbu mgc failed] is raised when using RMAN to
convert datafiles to a different endian then this might be the bug.
 
Check if any of the datafiles belong to the SYSTEM tablespace, or contain
undo blocks. If so, the operation is unsupported and the fix for this bug
will cause a more graceful error message (ORA-19928).
It is fixed in 11.2.0.3 and above. Unfortunately, the fix is just changing the ORA-600 error into a "more graceful error message":

In 11.2.0.3:
RMAN> convert datafile '/dsk01/oradata/TESTDB/system01.dbf'
FROM PLATFORM = 'Solaris[tm] OE (64-bit)'
TO PLATFORM = 'Linux x86 64-bit'
db_file_name_convert '/dsk01/oradata/TESTDB' '/dsk01/oradata/TESTDB_CVT';

Starting conversion at target at 16-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/dsk01/oradata/TESTDB/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of conversion at target command on ORA_DISK_1 channel at 10/16/2012 11:39:17
ORA-19928: CONVERT of data files with undo segments between different endian is not supported.


So, we are out of luck. I'd expect Oracle to implement this in probably release 12.2.