How to set up ssh connection between two servers for user oracle
1. connect to the remote system as user oracle
2. rm -rf $HOME/.ssh
3. /usr/local/bin/ssh-keygen -t dsa -f "$HOME/.ssh/id_dsa" -N ""
or: /usr/bin/ssh-keygen -t dsa -f "$HOME/.ssh/id_dsa" -N ""
4. cd $HOME/.ssh
5. cat id_dsa.pub >> authorized_keys2
6. check local connection, i.e. the following command should now work without having to enter a password (you might have to confirm with "yes" the first time, though):
ssh localhost date
If it doesn't work, i.e. if you're prompted to enter oracle's password, please check ownership and permissions on $HOME, it should owned by oracle:dba with permissions 755, i.e.:
ls -ld $HOME
drwxr-xr-x 10 oracle dba 5120 Jun 26 17:07 /app/oracle
7. Logon to the remote machine as user oracle.
8. Repeat the procedure above
9. When done, put the contents of id_dsa.pub in the other server's autorized_keys2 file.
10. Exchange is now done. You should be able to use ssh in both directions between the servers.
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts
Friday, March 21, 2014
Wednesday, March 12, 2014
How to check that an Oracle database parameter is set in a unix shell script
Probably many ways to do the same thing, but I tend to spool database information to disk, then assign the values found to shell script variables, as in the following example, where I need to determined whether the parameters db_file_name_convert and log_file_name_convert is set in the database:
############################################################### # Check that the db_convert_file_name and log_file_name_convert # are both set. If not, abort script. ############################################################### TRG_DB=${ORACLE_SID} cat << EoF > check_${TRG_DB}_convert_params.sql set termout off set lines 200 set trimspool on set heading off set pages 0 set feedback off set echo off set verify off col name format a30 col value format a40 spool check_${TRG_DB}_convert_params.lst select name,value from v\$parameter where name in ('db_file_name_convert','log_file_name_convert'); exit EoF sqlplus -s / as sysdba @check_${TRG_DB}_convert_params.sql CONV_DATA_FILE_SET=`cat check_${TRG_DB}_convert_params.lst | grep db_file | awk '{print $2}'` CONV_LOG_FILE_SET=`cat check_${TRG_DB}_convert_params.lst | grep log_file | awk '{print $2}'` case ${CONV_DATA_FILE_SET} in '') echo db_file_name_convert is not set. Correct and retry operation.;exit;; *) echo db_file_name_convert is set. Continuing...;; esac case ${CONV_LOG_FILE_SET} in '') echo log_file_name_convert is not set. Correct and retry operation.;exit;; *) echo log_file_name_convert is set. Continuing...;; esac exit
How to receive user response in a korn shell unix script
The following is valid for korn shell but not necessarily in other shell dialects, such as bash:
print -n "Do you want to proceed? [Y/N] "
read answer
[[ $answer == [yY] ]] || { echo "Exiting..."; exit 3; }
print -n "Do you want to proceed? [Y/N] "
read answer
[[ $answer == [yY] ]] || { echo "Exiting..."; exit 3; }
Monday, March 10, 2014
How to set up an alias that quickly shows you the running instances on a Solaris server
Thanks to Mats Strömberg who showed me this little trick on how to use the -o option with ps, to look directly at the command column of the output from ps.
oracle@testserv1:/home/oracle $ alias ri='ps -ef -o comm|grep -v grep|grep ora_[p]mon|sed '"'"'s/ora_pmon_//'"'"'|sort -n' oracle@testserv1:/home/oracle $ ri APITDB01 TESTDB01 TESTDB02 TESTDB03
Tuesday, January 21, 2014
How to use ssh to a Solaris 8 box - overcoming file size limitation
When transferring files to a Solaris 8 server, I have had some difficulties with files larger than 2 GB. The ssh process will simply abort after it has reached the limit.
To work around this problem, use the following syntax instead:
To work around this problem, use the following syntax instead:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # NOTE: if you are transfering dump files to a Solaris 8 box, # you need to tar and pipe the files to the receiving server. # Make sure you cd to the directory first, before attempting # to tar and ssh them. # Vegard K, 25.02.2010 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/usr/bin/bash cd /oracle/datapump/ tar cEf - dmpfile_01.dmp | ssh prodserver1 "cd /oracle/backup/datapump; tar xf -" exit $?
ksh: script that will send alert when flash recovery are is filling up
#!/usr/bin/ksh # Vegard Kasa # 11.07.2013 # # Alert when FRA is filling up... ############################################################################################################# export NOW=`date +\%d.\%m.\%y` export NLS_DATE_FORMAT='DD.MM.YYYY' #################################################################### # Set the script base to either $DBA_ADMIN in case of original build # or $DBA_ADMIN_HOME in case of newer build. #################################################################### if [ -n "${DBA_ADMIN}" ]; then ############## # Original build ############## SCRIPT_BASE=$DBA_ADMIN elif [ -n "${DBA_ADMIN_HOME}" ]; then ################# # Another build # uses different # variable names ################# SCRIPT_BASE=${DBA_ADMIN_HOME} fi cat << EoF > ${SCRIPT_BASE}/sql/get_sum_fra.sql set termout off set trimspool on set verify off set feedback off set echo off set linesize 200 set heading off set pagesize 0 spool ${SCRIPT_BASE}/log/alert_fra_full_${NOW}.log SELECT LTRIM(sum(PERCENT_SPACE_USED)) FROM V\$FLASH_RECOVERY_AREA_USAGE; exit EoF sqlplus -s / as sysdba @${SCRIPT_BASE}/sql/get_sum_fra.sql ########################################################## # Send the output via e-mail to the designated receipients ########################################################## PRC=`cat ${SCRIPT_BASE}/log/alert_fra_full_${NOW}.log` if [ ${PRC} -gt 80 ]; then echo "Warning: In database ${ORACLE_SID}, the FRA is ${PRC} percent used!" |mailx -r monitoring@yourdomain.com -s "FRA usage report for database ${ORACLE_SID}" dba@yourdomain.com fi exit
Tuesday, January 14, 2014
sdtperfmeter - a graphical monitoring of cpu, paging and I/O on Solaris
Create a file called monitor.sh:
#!/usr/bin/bash
/usr/dt/bin/sdtperfmeter -t page &
/usr/dt/bin/sdtperfmeter -t cpu &
/usr/dt/bin/sdtperfmeter -t disk &
exit
Start your X server, set display to your client, then execute in background:
./monitor.sh &
Works on Solaris 10 (and several previous versions)
#!/usr/bin/bash
/usr/dt/bin/sdtperfmeter -t page &
/usr/dt/bin/sdtperfmeter -t cpu &
/usr/dt/bin/sdtperfmeter -t disk &
exit
Start your X server, set display to your client, then execute in background:
./monitor.sh &
Works on Solaris 10 (and several previous versions)
Friday, January 10, 2014
How to retreive information about CPUs on a Solaris server
For analytic purposes when dealing with installations, system validations, database design and performance tuning, you will often need to know hard facts about the CPUs of a server hosting an oracle database. Here are some of my notes on the matter.
Use the psrinfo utility. The flag -p displays the number of physical processors, and the -v flag is for verbose output:
oracle@host1[PRODDB11] psrinfo -pv
The physical processor has 8 virtual processors (0-7)
SPARC64-VII (portid 1024 impl 0x7 ver 0x91 clock 2400 MHz)
The physical processor has 8 virtual processors (8-15)
SPARC64-VII (portid 1032 impl 0x7 ver 0x91 clock 2400 MHz)
Without any argument, psrinfo prints a tabular output of the CPUs(or cores), as follows:
oracle@host1[PRODDB11] psrinfo
0 on-line since 07/18/2011 18:18:57
1 on-line since 07/18/2011 18:19:58
2 on-line since 07/18/2011 18:19:58
3 on-line since 07/18/2011 18:19:58
4 on-line since 07/18/2011 18:19:58
5 on-line since 07/18/2011 18:19:58
6 on-line since 07/18/2011 18:19:58
7 on-line since 07/18/2011 18:19:58
8 on-line since 07/18/2011 18:19:58
9 on-line since 07/18/2011 18:19:58
10 on-line since 07/18/2011 18:19:58
11 on-line since 07/18/2011 18:19:58
12 on-line since 07/18/2011 18:19:58
13 on-line since 07/18/2011 18:19:58
14 on-line since 07/18/2011 18:19:58
15 on-line since 07/18/2011 18:19:58
The utility uname can also be helpful, when executed with the -X flag, which prints expanded system information:
oraoracle@host1[PRODDB11] uname -X
System = SunOS
Node = zus60h-0034
Release = 5.10
KernelID = Generic_137111-04
Machine = sun4u
BusType =
Serial =
Users =
OEM# = 0
Origin# = 1
NumCPU = 16
The prtdiag utility, likewise:
oraoracle@host1[PRODDB11] prtdiag |more
System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M4000 Server
System clock frequency: 1012 MHz
Memory size: 32768 Megabytes
==================================== CPUs ====================================
CPU CPU Run L2$ CPU CPU
LSB Chip ID MHz MB Impl. Mask
--- ---- ---------------------------------------- ---- --- ----- ----
00 0 0, 1, 2, 3, 4, 5, 6, 7 2530 5.5 7 160
00 1 8, 9, 10, 11, 12, 13, 14, 15 2530 5.5 7 160
Use the psrinfo utility. The flag -p displays the number of physical processors, and the -v flag is for verbose output:
oracle@host1[PRODDB11] psrinfo -pv
The physical processor has 8 virtual processors (0-7)
SPARC64-VII (portid 1024 impl 0x7 ver 0x91 clock 2400 MHz)
The physical processor has 8 virtual processors (8-15)
SPARC64-VII (portid 1032 impl 0x7 ver 0x91 clock 2400 MHz)
Without any argument, psrinfo prints a tabular output of the CPUs(or cores), as follows:
oracle@host1[PRODDB11] psrinfo
0 on-line since 07/18/2011 18:18:57
1 on-line since 07/18/2011 18:19:58
2 on-line since 07/18/2011 18:19:58
3 on-line since 07/18/2011 18:19:58
4 on-line since 07/18/2011 18:19:58
5 on-line since 07/18/2011 18:19:58
6 on-line since 07/18/2011 18:19:58
7 on-line since 07/18/2011 18:19:58
8 on-line since 07/18/2011 18:19:58
9 on-line since 07/18/2011 18:19:58
10 on-line since 07/18/2011 18:19:58
11 on-line since 07/18/2011 18:19:58
12 on-line since 07/18/2011 18:19:58
13 on-line since 07/18/2011 18:19:58
14 on-line since 07/18/2011 18:19:58
15 on-line since 07/18/2011 18:19:58
The utility uname can also be helpful, when executed with the -X flag, which prints expanded system information:
oraoracle@host1[PRODDB11] uname -X
System = SunOS
Node = zus60h-0034
Release = 5.10
KernelID = Generic_137111-04
Machine = sun4u
BusType =
Serial =
Users =
OEM# = 0
Origin# = 1
NumCPU = 16
The prtdiag utility, likewise:
oraoracle@host1[PRODDB11] prtdiag |more
System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M4000 Server
System clock frequency: 1012 MHz
Memory size: 32768 Megabytes
==================================== CPUs ====================================
CPU CPU Run L2$ CPU CPU
LSB Chip ID MHz MB Impl. Mask
--- ---- ---------------------------------------- ---- --- ----- ----
00 0 0, 1, 2, 3, 4, 5, 6, 7 2530 5.5 7 160
00 1 8, 9, 10, 11, 12, 13, 14, 15 2530 5.5 7 160
Wednesday, November 27, 2013
How to identify processes that are consuming lots of CPU power
Here is one way to identify processes that are consuming lots of CPU on your sever that I have used successfully in the past.
First, use the mpstat command, which will print the CPU statistics n times with n seconds interval.
For example, mpstat 5 5
would yield the following output:
In the output sample above, 4 of the 5 samples have CPU 0 with
* a combined user time and system time at 100
and
* idle time at 0 (column headings usr, sys, idl).
This indicates that the CPU is completely consumed on this system.
After gathering the data from mpstat, which indicates that the system CPU resources are overtaxed, you can use prstat to identify which processes are consuming the CPU resources.
The prstat -s cpu -n 5 command is used to list the five processes that are consuming the most CPU resources.
* The -s cpu flag tells prstat to sort the output by CPU usage.
* The -n 5 flag tells prstat to restrict the output to the top five processes.
First, use the mpstat command, which will print the CPU statistics n times with n seconds interval.
For example, mpstat 5 5
would yield the following output:
CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 1 0 0 345 224 589 220 0 0 0 799 29 1 0 70 0 1 0 0 302 200 752 371 0 0 0 1191 99 1 0 0 0 0 0 0 341 221 767 375 0 0 0 1301 100 0 0 0 0 0 0 0 411 256 776 378 0 0 0 1313 99 1 0 0 0 0 0 0 382 241 738 363 0 0 0 1163 97 3 0 0
In the output sample above, 4 of the 5 samples have CPU 0 with
* a combined user time and system time at 100
and
* idle time at 0 (column headings usr, sys, idl).
This indicates that the CPU is completely consumed on this system.
After gathering the data from mpstat, which indicates that the system CPU resources are overtaxed, you can use prstat to identify which processes are consuming the CPU resources.
The prstat -s cpu -n 5 command is used to list the five processes that are consuming the most CPU resources.
* The -s cpu flag tells prstat to sort the output by CPU usage.
* The -n 5 flag tells prstat to restrict the output to the top five processes.
prstat -s cpu -n 5 PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP 25906 oracle 2692M 1912M cpu2 0 0 0:34:39 3.1% oracle/11 25472 oracle 133M 130M cpu1 0 0 0:00:47 0.4% emagent/7 8709 oracle 33M 19M cpu28 10 0 0:00:03 0.4% perl/1 19404 root 88M 24M sleep 21 0 141:23:44 0.3% vxconfigd/1 9767 root 5752K 5224K sleep 59 0 0:00:01 0.2% vmstat/1
How to clean away control character from a text file
I found this little example on the internet and saved it as a shorthand - it has come in handy many times. Unfortunately I have forgotten the name of the original author.
When files are sent from windows to unix, you will sometimes see that the when you open the files in a unix text editor has ^M's in them.
For example
lines that have a ^M and no carrage return (and so blend into one). There are two steps to clean this up.
1. replace all extraneous ^M:
:%s/^M$//g
BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that have carriage returns
after them with nothing. (The dollar ties the search to the end of a line)
2. replace all ^M's that need to have carriage returns:
:%s/^M/ /g
Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that didn't have
carriage returns after them with a carriage return.
Voila! Clean file. Map this to something if you do it frequently.
When files are sent from windows to unix, you will sometimes see that the when you open the files in a unix text editor has ^M's in them.
For example
------------------------------------------------------------------ import java.util.Hashtable; ^M import java.util.Properties; ^Mimport java.io.IOException; import org.xml.sax.AttributeList; ^M import org.xml.sax.HandlerBase; ^Mimport org.xml.sax.SAXException; /**^M * XMLHandler: This class parses the elements contained^M * within a XML message and builds a Hashtable^M ------------------------------------------------------------------Notice that some programs are not consistent in the way they insert the line breaks so you end up with some lines that have both a carrage return and a ^M and some
lines that have a ^M and no carrage return (and so blend into one). There are two steps to clean this up.
1. replace all extraneous ^M:
:%s/^M$//g
BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that have carriage returns
after them with nothing. (The dollar ties the search to the end of a line)
2. replace all ^M's that need to have carriage returns:
:%s/^M/ /g
Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that didn't have
carriage returns after them with a carriage return.
Voila! Clean file. Map this to something if you do it frequently.
Friday, November 8, 2013
A good crontab helptext
# Use the hash sign to prefix a comment # +---------------- minute (0 - 59) # | +------------- hour (0 - 23) # | | +---------- day of month (1 - 31) # | | | +------- month (1 - 12) # | | | | +---- day of week (0 - 7) (Sunday=0 or 7) # | | | | | # * * * * * command to be executed
Tuesday, November 5, 2013
How to find the shared memory kernel parameter setting for a Sun Solaris Server
Use the utility prctl:
This corresponds to the setting in /etc/project:
cat /etc/project
18253611008/1024/1024 = 17 GB
prctl -n project.max-shm-memory -i project 110 project: 110: user.oracle NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT project.max-shm-memory privileged 17.0GB - deny - system 16.0EB max denyHere, 17 GB is the shared memory configuration ("privileged").
This corresponds to the setting in /etc/project:
cat /etc/project
system:0:::: user.root:1:::: noproject:2:::: default:3:::: group.staff:10:::: user.oracle:110:Oracle default project:::project.max-shm-memory=(privileged,18253611008,deny)
18253611008/1024/1024 = 17 GB
Tuesday, October 22, 2013
How to delete lines in vi (unix)
d1G = delete to top including current line
Dgg = delete from current line to bottom of file
Dgg = delete from current line to bottom of file
Subscribe to:
Posts (Atom)