Category Archives: Administration

Changing command prompt in LINUX

1. Logon as the user which you which to change the prompt. NOTE: You have to add this to your .profile file to have it survive reboot. This file is normally located /home/ directory and it is a hidden file so will be preceded by a period.
2. Export a new PS1 value with the text you want: In this example I am using ‘username@machine_name promt’

$export PS1='[\u@mylinux \W ]\$’
[oracle@mylinux ~ ]$

3. This completes changing command prompt on LINUX.
Larry Catt, OCP

Determining SID(s) from Database Server

Oracle Databases implemented on Unix and Linux have a file /etc/oratab file which determines the current SID, Oracle Homes, or
active status which exist on the server, if a proper installation is done. This procedure uses the file to extract
current SID(s).

1. Logon to your Oracle Server as the Oracle software owner.

[root@linux2 ~]# su – oracle
Last login: Wed Oct 5 15:16:55 EDT 2016 on pts/2
[oracle@linux2 ~]$

2. Execute the command: egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print $1}’

[oracle@linux2 ~]$ egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print $1}’
cdb1
[oracle@linux2 ~]$

3. For this system there is only one database with a SID of ‘cdb1’.

Larry Catt
OCP

Determining ORACLE_HOME(s) from Database Server

Oracle Databases implemented on Unix and Linux have a file /etc/oratab file which determines the current SID, Oracle Homes, or
active status which exist on the server, if a proper installation is done. This procedure uses the file to extract
current ORACLE_HOME(s).

1. Logon to your Oracle Server as the Oracle software owner.

[root@linux2 ~]# su – oracle
Last login: Wed Oct 5 15:16:55 EDT 2016 on pts/2
[oracle@linux2 ~]$

2. Execute the command: egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print $2}’

[oracle@linux2 ~]$ egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print $2}’
/opt/app/oracle/product/12.1.0.2/db_1
[oracle@linux2 ~]$

3. For this system there is only one database with a ORACLE_HOME of ‘/opt/app/oracle/product/12.1.0.2/db_1’.

Larry Catt
OCP

Determine the release of linux you are using

How determine what linux, you have installed.

Options:

1. Via release files in /etc directory.

[root@mylinux /# cat /etc/*-release
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Oracle Linux Server release 6.5
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Oracle Linux Server release 6.5
[root@mylinux /]#

2. Via lsb_release command.

[root@mylinux /]# lsb_release
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
[root@mylinux /]#

3. Via /proc/version file

[root@mylinux /]# cat /proc/version
Linux version 3.8.13-35.1.1.el6uek.x86_64 (mockbuild@ca-build44.us.oracle.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #2 SMP Fri Jun 6 10:52:33 PDT 2014
[root@mylinux /]#

Larry Catt
OCP

Set Linux Network Adapters to startup automatically

1. Logon as the root user to your Linux Server.

[larry@linux1 ~]$ sudo su
[root@linux1 larry]#

2. Execute the command: ip -o link show | awk -F’: ‘ ‘{print “ip link set dev “$2″ up”}’ >ip_up.sh

[root@linux1 larry]# ip -o link show | awk -F’: ‘ ‘{print “ip link set dev “$2″ up”}’ >ip_up.sh
[root@linux1 larry]#

3. Change Permission to 775 on file ip_up.sh

[root@linux1 larry]# chmod 770 ip_up.sh
[root@linux1 larry]#

4. Execute file ip_up.sh

[root@linux1 larry]# ./ip_up.sh
[root@linux1 larry]#

5. Execute the command:

find /etc/sysconfig/network-scripts -name “ifcfg-*” -not -name “*bak”| awk -F’: ‘ ‘{print “perl -pi.bak -e ‘”‘”‘s/ONBOOT=no/ONBOOT=yes/g'”‘”‘ “$1}’ > net_ifcfg_update.sh

6. Change the permissions to 775 on file net_ifcfg_update.sh.

[root@linux1 ~]# chmod 775 net_ifcfg_update.sh
[root@linux1 ~]#

7. Execute file net_ifcfg_update.sh.

[root@linux1 ~]# ./net_ifcfg_update.sh
[root@linux1 ~]#

8. Now restart your linux server with the command: reboot.

[root@linux1 larry]# reboot

9. This completes changing your Network adapters to automatically start at system start.

Larry Catt, OCP

Rename LINUX Server

1. Logon as the root user to your Linux Server.

[larry@localmachine ~]$ su –
Password:
Last login: Thu Jun 11 12:29:24 EDT 2017 on pts/1
[root@localmachine ~]#

2. You must edit the file /etc/hostname to change the local machine name. You can generate a statement to update /etc/hostname with the following bash command:

cat /etc/hostname | awk -F. ‘{print “\n\n perl -pi.bak -e ‘”‘”‘s/”$1″//g'”‘”‘ /etc/hostname”}’

[root@localmachine ~]# cat /etc/hostname | awk -F. ‘{print “\n\n perl -pi.bak -e ‘”‘”‘s/”$1″//g'”‘”‘ /etc/hostname”}’

perl -pi.bak -e ‘s/localmachine//g’ /etc/hostname
[root@localmachine ~]#

3. Take the resulting string and replace the text with the name of the machine you wish for your server.

Original Perl Command output:
perl -pi.bak -e ‘s/localmachine//g’ /etc/hostname

Edited Perl Command output: (New Server Name)

perl -pi.bak -e ‘s/localmachine/linux1/g’ /etc/hostname

[root@localmachine ~]# perl -pi.bak -e ‘s/localmachine/linux1/g’ /etc/hostname
[root@localmachine ~]#

4. Reboot your Linux Server.

[root@localmachine ~]# reboot

5. Logon to your Linux Server after reboot completes and see new name of Server with command: hostname.

[larry@linux1 ~]$ su –
Password:
Last login: Thu Jun 11 14:31:50 EDT 2017 from 10.30.15.69 on pts/1
[root@linux1 ~]# hostname
linux1.localdomain
[root@linux1 ~]#

6. This completes changing LINUX Server name.

Larry Catt, OCP

Current sid and serial# of a session from SQL*PLUS

1. From within Oracle SQL*Plus session.

2. Using the userenv(‘SESSIONID’) to retrieve current sid and serial#.

select sid, serial# from v$session where audsid=userenv(‘SESSIONID’);

SQL> select sid, serial# from v$session where audsid=userenv(‘SESSIONID’);

SID SERIAL#
———- ———-
408 16328

SQL>

3. Note: That logging out of SQL*Plus session or reconnecting will change your SID and SERIAL#.

Larry Catt
OCP

Creating new undo tablespace 11g

Error:

ORA-01578: ORACLE data block corrupted (file # 3, block # 136)
ORA_01110: data file 3: ‘/u01/oradata/ORCL/UNDOTBS01.DBF’

This procedure replaces the current UNDO tablespace which contains a corrupted block with a new clean tablespace.

1. Startup database in nomount mode.

SQL> startup nomount
ORACLE instance started.
Total System Global Area 1.2761E+10 bytes
Fixed Size 2240256 bytes
Variable Size 8388608256 bytes
Database Buffers 4362076160 bytes
Redo Buffers 7634944 bytes
SQL>

2. Verify that you are using an spfile and not a pfile for your system paramaters.

SQL> show parameter spfile
NAME TYPE VALUE
———————————— ———– ——————————
spfile string
SQL>

2a. If parameter spfile has a value, continue to step 3, if it does not perform 2b through 2e.

2b. Execute ‘create spfile’ command:

SQL> create spfile from pfile;
File created.
SQL>

2c. Shutdown the oracle instance.

SQL> shutdown
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>

2d. Startup the oracle instance in nomount mode.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 1.2761E+10 bytes
Fixed Size 2240256 bytes
Variable Size 8388608256 bytes
Database Buffers 4362076160 bytes
Redo Buffers 7634944 bytes
SQL>

2e. Verify the use of spfile with the show command.

SQL> show parameter spfile

NAME TYPE VALUE
———————————— ———– ——————————
spfile string /opt/app/oracle/ORCL_db/dbs/sp
fileORCL.ora
SQL>

3. Get the values for parameters undo_management and undo_tablespaces.

SQL> show parameter undo_management

NAME TYPE VALUE
———————————— ———– ——————————
undo_management string AUTO
SQL> show parameter undo_tablespace

NAME TYPE VALUE
———————————— ———– ——————————
undo_tablespace string UNDOTBS1
SQL>

4. Change the undo_management setting to manual.

SQL> alter system set undo_management=manual scope=spfile;
System altered.
SQL>

5. Mount and Open the database instance.

SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.
SQL>

6. Create new undo tablespace.

SQL> create undo tablespace undotbs02 datafile ‘/u02/oradata/ORCL/UNDOTBS02.DBF’ size 5G;

Tablespace created.
SQL>

7. alter parameter undo_tablespace to undotbs02.

SQL> alter system set undo_tablespace=undotbs02 scope=spfile;
System altered.
SQL>

8. alter parameter undo_management to auto.

SQL> alter system set undo_management=auto scope=spfile;
System altered.
SQL>

9. Shutdown and startup the oracle instance.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1.2761E+10 bytes
Fixed Size 2240256 bytes
Variable Size 8388608256 bytes
Database Buffers 4362076160 bytes
Redo Buffers 7634944 bytes
Database mounted.
Database opened.
SQL>

10. Check parameters undo_management and undo_tablespaces.

SQL> show parameter undo_management

NAME TYPE VALUE
———————————— ———– ——————————
undo_management string AUTO
SQL> show parameter undo_tablespace

NAME TYPE VALUE
———————————— ———– ——————————
undo_tablespace string UNDOTBS02
SQL>

That completes changing undotablespaces in 11g

Larry Catt
OCP

Finding SCN for Oracle Database by Date and time

Oracle provides the function TIMESTAMP_TO_SCN to determine the database SCN number for a given time. This is very useful in performing multiple Oracle Administrative tasks. This procedure explains the use of this function to extract SCN.

1. Logon to Oracle Database server as the Oracle software owner and start SQLPLUS.

[root@linux2 etc]# su – oracle
Last login: Thu Jun 1 09:25:23 EST 2017 on pts/1
[oracle@linux2 ~]$
[oracle@linux2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 1 13:47:01 2017

Copyright (c) 1982, 2014, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

2. Determine Oracle SCN one hour ago by specifying sysdate-1/24

SQL> select timestamp_to_scn(sysdate-1/24) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1/24)
——————————
5062307

SQL>

3. Determine Oracle SCN 1 day ago by specifying sysdate-1

SQL> select timestamp_to_scn(sysdate-1) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1)
—————————
4975332

SQL>

4. Determine Oracle SCN 1 week ago by specifying sysdate-7

SQL> select timestamp_to_scn(sysdate-7) from dual;

TIMESTAMP_TO_SCN(SYSDATE-7)
—————————
4696226

SQL>

5. Determine Oracle SCN by specific date time by using the to_date() function with appropriate date mask.

SQL> select timestamp_to_scn(to_date(’25-MAY-2017 06:30:00′,’DD-MON-YYYY HH24:MI_SS’)) from dual;

TIMESTAMP_TO_SCN(TO_DATE(’25-MAY-201706:30:00′,’DD-MON-YYYYHH24:MI_SS’))
————————————————————————
4696226

SQL>

6. This completes the use of the function TIMESTAMP_TO_SCN.

Larry Catt
OCP