Thursday, March 31, 2011

Recovering space of Statspack indexes

If the tablespace assigned to Statspack objects grows too much, you might try to recover space rebuilding some indexes and moving tables:

SQL> column SEGMENT_NAME format a50
SQL> select * from (select SEGMENT_NAME, SEGMENT_TYPE, BYTES/1024/1024 as MBYTES from dba_segments
where OWNER='PERFSTAT' and TABLESPACE_NAME='STATSPACK' order by BYTES desc) where rownum < 10;

SEGMENT_NAME SEGMENT_TYPE MBYTES
--------------------------------------------------- ------------------ ----------
STATS$SQL_SUMMARY TABLE 1245
STATS$SQL_SUMMARY_PK INDEX 240
STATS$PARAMETER_PK INDEX 42
STATS$SYSSTAT_PK INDEX 39
STATS$LATCH_PK INDEX 35
STATS$LATCH_MISSES_SUMMARY_PK INDEX 34
STATS$LATCH TABLE 33
STATS$SYSSTAT TABLE 26
STATS$PARAMETER TABLE 25

9 rows selected.

SQL> ALTER table PERFSTAT.STATS$SQL_SUMMARY move;

Table altered.

SQL> ALTER INDEX PERFSTAT.STATS$SQL_SUMMARY_PK REBUILD ONLINE;

Index altered.

SQL> ALTER INDEX PERFSTAT.STATS$LATCH_PK REBUILD ONLINE;

Index altered.

SQL> ALTER INDEX PERFSTAT.STATS$LATCH_PARENT_PK REBUILD ONLINE;

Index altered.

SQL> ALTER INDEX PERFSTAT.STATS$LATCH_MISSES_SUMMARY_PK REBUILD ONLINE;

Index altered.

SQL> ALTER INDEX PERFSTAT.STATS$LATCH_CHILDREN_PK REBUILD ONLINE;

Index altered.

SQL> ALTER INDEX PERFSTAT.STATS$SYSSTAT_PK REBUILD ONLINE;

Index altered.

Sometimes the tables and indexes grows so much that it might be better to just truncate everything; if this is the case then you can use the sptrunc script:

SQL> alter session set current_schema=PERFSTAT;

Session altered.

SQL> @?/rdbms/admin/sptrunc

Warning
~~~~~~~
Running sptrunc.sql removes ALL data from Statspack tables. You may
wish to export the data before continuing.


About to Truncate Statspack Tables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If would like to exit WITHOUT truncating the tables, enter any text at the
begin_or_exit prompt (e.g. 'exit'), otherwise if you would like to begin
the truncate operation, press (return)


Enter value for begin_or_exit:
Entered at the 'begin_or_exit' prompt

Beginning truncate operation


Table truncated.


Table truncated.

...

Commit complete.


Package altered.


Truncate operation complete

Wednesday, March 30, 2011

Managing an Oracle Physical Standby Database

This is an example about how to open a physical standby database in read-only mode:

SQL> select name, open_mode, database_role, switchover_status from v$database;

NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------- ---------------- --------------------
MYDB0001 MOUNTED PHYSICAL STANDBY SESSIONS ACTIVE

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

SQL> select name, open_mode, database_role, switchover_status from v$database;

NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------- ---------------- --------------------
MYDB0001 READ ONLY PHYSICAL STANDBY NOT ALLOWED

SQL> select instance_name, logins from v$instance;

INSTANCE_NAME LOGINS
---------------- ----------
mydbr001 ALLOWED


And this is an example about restoring redo apply in the standby database:

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
mydbr002

SQL> shutdown immediate;

Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 805306368 bytes
Fixed Size 2087520 bytes
Variable Size 205522336 bytes
Database Buffers 591396864 bytes
Redo Buffers 6299648 bytes
Database mounted.

SQL> alter database recover managed standby database disconnect;

Database altered.

SQL> select name, applied, archived from v$archived_log where applied='NO';

no rows selected

SQL> select open_mode, database_role, switchover_status from v$database;

OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
---------- ---------------- --------------------
MOUNTED PHYSICAL STANDBY SESSIONS ACTIVE

SQL> select instance_name, logins from v$instance;

INSTANCE_NAME LOGINS
---------------- ----------
mydbr002 ALLOWED


More information about managing physical standby databases:

Managing a Physical Standby Database

Tuesday, March 29, 2011

Dropping a job in Oracle 9i

You can drop a job in Oracle 9i with the job number and DBMS_JOB.REMOVE:


SQL> SELECT JOB, SUBSTR(WHAT,1,35), NEXT_DATE, NEXT_SEC, BROKEN FROM
DBA_JOBS;

JOB SUBSTR(WHAT,1,35) NEXT_DATE NEXT_SEC B
---------- ----------------------------------- --------- -------- -
182 SYS.MYJOB_1; 03-JUN-10 17:16:39 N
183 SYS.MYJOB_2; 03-JUN-10 21:45:21 N
41 SYS.OTHERJOB_1; 03-JUN-10 16:13:12 N
61 SYS.OTHERJOB_2; 06-JUN-10 08:54:07 N
204 statspack.snap; 03-JUN-10 16:13:22 N
161 SYS.LASTJOB; 01-JAN-00 00:00:00 Y

6 rows selected.

SQL> EXECUTE DBMS_JOB.REMOVE(204);

PL/SQL procedure successfully completed.

SQL> SELECT JOB, SUBSTR(WHAT,1,35), NEXT_DATE, NEXT_SEC, BROKEN FROM
DBA_JOBS;

JOB SUBSTR(WHAT,1,35) NEXT_DATE NEXT_SEC B
---------- ----------------------------------- --------- -------- -
182 SYS.MYJOB_1 03-JUN-10 17:16:39 N
183 SYS.MYJOB_2; 03-JUN-10 21:45:21 N
41 SYS.OTHERJOB_1; 03-JUN-10 16:13:12 N
61 SYS.OTHERJOB_2; 06-JUN-10 08:54:07 N
161 SYS.LASTJOB; 01-JAN-00 00:00:00 Y

Monday, March 28, 2011

Creation of an ASM instance

This is an example of creating an ASM instance:

oracle@myserver:~# export ORACLE_BASE=/opt/oracle
oracle@myserver:~# export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
oracle@myserver:~# export ORACLE_SID="+ASM"
oracle@myserver:~# echo "INSTANCE_TYPE=ASM" > /tmp/init+ASM.ora
oracle@myserver:~# sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 28 11:27:55 2011

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining Scoring Engine options

SQL> CREATE SPFILE FROM PFILE='/tmp/init+ASM.ora';

SQL> startup nomount

ASM instance started

Total System Global Area 125829120 bytes
Fixed Size 1301456 bytes
Variable Size 124527664 bytes
Database Buffers 0 bytes
Redo Buffers 0 bytes

SQL> alter system set asm_diskstring='/opt/oracle/product/10.2.0/db_1/devices/dev*';

SQL> show parameter asm_diskstring

NAME TYPE VALUE
--------------- ----------- ---------------------------------------------
asm_diskstring string /opt/oracle/product/10.2.0/db_1/devices/dev*

SQL> CREATE DISKGROUP disk NORMAL REDUNDANCY
SQL> FAILGROUP failure_group_1 DISK
SQL> '/opt/oracle/product/10.2.0/db_1/devices/deva1' NAME diska1,
SQL> '/opt/oracle/product/10.2.0/db_1/devices/deva2' NAME diska2,
SQL> FAILGROUP failure_group_2 DISK
SQL> '/opt/oracle/product/10.2.0/db_1/devices/devb1' NAME diskb1,
SQL> '/opt/oracle/product/10.2.0/db_1/devices/devb2' NAME diskb2;

SQL> select name, header_status, path from v$asm_disk;

NAME HEADER_STAT PATH
------------- ----------- ---------------------------------------------
DISKB1 MEMBER /opt/oracle/product/10.2.0/db_1/devices/devb1
DISKA3 CANDIDATE /opt/oracle/product/10.2.0/db_1/devices/deva3
DISKA1 MEMBER /opt/oracle/product/10.2.0/db_1/devices/deva1
DISKB3 CANDIDATE /opt/oracle/product/10.2.0/db_1/devices/devb3
DISKB2 MEMBER /opt/oracle/product/10.2.0/db_1/devices/devb2
DISKA2 MEMBER /opt/oracle/product/10.2.0/db_1/devices/deva2

SQL> CREATE DISKGROUP fra EXTERNAL REDUNDANCY DISK
SQL> '/opt/oracle/product/10.2.0/db_1/devices/deva3' NAME diska3,
SQL> '/opt/oracle/product/10.2.0/db_1/devices/devb3' NAME diskb3;

SQL> select g.name as DISKGROUP, d.name as DISK, FAILGROUP, TYPE, d.TOTAL_MB, d.FREE_MB
SQL> from v$asm_disk d, v$asm_diskgroup g where d.GROUP_NUMBER=g.GROUP_NUMBER order by 1, 3, 2;

DISKGROUP DISK FAILGROUP TYPE TOTAL_MB FREE_MB
---------- ---------- -------------------- ------ ---------- ----------
DISK DISKA1 FAILURE_GROUP_1 NORMAL 1500 746
DISK DISKA2 FAILURE_GROUP_1 NORMAL 1500 772
DISK DISKB1 FAILURE_GROUP_2 NORMAL 1500 752
DISK DISKB2 FAILURE_GROUP_2 NORMAL 1500 766
FRA DISKA3 DISKA3 EXTERN 1500 1184
FRA DISKB3 DISKB3 EXTERN 1500 1186


Links related to ASM:

Using Automatic Storage Management
Automatic Storage Management (ASM) in Oracle Database 10g
Migrating Databases To and From ASM with Recovery Manager

Friday, March 25, 2011

Creating unique indexes and constraints

If you create a table with a primary key clause in the create table statement, Oracle will create the table and also an unique index to enforce the uniqueness of the primary key, and if you drop the constraint you will drop the unique index too:


SQL> create table miprueba (id number primary key, fecha date);
Table created.

SQL> insert into miprueba values (1, sysdate);

1 row created.

SQL> insert into miprueba values (1, sysdate);
insert into miprueba values (1, sysdate)
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C004346) violated

SQL> select table_NAME from dba_indexes where index_name='SYS_C004346';

TABLE_NAME
------------------------------
MIPRUEBA

SQL> alter table miprueba drop constraint SYS_C004346;

Table altered.

SQL> select table_NAME from dba_indexes where index_name='SYS_C004346';

no rows selected

SQL> select * from dba_constraints where CONSTRAINT_NAME='SYS_C004346';

no rows selected

SQL> drop table miprueba;

Table dropped.


But if you create a table first and later create an unique index and finally add a constraint, you can name the index and the constraint the same, and even if the constraint uses the existing unique index to enforce the primary key constraint, if you drop the constraint you won't be dropping the unique index because they were created separately:


SQL> create table miprueba(id number, fecha date);

Table created.

SQL> create unique index pk_miprueba on miprueba (id);

Index created.

SQL> select INDEX_NAME from dba_indexes where TABLE_NAME='MIPRUEBA';

INDEX_NAME
------------------------------
PK_MIPRUEBA

SQL> ALTER TABLE miprueba add (constraint pk_miprueba primary key (id));

Table altered.

SQL> select constraint_name from dba_constraints where table_NAME='MIPRUEBA';
CONSTRAINT_NAME
------------------------------
PK_MIPRUEBA

SQL> select INDEX_NAME from dba_indexes where TABLE_NAME='MIPRUEBA';

INDEX_NAME
------------------------------
PK_MIPRUEBA

SQL> alter table miprueba drop constraint pk_miprueba;

Table altered.

SQL> select INDEX_NAME from dba_indexes where TABLE_NAME='MIPRUEBA';

INDEX_NAME
------------------------------
PK_MIPRUEBA

SQL> select constraint_name from dba_constraints where table_NAME='MIPRUEBA';

no rows selected

Thursday, March 24, 2011

How to check errors of 10g jobs

To check what happened with failed or stopped jobs in Oracle 10g:

SQL> column LOG_DATE format a40
SQL> column JOB_NAME format a20
SQL> column ADDITIONAL_INFO format a40
SQL> select LOG_ID, LOG_DATE, JOB_NAME, STATUS, ADDITIONAL_INFO from DBA_SCHEDULER_JOB_RUN_DETAILS
where STATUS in ('STOPPED','FAILED') order by LOG_DATE;


LOG_ID LOG_DATE JOB_NAME STATUS ADDITIONAL_INFO
------- ------------------------------------ ------------- -------- ----------------------------------------
6076 22-MAR-11 09.22.00.880338 PM -06:00 MY_JOB FAILED ORA-30036: unable to extend segment by O
RA-30036: unable to extend segment by 8
in undo tablespace 'UNDO'
ORA-06512: at "SYS.MY_PROCEDURE",
line 16
ORA-06512: at line 1
in undo tablespace ''

6085 23-MAR-11 09.22.00.608055 PM -06:00 MY_JOB FAILED ORA-30036: unable to extend segment by O
RA-30036: unable to extend segment by 8
in undo tablespace 'UNDO'
ORA-06512: at "SYS.MY_PROCEDURE",
line 16
ORA-06512: at line 1
in undo tablespace ''

6088 24-MAR-11 05.45.00.821410 AM -06:00 MY_OTHER_JOB STOPPED REASON="Stop job called"

Tuesday, March 22, 2011

Unable to spawn jobq slave process

Some day one Oracle database stopped launching job processes, and it was because there was a lot of jobs spawned but neither responding or finishing its execution:


SQL> select count(*) from dba_SCHEDULER_RUNNING_CHAINS;

COUNT(*)
----------
0

SQL> select count(*) from dba_SCHEDULER_RUNNING_JOBS;

COUNT(*)
----------
0

SQL> select LOG_DATE, OWNER, JOB_NAME from dba_SCHEDULER_JOB_RUN_DETAILS
where LOG_DATE > (select STARTUP_TIME from v$instance) order by LOG_DATE;

LOG_DATE OWNER JOB_NAME
----------------------------------- ------------------------------ -------------------------
25-MAR-10 09.00.13.415604 PM -06:00 ORACLE_OCM MGMT_CONFIG_JOB
25-MAR-10 09.00.17.223307 PM -06:00 ORACLE_OCM MGMT_CONFIG_JOB_1
25-MAR-10 09.04.02.054297 PM -06:00 SYS JOB_DEPURA_AUD_TAB
25-MAR-10 09.05.52.943314 PM -06:00 SYS AUTO_SPACE_ADVISOR_JOB
25-MAR-10 09.19.52.891362 PM -06:00 SYS GATHER_STATS_JOB
26-MAR-10 01.45.01.080361 AM -06:00 SYS JOB_DAILY_SCHEMA_STATS
26-MAR-10 02.00.03.321536 AM -06:00 SYS PURGE_LOG
26-MAR-10 09.00.09.986098 PM -06:00 ORACLE_OCM MGMT_CONFIG_JOB
26-MAR-10 09.00.13.454394 PM -06:00 ORACLE_OCM MGMT_CONFIG_JOB_1
26-MAR-10 09.04.02.741707 PM -06:00 SYS JOB_DEPURA_AUD_TAB
26-MAR-10 09.07.58.011419 PM -06:00 SYS AUTO_SPACE_ADVISOR_JOB
26-MAR-10 09.10.58.165905 PM -06:00 SYS GATHER_STATS_JOB
27-MAR-10 01.00.02.342037 AM -06:00 SYS JOB_WEEKLY_SHRINK
27-MAR-10 02.00.03.041060 AM -06:00 SYS PURGE_LOG
27-MAR-10 05.00.08.906376 AM -06:00 ORACLE_OCM MGMT_CONFIG_JOB
27-MAR-10 05.00.09.878583 AM -06:00 ORACLE_OCM MGMT_CONFIG_JOB_1
27-MAR-10 05.05.28.660496 AM -06:00 SYS AUTO_SPACE_ADVISOR_JOB
27-MAR-10 05.07.10.629614 AM -06:00 SYS GATHER_STATS_JOB
16-APR-10 09.18.47.772170 PM -05:00 SYS JOB_DEPURA_AUD_TAB

============================================

myserver:mydb> tail -13l alert_mydb.log
Sat Mar 27 05:05:28 2010
Thread 1 advanced to log sequence 3440 (LGWR switch)
Current log# 2 seq# 3440 mem# 0: /dat_mydb/logfile/redo02a.rdo
Current log# 2 seq# 3440 mem# 1: /dat_mydb/logfile/redo02b.rdo
Sat Mar 27 10:21:56 2010
kkjcre1p: unable to spawn jobq slave process
Sat Mar 27 10:21:56 2010
Errors in file /oracle_dba10g/app/oracle/admin/mydb/bdump/mydb_cjq0_778366.trc:

Sat Mar 27 21:25:22 2010
Thread 1 advanced to log sequence 3441 (LGWR switch)
Current log# 3 seq# 3441 mem# 0: /dat_mydb/logfile/redo03a.rdo
Current log# 3 seq# 3441 mem# 1: /dat_mydb/logfile/redo03b.rdo

myserver:mydb> ps ax|grep j00
381146 - T 0:00 ora_j001_mydb
1437892 - A 115:53 ora_j007_mydb
1638584 - A 118:10 ora_j003_mydb
1700004 - A 115:59 ora_j006_mydb
1736896 - A 115:41 ora_j009_mydb
1798374 - A 0:00 ora_j000_mxod0002
1822936 - A 116:00 ora_j005_mydb
1917100 - A 116:00 ora_j004_mydb
1966264 - A 118:12 ora_j000_mydb
2064440 - A 118:11 ora_j002_mydb
2068652 - A 115:48 ora_j008_mydb
2109622 pts/1 A 0:00 grep j00

First post

This is a blog mainly for personal use, in order to keep my IT technical knowledge easily accessible (when Websense doesn't label my blog as hacking) and practice English at the same time, therefore use it at your own risk and don't complain about my broken English. =)

I'm planning to put my knowledge worth of it in Google Gadgets in an ordered and structured way, but before that I think would be a good idea putting bits of knowledge like in a journal so that's why I chose a blog. This way I can write freely without worrying about the format, and later I can refer to this posts if I need examples or more information that cannot be put in Gadgets due to space constraints.

By the way, are you a Spanish speaker? You might prefer to read the translated version, Mi bitácora técnica.