Friday, September 11, 2020

Oracle 18c New Features

 Oracle 18c New Features


Introduction


In this blog i am going to explain three new Oracle 18c New Features which is useful for oracle database administrators 

SET ROWLIMIT 

ORAVERSION UTILITY

SET FEEDBACK OPTION


SET ROWLIMIT command enables users to set a limit for the number of rows displayed for a query.


for limiting number  of rows to 5 in Oracle 18c New Features


SQL> set rowlimit 5

SQL> select username from dba_users;



USERNAME

—————————

SYS

SYSTEM

ABHIRAM

CHAITANYA

MANASA


5 rows selected. (rowlimit reached)


for limiting number  of rows to 3

SQL> set rowlimit 3

SQL> select username from dba_users;



USERNAME

————————

SYS

SYSTEM

CHAITANYA


3 rows selected. (rowlimit reached)



Oraversion Utility in Oracle 18c New Features


A new utility Oraversion has been introduced in Oracle 18c New Features Which provides Oracle database version/release related information.


oraversion -help


This program prints release version information.


These are its possible arguments:


-compositeVersion: Print the full version number: a.b.c.d.e.

-baseVersion: Print the base version number: a.0.0.0.0.

-majorVersion: Print the major version number: a.

-buildStamp: Print the date/time associated with the build.

-buildDescription: Print a description of the build.

-help: Print this message.


$ oraversion -compositeVersion

18.3.0.0.0

 

$ oraversion -baseVersion

18.0.0.0.0

 

$ oraversion -majorVersion

18

 

$ oraversion -buildStamp

180628094320

 

$ oraversion -buildDescription

Release_Update



In Oracle 18c New Features, we can display the sql_id of the sql queries we are running using set feedback option.


By default it will be OFF.


SQL> set feedback ON SQL_ID

SQL> select name from v$database;


NAME

———

ORA18C


1 row selected.


SQL_ID: 0btb065ytg2v0 –  > This is the sql_id of the query . 



Note : Info on  Oracle 18c New Features it maybe differ in your environment like production,testing,development etc and naming conventions


THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME 

Thursday, September 10, 2020

Crontab Linux

Crontab Linux


Introduction:

Crontab Linux system has a useful task scheduler named crontab, to automate the scheduled to run the process as a Root, the Unix Scheduling tool, The Cron tab commands opens the cron table for editing.The cron table is the list of tasks scheduled to run at regulartime intervals on the system

The Daemon which reads the crontab and executes the commands at the right time is called Crontab Linux for instance you can automate like backup,schedule updates andsynchroniztion files and many more


In Crontab Linux Oracle DBA jobs to be managed


Analyze Database


Rman backups


Datapump jobs


Hot/cold backups


Archive log backups


House keeping jobs --Cleaning alert log/Trace files


Gathering stats


Delete old log files


Send out any notification email such as newsletter,passwords,expiration mail


Regular cleaned up of cached data


Crontab Linux is used to automate sytem mainatanace




Let us Start the process


Crontab Linux Format


MIN   HOUR   DOM  MON   DOW   CMD




Field Description     Allowed Value


MIN Minute field      0 to 59

HOUR Hour field       0 to 23

DOM Day of Month       1-31

MON Month field        1-12

DOW Day Of Week          0-6

CMD Command       Any command to be executed.


 

chaitanyaoracledba blog


Asterics(*) : use for matching


Define Range : Allows you to define range with the help of hypen like 1-10 or 30 -40 or jan-mar,mon-wed


Define Multiple Ranges: Alows you to define various ranges with command separated like apr-jun,oct-dec



Crontab Linux Commands



How to Add /Modify crontab job  with the help of cron tab command


$ crontab -u -e 



To List the Crontab jobs 


$ crontab -l



To Remove the Crontab tasks 


$ crontab -r


To add or update job in crontab 


$ crontab -e


Command to edit others users crontab


$ crontab -u username -e


Command to view crontab entries of current user


$ crontab -l


Command to view crontab entries of a specific user


crontab -u username -l



Here Some of the Crontab Examples



Crontab Linux to do the various scheduling jobs. Below given command execute at 7 AM and 5 PM daily.


0 7,17 * * * /orabackup/scripts/scriptjob.sh



Command to execute a cron after every 5 minutes.


*/5* * * * * /orabackup/scripts/scriptjob.sh



Cron scheduler command helps you to execute the task on every Monday at 5 AM. This command is helpful for doing weekly tasks like system clean-up.


0 5 * * mon  /orabackup/scripts/scriptjob.sh


Command run your script on 3 minutes interval.


*/3 * * * * /orabackup/scripts/scriptjob.sh



Command to schedule a cron to which executes for a specific month. This command to run tasks run in Feb, June and September months. Sometimes we need to schedule a task to execute a select monthly task.


* * * feb,jun,sep * /orabackup/scripts/scriptjob.sh


Command to execute on selected days. This example will run each Monday and Wednesday at 5 PM.


0 17 * * mon,wed  /orabackup/scripts/scriptjob.sh


This command allows cron to execute on first Saturday of every month.


0 2 * * sat  [ $(date +%d) -le 06 ] && /orabackup/scripts/scriptjob.sh



Command to run a script for 6 hours interval so it can be configured like below.


0 */6 * * * /orabackup/scripts/scriptjob.sh



This command schedule a task to execute twice on Monday and Tuesday. Use the following settings to do it.


0 4,17 * * mon,tue /orabackup/scripts/scriptjob.sh



Command schedule a cron to execute after every 15 Seconds.


* * * * * /orabackup/scripts/scriptjob.sh

* * * * *  sleep 15; /orabackup/scripts/scriptjob.sh



Command to schedule tasks on a yearly basis.

@yearly timestamp is= to "0 0 5 1 *". This executes the task in the fifth minute of every year. You can use it to send for new year greetings.



@yearly /orabackup/scripts/scriptjob.sh



Command tasks to execute on a monthly basis.

@monthly timestamp is similar to "0 0 1 * *". This command expression allows the execution of a task in the first minute of the month.


@monthly /orabackup/scripts/scriptjob.sh



Command to execute multiple tasks using a single cron.


* * * * * /orabackup/scripts/scriptjob.sh; /orabackup/scripts/scriptjob2.sh



Command to schedule tasks to execute on a weekly basis.

@weekly timestamp is similar to "0 0 4 * sun". This is used to perform the weekly tasks like the system cleanup etc.


@weekly /bin/orabackup/scripts/scriptjob.sh



Task will be scheduled to execute on a daily basis.

@daily timestamp is similar to "0 2 * * *". It executes the task in the second minute of every day.


@daily /orabackup/scripts/scriptjob.sh



Allows tasks to execute on an hourly.

@hourly timestamp is similar to "0 * * * *". This command executes a task in the first minute of every hour.


@hourly /orabackup/scripts/scriptjob.sh


Allows tasks to execute on system reboot.

@reboot expression is useful for those tasks that the system wants to run on your system startup. This is helpful to begin tasks background automatically.


@reboot /orabackup/scripts/scriptjob.sh



we use shell scripts to create jobs


.sh /.ksh (types of shell are korn(IBM-AIX) / bash (linux c shell)


scripts in /orabackup/scripts


Sample Scenario



32  11  *  *  */orabackups/script/scriptjob.sh


create the script


$ vi scriptjob.sh


#!/bin/sh


find /archives/prod-name " *.arc" -mtime +1-exec gzip{ }\;


find /archives/prod-name " *.gz"  mtime +7 -exec rm-rf{ }\;


now save  :wq!



Give execution permission


$ chmod +x scriptjob.sh


edit the crontab


$ crontab -e


# give an entry as follows 


30  11  4  6  *  / orabackup/script/scriptjob.sh


then save it




*   *  *  *  *  * command to executed


Min  (0-59)


  Hour      (0-23)


     Day of Month  (1-31)


               month        (1-12)


       Day of the week   (0-6)  (0/7 is sunday  sunday =0 or7)



Note : Info on Crontab Linux it may be differ in yourenvironment like production,testing,development and naming conventions etc



THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME


Wednesday, September 9, 2020

Shell Script Basics

 Shell Script Basics


Let us start the process in this Blog i am going to explain  Shell Script Basics and shell script  if condition statement ,else if condition statement, and or operators in bash shell 

Introduction

Shell: When ever you login to  a unix system you are placed in a program called the shell acts as a command interpreter , it takes each command and passes it to the operating system kernel to be acted upon it then displays the results of this operation on completion on your screen


DIFFERENT FLAVOURS OF SHELL IN UNIX


Bourne Shell: Bourne Shell scripts to specify the shell to use for the scripts. The default prompt on the Unix for this is $

#!/bin/bsh


C Shell:C Shell Scripts to specify the shell to use for the scripts.The default prompt on the Unix for this is %,  

#!/bin/csh


Korn Shell: Korn Shell Scripts  to specify the shell to use for the scripts.The default prompt on the Unix for this is $,

#!/bin/ksh



Shell Script: Shell Scripts collection of command which are executed in a order given. There are conditional statement and looping also available like if ,while which helps in finding if a particular value is greater than another value .


To write any comments in the shell scripts ,it has to be written with # preceded


Example


# Author of the script is


There are some variables Shell Script Basics which are set internally by the shell and which are available to the user


$1 – $9 Variables are the positional parameters.


$0 Name of the command currently being executed.


$# Number of positional arguments given to this invocation of the shell.


$? Exit status of the last command executed is given as a decimal string. When a command completes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status.


$$ Process number of this shell – useful for including in filenames, to make them unique.


$! Process id of the last command run in the background.


$* String containing all the arguments to the shell, starting at $1.


Shell scripts and functions are both interpreted. This means they are not compiled.


Commands in Shell


All shell have a number of built in command which are executed in the shell owns process like echo ,cd,  when you enter a command first it will check the built in shell command echo or cd  or it is directly interpreted by the shell,if the command begins with  / shell assumes that command is absolute path name.

unix commands are executabale binary files located in directories with the name bin (for binary) many of the commands that are located in the directory /usr/bin.



Typical path variable might be 


/bin:/usr/bin:/usr/local/utils/bin:$HOME/bin



Shell Script Example


cat chaitanya.sh


#Written by ChaitanyaOracleDbaBlog


TODAY=date '+%m%d%y_%H%M'


echo "This is Chaitanya  at" $TODAY



The Name of each script must reflect its use,and each script must have a suffix that describes the what type of script it is “.sh” for Bourne shell ,“.ksh” for Korn shell or “.cgi” for Common Gateway Interface scripts


Lets start the first shell script


#!/bin/ksh   # This script displays the date, time, username and

# current directory.

# Author Chaitanya

echo "Current date and time is:"

date

echo

echo "Your username is: `whoami` \\n"

echo "Your current directory is: \\c"

pwd echo "Your system name is :`hostname`\\n"   



How to execute the shell script 


Once the shell scripts are created ,they can be executed in two ways 


1. We specify the shell type and then the script name 


 sh  chaitanya.sh



2.We change the permission of the shell scripts to perform execution


 chmod  +x chaitanya.sh


 ./ chaitanya.sh



Bash if statement syntax


1.Bash if ...then..fi statement


if [ conditional expression ]


then

statement1

statement2

.

fi


Bash if then fi example


#!/bin/bash

count=300


if [ $count -eq 300 ]


then


  echo "The Count is 300"


fi


2. Bash if ..then..else..fi statement  syntax


If [ conditional expression ]


then

statement1

statement2

.

else

statement3

statement4

.

fi


Bash if ..then..else..fi statement  Example


#!/bin/bash


count=299


if [ $count -eq 300 ]


then


  echo " The Count is 300"


else


  echo "The Count is not 300"


fi



3. Bash If....elif...else..fi statement syntax


If [ conditional expression1 ]


then

statement1

statement2

.

elif [ conditional expression2 ]


then

statement3

statement4

.

else

statement5


fi


Bash If....elif...else..fi statement Example


#!/bin/bash


count=299


if [ $count -eq 300 ]


then


  echo "Count is 300"


elif [ $count -gt 300 ]


then


  echo "Count is greater than 300"


else


  echo "Count is less than 300"


fi


4. Bash If..then..else..if..then..fi..fi.. syntax



If [ conditional expression1 ]


then

statement1

statement2

.

else

if [ conditional expression2 ]


then

statement3

.

fi

fi


Bash If..then..else..if..then..fi..fi.. Example


#!/bin/bash


count=299


if [ $count -eq 300 ]


then


  echo " The Count is 300"

else

  if [ $count -gt 300 ]


  then


    echo "The Count is greater than 300"


  else


  echo "The Count is less than 300"


  fi


fi



Test for numbers


-eq ------->   equal to--------->   x==y


-ge-------->  greater than or equal to--->  x>=y


-gt --------> greater than    -----> x>y     


-le ---------> less than or equal to  ------>   x<=y


-lt ---------> less than------> x<y


-ne ---------> not equal to ---->   x!=y     



AND and OR  operator 


&& ------> This stand for AND condition( if both the conditions are true then whole Condition will be true)


[[ $1 == yes && -r $1.txt ]]


|| --------> This stand for OR condition (if only one Condition is true then whole Condition will be true


[[ $1 == yes || -r $1.txt ]]




Note : Info on Shell Script Basics it may be differ in your environment like production,testing,development  and naming conventions etc



THANKS FOR VIEWING MYBLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME

Tuesday, September 8, 2020

NID Utility in Oracle Database to Change DBID or DBNAME or Both

 

NID Utility in Oracle Database to Change DBID or DBNAME or Both


Introduction


In this Blog i am going to explain NID Utility in Oracle Database to Change DBID or DBNAME or Both The DBNEWID(NID) utility is introduced in oracle database this NID commands is the oracle program  that changes the SID of the database to use this utility we need SYS Account Password and the new SID for the Database


The NID utility in oracle always  you to change only the DBNAME or DBID or both DBNAME and DBID in the same command


Let us Start the Process NID Utility in Oracle Database to Change DBID or DBNAME or Both


CHANGE ONLY THE DBID USING NID UTILITY


Here we will only changing the DBID of the oracle database


Step 1: Backup Database

 rman target /

 backup database;

 exit



Step2:  Shutdown Immediate

sqlplus / as sysdba

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>exit



Step 3: Startup mount

sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.

SQL> exit


Step 4: Open in one session and run NID utility(DBNEWID) with sysdba privileges to change the DBID


nid TARGET=SYS/password@proddb


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

 

Password:

Connected to database  PRODDB(DBID=466474)

 

Connected to server version 11.2.0

 

Control Files in database:

    +DATA/PRODDB/control01.ctl

    +FLASH/PRODDB/control02.ctl

   

 

Change database ID ? (Y/[N]) => Y

 

Proceeding with operation

Changing database ID from 466474 to 466474424

 


Database ID for database PRODB changed to 466474424

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open database with RESETLOGS option.

Successfully changed database  ID.

DBNEWID - Completed successfully.



Step 5: Start up the database with open resetlogs

sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.


SQL> alter database open resetlogs;




CHANGE ONLY THE DBNAME


Here we will changing  only the DBNAME in oracle database

 

Step1: Backup Database


rman target /

backup database;

exit


Step 2 : shutdown Immediate


sqlplus / as sysdba


SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>exit


Step 3: Startup mount


sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.

SQL> exit


Step 4: Open one session and run NID with sysdba privilege


nid TARGET=SYS/password@chaitu_123 DBNAME=proddb2 SETNAME=Y

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

 

Password:

Connected to database PRODDB (DBID=466474)

 

Connected to server version 11.2.0

 

Control Files in database:

    +DATA/PRODDB/control01.ctl

    +FLASH/PRODDB/control02.ctl

   

 

Change database name ? (Y/[N]) => Y

 

Proceeding with operation

Database name changed to PRODDB2

 

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database name.

DBNEWID - Completed succesfully.


The value of the DBNAME is the new db_name of the database


SETNAME must be set to Y .the default is N and causes the DBID to be changed also



Step 5: Set the DB_NAME initialization paramater in the initialization parameter file to the new database name


Step 6: Create a new password file using orapwd


Step 7: Startup the database (with resetlogs)


sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.



CHANGE BOTH DBID AND DBNAME


Here we will change the both DBID and DBNAME in oracle database


Step 1: Backup Database


rman target /

backup database;

exit


Step 2: shutdown immediate


sqlplus / as sysdba


SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>exit


Step 3: startup mount


sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.

SQL> exit


Step 4: Open one session and run NID with sysdba privilige


nid TARGET=SYS/password@chaitu_123 DBNAME=proddb2


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


Password:

Connected to database PRODDB (DBID=466474)


Connected to server version 11.2.0


Control Files in database:

+DATA/PRODDB/control01.ctl

+FLASH/PRODDB/control02.ctl



Change database name and ID ? (Y/[N]) => Y


Proceeding with operation

Database name changed to PRODDB2

Modify parameter file and generate a new password file before restarting.

Database ID for database EXPTEST_DB2 changed to 466474424

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open database with RESETLOGS option.

Successfully changed database name and ID.

DBNEWID - Completed successfully.


the value of the DBNAME is the new dbname of the database


Step 5: After DBNEWID sucessfully changes the DBID ,shutdown immediate


Step 6: Set the DB_NAME initilation parameter in the initilization parameter file to the new database name


Step 7: Create the new password file with orapwd


Step 8: Startup the database with open resetlogs


sqlplus / as sysdba


SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 3764747643 bytes

Fixed Size                  1253583 bytes

Variable Size             357873300 bytes

Database Buffers          243860700 bytes

Redo Buffers                6471103 bytes

Database mounted.


SQL> alter database open resetlogs;


Note: Info on NID Utility in Oracle Database to Change DBID or DBNAME or Both it may be differ in your environment like production,testing,development etc and naming conventions 


THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOWMEOR SUBSCRIBE ME

Monday, September 7, 2020

Lock Account Automatically with INACTIVE_ACCOUNT_TIME


Lock Account Automatically with  INACTIVE_ACCOUNT_TIME



Introduction


In Oracle 12.2 Release We can use the INACTIVE_ACCOUNT_TIME resource parameter in profile to automatically lock the account of a database user who has not logged in to the database instance in a specified number of days.In Production database or Testing database or Development database


1. By default, it is set to UNLIMITED.

2. The minimum setting is 15 and the maximum is 24855.



SQL> select RESOURCE_NAME,limit from dba_profiles where profile='DEFAULT';

 

RESOURCE_NAME                               LIMIT

------------------------------------------- -----------------------

COMPOSITE_LIMIT                                UNLIMITED

SESSIONS_PER_USER                            UNLIMITED

CPU_PER_SESSION                             UNLIMITED

CPU_PER_CALL                                   UNLIMITED

LOGICAL_READS_PER_SESSION                   UNLIMITED

LOGICAL_READS_PER_CALL                      UNLIMITED

IDLE_TIME                                        UNLIMITED

CONNECT_TIME                                UNLIMITED

PRIVATE_SGA                                     UNLIMITED

FAILED_LOGIN_ATTEMPTS                       10

PASSWORD_LIFE_TIME                          180

PASSWORD_REUSE_TIME                         UNLIMITED

PASSWORD_REUSE_MAX                          UNLIMITED

PASSWORD_VERIFY_FUNCTION                    NULL

PASSWORD_LOCK_TIME                          1

PASSWORD_GRACE_TIME                         7

INACTIVE_ACCOUNT_TIME                       UNLIMITED ----------- > This is the resource_name introduced in oracle 12.2.

 

17 rows selected.

 


To make an account lock automatically after 30 days of inactivity, Create a profile by setting INACTIVE_ACCOUNT_TIME to 30 and Set the profile to that user.


 

   CREATE PROFILE "ENDUSERINACTIVE"

    LIMIT

         COMPOSITE_LIMIT UNLIMITED

         SESSIONS_PER_USER UNLIMITED

         CPU_PER_SESSION UNLIMITED

         CPU_PER_CALL UNLIMITED

         LOGICAL_READS_PER_SESSION UNLIMITED

         LOGICAL_READS_PER_CALL UNLIMITED

         IDLE_TIME UNLIMITED

         CONNECT_TIME UNLIMITED

         PRIVATE_SGA UNLIMITED

         FAILED_LOGIN_ATTEMPTS 10

         PASSWORD_LIFE_TIME 1552000/86400

         PASSWORD_REUSE_TIME UNLIMITED

         PASSWORD_REUSE_MAX UNLIMITED

         PASSWORD_VERIFY_FUNCTION NULL

         PASSWORD_LOCK_TIME 86400/86400

         PASSWORD_GRACE_TIME 604800/86400

         INACTIVE_ACCOUNT_TIME 30;

 

SQL>  select RESOURCE_NAME,limit from dba_profiles where profile='ENDUSERINACTIVE' and resource_name='INACTIVE_ACCOUNT_TIME';

 

RESOURCE_NAME                               LIMIT

-------------------------------------------   -----------------------

INACTIVE_ACCOUNT_TIME                       30

 

SQL> CREATE USER chaitanya identified by chaitanya123 profile ENDUSERINACTIVE;

 

User created.


If you try to give a value less than 15, it will throw error like – ORA-02377: invalid profile limit INACTIVE_ACCOUNT_TIME

 

   CREATE PROFILE "ENDUSERINACTIVE"

    LIMIT

         COMPOSITE_LIMIT UNLIMITED

         SESSIONS_PER_USER UNLIMITED

         CPU_PER_SESSION UNLIMITED

         CPU_PER_CALL UNLIMITED

         LOGICAL_READS_PER_SESSION UNLIMITED

         LOGICAL_READS_PER_CALL UNLIMITED

         IDLE_TIME UNLIMITED

         CONNECT_TIME UNLIMITED

         PRIVATE_SGA UNLIMITED

         FAILED_LOGIN_ATTEMPTS 10

         PASSWORD_LIFE_TIME 15552000/86400

         PASSWORD_REUSE_TIME UNLIMITED

         PASSWORD_REUSE_MAX UNLIMITED

         PASSWORD_VERIFY_FUNCTION NULL

         PASSWORD_LOCK_TIME 86400/86400

         PASSWORD_GRACE_TIME 604800/86400

         INACTIVE_ACCOUNT_TIME 10;

 

   CREATE PROFILE "ENDUSERINACTIVE"

*

ERROR at line 1:

ORA-02377: invalid profile limit INACTIVE_ACCOUNT_TIME


Note: Info On Lock Acoount Automatically with INACTIVE_ACCOUNT_TIME it may be differ in your environment like production,testing ,development and naming conventions etc



THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME

 

ORA-12985 Tablespace Users is Read Only, Cannot Drop Column

 ORA-12985 Tablespace Users is Read Only, Cannot Drop Column 


Introduction



If you try to Drop a column from a table in a read only ,you got an error like this ORA-12985 Tablespace Users is Read Only, Cannot Drop Column if you really drop the column ,you must put the tablespace into READ WRITE mode  



Probem:


While dropping a column, in a paticular owner and particlar object below got an errorORA-12985 Tablespace Users is Read Only, Cannot Drop Column ,while drop a column in tablespace


 SQL> alter table chaitanyadba.master03 drop (OWNER,OBJECT_NAME);

alter table chaitanyadba.master03 drop (OWNER,OBJECT_NAME)

*

ERROR at line 1:

ORA-12985 Tablespace Users is Read Only, Cannot Drop Column 



Now let us Start the process to find out the Solution



The Object which is trying to drop belongs to a table sapce is in read only mode



Step 1 : Find the tablespace of that particular table


SQL> select tablespace_name from dba_segments where segment_name='MASTER03';

 

TABLESPACE_NAME

------------------------------

USERS



Step 2 : Find the staus of the tablespace



SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='USERS';

 

TABLESPACE_NAME                STATUS

------------------------------ --------------------

USERS                                       READ ONLY

 


Step 3: Inorder to Drop a column ,We need to make the tablespace READ and WRITE mode only  



SQL> ALTER TABLESPACE users READ WRITE;

 

Tablespace altered.

 

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='USERS';

 

TABLESPACE_NAME                STATUS

------------------------------ ------------------

USERS                                          ONLINE

 

SQL> alter table chaitanyadba.master03 drop (OWNER,OBJECT_NAME);

 

Table altered.



Note : Info on ORA-12985 Tablespace Users is Read Only, Cannot Drop Column  it may differin your environment like production,testing,development and naming conventions etc



THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME

 

 

Sunday, September 6, 2020

How to Kill a Session In Oracle Database

 How to Kill a Session In Oracle Database


Introduction


In this blog How to Kill a Session In Oracle Database  we can kill oracle session by using the sql command alter system kill session and also many ways to kill the session why we we kill the process bacause  inactive and holding locks, process for long time it will occupies more memory and more resources the users are unable to login the database or hanging the system it will take take long time 


 Now let us start the process How to Kill a Session In Oracle Database


The syntax to kill a session in oracle database 


ALTER SYSTEM KILL SESSION ‘SID,SERIAL#’ IMMEDIATE;


Here sid,serial# can be obtained from v$session view


select sid,serial# from v$session where username like 'CHAITANYA'


Step 1: first get the sid and serial# of the session;


Here the session is executing the query SELECT * FROM CHAITANYADBA;


Use the below query to get the sid and serial# of this sql query.


COL SQL_TEXT format a45


SQL>  SELECT a.sid,a.serial#,substr(b.sql_text,1,200) sql_text from v$sql b,

     v$session a where a.sql_id=b.sql_id and  upper(b.sql_text)

     like '%CHAITANYADBA%' and upper(b.sql_text) not like '%V$SQL%';  2  

 

       SID    SERIAL# SQL_TEXT

---------- ---------- ---------------------------------------------

33 26316 select * from chaitanyadba

 

 

Now kill session :

 

SQL>  alter system kill session '33,26316'  immediate;

 

System altered.



For Oracle RAC Database


You can login to the same instance where session is running and then run the above alter system kill session command or you can use the  below command also



ALTER SYSTEM KILL SESSION 'SID,SERIAL#, @INSTANCE_ID';


where instance_id is the instance where the current session is running this command is useful  when you want to kill multiple session from instance in oracle rac database,generally this command is used for want to clear session which is inactive and holding locks ,long running session if the command is not able to kill the session as it has to undo lot of transaction, it will return as marked for killed , once the undo is over ,it will killed itself ,if the session is not doing  undo but it is stuck some where ,you can kill the sever process in th ebackground to clear the session



SQL> ALTER SYSTEM KILL SESSION ’31,3123';


ALTER SYSTEM KILL SESSION ’31,3123'

*

ERROR at line 1:

ORA-00031: session marked for kill


SQL> select username, status from v$session where SID=12;


USERNAME STATUS

——————– ——–

CHAITANYA  KILLED



 How to kill the server process associated with session


NON RAC DATABASE


SELECT s.sid, s.serial#, p.spid

FROM v$session s, v$process p

WHERE s.paddr = p.addr

AND username = 'CHAITANYA';


RAC DATBASE


SELECT s.inst_id, s.sid, s.serial#, p.spid

FROM gv$session s, gv$process p

WHERE s.paddr = p.addr

AND s.inst_id = p.inst_id

AND username = 'CHAITANYA';


Once you executing this sql query we will get the SPID yo can login to database server and kill the SPID


ps -ef | gep <SPID>


Confirm this is  oracle database shadow proces and kill it



kill -9 <spid>



DISCONNECT SESSION


There is another command which can be usedto kill oracle session


alter system disconnect session 'SID,SERIAL#' POST_TRANSACTION | IMMEDIATE;



USEFUL QUERIES FOR KILL ORACLE SESSION



Query to generate kill session command for all sessions with given schema name


select 'alter system kill session ' ||''''|| sid||','|| serial#||''''||';' from v$session where SCHEMANAME='CHAITANYA'


Here i am using CHAITANYA is the schema like scott



Query to generate kill oracle session command for all session with the given module and status being inactive


col event format a30

col module format a15

col program format a30

set lines 100

select 'alter system kill session ' ||''''|| sid||','|| serial#||''''||';'

from v$session_wait sw, v$session s

where sw.sid = s.sid

and sw.sid in (select sid from v$session where module like '%&module%')

and s.status='INACTIVE';



Query to Genearte kill session command for all session which are connecting with sqlplus



select 'alter system kill session ' ||''''|| s.sid||','|| s.serial#||''''||';'

from v$session s where program like '%sqlplus@%'



Query to check killed session in oracle



select sid, serial#, status, username , module, form

from v$session s where status like '%KILLED%'


Query to remove killed session in oracle database



Non RAC database


SELECT 'kill -9 '|| p.spid

FROM v$session s, v$process p

WHERE s.paddr = p.addr

AND s.status = 'KILLED';


RAC database


SELECT 'kill -9 '|| p.spid

FROM gv$session s, gv$process p

WHERE s.paddr = p.addr

AND s.inst_id = p.inst_id

AND s.status = 'KILLED';



Query to check inactive session in oracle database



select sid, serial#, status, username , module, form

from v$session s where status like '%INACTIVE%'



Query to kill inactive session in oracle



select 'alter system kill session ' ||''''|| s.sid||','|| s.serial#||''''||';'

from v$session s where status like '%INACTIVE%'



IDENTIFY THE SESSION USING THE GV$SESSION and GV$PROCESS VIEWS AS FOLLOWS


SET LINESIZE 100

COLUMN spid FORMAT A10

COLUMN username FORMAT A10

COLUMN program FORMAT A45


SELECT s.inst_id,

       s.sid,

       s.serial#,

       --s.sql_id,

       p.spid,

       s.username,

       s.program

FROM   gv$session s

       JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id

WHERE  s.type != 'BACKGROUND';


   INST_ID        SID    SERIAL# SPID       USERNAME   PROGRAM

---------- ---------- ---------- ---------- ---------- ---------------------------------------------

         1         30         25 3859       PROD       chaitanya@chaitu-12gr2.localdomain (TNS V1-V2)

         1         13        387 3834       SYS        abhiram@chaiu-12gr2.localdomain (TNS V1-V2)

         1         30        487 4663                  manasa@chaitu-12gr2.localdomain (Z003)

         1         28        225 4665                  pavan@chaitu-12gr2.localdomain (Z001)



Note: Info on How to Kill a Session In Oracle Database it maybe differ in your enviroment like production,testing ,development and naming conventions etc 



THANKS FOR VIEWING MYBLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME


ITIL Process

ITIL Process Introduction In this Blog i am going to explain  ITIL Process, ITIL stands for Information Technology Infrastructure Library ...