quarta-feira, 3 de dezembro de 2014

Como alterar o valor de um parâmetro de outra sessão

Postado por Alex Zaballa no GPO

Imaginem um cenário onde é necessário alterar o valor de um parâmetro de uma sessão que já está aberta no banco de dados e sem uma interface SQL para realizar um ALTER SESSION.

Para resolver este problema, podemos utilizar as procedures SET_INT_PARAM_IN_SESSION e SET_BOOL_PARAM_IN_SESSION da package DBMS_SYSTEM.

dbms_system.set_bool_param_in_session(
sid     IN NUMBER,
serial# IN NUMBER,
parnam  IN VARCHAR2,
bval    IN BOOLEAN);

dbms_system.set_int_param_in_session(
sid     IN NUMBER,
serial# IN NUMBER,
parnam  IN VARCHAR2,
intval  IN BINARY_INTEGER);

Neste exemplo, vamos alterar o parâmetro sort_area_size da sessão abaixo:

[oracle@oracle01 ~]$ sqlplus scott/tiger

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 20 11:08:29 2014

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

Last Successful login time: Thu Nov 20 2014 11:07:59 +01:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options

SQL> show parameter sort_area

NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
sort_area_size     integer 65536

Buscando as informações e alterando o valor do parâmetro SORT_AREA_SIZE da sessão do usuário SCOTT:

[oracle@oracle01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 20 11:13:08 2014

Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options

SQL> select sid,serial# from v$session where username='SCOTT';

      SID      SERIAL#
----------   ----------
      237 49369

SQL> exec dbms_system.SET_INT_PARAM_IN_SESSION(237, 49369, 'SORT_AREA_SIZE',131072);

PL/SQL procedure successfully completed.
Verificando o novo valor do parâmetro SORT_AREA_SIZE na sessão do usuário SCOTT:

SQL> select name, value
      from V$SES_OPTIMIZER_ENV
     where sid=237
       and name='sort_area_size';

NAME VALUE
---------------------------------------- -------------------------
sort_area_size 131072

sexta-feira, 21 de novembro de 2014

sexta-feira, 12 de setembro de 2014

Torne sua vida um pouco mais simples, utilize o que os mais de 30000 engenheiros da Oracle desenvolveram

O sql_tunning_task ajuda muito, abaixo o que uso:

Encontre o sql_id da query que você quer melhorar

--Crie a task
DECLARE 
   RET_VAL VARCHAR2(4000); 
BEGIN 
   RET_VAL := DBMS_SQLTUNE.CREATE_TUNING_TASK(SQL_ID => '0cy3wcc00qxf9', 
   SCOPE => DBMS_SQLTUNE.SCOPE_COMPREHENSIVE, 
   TIME_LIMIT => 10000, 
   TASK_NAME => '0cy3wcc00qxf9', 
   DESCRIPTION => '0cy3wcc00qxf9'); 
END; 
/ 

--Execute a task
EXEC DBMS_SQLTUNE.EXECUTE_TUNING_TASK('0cy3wcc00qxf9'); 

--Veja as recomendações
set long 999999999
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('0cy3wcc00qxf9') RECOMMENTATION FROM DUAL; 

--Gere os comandos para aplicar as recomendações
SELECT DBMS_SQLTUNE.SCRIPT_TUNING_TASK('0cy3wcc00qxf9') RECOMMENTATION FROM DUAL; 


Use com moderação, nem sempre a recomendação vai melhorar.

Abraço


segunda-feira, 18 de agosto de 2014

Como testar uma gravação de arquivo em um DIRECTORY do Oracle

Esse teste é muito legal, pois ajuda quando o usuário relata problemas de gravação em diretórios no oracle.
O DIRECTORY do exemplo se chama test_dir e fica no /home/oracle

Esse é o resultado final


E foi assim que fiz, minto, copiei de algum indiano!!!



create directory test_dir as '/home/oracle/'
/

grant read, write on directory test_dir to public
/

create or replace procedure test_write (
dir in varchar2,
filename in varchar2,
firstline in varchar2,
secondline in varchar2)

is
output_file utl_file.file_type;
begin
  output_file := utl_file.fopen (dir,filename, 'W');
  utl_file.put_line (output_file, firstline);
  utl_file.put_line (output_file, secondline);
  utl_file.fclose(output_file);
end;
/

exec test_write('TEST_DIR', 'Teste_Hello_World.txt', 'hello', 'world')
/

Vlw

quarta-feira, 8 de maio de 2013

Guia para instalação de patch 11.2.0.3 e bundle patch 16056266 - Linux 64 bits


1 - Rodar o script de pre-upgrade 
--How to Download and Run Oracle's Database Pre-Upgrade Utility [ID 884522.1]

utlu112i_5.sql

2 - Instalar o novo oracle_home

criar o diretório que vai receber o novo home
mkdir -p /u01/app/oracle/product/11.2.0.3

-Editar o arquivo db_install.rsp com as informações para instalação do novo binário, esse foi o usuado no upgrade do oradsvme
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oradsvme
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/oraInventory
SELECTED_LANGUAGES=en
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.3.0,oracle.oraolap:11.2.0.3.0,oracle.rdbms.dm:11.2.0.3.0,oracle.rdbms.dv:11.2.0.3.0,oracle.rdbms.lbac:11.2.0.3.0,oracle.rdbms.rat:11.2.0.3.0
oracle.install.db.DBA_GROUP=oinstall
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=
oracle.install.db.config.starterdb.globalDBName=
oracle.install.db.config.starterdb.SID=
oracle.install.db.config.starterdb.characterSet=WE8MSWIN1252
oracle.install.db.config.starterdb.memoryOption=false
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=


--nls_language, o atual era o WE8ISO8859P1, foi usado o WE8MSWIN1252 no arquivo de response, esse characterset possui todos os caracteres do WE8ISO8859P1 e naus 27 novos caracteres
Difference between WE8MSWIN1252 and WE8ISO8859P1 characterset [ID 341676.1]

 ./runInstaller -responseFile /d01dmp/d01dmp/patch_11203_linux_64/database/response/db_install.rsp -ignorePrereq -showProgress -silent

**se usar o response file, esse parametro tem que ficar como true, se não vai dar erro por causa do usuário do my oracle support
DECLINE_SECURITY_UPDATES=true

--ajustar o profile(/home/oracle/.bash_profile) do user oracle para o caminho do novo home

Realizar logoff-logon para que o novo caminho do home seja carregado em memória

Instalando o binário

[oracle@oradsv01:oradsvme database]$./runInstaller -responseFile /d01dmp/d01dmp/patch_11203_linux_64/database/response/db_install.rsp -ignorePrereq -showProgress -silent
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 1961 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3898 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2013-05-07_06-00-52PM. Please wait ...[oracle@oradsv01:oradsvme database]$You can find the log of this install session at:
 /u01/app/oracle/oraInventory/logs/installActions2013-05-07_06-00-52PM.log

Prepare in progress.
..................................................   9% Done.

Prepare successful.

Copy files in progress.
..................................................   14% Done.
..................................................   20% Done.
..................................................   26% Done.
..................................................   31% Done.
..................................................   36% Done.
..................................................   44% Done.
..................................................   49% Done.
..................................................   55% Done.
..................................................   63% Done.
..................................................   68% Done.
..................................................   73% Done.
..................................................   78% Done.
..................................................   83% Done.
..............................
Copy files successful.

Link binaries in progress.
..........
Link binaries successful.

Setup files in progress.
..................................................   88% Done.
..................................................   94% Done.

Setup files successful.
The installation of Oracle Database 11g was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2013-05-07_06-00-52PM.log' for more details.

Execute Root Scripts in progress.

As a root user, execute the following script(s):
        1. /u01/app/oracle/product/11.2.0.3/root.sh


..................................................   100% Done.



Execute Root Scripts successful.
--com root
[root@oradsv01 11.2.0.3]# ./root.sh
Check /u01/app/oracle/product/11.2.0.3/install/root_oradsv01_2013-05-07_18-49-51.log for the output of root script
[root@oradsv01 11.2.0.3]# cat /u01/app/oracle/product/11.2.0.3/install/root_oradsv01_2013-05-07_18-49-51.log

Performing root user operation for Oracle 11g 

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/11.2.0.3
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
[root@oradsv01 11.2.0.3]# pwd
/u01/app/oracle/product/11.2.0.3
[root@oradsv01 11.2.0.3]# date
Tue May  7 18:50:30 BRT 2013
[root@oradsv01 11.2.0.3]#

--com o user oracle
Successfully Setup Software.



3 - Escolher o método que será feito o upgrade, aqui será feito manualmente

--backup do banco - não rodei backup para a base de dev
RUN
{
    ALLOCATE CHANNEL chan_name TYPE DISK;
    BACKUP DATABASE FORMAT '/dados/some_backup_directory%U' TAG before_upgrade;
    BACKUP CURRENT CONTROLFILE FORMAT '/dados/control_file';
}


4 - Executando o upgrade da base
criar um pfile from spfile
shutdown no banco
copiar o init e listener.ora(não havia listener.ora na máquina oradsv01, foi copiado tb o tnsnames.ora) para o novo home
ir para o diretorio
cd $ORACLE_HOME/rdbms/admin
conectar com o sysdba
startup upgrade
SPOOL upgrade.log
@catupgrd.sql
--o script dá shutdown no banco
startup
@utlu112s.sql --checar se houve algum erro no spo do script @utlu112s.sql
@catuppst.sql --checar se houve algum erro no spo do script @catuppst.sql
--recompilar objetos
@utlrp.sql
--validar objetos inválidos
SELECT count(*) FROM dba_invalid_objects;
SELECT distinct object_name FROM dba_invalid_objects where owner in('SYS','SYSTEM') AND STATUS='INVALID';


--opatch
Atualizar o OPatch com a versão mais recente, realizar um backup da pasta $ORACLE_HOME/OPatch, depois apagar o conteúdo e decompactar o arquivo p6880880_112000_Linux-x86-64.zip no $ORACLE_HOME

--instalando o bundle patch
Decompactar o arquivo p16056266_112030_Linux-x86-64.zip na pasta $ORACLE_HOME/OPatch

cd $ORACLE_HOME/OPatch/16056266

--se for um single instance, precisa baixar o banco e listener, para rac é possível fazer sem gerar indisponibilidade

[oracle@oradsv01:oradsvme 16056266]$/u01/app/oracle/product/11.2.0.3/OPatch/opatch apply
Oracle Interim Patch Installer version 11.2.0.3.4
Password (optional):                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

--Ignorar mensagens de tentativa de conexão com o metalink, preencha com NONE onde for solicitado


Is the local system ready for patching? [y|n]
y
User Responded with: Y
Backing up files...
Applying sub-patch '13343438' to OH '/u01/app/oracle/product/11.2.0.3'

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.rdbms.dbscripts, 11.2.0.3.0...

Verifying the update...
Applying sub-patch '13696216' to OH '/u01/app/oracle/product/11.2.0.3'

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.sdo.locator, 11.2.0.3.0...

Patching component oracle.sysman.console.db, 11.2.0.3.0...

Patching component oracle.sysman.oms.core, 10.2.0.4.4...

Verifying the update...
Applying sub-patch '13923374' to OH '/u01/app/oracle/product/11.2.0.3'
ApplySession: Optional component(s) [ oracle.network.cman, 11.2.0.3.0 ]  not present in the Oracle Home or a higher version is found.

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.rdbms.dbscripts, 11.2.0.3.0...

Patching component oracle.network.rsf, 11.2.0.3.0...

Patching component oracle.network.listener, 11.2.0.3.0...

Patching component oracle.sysman.console.db, 11.2.0.3.0...

Verifying the update...
Applying sub-patch '14275605' to OH '/u01/app/oracle/product/11.2.0.3'
ApplySession: Optional component(s) [ oracle.precomp.lang, 11.2.0.3.0 ]  not present in the Oracle Home or a higher version is found.

Patching component oracle.network.client, 11.2.0.3.0...

Patching component oracle.network.rsf, 11.2.0.3.0...

Patching component oracle.precomp.common, 11.2.0.3.0...

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.rdbms.dbscripts, 11.2.0.3.0...

Patching component oracle.rdbms.rman, 11.2.0.3.0...

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.rdbms.util, 11.2.0.3.0...

Verifying the update...
Applying sub-patch '14727310' to OH '/u01/app/oracle/product/11.2.0.3'

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.rdbms.dbscripts, 11.2.0.3.0...

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.sdo.locator, 11.2.0.3.0...

Patching component oracle.sysman.console.db, 11.2.0.3.0...

Patching component oracle.sysman.oms.core, 10.2.0.4.4...

Verifying the update...
Applying sub-patch '16056266' to OH '/u01/app/oracle/product/11.2.0.3'
ApplySession: Optional component(s) [ oracle.network.cman, 11.2.0.3.0 ]  not present in the Oracle Home or a higher version is found.

Patching component oracle.network.listener, 11.2.0.3.0...

Patching component oracle.network.rsf, 11.2.0.3.0...

Patching component oracle.ovm, 11.2.0.3.0...

Patching component oracle.rdbms, 11.2.0.3.0...

Patching component oracle.rdbms.rman, 11.2.0.3.0...

Patching component oracle.rdbms.rsf, 11.2.0.3.0...

Patching component oracle.sdo.locator, 11.2.0.3.0...

Patching component oracle.rdbms.deconfig, 11.2.0.3.0...

Verifying the update...

OPatch found the word "warning" in the stderr of the make command.
Please look at this stderr. You can re-run this make command.
Stderr output:
ins_precomp.mk:19: warning: overriding commands for target `pcscfg.cfg'
/u01/app/oracle/product/11.2.0.3/precomp/lib/env_precomp.mk:2160: warning: ignoring old commands for target `pcscfg.cfg'
/u01/app/oracle/product/11.2.0.3/precomp/lib/ins_precomp.mk:19: warning: overriding commands for target `pcscfg.cfg'
/u01/app/oracle/product/11.2.0.3/precomp/lib/env_precomp.mk:2160: warning: ignoring old commands for target `pcscfg.cfg'


Composite patch 16056266 successfully applied.
OPatch Session completed with warnings.
Log file location: /u01/app/oracle/product/11.2.0.3/cfgtoollogs/opatch/opatch2013-05-07_21-47-12PM_1.log

OPatch completed with warnings.

--rodar o script abaixo na base de dados
cd $ORACLE_HOME/rdbms/admin
sqlplus "/as sysdba"

startup
@catbundle.sql psu apply

--confirmar que os patchs foram instalados
[oracle@oradsv01:oradsvme OPatch]$./opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.4
Copyright (c) 2012, Oracle Corporation.  All rights reserved.


Oracle Home       : /u01/app/oracle/product/11.2.0.3
Central Inventory : /u01/app/oracle/oraInventory
   from           : /u01/app/oracle/product/11.2.0.3/oraInst.loc
OPatch version    : 11.2.0.3.4
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0.3/cfgtoollogs/opatch/opatch2013-05-07_22-05-55PM_1.log

Lsinventory Output file location : /u01/app/oracle/product/11.2.0.3/cfgtoollogs/opatch/lsinv/lsinventory2013-05-07_22-05-55PM.txt

--------------------------------------------------------------------------------
Installed Top-level Products (1):

Oracle Database 11g                                                  11.2.0.3.0
There are 1 products installed in this Oracle Home.


Interim patches (1) :

Patch  16056266     : applied on Tue May 07 21:54:20 BRT 2013
Unique Patch ID:  15962803
Patch description:  "Database Patch Set Update : 11.2.0.3.6 (16056266)"
   Created on 12 Mar 2013, 02:14:47 hrs PST8PDT
Sub-patch  14727310; "Database Patch Set Update : 11.2.0.3.5 (14727310)"
Sub-patch  14275605; "Database Patch Set Update : 11.2.0.3.4 (14275605)"
Sub-patch  13923374; "Database Patch Set Update : 11.2.0.3.3 (13923374)"
Sub-patch  13696216; "Database Patch Set Update : 11.2.0.3.2 (13696216)"
Sub-patch  13343438; "Database Patch Set Update : 11.2.0.3.1 (13343438)"
   Bugs fixed:
     13566938, 13593999, 10350832, 14138130, 12919564, 13561951, 13624984
     13588248, 13080778, 13914613, 13804294, 14258925, 12873183, 13645875
     14472647, 12880299, 14664355, 14409183, 12998795, 14469008, 13719081
     13492735, 13496884, 12857027, 14263036, 14263073, 13732226, 13742433
     16368108, 16314469, 12905058, 13742434, 12849688, 12950644, 13742435
     13464002, 13534412, 12879027, 13958038, 14613900, 12585543, 12535346
     12588744, 11877623, 13786142, 12847466, 13649031, 13981051, 12582664
     12797765, 14262913, 12923168, 13384182, 13612575, 13466801, 13484963
     14207163, 11063191, 13772618, 13070939, 12797420, 13041324, 16314467
     16314468, 12976376, 11708510, 13680405, 14589750, 13026410, 13742437
     13737746, 14644185, 13742438, 13326736, 13596521, 13001379, 16344871
     13099577, 9873405, 14275605, 13742436, 9858539, 14841812, 11715084
     16231699, 14040433, 12662040, 9703627, 12617123, 12845115, 12764337
     13354082, 14459552, 13397104, 13913630, 12964067, 12983611, 13550185
     13810393, 12780983, 12583611, 14546575, 13476583, 15862016, 11840910
     13903046, 15862017, 13572659, 16294378, 13718279, 14088346, 13657605
     13448206, 16314466, 14480676, 13419660, 13632717, 14063281, 14110275
     13430938, 13467683, 13420224, 13812031, 14548763, 16299830, 12646784
     13616375, 14035825, 12861463, 12834027, 15862021, 13632809, 13377816
     13036331, 14727310, 13685544, 15862018, 13499128, 16175381, 13584130
     12829021, 15862019, 12794305, 14546673, 12791981, 13787482, 13503598
     10133521, 12718090, 13399435, 14023636, 13860201, 12401111, 13257247
     13362079, 14176879, 12917230, 13923374, 14220725, 14480675, 13524899
     13559697, 9706792, 14480674, 13916709, 13098318, 13773133, 14076523
     13340388, 13366202, 13528551, 12894807, 13454210, 13343438, 12748240
     14205448, 13385346, 15853081, 14273397, 12971775, 13582702, 10242202
     13035804, 13544396, 16382353, 8547978, 14226599, 14062795, 13035360
     12693626, 13332439, 14038787, 14062796, 12913474, 14841409, 14390252
     16314470, 13370330, 13059165, 14062797, 14062794, 12959852, 13358781
     12345082, 12960925, 9659614, 13699124, 14546638, 13936424, 13338048
     12938841, 12658411, 12620823, 12656535, 14062793, 12678920, 13038684
     14062792, 13807411, 13250244, 12594032, 15862022, 9761357, 12612118
     13742464, 14052474, 13911821, 13457582, 13527323, 15862020, 13910420
     13502183, 12780098, 13705338, 13696216, 14841558, 10263668, 15862023
     16056266, 15862024, 13554409, 13645917, 13103913, 13011409, 14063280



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

OPatch succeeded.

--acompanhar alert log do banco