Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Wednesday, January 15, 2020

Analyzing why Oracle archive log takes a lot of space

Problem


Oracle archivelog grows extensively. Need to figure out what objects are being changed most frequently.

Solution

Run following statement to get statistics by snapshot date, object name and max number of changes.

SELECT to_char(begin_interval_time,'YYYY-MM-DD HH24:MI') snap_time,
        dhsso.object_name,
        sum(db_block_changes_delta) as maxchages
  FROM dba_hist_seg_stat dhss,
         dba_hist_seg_stat_obj dhsso,
         dba_hist_snapshot dhs
  WHERE dhs.snap_id = dhss.snap_id
    AND dhs.instance_number = dhss.instance_number
    AND dhss.obj# = dhsso.obj#
    AND dhss.dataobj# = dhsso.dataobj#
    AND begin_interval_time BETWEEN to_date('2020-05-22 17','YYYY-MM-DD HH24')
                                           AND to_date('2020-05-22 21','YYYY-MM-DD HH24')
  GROUP BY to_char(begin_interval_time,'YYYY-MM-DD HH24:MI'),
           dhsso.object_name order by maxchages asc;

In order to find out SQL statements that cause these changes, please use following query:

SELECT to_char(begin_interval_time,'YYYY-MM-DD HH24:MI'),
         dbms_lob.substr(sql_text,4000,1),
         dhss.instance_number,
         dhss.sql_id,executions_delta,rows_processed_delta
  FROM dba_hist_sqlstat dhss,
         dba_hist_snapshot dhs,
         dba_hist_sqltext dhst
  WHERE upper(dhst.sql_text) LIKE '%<your object name>%'
    AND dhss.snap_id=dhs.snap_id
    AND dhss.instance_Number=dhs.instance_number
 AND begin_interval_time BETWEEN to_date('2020-01-10 01','YYYY-MM-DD HH24') AND to_date('2020-01-20 21','YYYY_MM_DD HH24')
    AND dhss.sql_id = dhst.sql_id;

Tuesday, April 30, 2019

ORA-01102: cannot mount database in EXCLUSIVE mode

Problem

ORA-01102: cannot mount database in EXCLUSIVE mode during database instance startup

sqlplus / as sysdba
QL*Plus: Release 12.2.0.1.0 Production on Tue Apr 30 21:26:57 2019

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

Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area 6174015488 bytes
Fixed Size                  8634320 bytes
Variable Size            1241514032 bytes
Database Buffers         4915724288 bytes
Redo Buffers                8142848 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode

Solution

Same as https://sk.solutionmentors.com/2019/04/ora-01012-not-logged-on-startup-failed.html, seems this problem appeared because database was not stopped properly.

Follow great article http://www.dba-oracle.com/t_ora_01102_cannot_mount_database_in_exclusive_mode.htm

+++++++++++

POSSIBLE SOLUTION:
Verify that the database was shutdown cleanly by doing the following:

1. Verify that there is not a "sgadef<sid>.dbf" file in the directory
"ORACLE_HOME/dbs".

% ls $ORACLE_HOME/dbs/sgadef<sid>.dbf

If this file does exist, remove it.

% rm $ORACLE_HOME/dbs/sgadef<sid>.dbf

2. Verify that there are no background processes owned by "oracle"

% ps -ef | grep ora_ | grep $ORACLE_SID

If background processes exist, remove them by using the Unix
command "kill". For example:

% kill -9 <Process_ID_Number>

3. Verify that no shared memory segments and semaphores that are owned
by "oracle" still exist

% ipcs -b

If there are shared memory segments and semaphores owned by "oracle",
remove the shared memory segments

% ipcrm -m <Shared_Memory_ID_Number>

and remove the semaphores

% ipcrm -s <Semaphore_ID_Number>

NOTE: The example shown above assumes that you only have one
database on this machine. If you have more than one
database, you will need to shutdown all other databases
before proceeding with Step 4.

4. Verify that the "$ORACLE_HOME/dbs/lk<sid>" file does not exist. This is what caused issue in our case. Simple removal of this file did the trick.

5. Startup the instance

Related issues
https://sk.solutionmentors.com/2019/04/ora-01012-not-logged-on-startup-failed.html
https://sk.solutionmentors.com/2019/04/ora-27125-unable-to-create-shared.html

Reference
http://www.dba-oracle.com/t_ora_01102_cannot_mount_database_in_exclusive_mode.htm

ORA-27125: unable to create shared memory segment during startup

Problem

After reboot, unable to startup Oracle 12c database instance (Red Hat Enterprise Server 7.6)

ORA-27125: unable to create shared memory segment
Linux-x86_64 Error: 28: No space left on device
Additional information: 3822
Additional information: 6157238272

Solution

Verify OS kernel.shmall memory setting.

1. Get current value 
cat /proc/sys/kernel/shmall
1677722

This seems to be too high..

2. Determine page size
getconf PAGE_SIZE
4096

3. Calculate recommended value for shmall

shmall = <total size of SGA>/<page size>

In our case, we have 16GB RAM, so, shmall = 16 * 1024 * 1024 * 1024 / 4096 = 4194304

4. Update /etc/sysctl.conf
vi /etc/sysctl.conf
kernel.shmall=4194304
sudo sysctl -p

5. Verify  kernel.shmall again
cat /proc/sys/kernel/shmall
4194304

6. Start Oracle instance
sudo su - oracle
sqlplus / as sysdba
startup;

This of course leads to another error..


References


Formula to set proper values for max processes, sessions and transactions in Oracle

Problem

Need to adjust max number of sessions in Oracle DB.

Solution

Standard formula looks like:

PROCESSES = Operating System Dependant
SESSIONS = (1.1 * PROCESSES) + 5
TRANSACTIONS = 1.1 * SESSIONS

alter system set sessions=1000 scope=spfile;
alter system set processes=905 scope=spfile;
alter system set transactions=1100 scope=spfile;

shutdown immediate;
startup;

Thursday, June 23, 2011

oracle export import shell scripts

Use Case

Need to  export / import oracle schema from command line (linux shell)

Solution

Great scripts could be found at: http://noerror.blogspot.com/2005/01/expimp-korn-shell-scripts.html
However, on my environment they could not be executed due to very minor syntax issues which could be result of different versions of shell executable.

My corrected version is listed below (slightly updated, since I have to call exp / imp under hi-privileged account).

Usage is easy:

./export.sh -p [dba_user_password] -f [export_file_name] -s [schema_name1,schema_name2,...]
./import.sh -p [dba_user_password] -f [export_file_name] -o [from_schema_name] -t [to_schema_name]

Also, some useful information could be found at:
http://www.dbaexpert.com/blog/2008/04/comprehensive-shell-script-to-export-the-database-to-devnull/
and http://dbamac.wordpress.com/2008/08/01/running-sqlplus-and-plsql-commands-from-a-shell-script/

===============  export.sh  =================


#!/usr/bin/ksh
# export.sh - Korn Shell script to export (an) Oracle schema(s).
# January 6, 2005
# Author - John Baughman
# Hardcoded values: copy_dir, pipefile, dba
# Jun 23, 2011
# Changed by SK
dba=sys

copy_dir=/home/oracle/dbcopy/
# Check the dump directory exists
if [[ ! -d "${copy_dir}" ]];then
echo
echo "${copy_dir} does not exist !"
echo
exit 1
fi

pipefile=~/backup/backup_pipe
# Check we have created the named pipe file, or else there is no point
# continuing
if [[ ! -p ${pipefile} ]];then
echo
echo "Create the named pipe file ${pipefile} using "
echo " $ mknod ${pipefile} p"
echo
exit 1
fi

# Loop through the command line parameters
# -p - Currently the PSG user password.
# -d - The Oracle SID of the database to export. This matches the TNS entry.
# -s - The schema to import
# If either/all of these don't exist, prompt for them.
# Now, check the parameters...
while getopts ":p:f:s" opt; do
case $opt in
p ) psg_password=$OPTARG ;;
f ) raw_name=$OPTARG ;;  #raw_name=${OPTARG##/*/} ;;
s ) shift $(($OPTIND-1))
raw_schema=$* ;;
\? ) print "usage: export.sh -p password -s schema[...]"
exit 1 ;;
esac
done

# Get the missing ${dba} user password
while [[ -z ${psg_password} ]]; do
read psg_password?"Enter ${dba} Password: "
done

# Get the missing SID
#while [[ -z ${sid} ]]; do
#read sid?"Enter Oracle SID: "
#done

# Get the missing "raw" name
while [[ -z ${raw_name} ]]; do
read raw_name?"Enter the export dump file name: "
done



while [[ -z ${raw_schema} ]]; do
print "Enter the schema(s)"
read raw_schema?"(if more than one schema, they can either be space or comma delimited): "
done

# Fix up the raw schema list
schema_list=""
#raw_schema=$(print $raw_schema tr "[a-z]" "[A-Z]")
for name in $raw_schema; do
if [[ -z $schema_list ]]; then
schema_list="${name}"
else
schema_list="${schema_list},${name}"
fi
done
raw_schema=${schema_list}
schema_list="(${schema_list})"

# Fix up the export file name here...
export_file=${copy_dir}${raw_name}.Z

# Let's go!!!
print ""
print "*******************************************************"
print "* Exporting ${raw_schema} schema(s) at `date`"
print "*******************************************************"
print

compress < ${pipefile} > ${export_file} &
exp \'${dba}/${psg_password} as sysdba\' direct=y log=${copy_dir}${raw_name}.exp.log statistics=none buffer=1000000 feedback=10000 file=${pipefile} owner=${schema_list}
#exp ${dba}/${psg_password}@${sid} direct=y log=${copy_dir}${raw_name}.exp.log statistics=none buffer=1000000 feedback=10000 file=${pipefile} owner=${schema_list}

print
print "*******************************************************"
print "* Export Completed at `date`"
print "*******************************************************"
print

exit 0



===============  import.sh  =================

#!/usr/bin/ksh
# import.sh - Korn Shell script to import (an) Oracle schema(s).
# January 6, 2005
# Author - John Baughman
# Hardcoded values: copy_dir, pipefile, dba
# Jun 23, 2011
# Changed SK

dba=sys

copy_dir=/home/oracle/dbcopy/
# Check the dump directory exists
if [[ ! -d "${copy_dir}" ]];then
echo
echo "${copy_dir} does not exist !"
echo
exit 1
fi

pipefile=~/backup/backup_pipe2
# Check we have created the named pipe file, or else there is no point
# continuing
if [[ ! -p ${pipefile} ]]; then
echo
echo "Create the named pipe file ${pipefile} using "
echo " $ mknod ${pipefile} p"
echo
exit 1
fi

# Loop through the command line parameters
# -p - Currently the PSG user password.
# -d - The Oracle SID of the database to export. This matches the TNS entry.
# -f - The export file to import.
# If either/all of these don't exist, prompt for them.
# Now, check the parameters...
while getopts ":p:f:o:t" opt; do
case $opt in
p ) psg_password=$OPTARG ;;
f ) raw_name=${OPTARG##/*/} ;;
o ) from_user=$OPTARG ;;
t ) shift $(($OPTIND-1))
to_user=$* ;;
\? ) print "usage: import.sh -p password -f dump_file.dmp -o from_user -t to_user"
exit 1 ;;
esac
done

# Get the missing ${dba} user password
while [[ -z ${psg_password} ]]; do
read psg_password?"Enter ${dba} Password: "
done

# Get the missing SID
#while [[ -z ${sid} ]]; do
#read sid?"Enter Oracle SID: "
#done

# Get the missing "raw" name
while [[ -z ${raw_name} ]]; do
read raw_name?"Enter the export dump file name: "
done

# Get the missing "from_user" name
while [[ -z ${from_user} ]]; do
read from_user?"Enter the from_user name: "
done

# Get the missing "to_user" name
while [[ -z ${to_user} ]]; do
read to_user?"Enter the to_user name: "
done

# Fix up the export file name here...
export_file=${copy_dir}${raw_name}.Z

print
print "*******************************************************"
print "* Importing ${export_file} at `date`"
print "*******************************************************"
print

uncompress < ${export_file} > ${pipefile} & imp \'${dba}/${psg_password} as sysdba\' log=${copy_dir}${raw_name}.imp.log statistics=none buffer=1000000 feedback=10000 file=${pipefile} ignore=y fromuser=${from_user} touser=${to_user}

print
print "*******************************************************"
print "* Import Completed at `date`"
print "*******************************************************"
print

Oracle 10g exp problem - EXP-00008: ORACLE error 6550 encountered, ORA-06550: line 1, column 13

Use Case

During exp following error occured:


EXP-00008: ORACLE error 6550 encountered
ORA-06550: line 1, column 13:
PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
EXP-00083: The previous problem occurred when calling EXFSYS.DBMS_EXPFIL_DEPASEXP.schema_info_exp
. exporting statistics
Export terminated successfully with warnings.

Solution

Please, follow these steps:

1. Connect as SYS using SQL*Plus

2. Run CATEXF.SYS
@ ?/rdbms/admin/catexf.sql


Now, if EXFSYS schema is not created look into log files and search for any errors.

Another helpful link: http://oracle-in-examples.blogspot.com/2008/03/exp-00008-oracle-error-6550-encountered.html

Wednesday, June 1, 2011

oracle schema export / import

To export single schema, use following command.

exp username/password FILE=dump.dmp OWNER=username

imp username/password FROMUSER=user1 TOUSER=user2 FILE=dump.dmp

In some cases, exp/imp must be running as SYSDBA, in this case, enclose username into single quotes with backslashes.

imp \'sys/***** as sysdba\' FROMUSER=user1 TOUSER=user2 FILE=dump.dmp

Tuesday, November 9, 2010

View oracle objects compile errors

Use Case

Check if there were any errors during oracle objects compilation (procedures, functions, packages, triggers, or package).

Solution

Oracle stores information about errors occured during objects compilation in system tables (e.g. USER_ERRORS). To view error run following sql statement:

select * from sys.user_errors where name = 'object name' and type = 'object type'

Please refer following resources for more information:

Tuesday, October 26, 2010

Simplest way to create user in oracle

Use Case

You need to create new user in Oracle database with ability to connect and manage data objects

Solution

The simplest form is:

create user ecxtenant102 identified by ecxtenant102_secret

where ecxtenant102_secret is user's password

For more comprehensive explanation, please refer to http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_8003.htm

I also had to assign two roles to that user.

grant connect, resource to ecxtenant102

Oracle Sql Developer migrate connectons

Use Case

You've reinstalled OS from a scratch and need to import your Oracle Sql Developer settings

Solution
Copy file "I:\Users\xxx\AppData\Roaming\SQL Developer\system1.5.4.59.40\o.jdeveloper.db.connection.11.1.1.0.22.49.48\connections.xml" to appriate location on your system drive

where I: - your backup disk drive, xxx - your username

More information can be found at: http://www.webxpert.ro/andrei/2008/06/12/oracle-sql-developer-import-connections/




Monday, October 25, 2010

ORA-19809: limit exceeded for recovery files

Use Case

After some database intensive operations following error occured:

ORA-16038: log 1 sequence# 572 cannot be archived
ORA-19809: limit exceeded for recovery files
ORA-00312: online log 1 thread 1: '/opt/oracle/oradata/orcl/redo01.log'

Solution

Quick googling gaves a tip: The flash recovery area is full (http://www.dba-oracle.com/t_ora_19809_limit_exceeded_for_recovery.htm)

To verify this, run following sql statement:

select * from v$recovery_file_dest;

In my case space_used was much greater than space_limit (that was self-efficient Oracle 10g VM).

To fix the problem, we can either increase flash recovery area size or clean / backup files from it.

If you have sufficient disk space available you can use following query (IMPORTANT! New flash recovery area size must be greater than space_used in previous query):

conn system/oracle@orcl
alter system set db_recovery_file_dest_size=10G scope=both
alter database open;

To remove files we have to use RMAN. If we will simply remove files from the host operating system, disk space will be emptied but Oracle won't be aware of it. So, something like that can be done:

rman target / catalog sys/oracle 
run { allocate channel t1 type disk; 
backup archivelog all delete input format '/<temp backup location>/arch_%d_%u_%s'; 
release channel t1; 

Wednesday, October 13, 2010

Turn on ODP.NET Debug Tracing

As states in section "ODP.NET Configuration" from Oracle Data Provider .NET Development Guide, place smth like in your .config file.


  <oracle.dataaccess.client>
    <settings>
      <add name="DbNotificationPort" value="-1"/>
      <add name="DllPath" value="C:\oracle\product\11.1.0\client_1\bin"/>
      <add name="DynamicEnlistment" value="0"/>
      <add name="FetchSize" value="131072"/>
      <add name="MetaDataXml" value="CustomMetaData.xml"/>
      <add name="PerformanceCounters" value="4095"/>
      <add name="PromotableTransaction" value="promotable"/>
      <add name="StatementCacheSize" value="50"/>
      <add name="ThreadPoolMaxSize" value="30"/>
      <add name="TraceFileName" value="C:\Trace\trace.log"/>
      <add name="TraceLevel" value="127"/>
      <add name="TraceOption" value="0"/>
   </settings>
  </oracle.dataaccess.client>

Oracle data provider for .net best practices.

Good article could be found at: http://nvtechnotes.wordpress.com/2009/04/13/oracle-data-provider-for-net-best-practices/

Check oracle number of connections

To check max number of connections that is allowed for an Oracle database (http://stackoverflow.com/questions/162255/how-to-check-the-maximum-number-of-allowed-connections-to-an-oracle-database)

SELECT
'Currently, '
|| (SELECT COUNT(*) FROM V$SESSION)
|| ' out of '
|| VP.VALUE
|| ' connections are used.' AS USAGE_MESSAGE
FROM
V$PARAMETER VP
WHERE VP.NAME = 'sessions'

To monitor number of connections in Oracle (http://decipherinfosys.wordpress.com/2007/02/10/monitoring-number-of-connections-in-oracle/)

SELECT s.username AS username,
  (
  CASE
    WHEN grouping(s.machine) = 1
    THEN '**** All Machines ****'
    ELSE s.machine
  END)     AS machine,
  COUNT(*) AS session_count
FROM v$session s,
  v$process p
WHERE s.paddr   = p.addr
AND s.username IS NOT NULL
GROUP BY rollup (s.username, s.machine)
ORDER BY s.username,
  s.machine;

To see what SQL users are running on the Oracle database (thanks to http://www.dba-oracle.com/concepts/query_active_users_v$session.htm):

SELECT a.sid,
  a.serial#,
  a.username,
  b.sql_text
FROM v$session a,
  v$sqlarea b
WHERE a.sql_address=b.address;

To see what sessions are blocking other sessions (thanks to http://www.dba-oracle.com/concepts/query_active_users_v$session.htm):

SELECT blocking_session,
  sid,
  serial#,
  wait_class,
  seconds_in_wait
FROM v$session
WHERE blocking_session IS NOT NULL
ORDER BY blocking_session;


And finally, when "bad" sessions are found, we can kill them using (http://www.oracle-base.com/articles/misc/KillingOracleSessions.php):

ALTER SYSTEM KILL SESSION 'sid,serial#';

Another good queries from http://stackoverflow.com/questions/622289/how-to-check-oracle-database-for-long-running-queries


This one shows SQL that is currently "ACTIVE"

select S.USERNAME, s.sid, s.osuser, t.sql_id, sql_text
from v$sqltext_with_newlines t,V$SESSION s
where t.address =s.sql_address
and t.hash_value = s.sql_hash_value
and s.status = 'ACTIVE'
and s.username <> 'SYSTEM'
order by s.sid,t.piece
/

This shows locks

select
  object_name, 
  object_type, 
  session_id, 
  type,   -- Type or system/user lock
  lmode,     -- lock mode in which session holds lock
  request, 
  block, 
  ctime   -- Time since current mode was granted
from
  v$locked_object, all_objects, v$lock
where
  v$locked_object.object_id = all_objects.object_id AND
  v$lock.id1 = all_objects.object_id AND
  v$lock.sid = v$locked_object.session_id
order by
  session_id, ctime desc, object_name
/

This is a good one for finding long operations (e.g. full table scans). If it is because of lots of short operations, nothing will show up.

COLUMN percent FORMAT 999.99 

SELECT sid, to_char(start_time,'hh24:mi:ss') stime, 
message,( sofar/totalwork)* 100 percent 
FROM v$session_longops
WHERE sofar/totalwork < 1
/




To be continued... More documentation can be found at: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2088.htm

Tuesday, October 12, 2010

.net oracle performance counters disabled

During development of complex database applications on .net, we need to have ability to monitor various parameters like number of connections, number of pooled connections, number of pooled groups and so on.

Perfmon.exe comes to rescue. Just setup valid value for PerformanceCounters variable under HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ODP.NET\Assembly_Version, where Assembly_Version is is the full assembly version number of Oracle.DataAccess.dll.

For more information please refer to: http://download.oracle.com/docs/html/E10927_01/featConnecting.htm#CJADIIFD