Browsing "Older Posts"

Browsing Category "ORA-"

Tablespaces verkleinern (TEMP, USER_TS, ORA-03297)

Von Tobias Arnhold → 11.28.2016

Info
Die Select-Statements in diesem Blogpost habe ich von anderen Webseiten kopiert. Daher ist dieser Beitrag eher als Zusammenfassung unterschiedlicher Lösungsversuche zu sehen und dient mir als schnelle Hilfe bei der Verkleinerung eines zu großen Tablespaces. Schaut euch die Quellen an, die sehr viel detaillierter auf die jeweiligen Probleme eingehen.

Wer kennt nicht die Situation? Der DBA ruft an und meint der TEMP Tablespace verbraucht mehrere hundert Gigabyte an Speicher.

Was ist in solch einer Situation zu tun?
In dem Moment wo ein TEMP Tablespace überproportional ansteigt, muss eine Session diesen Anstieg verursachen. Mit dem folgenden Select erfahren Sie welche Session wie viel Speicher im TEMP-Tablespace verbraucht.

-- Source: http://stackoverflow.com/questions/174727/discover-what-process-query-is-using-oracle-temp-tablespace
select   b.tablespace
       , b.segfile#
       , b.segblk#
       , round (  (  ( b.blocks * p.value ) / 1024 / 1024 ), 2 ) size_mb
       , a.sid
       , a.serial#
       , a.sql_id
       , a.username
       , a.osuser
       , a.program
       , a.status
    from v$session a
       , v$sort_usage b
       , v$process c
       , v$parameter p
   where p.name = 'db_block_size'
     and a.saddr = b.session_addr
     and a.paddr = c.addr
order by b.tablespace
       , b.segfile#
       , b.segblk#
       , b.blocks;

Über die SQL_ID können Sie wenn vorhanden auch auf das Verursacher-Select zugreifen:
-- Source: http://cheatsheet4oracledba.blogspot.de/2014/01/how-to-find-top-temp-using-oracle.html
select sql_text 
from v$sql 
where sql_id='b6kta08q9jj3f';

Über den SQL Developer > Tools > Monitor Sessions können Sie die betroffene SID killen.

Anschließend wird der Verbrauch des TEMP-Tablespace zwar wieder zurückgefahren, aber die Größe bleibt bestehen.

Prüfen Sie daher zunächst die aktuelle verwendete Größe im TEMP-Tablespace:
-- Source: https://alexzeng.wordpress.com/2012/06/13/how-to-find-the-sql-that-using-lots-of-temp-tablespace-in-oracle/
select b.total_mb,
       b.total_mb - round(a.used_blocks*8/1024) current_free_mb,
       round(used_blocks*8/1024)                current_used_mb,
      round(max_used_blocks*8/1024)             max_used_mb
from v$sort_segment a,
 (select round(sum(bytes)/1024/1024) total_mb from dba_temp_files ) b;

-- Oder:
select * from dba_temp_free_space;

Wenn der Wert (current_used_mb) entsprechend klein ist, dann können Sie den TEMP-Tablespace verkleinern, andernfalls haben Sie nicht die richtige Session gekillt.

TEMP-Tablespace verkleinern:
select file_name,bytes,blocks from dba_temp_files;
-- .../tempfile/temp.911 564863696896 68953088

alter tablespace temp shrink space;

select file_name,bytes,blocks from dba_temp_files;
-- ../tempfile/temp.911 289513472 35341


Es kann aber auch vorkommen das eine normaler Tablespace zu groß wurde und dadurch viel mehr Platz verbraucht als es aktuell verwendet.
Um darüber einen Überblick zu erhalten, führen Sie folgendes Select aus:
 -- Source: Nicht mehr bekannt :(
select
   mb.*
  ,nvl(round(100 * freemb / sizemb,1),0) free_prozent
from 
 (select 
    b.tablespace_name
   ,round(tbs_size,2) as sizemb
   ,a.free_space freemb
  from 
    (select 
       tablespace_name
      ,round(sum(bytes)/1024/1024 ,2) as free_space 
     from dba_free_space group by tablespace_name
    ) a
   ,(select 
      tablespace_name, 
      sum(bytes)/1024/1024 as tbs_size 
     from dba_data_files group by tablespace_name
     union
     select 
       tablespace_name, 
       sum(bytes)/1024/1024 tbs_size
     from dba_temp_files
     group by tablespace_name 
    ) b
  where a.tablespace_name(+)=b.tablespace_name
  ) mb
order by free_prozent;

Bei einer solchen Situation muss anstelle des Tablespaces die Datendatei verkleinert werden.
Nun benötigen Sie dafür noch den richtigen Dateinamen, um die korrekte Datei zu verkleinern:
SELECT 
  name, 
  bytes/1024/1024 AS size_mb
FROM   v$datafile
;

Statement zum verkleinern der Datendatei:
ALTER DATABASE DATAFILE '.../DATAFILE/my_schema.033.123331' RESIZE 3G

Die Verkleinerung kann aber in einem ORA-03297 Fehler enden.

ALTER DATABASE DATAFILE '.../DATAFILE/my_schema.033.123331' RESIZE 3G
Error report -
SQL Error: ORA-03297: file contains used data beyond requested RESIZE value

Jetzt bleiben Ihnen 3 Schritte um mit geringem Aufwand diese Datei doch noch zu verkleinern:

1. Fragmentierung bereinigen
Die Datendatei wurde fragmentiert und eine Tabelle liegt am Ende der Datei und verhindert dadurch die Verkleinerung.

Beispiel:
Die Datendatei ist 90 GB groß und tatsächlich werden nur 2 GB verwendet.
Eine Tabelle liegt von der Verteilung her zwischen 82-83 GB. Heißt, ich könnte die Datendatei nur auf 84G verkleinern. Also müssen Sie in solch einem Fall das Objekt ausfindig machen und löschen. Sinnvollerweise kopiere ich vorher die Tabelle in einen anderen Tablespace, um diese anschließend wieder herstellen zu können. :)

Um die Blockverteilung analysieren zu können, muss vorher die richtige File-ID ausgelesen werden:
select 
  s.tablespace_name, s.owner, s.segment_name, s.segment_type,
  sum(s.bytes) size_in_bytes,
  round(sum(s.bytes) / 1024 / 1024, 2) size_in_m,
  sum(round(sum(s.bytes) / 1024 / 1024, 2)) over() as size_in_m_gesamt,
  f.file_id,
  f.file_name
from sys.dba_segments s, sys.dba_data_files f
where f.tablespace_name = s.tablespace_name
and f.file_id = s.header_file
and s.tablespace_name in ('NTDC03')
group by s.tablespace_name, s.owner, s.segment_name, s.segment_type, f.file_id, f.file_name
order by s.tablespace_name, s.owner, s.segment_name;

Das folgende Select zeigt die Blockverteilung mit den verwendeten DB-Objekten innerhalb der Datendatei:
 Source: http://www.orait.de/db_fehler/ora-03297_file-contains-used-data-beyond.html
select 
  file_id,
  block_id, 
  blocks*8192/1024/1024 as mb,
  owner||'.'||segment_name as object_name,
  block_id*8192/1024/1024 as position_mb
from sys.dba_extents
where file_id = 206
union
select 
  file_id, 
  block_id, 
  blocks*8192/1024/1024 as mb, 
  'Free' as object_name,
  block_id*8192/1024/1024 as position_mb
from sys.dba_free_space
where file_id = 206
order by 1,2,3;


Wenn Sie die betroffenen Tabellen gelöscht haben, dann klappt auch die Verkleinerung wieder:  
ALTER DATABASE DATAFILE '.../DATAFILE/my_schema.033.123331' RESIZE 3G 
Database datafile '.../DATAFILE/my_schema.033.123331' altered.

2. Recycle Bin löschen
purge recyclebin;

3. Coalesce Tablespace
alter tablespace fred coalesce;

Info: TEMP Tablespace auf Unlimited setzen
alter database tempfile '.../TEMPFILE/temp.910.901132571' autoextend on next 250m maxsize unlimited;

MySQL/Oracle XE integration: Invalid identifier problem

Von Tobias Arnhold → 2.08.2010
I linked a MySQL table into an OracleXE database (Short How to) and discovered a really strange behavior. When I tried an usual select about the MySQL table from my sqlplus client an error occurred: ORA-00904: "last_name": Invalid identifier

Here the whole description:

-- Error:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as test_user

SQL> SELECT "last_name" FROM tbl_users@MYSQL_USER u;

SELECT "last_name" FROM tbl_users@MYSQL_USER u

ORA-00904: "last_name": ungültiger Bezeichner

SQL>

-- MySQL DDL TABLE:
DROP TABLE IF EXISTS 'my_sqldb'.'tbl_users';
CREATE TABLE 'my_sqldb'.'tbl_users' (
'u_id' int(10) unsigned NOT NULL auto_increment,
'last_name' varchar(50) NOT NULL,
'forename' varchar(50) NOT NULL,
'department_id' int(10) unsigned NOT NULL,
PRIMARY KEY ('u_id')
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

Solution:
Query MySQL table through Oracle APEX database using Oracle database link fails
Issue while querying MySQL tables through Oracle Generic Connectivity Using ODBC

Solution description:

...I changed the character set settings to "utf8" of v5.1.6 mysql odbc driver
through "Details -> Misc Options" as suggested and finally the problem was
resolved - the query returned the correct results...

APEX-AT-WORK no image

Ignore sql error messages in pl/sql process

Von Tobias Arnhold → 11.16.2009
Have you experienced the case that you want to execute a process and when a specified error occurs then it should go on like nothing happened.

In my case I had several pl/sql processes and one was to delete a database link. In my special case there shouldn't be an error if no database link exists.

Here is the code snippet for it:

declare
-- error variable
v_no_link EXCEPTION;
-- Map error number returned by raise_application_error to user-defined exception.
PRAGMA EXCEPTION_INIT(v_no_link, -2024);
-- About the error: http://download.oracle.com/docs/cd/B28359_01/server.111/b28278/e1500.htm#sthref1158

begin
-- Drop existing database link
EXECUTE IMMEDIATE 'drop database link ' || UPPER(:P1_I_INSTANCE_NAME);

EXCEPTION
WHEN v_no_link THEN
null;
--WHEN OTHERS THEN
-- raise_application_error(SQLCODE, 'SQLERRM');
end;

More information: PL/SQL User's Guide and Reference - Error Handling

ORA-07445 _npierr+487 error in APEX runinng under a XE database

Von Tobias Arnhold → 5.15.2009
I created a dynamic pl/sql report where the select was based on an external table (transcribed through a database link).

DECLARE
v_query varchar2(1000);
BEGIN
IF :P1_INSTANCE_NAME is not null THEN
v_query := 'SELECT NAME,
VALUE,
isdefault,
isses_modifiable,
issys_modifiable,
ismodified,
isadjusted,
description
FROM v$parameter@'||:P1_INSTANCE_NAME;
ELSE
v_query := 'SELECT 1 FROM dual WHERE 1=0';
END IF;
return(v_query);
END;

Tip: If you are more interested into dynamic reports! Then here comes a really handy explanation:
http://www.apex-blog.com/oracle-apex/dynamic-report-regions-tutorial-32.html

After the login into the APEX application builder a strange download error occurred. When I clicked on a APEX link a download window opened and showed the following arguments:


At the same time when the error occurred the following entries in the alertlog file got created:

Fri May 15 13:14:43 2009
Errors in file c:\oracle\admin\xe\bdump\xe_s000_1436.trc:
ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_npierr+487] [PC:0x5F22C3] [ADDR:0x4] [UNABLE_TO_READ] []

Fri May 15 13:15:27 2009
found dead shared server 'S000', pid = (14, 2)
Fri May 15 13:17:07 2009
Errors in file c:\oracle\admin\xe\bdump\xe_s002_2492.trc:
ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_npierr+487] [PC:0x5F22C3] [ADDR:0x4] [UNABLE_TO_READ] []

Fri May 15 13:17:24 2009
found dead shared server 'S002', pid = (16, 1)

I looked in Metalink, the Oracle forum and the web itself and came to the following conclusion:
That error occurs when you call a database link in a web application. There is no official workaround at least no one for the XE database. It should be patched in the following Oracle database versions: 11.2, 11.1.0.6.P11

Another hint came from the Oracle forum. They meant you should set up your browser to "en-us" language. I tried it but it didn't help either.
Anyway I created a application with German language so it wouldn't be such a good hotfix. ;D

My workaround:
Creating a new table where I import the information before via a pl/sql package and the dbms scheduler. It's not really what I wanted but the only way for now.

Here are the web links I rallied to it:
Metalink note: 6798427.8
Metalink note: 809366.1
Metalink bug no.: 6798427
XE forum: Beta 3 Bug: using database link freezes apex and xdb
XE forum: Universal edition choke on en-GB browser, core dumped, ORA-07445, _npierr+4
APEX forum: page not found, ORA-07445: exception encountered: core dump

Update 22.06.2009
I had the idea to use a function selecting the external data (with execute immediate) and save this data into a temporary table.
Then I created a new APEX "Before Header Process" and called this database function and made a select into my page variables.
But I still get this error... I give up!
APEX-AT-WORK no image

Solution for APEX import error ORA-20001, ORA-02047 (3)

Von Tobias Arnhold → 11.24.2008
Just for the people who are curios about the APEX import error ORA-02047 I had the last couple of weeks.

On the next workday I followed the hint from Dietmar and changed the settings in my dads.conf:

<Location /pls/xe>
PlsqlNLSLanguage GERMAN_GERMANY.AL32UTF8
</Location>

After that the error did not occur again.
In this time I did around 20 to 40 import and exports without any problems. I would say: That's it!

You always have to use AL32UTF8 in your PlsqlNLSLanguage variable.

Update:
28.11.2008 - Error occurred again... For now I just restarted the OAS service and the import worked as well as before.

Update:
12.02.2009 - Error now occurred several times again. Last week I couldn't restart the OAS service but when I tried it this week again it worked. Without any changes except restart my client. This error drives me crazy. At least right now it works...

Update:
15.05.2009 - Now I could fix the issue ones by looking into the sessions of the external database. There I canceled all sessions for the database user which I was connecting through APEX. Afterwards the import run again without a OAS restart.
I came to the idea through some fabulous hints from Scott and Joel.
Link: Import err: ORA-20001,ORA-02047,alter session set nls_numeric_characters...
APEX-AT-WORK no image

Again import error ORA-02047: cannot join the distributed... (2)

Von Tobias Arnhold → 11.07.2008
Hi APEX folks!

Here some new happenings to error:

ORA-20001: GET_BLOCK Error. ORA-20001: Execution of the statement was unsuccessful.
ORA-02047: cannot join the distributed transaction in progress <pre>
begin execute immediate 'alter session set nls_numeric_characters='''||wwv_flow_api.g_nls_numeric_chars||''''; end; </pre>

What happend?
Just like yesterday! When I try to import from test to prod the error ORA-02047 comes up. I did a couple of imports today without problems before.

What did I do this time?
1. Changed the focus at the page:
Home>Application Builder>Application 306>Page 100>Edit Page>Display Attributes>Cursor Focus:
First item on page

2. Add a new Display as Text (does not save state) item without label (no label).

Is there something important to know?
No I didn't changed anything else. Application has just 4 pages!
App ID's just for better understanding:
ID: 105 (production system)
ID: 106 (that is where I develop in)
ID: 107 (another test app for import tests)

Here the results of my invalid objects select statement:

select all invalid object inside the database:
select owner, object_name, object_type from ALL_OBJECTS where status = 'INVALID';
---------------------------------------------------------------------------------
OWNER OBJECT_NAME OBJECT_TYPE
PUBLIC DBA_HIST_FILESTATXS SYNONYM
PUBLIC DBA_HIST_SQLSTAT SYNONYM
PUBLIC DBA_HIST_SQLBIND SYNONYM
PUBLIC DBA_HIST_SYSTEM_EVENT SYNONYM
PUBLIC DBA_HIST_WAITSTAT SYNONYM
PUBLIC DBA_HIST_LATCH SYNONYM
PUBLIC DBA_HIST_LATCH_MISSES_SUMMARY SYNONYM
PUBLIC DBA_HIST_DB_CACHE_ADVICE SYNONYM
PUBLIC DBA_HIST_ROWCACHE_SUMMARY SYNONYM
PUBLIC DBA_HIST_SGASTAT SYNONYM
PUBLIC DBA_HIST_SYSSTAT SYNONYM
PUBLIC DBA_HIST_SYS_TIME_MODEL SYNONYM
PUBLIC DBA_HIST_OSSTAT SYNONYM
PUBLIC DBA_HIST_PARAMETER SYNONYM
PUBLIC DBA_HIST_SEG_STAT SYNONYM
PUBLIC DBA_HIST_ACTIVE_SESS_HISTORY SYNONYM
PUBLIC DBA_HIST_TABLESPACE_STAT SYNONYM
PUBLIC DBA_HIST_SERVICE_STAT SYNONYM
PUBLIC DBA_HIST_SERVICE_WAIT_CLASS SYNONYM
USER PRC_IMPORT_XXX PROCEDURE

Recompiled PRC_IMPORT_XXX from other user.
New try, import into app id 107 instead of 105 > Error occurred again.

Recompiled all invalid objects:

SQL > @utlrp.sql;
---------------------------------------------
PL/SQL-Prozedur erfolgreich abgeschlossen.
...
OBJECTS WITH ERRORS
------------------- 0
0
...
ERRORS DURING RECOMPILATION
--------------------------- 0
0

PL/SQL-Prozedur erfolgreich abgeschlossen.

Now I went on testing:
Made a new export. Import into app id 107 > Error occurred again.
Try to import the last working export into 107 > Error occurred again.
Log out of APEX and restart of Browser (Firefox 3). Start new instance of Firefox.
Go to app 107. Try to import the last working export into 107. Error occurred again.
You could get the feeling to give up by now... I DON'T!!!
Log out of APEX > Log in to other workspace in the same database.
Import a working export I made before > BOOM error occurred again.
By now I could say I just had luck yesterday! :O

What do i know now?
No more invalid objects! No import is possible anymore!

Lets go on:
Restart of OAS Service!
Import of not working export into id 107 > BOAH it worked again
Import of not working export into id 105 (prod app) > It worked too!

What does it mean?
It's not the exported file. Not even an invalid object problem. It doesn't seem to have to do with changes during the development on the application. What is it then?
Maybe it has to do with the PlsqlNLSLanguage I use. The last thing I did with the OAS was to patch to the newest patchset (Oct 2008) without any problems two weeks ago. I restarted the OAS but not the XE database!?

What's next to do?
I will write again if it happens again. I don't hope so but I almost sure that it will happen.

I got a hint from Dietmar to my last post APEX error ORA-20001 and ORA-02047 during application import (1)
I should use the following setting in my dads.conf:

<Location /pls/xe>
PlsqlNLSLanguage GERMAN_GERMANY.AL32UTF8
</Location>

I will try again on Monday!
APEX-AT-WORK no image

APEX error ORA-20001 and ORA-02047 during application import (1)

Von Tobias Arnhold → 11.06.2008
Today I came across a quite known error, at least if I count the forum entries to it. When I tried to import a application from the test to a production environment in my case the same server and the same schema/user. I got the following error:

ORA-20001: GET_BLOCK Error. ORA-20001: Execution of the statement was unsuccessful.
ORA-02047: cannot join the distributed transaction in progress &lt ;pre&gt ;
begin execute immediate 'alter session set nls_numeric_characters='''||wwv_flow_api.g_nls_numeric_chars||''''; end; &lt ;/pre&gt ;

What I wanted to know was how I could solve that issue. The environment I work with looks like that:
  • WinXP SP2 with
  • OracleXE database with
  • APEX 3.1.2 and PL/SQL Web Toolkit 10.1.2.0.6
  • OAS 10 with Apache Server for APEX
  • DADS.conf extract

<Location /pls/xe>
...
PlsqlNLSLanguage GERMAN_GERMANY.WE8MSWIN1252
...
</Location>

What did I do? Did I changed anything on my environment?
I worked in this environment since half a year with a lot of app imp- and exports without any errors or problems. I didn't change anything on the environment but I did work on the application. Error just came up today when I tried to import one application export. I exported the application several times and tried to import with no success. Then I tried to import it into a new application id instead of overwriting the production app. Again the same error...

How could I fix it?
I found a quite good post at the Oracle APEX forum: Application import error
What I did then was to check for the version of the PL/SQL Web Toolkit.

select owa_util.get_version from dual;
----------------------------------------------
10.1.2.0.6

Was the right version. Now I let the utlrp.sql run to recompile all invalid object in my XE database.
SQL> @rdbms\admin\utlrp.sql
All went all right no errors.
I tried again to import the application and again the error occurred. Then I tried to import another application (same database just another schema/user) and that worked fine. I compared the error app with an older version (via WinMerge) and came across a comment I made:
Home>Application Builder>Application 101>Page 1>Edit Page Item>Element>Pre Element Text

I took this out (via APEX) and made a new export file. Now I tried with the new application export and finally I could succeed getting it to work. No error occurred. Strange thing was I made another import with an export where the comment was still in it (no changes or anything) and also that worked fine.

What does it all mean??
I guess it has to do with invalid objects. Normally every weekend a batch job runs which corrects invalid objects inside the database. Job looks like that:
Filename: RECOMPILE_INVALID_OBJECTS.bat

set ORACLE_SID=XE
C:
cd C:\oracle\product\10.2.0\server\RDBMS\ADMIN
sqlplus "/ as sysdba" @C:\oracle\jobs\RECOMPILE_INVALID_OBJECTS.sql

Filename: RECOMPILE_INVALID_OBJECTS.sql

spool C:\oracle\log\recompile_invalid_objects.log
set heading on
set verify on
set term on
set serveroutput on size 1000000
set wrap on
set linesize 200
set pagesize 1000

select 'Session started at '||to_char(sysdate,'dd.mm.yyyy HH24:MI') from dual;
select instance_name from v$instance;
select * from ALL_OBJECTS where status = 'INVALID';

@utlrp.sql;

select * from ALL_OBJECTS where status = 'INVALID';
select 'Session finished at '||to_char(sysdate,'dd.mm.yyyy HH24:MI') from dual;

spool off
exit

What to do now??
Wait until it happens again and then you will get to know about it.