viernes, 30 de diciembre de 2011

Eliminando una base de datos Oracle

Es muy fácil borrar una base de datos Oracle, como puedes ver en este ejemplo:

myserver:mydb> sqlplus '/ as sysdba'

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Sep 24 08:50:22 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to an idle instance.

SQL> startup mount exclusive;
ORACLE instance started.

Total System Global Area 268435456 bytes
Fixed Size 2083368 bytes
Variable Size 163579352 bytes
Database Buffers 100663296 bytes
Redo Buffers 2109440 bytes
Database mounted.

SQL> select instance_name, host_name from v$instance;

INSTANCE_NAME HOST_NAME
---------------- ----------------
mydb myserver

SQL> alter system enable restricted session;

System altered.

SQL> drop database;

Database dropped.

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
SQL> exit

En una nota relacionada, la sentencia DROP DATABASE no existe en Oracle 9i, tienes que dar de baja la base de datos y borrar todos los archivos de la base de datos con comandos de sistema operativo:

Drop database in Oracle 9i

jueves, 29 de diciembre de 2011

Carga extra por memoria

Hablando sobre computadoras lo usual es que mientras más mejor, pero esto no es verdad siempre. Por ejemplo, ve la cantidad de memoria y carga en bigservr; este servidor tiene 64 gigabytes de memoria pero sólo están usados 3 gigabytes, y aún si no hay procesos corriendo y el uso de CPU es casi cero la carga promedio es algo alta. En comparación, smallsrv está más ocupado y aún habiendo paginado memoria la carga promedio es menor que en bigservr.

La administración del hardware por el kernel de Linux requiere recursos, y para manejar mucha memoria el kernel requiere ... muchas estructuras de memoria. Por lo tanto, si no vas a usar mucha memoria sería preferible (y más barato) instalar sólo la memoria que necesitas.

myuser@bigservr> top

top - 08:50:32 up 6 days, 13:00, 4 users, load average: 0.71, 0.74, 0.66
Tasks: 272 total, 1 running, 271 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.8%us, 0.1%sy, 0.0%ni, 99.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 65791000k total, 3227812k used, 62563188k free, 309716k buffers
Swap: 5406712k total, 0k used, 5406712k free, 2649252k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10768 root 15 0 16420 2456 2124 S 0.3 0.0 0:39.00 cmaeventd
22241 myuser 15 0 2336 1136 800 R 0.3 0.0 0:01.14 top
1 root 15 0 2072 616 532 S 0.0 0.0 0:08.29 init
2 root RT -5 0 0 0 S 0.0 0.0 0:01.17 migration/0
3 root 39 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:01.44 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root RT -5 0 0 0 S 0.0 0.0 0:01.01 migration/2
9 root 34 19 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/2
10 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/2
11 root RT -5 0 0 0 S 0.0 0.0 0:01.72 migration/3

root@smallsrv:~# top

top - 08:51:20 up 29 min, 6 users, load average: 0.16, 0.21, 0.46
Tasks: 184 total, 2 running, 182 sleeping, 0 stopped, 0 zombie
Cpu(s): 7.0%us, 12.3%sy, 0.0%ni, 79.3%id, 1.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1016864k total, 987644k used, 29220k free, 44384k buffers
Swap: 2980016k total, 204780k used, 2775236k free, 604592k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2599 myuser 10 -10 271m 186m 177m S 9.6 18.8 2:55.94 vmware-vmx
2377 myuser 20 0 388m 103m 19m S 4.3 10.4 0:50.69 firefox-bin
1030 root 20 0 105m 20m 9428 S 3.0 2.1 1:00.57 Xorg
2435 myuser 20 0 73624 13m 9.9m S 1.3 1.4 0:15.40 plugin-containe
3479 root 20 0 2472 1196 880 R 0.7 0.1 0:00.06 top
16 root 15 -5 0 0 0 S 0.3 0.0 0:00.39 ata/0
2028 myuser 20 0 110m 10m 5832 S 0.3 1.1 0:12.17 compiz.real
2206 myuser 20 0 113m 11m 8324 S 0.3 1.2 0:04.71 gnome-terminal
2938 root 0 -20 0 0 0 R 0.3 0.0 0:08.41 vmware-rtc
1 root 20 0 2532 1420 1096 S 0.0 0.1 0:00.98 init
2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 15 -5 0 0 0 S 0.0 0.0 0:00.09 ksoftirqd/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
6 root 15 -5 0 0 0 S 0.0 0.0 0:00.02 events/0
7 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 cpuset
8 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khelper

miércoles, 28 de diciembre de 2011

Oracle, máquinas virtuales y tiempo raro

Si tu has usado máquinas virtuales bastante, quizás sepas que algunas veces hay problemas con el tiempo de las máquinas virtuales y que es una buena práctica mantener el tiempo en sincronía (con servicios como NTP). Los problemas que he visto con el tiempo de las máquinas virtuales han estado relacionados principalmente con carga pesada y hardware no óptimo para dicha carga, pero hay más problemas relacionados con máquinas virtuales aparte de estos.

Un día tuve un problema raro con una base de datos Oracle 10g: de pronto había muchos datos de AWR y el tablespace estaba creciendo rápido. El intervalo entre muestras era de una hora y el tiempo de retención de siete días, pero al investigar más a fondo descubrí que los snapshots estaban siendo hechos cada minuto:

SQL> select snap_interval, retention from dba_hist_wr_control;

SNAP_INTERVAL RETENTION
---------------------------------------- -------------------
+00000 01:00:00.0 +00007 00:00:00.0

SQL> select SNAP_ID, STARTUP_TIME, BEGIN_INTERVAL_TIME, END_INTERVAL_TIME from dba_hist_snapshot order by SNAP_ID;

SNAP_ID STARTUP_TIME BEGIN_INTERVAL_TIME END_INTERVAL_TIME
-------- ---------------------------- --------------------------- --------------------------
8123 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.07.28.091 AM 19-JUL-10 10.08.35.353 AM
8124 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.08.35.353 AM 19-JUL-10 10.09.46.060 AM
8125 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.09.46.060 AM 19-JUL-10 10.10.56.047 AM
8126 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.10.56.047 AM 19-JUL-10 10.12.04.798 AM
8127 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.12.04.798 AM 19-JUL-10 10.13.13.762 AM
8128 04-JUL-10 07.34.43.000 PM 19-JUL-10 10.13.13.762 AM 19-JUL-10 10.14.24.432 AM
...

Revisé muchas cosas en la base de datos Oracle pero después de no encontrar nada me imaginé que había un problema con el sistema operativo. El tiempo estaba bien pero el comando top refrescaba la información bastante rápido, por lo que intenté con top -d 300 y esta vez la información se refrescaba cada tres segundos ... Aún si debía refrescarse cada cinco minutos con top -d 300.

Después de encontrar esto notifiqué a los administradores de sistemas esta situación y algún tiempo después el problema fue arreglado, pero los administradores de sistemas nunca me dijeron cuál fue el problema; creo que el problema estaba relacionado con un bug de VMware:

Weird timing voodoo. Linux top command very fast

martes, 27 de diciembre de 2011

Problemas con el nombre de la computadora

Si se te generan muchos archivos de volcado y sale este error en el alert log:

Warning: keltnfy call to ldmInit failed with error 46

Revisa que el nombre de la computadora puede ser resuelto y que su dirección IP es correcta; en este ejemplo en Linux puedes ver que el nombre no está en /etc/hosts:

MYHOST:mydb> uname -n
MYHOST
MYHOST:mydb> cat /etc/hostname
MYHOST
MYHOST:mydb> cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
MYHOST:mydb> ping MYHOST
ping: unknown host MYHOST
MYHOST:mydb> sqlplus /

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jul 13 10:01:38 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set linesize 150
SQL> select INSTANCE_NAME, HOST_NAME, STATUS from v$instance;

INSTANCE_NAME HOST_NAME STATUS
---------------- ---------- ---------------
mydb MYHOST OPEN

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release
10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

lunes, 26 de diciembre de 2011

Revisando el uso de memoria en HP-UX

Si sientes que tu servidor está más lento de lo usual, puedes revisar el uso de memoria y paginación con ps, top, vmstat y glance. En este ejemplo, como puedes ver en Mem Util y Swap Util en glance este servidor usó mucha memoria y espacio de paginación en algún momento, pero al momento de esta muestra no había paginación o falta de memoria como se puede ver en la memoria "active" (entre paréntesis) en el reporte de top, como se ve en los valores bajos de Page In y Page Out en glance, y también los valores bajos de pi y po en el reporte de vmstat.

$ ps -elx|sort -k 10b,10rn|more
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME COMD
1401 S 113 6938 1 0 154 20 e000000163528680 9728 e000000149c7d080 ? 465:09 ora_s000_mydb
1401 S 113 6083 1 0 154 20 e0000001bcc40400 9620 e0000001674f6ee8 ? 0:00 oraclemydb (LOCAL=NO)
1401 S 113 6940 1 0 154 20 e0000001635c5100 9147 e000000149c7d080 ? 3:13 ora_d000_mydb
1401 S 113 6932 1 0 156 20 e0000001636fc700 9103 e000000167e27128 ? 2:40 ora_smon_mydb
1401 S 113 6926 1 0 156 20 e000000163664980 9012 e000000167e270f8 ? 25:24 ora_dbw0_mydb
1401 S 113 6934 1 0 156 20 e00000016362a700 8992 e000000167e27138 ? 0:02 ora_reco_mydb
1401 S 113 6924 1 0 154 20 e00000016340b700 8979 e000000149c7d080 ? 9:48 ora_pmon_mydb
1401 S 113 6936 1 0 156 20 e00000016348ba00 8967 e000000167e27148 ? 12:17 ora_cjq0_mydb
1401 S 113 6930 1 0 156 20 e000000163370980 8938 e000000167e27118 ? 12:59 ora_ckpt_mydb
1401 S 113 6928 1 0 156 20 e0000001634d6980 8924 e000000167e27108 ? 9:48 ora_lgwr_mydb
2541 R 0 6003 1 0 -16 10 e0000001a7370d00 4271 - ? 0:22 /opt/perf/bin/midaemon
2401 S 113 5999 5798 0 154 10 e0000001bb0fba00 1016 e00000018409c800 pts/0 0:19 glance
541 R 0 1 0 0 152 20 e00000010853e380 574 - ? 0:10 init
1401 S 113 6961 1 0 154 20 e000000163945a00 552 e000000149c7d080 ? 1:02 /oracle92/product/9.2.0/bin/tnslsnr LISTENER -inherit
1401 S 0 6088 1564 0 154 20 e0000001b1098980 491 e00000030f73fe68 ? 0:00 sshd: oracle [priv]
3401 S 113 6090 6088 0 154 20 e0000001b2c90100 491 e000000149c7d080 ? 0:00 sshd: oracle@pts/1
3401 S 127 6333 6331 0 154 20 e0000001c2b09d00 487 e000000149c7d080 ? 0:00 sshd: myuser@pts/2
1401 S 0 6331 1564 0 154 20 e0000001c8a15d00 471 e00000014eeffee8 ? 0:00 sshd: myuser [priv]
1401 S 0 6605 1564 0 154 20 e0000001ac0fc980 471 e000000164a63568 ? 0:00 sshd: otherusr [priv]
3401 S 12 6617 6605 0 154 20 e0000001b550c680 471 e000000149c7d080 ? 0:00 sshd: otherusr@pts/3
3401 S 113 5794 5791 0 154 20 e0000001b8695380 466 e000000149c7d080 ? 0:00 sshd: oracle@pts/0
$ top

System: myserver Fri Apr 8 10:37:43 2011
Load averages: 0.02, 0.12, 0.34
182 processes: 141 sleeping, 41 running
Cpu states:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS
0 0.02 0.2% 0.0% 0.2% 99.6% 0.0% 0.0% 0.0% 0.0%
--- ---- ----- ----- ----- ----- ----- ----- ----- -----
avg 0.02 0.2% 0.0% 0.2% 99.6% 0.0% 0.0% 0.0% 0.0%

System Page Size: 4Kbytes
Memory: 1151700K (788492K) real, 3840196K (2936972K) virtual, 26556K free Page# 1/14

CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND
0 ? 27479 root 152 20 264M 20128K run 95:34 0.34 0.34 agctrlcell
0 ? 6938 oracle 154 20 1973M 4444K sleep 465:16 0.32 0.31 ora_s000_mydb
0 ? 2731 root 152 20 155M 7928K run 4:22 0.31 0.31 vxpal
0 ? 75 root 152 20 17208K 15296K run 44:50 0.29 0.29 vxfsd
0 ? 2666 root 152 20 112M 4332K run 1:30 0.29 0.29 vxsvc
0 ? 27475 root 152 20 694M 15332K run 84:10 0.29 0.29 evtcell
0 ? 3532 root 168 20 11700K 592K sleep 307:47 0.29 0.29 utild
0 ? 2357 root 152 20 26072K 1880K run 0:29 0.14 0.14 rpcd
0 ? 3021 root 152 20 92272K 2296K run 0:09 0.14 0.14 vxpal
0 ? 3078 root 152 20 99636K 1568K run 0:08 0.14 0.14 vxpal
0 ? 3197 root 152 20 25832K 1612K run 0:54 0.14 0.14 swagentd
$ glance

C - cum/interval toggle Page 1 of 2
ProcList CPU Rpt Mem Rpt Disk Rpt NextKeys SlctProc Help Exit
Glance C.04.70.001 10:31:24 myserver ia64 Current Avg High
------------------------------------------------------------------------------------------------------------------------------------------------------
CPU Util SSU U | 5% 32% 86%
Disk Util F | 1% 30% 77%
Mem Util S SU U | 99% 100% 100%
Swap Util U UR R | 26% 26% 26%
------------------------------------------------------------------------------------------------------------------------------------------------------
MEMORY REPORT Users= 4
Event Current Cumulative Current Rate Cum Rate High Rate
--------------------------------------------------------------------------------
Page Faults 0 7593 0.0 12.5 548.6
Page In 0 5149 0.0 8.4 350.8
Page Out 0 56 0.0 0.0 1.3
KB Paged In 0kb 20.1mb 0.0 33.9 7455.2
KB Paged Out 0kb 224kb 0.0 0.3 5.4
Reactivations 0 0 0.0 0.0 0.0
Deactivations 0 0 0.0 0.0 0.0
KB Deactivated 0kb 0kb 0.0 0.0 0.0
VM Reads 0 435 0.0 0.7 33.1
VM Writes 0 0 0.0 0.0 0.0
Total VM : 3.6gb Sys Mem : 2.6gb User Mem: 924mb Phys Mem : 3.7gb
Active VM: 2.3gb Buf Cache: 1mb Free Mem: 25mb FileCache: 215mb
MemFS Blk Cnt: 0 MemFS Swp Cnt: 0

ProcList CPU Rpt Mem Rpt Disk Rpt NextKeys SlctProc Help Exit
$ vmstat 10
procs memory page faults cpu
r b w avm free re at pi po fr de sr in sy cs us sy id
3 1 0 667747 14981 1 0 7 10 1 0 34 297 2178 238 3 1 96
1 1 0 562145 14956 4 0 12 0 0 0 0 221 644 139 1 1 98
1 1 0 762287 14964 0 0 0 0 0 0 0 133 545 97 1 0 98
1 1 0 761304 14980 0 0 0 0 0 0 0 118 451 87 0 0 100
1 1 0 550784 14964 0 0 0 0 0 0 0 118 387 88 0 0 100

Además, si tienes acceso como root puedes revisar el uso de memoria con swapinfo, sam y en /dev/mem como en el siguiente ejemplo (de un servidor diferente):

# swapinfo -tm
Mb Mb Mb PCT START/ Mb
TYPE AVAIL USED FREE USED LIMIT RESERVE PRI NAME
dev 8192 490 3606 6% 0 - 1 /dev/vg00/lvol2
reserve - 2986 -2986
memory 3016 2780 236 92%
total 11208 6256 856 56% - 0 -
# echo phys_mem_pages/D | adb -k /stand/vmunix /dev/mem
phys_mem_pages:
phys_mem_pages: 1048064
# sam

┌ System Properties (MYSERVR) ┐
│┌────────────────────────────────────────┐│
││ ^│
││ [ Refresh ] │
││ │
││ ┌─────┐┌────┐┌─────────┐┌─────┐┌────┐ │
││ │ Processor ││ Memory ││ Operating System ││ Network ││ Dynamic │ │
││ ┌───────/ \──────────────────────────┐ │
││ │┌────────────────────────────────────┐│ │
││ ││Physical Memory: 4097.7 MB ││ │
││ ││Real Memory: ││ │
││ ││ Active: 954731.6 KB ││ │
││ ││ Total: 1318838.6 KB ││ │
││ ││Virtual Memory: ││ │
││ ││ Active: 1850220.6 KB ││ │
││ ││ Total: 2375723.8 KB ││ │
││ ││Free Memory Pages: 21640 at 4 KB/page ││ │
││ ││Swap Space: ││ │
││ ││ Avail: 8192 MB ││ │
││ ││ Used: 3461 MB ││v│
│└────────────────────────────────────────┘│
│──────────────────────────────────────────│
│ [ OK ] [ Help ] │
└──────────────────────────────────────────┘

Más información:

Memory Usage (What is using all of the memory?)

domingo, 25 de diciembre de 2011

Cómo obtener el tamaño de una base de datos Oracle

Si necesitas obtener el tamaño de una base de datos Oracle (excluyendo software, logs y cosas así), puedes hacerlo de esta forma:

SQL> select 'ONLINE_REDOLOG' as TYPE, sum(BYTES*MEMBERS)/1048576 as SIZE_MB from v$log union
select 'DATAFILES', sum(BYTES)/1048576 from v$datafile union
select 'TEMPFILES', sum(BYTES)/1048576 from v$tempfile union
select 'CONTROLFILES', sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1048576 from v$controlfile union
select 'FLASH_RECOVERY_AREA', VALUE/1048576 from v$parameter where NAME='db_recovery_file_dest_size';

TYPE SIZE_MB
------------------- ----------
CONTROLFILES 14.1875
DATAFILES 1230
FLASH_RECOVERY_AREA 3072
ONLINE_REDOLOG 300
TEMPFILES 25

viernes, 23 de diciembre de 2011

Cómo obtener los DDL de objetos de un esquema

En Oracle, si necesitas recrear, copiar o comparar un esquema completo (o incluso una base de datos completa) sin los datos, puedes usar el paquete DBMS_METADATA.GET_DDL para obtener los DDL de los objetos como en el siguiente ejemplo:

set linesize 150
set long 90000
set pagesize 0
set wrap on
column mdata format a150

SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) as mdata FROM DBA_OBJECTS
WHERE OWNER = 'MYSCHEMA' and OBJECT_TYPE not in ('LOB') ORDER BY object_type, object_name;

Más información sobre obtener DDL de objetos:

Get table and index DDL the easy way
DDL Generation--Oracle's Answer to Save You Time and Money