MERCADOS FINANCIEROS

martes, 27 de octubre de 2020

ORACLE LINUX REPOSITORIO

3.6 Installing Oracle Linux with Oracle Linux Yum Server Support Use the following procedure to install Oracle Linux and configure your Linux installation for security errata or bug fix updates using the Oracle Linux yum server: Obtain Oracle Linux DVDs from Oracle Store, or download Oracle Linux from the Oracle Software Delivery Cloud: Oracle Store: https://shop.oracle.com Oracle Software Delivery Cloud website: https://edelivery.oracle.com/linux Install Oracle Linux from the ISO or DVD image. Log in as root Download the yum repository file for your Linux distribution from http://yum.oracle.com/, using the instructions you can find on the Oracle Linux yum server website. For example: # cd /etc/yum.repos.d/ # wget http://yum.oracle.com/public-yum-ol6.repo Ensure that the olrelease_latest file (for example, ol6_latest for Oracle Linux 6) is enabled, as this is the repository that contains the Oracle Preinstallation RPM. (Optional) Edit the repo file to enable other repositories. For example, enable the repository ol6_UEK_latest by setting enabled=1 in the file with a text editor. Run the command yum repolist to verify the registered channels. Start a terminal session and enter the following command as root, depending on your platform. For example: Oracle Linux 6 and Oracle Linux 7: # yum install oracle-rdbms-server-12cR1-preinstall # yum install -y oracleasm # yum install -y oracleasm-support # yum install oracleasmlib /usr/sbin/oracleasm configure -i /usr/sbin/oracleasm init # yum install oracle-validated You should see output indicating that you have subscribed to the Oracle Linux channel, and that packages are being installed. For example: el5_u6_i386_base el5_u6_x86_64_patch Oracle Linux automatically creates a standard (not role-allocated) Oracle installation owner and groups, and sets up other kernel configuration settings as required for Oracle installations. After installation, run the command yum update as needed to obtain the most current security errata and bug fixes for your Oracle Linux installation.

lunes, 26 de octubre de 2020

VISTA ARCHIVOS DE TRACE V$DIAG_INFO

SQL> select name,value from v$diag_info; Diag Enabled TRUE ADR Base /u01/app/oracle ADR Home /u01/app/oracle/diag/rdbms/acme/acme Diag Trace /u01/app/oracle/diag/rdbms/acme/acme/trace Diag Alert /u01/app/oracle/diag/rdbms/acme/acme/alert Diag Incident /u01/app/oracle/diag/rdbms/acme/acme/incident Diag Cdump /u01/app/oracle/diag/rdbms/acme/acme/cdump Health Monitor /u01/app/oracle/diag/rdbms/acme/acme/hm Default Trace File /u01/app/oracle/diag/rdbms/acme/acme/trace/acme_ora_10592.trc Active Problem Count 0 Active Incident Count 0

VISTA PROCESOS V$BGPROCESS

VISTA PROCESOS V$BGPROCESS POR SISTEMA OPERATIVO CONSULTANDO LOS PROCESOS BACKGROUND [oracle@localhost ~]$ ps -fea | grep pmon oracle 3478 1 0 Oct19 ? 00:03:56 asm_pmon_+ASM oracle 3658 1 0 Oct19 ? 00:04:31 ora_pmon_acme oracle 8828 1 0 06:35 ? 00:00:00 ora_pmon_orcl oracle 9427 8795 1 07:01 pts/2 00:00:00 grep pmon [oracle@localhost ~]$ [oracle@localhost ~]$ [oracle@localhost ~]$ ps -fea | grep smon oracle 3502 1 0 Oct19 ? 00:00:40 asm_smon_+ASM oracle 3684 1 0 Oct19 ? 00:01:14 ora_smon_acme oracle 8854 1 0 06:35 ? 00:00:00 ora_smon_orcl oracle 9429 8795 0 07:01 pts/2 00:00:00 grep smon [oracle@localhost ~]$ [oracle@localhost ~]$ ps -fea | grep lgwr oracle 3498 1 0 Oct19 ? 00:00:51 asm_lgwr_+ASM oracle 3680 1 0 Oct19 ? 00:03:18 ora_lgwr_acme oracle 8850 1 0 06:35 ? 00:00:01 ora_lgwr_orcl oracle 9435 8795 0 07:01 pts/2 00:00:00 grep lgwr [oracle@localhost ~]$ [oracle@localhost ~]$ ps -fea | grep dbw0 oracle 3496 1 0 Oct19 ? 00:00:49 asm_dbw0_+ASM oracle 3678 1 0 Oct19 ? 00:02:35 ora_dbw0_acme oracle 8848 1 0 06:35 ? 00:00:00 ora_dbw0_orcl oracle 9444 8795 0 07:02 pts/2 00:00:00 grep dbw0 [oracle@localhost ~]$ ps -fea | grep reco root 3132 2931 0 Oct19 ? 00:00:00 /usr/sbin/restorecond -u oracle 3686 1 0 Oct19 ? 00:00:22 ora_reco_acme oracle 8856 1 0 06:35 ? 00:00:00 ora_reco_orcl oracle 9603 8795 0 07:10 pts/2 00:00:00 grep reco [oracle@localhost ~]$ ps -fea | grep lreg oracle 3504 1 0 Oct19 ? 00:00:53 asm_lreg_+ASM oracle 3689 1 0 Oct19 ? 00:00:55 ora_lreg_acme oracle 8858 1 0 06:35 ? 00:00:00 ora_lreg_orcl oracle 9637 8795 0 07:13 pts/2 00:00:00 grep lreg [oracle@localhost ~]$ [oracle@localhost ~]$ ps -fea | grep arc oracle 3734 1 0 Oct19 ? 00:00:32 ora_arc0_acme oracle 3736 1 0 Oct19 ? 00:00:32 ora_arc1_acme oracle 3738 1 0 Oct19 ? 00:01:20 ora_arc2_acme oracle 3740 1 0 Oct19 ? 00:00:32 ora_arc3_acme oracle 8880 1 0 06:36 ? 00:00:00 ora_arc0_orcl oracle 8882 1 0 06:36 ? 00:00:00 ora_arc1_orcl oracle 8884 1 0 06:36 ? 00:00:00 ora_arc2_orcl oracle 8888 1 0 06:36 ? 00:00:01 ora_arc3_orcl oracle 9775 8557 0 07:20 pts/1 00:00:00 grep arc [oracle@localhost ~]$

VISTAS ARCHIVOS ORACLE DBA_DATA_FILES - DBA_TEMP_FILES

SQL> desc v$controlfile; Name Null? Type ----------------------------------------- -------- ---------------------------- STATUS VARCHAR2(7) NAME VARCHAR2(513) IS_RECOVERY_DEST_FILE VARCHAR2(3) BLOCK_SIZE NUMBER FILE_SIZE_BLKS NUMBER CON_ID NUMBER SQL> desc v$log; Name Null? Type ----------------------------------------- -------- ---------------------------- GROUP# NUMBER THREAD# NUMBER SEQUENCE# NUMBER BYTES NUMBER BLOCKSIZE NUMBER MEMBERS NUMBER ARCHIVED VARCHAR2(3) STATUS VARCHAR2(16) FIRST_CHANGE# NUMBER FIRST_TIME DATE NEXT_CHANGE# NUMBER NEXT_TIME DATE CON_ID NUMBER SQL> desc v$logfile; Name Null? Type ----------------------------------------- -------- ---------------------------- GROUP# NUMBER STATUS VARCHAR2(7) TYPE VARCHAR2(7) MEMBER VARCHAR2(513) IS_RECOVERY_DEST_FILE VARCHAR2(3) CON_ID NUMBER SQL> SQL> desc dba_data_files; Name Null? Type ----------------------------------------- -------- ---------------------------- FILE_NAME VARCHAR2(513) FILE_ID NUMBER TABLESPACE_NAME VARCHAR2(30) BYTES NUMBER BLOCKS NUMBER STATUS VARCHAR2(9) RELATIVE_FNO NUMBER AUTOEXTENSIBLE VARCHAR2(3) MAXBYTES NUMBER MAXBLOCKS NUMBER INCREMENT_BY NUMBER USER_BYTES NUMBER USER_BLOCKS NUMBER ONLINE_STATUS VARCHAR2(7) SQL> desc dba_temp_files; Name Null? Type ----------------------------------------- -------- ---------------------------- FILE_NAME VARCHAR2(513) FILE_ID NUMBER TABLESPACE_NAME NOT NULL VARCHAR2(30) BYTES NUMBER BLOCKS NUMBER STATUS VARCHAR2(7) RELATIVE_FNO NUMBER AUTOEXTENSIBLE VARCHAR2(3) MAXBYTES NUMBER MAXBLOCKS NUMBER INCREMENT_BY NUMBER USER_BYTES NUMBER USER_BLOCKS NUMBER

viernes, 23 de octubre de 2020

SERVETOUTPUT ON - DBMS_OUTPUT

 SET SERVEROUTPUT ON

 
BEGIN
 Dbms_Output.Put_Line(Systimestamp);
END;
/

DB_FLASHBACK_RETENTION_TARGET

 Configuration Best Practices

  1. Set DB_FLASHBACK_RETENTION_TARGET correctly.  Set DB_FLASHBACK_RETENTION_TARGET initialization parameter to the largest value prescribed by any of the following conditions that apply:
    • To leverage flashback database to reinstate your failed primary database after Data Guard failover, for most cases set DB_FLASHBACK_RETENTION_TARGET to a minimum of 60 (minutes) to enable reinstatement of a failed primary. 
    • Consider cases where there are multiple outages (e.g. first a network outage, followed later by a primary database outage) that may result in a transport lag between primary and standby database at failover time.  For such cases set DB_FLASHBACK_RETENTION_TARGET to a value equal to the sum of 60 (mins) plus the maximum transport lag that you wish to accommodate.  This will insure that the failed primary database can be flashed back to an SCN that precedes the SCN at which the standby became primary - a requirement for primary reinstatement.
    • If using Flashback Database for fast point in time recovery from user error or logical corruptions, set DB_FLASHBACK_RETENTION_TARGET to a value equal to the farthest time in the past that you wish to be able to recover to.
    • Set Primary and Standby  DB_FLASHBACK_RETENTION_TARGET to be the same.
  2. Size Fast Recovery Area (FRA).  Ensure the fast recovery area has allocated sufficient space to accommodate flashback database flashback logs for the target retention size and for peak batch rates.  Sizing the fast recovery area is described in detail in the 10g Database Backup and Recovery Basics guide  and the 11g Database Backup and Recovery User's Guide /  12c Database Backup and Recovery User's Guide  but the general rule of thumb is the volume of flashback log generation is approximately the same order of magnitude as redo log generation.  Use the following conservative formula and approach

Target FRA = Current FRA + DB_FLASHBACK_RETENTION_TARGET x 60 x Peak Redo Rate (MB/sec)

      Example:

  • Current FRA or DB_RECOVERY_FILE_DEST_SIZE=1000G
  • Target DB_FLASHBACK_RETENTION_TARGET=360 (360 minutes)
  • From AWR:  1) Peak redo rate for OLTP workload is 3 MB/sec for database.  2)  Peak redo rate for batch workload is 30 MB/sec for database and longest duration is 4 hours.   3) worst-case redo generation size for 6 hour window is       ( 240 minutes x 30 MB/sec x 60 secs/min) +  (120 minutes x 3 MB/sec x 60 secs/min ) = 453,600 MB or approx 443 GB
  • Proposed FRA or DB_RECOVERY_FILE_DEST_SIZE= 443 GB +1000 GB = 1443 GB.

An additional method to determine fast recovery area sizing is to enable flashback database and allow the database applications to run for a short period (2-3 hours) and query V$FLASHBACK_DATABASE_STAT.ESTIMATED_FLASHBACK_SIZE.

Note that the DB_FLASHBACK_RETENTION_TARGET is a target and there is no guarantee that you can flashback the database that far.  In some cases if there is space pressure in the flash recovery area where the flashback logs are stored then the oldest flashback logs may be deleted.  For a detailed explanation of the flash recovery area deletion rules see the Database Backup and Recovery User's Guide, Maintaining the Fast Recovery Area section.  To guarantee a flashback point-in-time you must use guaranteed restore points (GRP).  With GRP, the required flashback logs will never be recycled or purged until GRP is dropped.     You can hang the database if you have a GRP and there’s insufficient space; so you need allocate more space in the FRA depending on the intended duration of the GRP.

  1. Configure sufficient I/O bandwidth for Fast Recovery Area.  Insufficient I/O bandwidth with flashback database on is usually indicated by a high occurrence of the "FLASHBACK BUF FREE BY RVWR" wait event in an Automatic Workload Repository (AWR) report for OLTP workloads and “FLASHBACK LOG FILE WRITE” latency > 30 ms for large insert operations.   In general, flashback IOs are 1 MB in size and the overall write throughput will be similar to the redo generation rate if database force logging was enabled or similar to your load rate for direct load operations.   For simplicity, configure one large shared storage GRID and configure DATA on the outer portion of the disks or LUNS and RECO (fast recovery area) on the inner portion of the disks or LUNS.
  2. Recommended LOG_BUFFER settings to give flashback database more buffer space in memory.

    Recommend to set the LOG_BUFFER to maximum value for the specific database release and platform.   
    The previous 8 MB recommendation does not work well in high throughput applications with flashback database enabled.   

    We now recommend  64 MB for 32-bit systems
                 and up to  256 MB for 64-bit systems

  3. Set _DB_FLASHBACK_LOG_MIN_SIZE = <redo log size> for any 11.2.0.2 release.   In previous releases, the initially flashback log allocations are hindered because the initial file sizes are too small which may impact primary load performance.  As of 11.2.0.3, the default min size is the redo log group size which is the prescribed best practice.    This enhancement is not available in Oracle 10g so customers may experience some additional performance overhead until DB_FLASHBACK_RETENTION_TARGET is met 

     Example:

     SQL> alter system set "_db_flashback_log_min_size"=4g;

  1. Set _DB_FLASHBACK_LOG_MIN_TOTAL_SPACE =< projected flashback size> temporarily if you want to pre-allocate flashback logs in the FRA but you must add more space to FRA beforehand.  This is normally unnecessary since Oracle will allocate flashback logs as you generate changes.   We do recommend enabling flashback database at a non-peak period especially avoiding periods immediately prior to or during your direct load operations.   You can then monitor by querying V$FLASHBACK_DATABASE_LOG.FLASHBACK_SIZE.   Setting this undocumented parameter may be useful if you want to create a guaranteed restore point or enable flashback database prior to a big load and you want to quickly pre-allocate the necessary flashback logs.    

        Example:

            SQL> alter system set "_db_flashback_log_min_size"=4g;

            SQL> alter system set "_db_flashback_log_min_total_space"=50g;

Wait 5 minutes and query “select flashback_size from V$flashback_database_log;”   Repeat until flashback target minimum size is met.  When completed unset _DB_FLASHBACK_LOG_MIN_TOTAL_SPACE.

Operational Best Practices

  1. Gather database statistics using Automatic Workload Repository (AWR), Enterprise Manager before and after enabling flashback database so you can measure the impact of enabling flashback database.
  2. Set the Enterprise Manager monitoring metric, "Recovery Area Free Space (%)" for proactive alerts of space issues with the fast recovery area.
  3. From 11.2 onward, you can enable flashback database while the database is open.  However this operation may fail and signal an error if it fails to get enough contiguous memory.  To guarantee success, you can enable flashback in mount mode.
  4. To monitor the progress of a flashback database operation you can query the V$SESSION_LONGOPS view.  An example query to monitor progress is:

     select * from v$session_longops where opname like 'Flashback%';

If more detail is required on the flashback database operation then set _FLASHBACK_VERBOSE_INFO=TRUE database parameter which will generate a detailed trace of the flashback database operation in the DIAGNOSTIC_DEST trace directory for the database

  1. When using flashback database to perform repeated tests on a test database, it is recommended to use Guaranteed Restore Points (GRP) only without explicitly turning on flashback database.  To minimize space usage and flashback performance overhead, follow this recommended approach:

Create Guaranteed Restore Point (GRP)
Execute test
loop

     Flashback database to GRP
     Open resetlogs
     Create new GRP
     Drop old GRP
     Execute test

End loop

  1. Follow the Data Guard redo apply best practices described in Best Practices for Data Guard and Active Data Guard Redo Apply Performance.
  2. Also review the 10g Database Backup and Recovery Basics guide or the 11g Release 2 Backup and Recovery User's Guide.

Performance tuning for specific application use cases

lunes, 19 de octubre de 2020

sqlnet.ora BLOQUEAR ACCESO A ORACLE DESDE UNA IP

 

1. Bloquear el acceso a Oracle desde una IP

En caso de no tener un firewall para bloquear el acceso de ciertas ips a una base de datos lo podemos realizar a través del sqlnet.ora.

El “secreto” para bloquear o restringir el acceso por IP a la base de datos se realiza en el archivo sqlnet.ora. Este archivo lo podemos encontrar en el directorio $ORACLE_HOME/network/admin junto con los archivos tnsnames.ora y listener.ora

Editamos el archivo sqlnet.ora y añadimos las siguientes líneas:

tcp.validnode_checking = yes

Con esto conseguimos chequear los listeners que tengamos activos.

A continuación escribimos lo siguiente:

tcp.invited_nodes = (hostnameA, hostnameB)
tcp.excluded_nodes = (192.168.2.15)

Con tcp.invited_nodes puedo especificar qué máquinas quiero que su conexión sea aceptada por las base de datos.
Con tcp.excluded_nodes excluimos las máquinas que no queremos que se conecten a las bases de datos.

La idea de este mecanismo es realizar una lista de las máquinas que queremos que se conecten o realizar una lista de las máquinas que no queremos que se conecten a nuestra base de datos.

A pesar de este mecanismo de seguridad, no podemos decir que estemos totalmente exentos de recibir ataques.

Algunas reglas a tener en cuenta para generar la lista de IPS / hostnames invitados o excluidos pueden ser la siguiente:

  • Poner todos los nodos excluidos en una única línea.
  • Poner todos los nodos invitados en una única línea.
  • Se debería incluir en el listado de nodos invitados localhost.

Después de introducir estas reglas en nuestro sqlnet.ora debemos de reiniciar los listeners de la máquina.

Con nuestro usuario oracle realizamos lo siguiente:

$ lsnrctl stop nb_listener
$ lsnrctl start nb_listener

TRIGGER AFTER LOGIN RESTRINGIR SQL DEVELOPER

CREATE OR REPLACE TRIGGER LOG_T_LOGON
AFTER LOGON ON DATABASE
DECLARE
    osUser VARCHAR2(30);
    machine VARCHAR2(100);
    prog VARCHAR2(100);
    ip_user VARCHAR2(15);
BEGIN
    SELECT OSUSER, MACHINE, PROGRAM, ora_client_ip_address
    INTO osUser, machine, prog, ip_user
    FROM v$session
    WHERE SID = SYS_CONTEXT('USERENV', 'SID');
    IF (osUser = 'APuente' AND prog = 'SQL Developer')THEN
        RAISE_APPLICATION_ERROR(-20000,'Denied!  You are not allowed to logon from host '||prog|| ' using '|| osUser);
    END IF;
END;
/

VMWARE HERRAMIENTAS

Cross vCenter Workload Migration Utility

Vmware Cross Vcenter Vmotion Utility -> Migracion entre Maquinas virtuales Online VCENTERS 

Vmware Vcenter Converter


Verificar la version de vmware tools

vmware-toolbox-cmd -v

miércoles, 14 de octubre de 2020

CREATE SEQUENCES CURRVAL NEXTVAL

select * from USER_sequences

select locations_seq.currval from dual;

SQL> select sysdate from dual;

SQL> select hr.locations_seq.currval from dual;
select hr.locations_seq.currval from dual
                                     *
ERROR at line 1:
ORA-08002: sequence LOCATIONS_SEQ.CURRVAL is not yet defined in this session

SE GENERA ESTE ERROR ES PORQUE LA SECUENCIA NO SE HA UTILIZADO

SQL> select hr.locations_seq.nextval from dual;

   NEXTVAL
----------
      3300

SQL> select hr.locations_seq.currval from dual;

   CURRVAL
----------
      3300

SQL> 




lunes, 5 de octubre de 2020

ORATAB CONSULTA BASES DE DATOS EXISTENTES

[oracle@localhost etc]$ pwd

/etc

[oracle@localhost etc]$ cat /etc/oratab

#Backup file is  /u01/app/oracle/product/12.1.0/grid/srvm/admin/oratab.bak.localhost line added by Agent

#




# This file is used by ORACLE utilities.  It is created by root.sh

# and updated by either Database Configuration Assistant while creating

# a database or ASM Configuration Assistant while creating ASM instance.


# A colon, ':', is used as the field terminator.  A new line terminates

# the entry.  Lines beginning with a pound sign, '#', are comments.

#

# Entries are of the form:

#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:

#

# The first and second fields are the system identifier and home

# directory of the database respectively.  The third field indicates

# to the dbstart utility that the database should , "Y", or should not,

# "N", be brought up at system boot time.

#

# Multiple entries with the same $ORACLE_SID are not allowed.

#

#

orcl:/u01/app/oracle/product/12.1.0/db_1:N

+ASM:/u01/app/oracle/product/12.1.0/grid:N: # line added by Agent

acme:/u01/app/oracle/product/12.1.0/db_1:N: # line added by Agent

[oracle@localhost etc]$ 





martes, 8 de septiembre de 2020

DBMS_APPLICATION_INFO

Summary of DBMS_APPLICATION_INFO Subprograms

Table 22-1 DBMS_APPLICATION_INFO Package Subprograms
SubprogramDescription
READ_CLIENT_INFO ProcedureReads the value of the client_info field of the current session
READ_MODULE ProcedureReads the values of the module and action fields of the current session
SET_ACTION ProcedureSets the name of the current action within the current module
SET_CLIENT_INFO ProcedureSets the client_info field of the session
SET_MODULE ProcedureSets the name of the module that is currently running to a new module
SET_SESSION_LONGOPS ProcedureSets a row in the V$SESSION_LONGOPS table

READ_CLIENT_INFO Procedure

This procedure reads the value of the client_info field of the current session.
Syntax
DBMS_APPLICATION_INFO.READ_CLIENT_INFO (
   client_info OUT VARCHAR2); 
Parameters
Table 22-2 READ_CLIENT_INFO Procedure Parameters
ParameterDescription
client_infoLast client information value supplied to the SET_CLIENT_INFO procedure.

READ_MODULE Procedure

This procedure reads the values of the module and action fields of the current session.
Syntax
DBMS_APPLICATION_INFO.READ_MODULE ( 
   module_name OUT VARCHAR2, 
   action_name OUT VARCHAR2); 
Parameters
Table 22-3 READ_MODULE Procedure Parameters
ParameterDescription
module_nameLast value that the module name was set to by calling SET_MODULE.
action_nameLast value that the action name was set to by calling SET_ACTION or SET_MODULE.
Usage Notes
Module and action names for a registered application can be retrieved by querying V$SQLAREA or by calling the READ_MODULE procedure. Client information can be retrieved by querying the V$SESSION view, or by calling the READ_CLIENT_INFO Procedure.
Examples
The following sample query illustrates the use of the MODULE and ACTION column of the V$SQLAREA.
SELECT sql_text, disk_reads, module, action 
FROM v$sqlarea 
WHERE module = 'add_employee'; 

SQL_TEXT DISK_READS MODULE ACTION 
------------------- ---------- ------------------ ---------------- 
INSERT INTO emp 1 add_employee insert into emp 
(ename, empno, sal, mgr, job, hiredate, comm, deptno) 
VALUES 
(name, next.emp_seq, manager, title, SYSDATE, commission, department) 

1 row selected.

SET_ACTION Procedure

This procedure sets the name of the current action within the current module.
Syntax
DBMS_APPLICATION_INFO.SET_ACTION (
   action_name IN VARCHAR2); 
Parameters
Table 22-4 SET_ACTION Procedure Parameters
ParameterDescription
action_nameThe name of the current action within the current module. When the current action terminates, call this procedure with the name of the next action if there is one, or NULL if there is not. Names longer than 32 bytes are truncated.
Usage Notes
The action name should be descriptive text about the current action being performed. You should probably set the action name before the start of every transaction.
Set the transaction name to NULL after the transaction completes, so that subsequent transactions are logged correctly. If you do not set the transaction name to NULL, subsequent transactions may be logged with the previous transaction's name.
Example
The following is an example of a transaction that uses the registration procedure:
CREATE OR REPLACE PROCEDURE bal_tran (amt IN NUMBER(7,2)) AS 
BEGIN 

-- balance transfer transaction 

   DBMS_APPLICATION_INFO.SET_ACTION(
      action_name => 'transfer from chk to sav'); 
   UPDATE chk SET bal = bal + :amt 
      WHERE acct# = :acct; 
   UPDATE sav SET bal = bal - :amt 
      WHERE acct# = :acct; 
   COMMIT; 
   DBMS_APPLICATION_INFO.SET_ACTION(null); 

END;  

SET_CLIENT_INFO Procedure

This procedure supplies additional information about the client application.
Syntax
DBMS_APPLICATION_INFO.SET_CLIENT_INFO (
   client_info IN VARCHAR2); 
Parameters
Table 22-5 SET_CLIENT_INFO Procedure Parameters
ParameterDescription
client_infoSupplies any additional information about the client application. This information is stored in the V$SESSION view. Information exceeding 64 bytes is truncated.
Note:
CLIENT_INFO is readable and writable by any user. For storing secured application attributes, you can use the application context feature.

SET_MODULE Procedure

This procedure sets the name of the current application or module.
Syntax
DBMS_APPLICATION_INFO.SET_MODULE ( 
   module_name IN VARCHAR2, 
   action_name IN VARCHAR2); 
Parameters
Table 22-6 SET_MODULE Procedure Parameters
ParameterDescription
module_nameName of module that is currently running. When the current module terminates, call this procedure with the name of the new module if there is one, or NULL if there is not. Names longer than 48 bytes are truncated.
action_nameName of current action within the current module. If you do not want to specify an action, this value should be NULL. Names longer than 32 bytes are truncated.
Usage Notes
Example
CREATE or replace PROCEDURE add_employee( 
  name VARCHAR2, 
  salary NUMBER, 
  manager NUMBER, 
  title VARCHAR2, 
  commission NUMBER, 
  department NUMBER) AS 
BEGIN 
  DBMS_APPLICATION_INFO.SET_MODULE( 
    module_name => 'add_employee', 
    action_name => 'insert into emp'); 
  INSERT INTO emp 
    (ename, empno, sal, mgr, job, hiredate, comm, deptno) 
    VALUES (name, emp_seq.nextval, salary, manager, title, SYSDATE, 
            commission, department); 
  DBMS_APPLICATION_INFO.SET_MODULE(null,null); 
END;

SET_SESSION_LONGOPS Procedure

This procedure sets a row in the V$SESSION_LONGOPS view. This is a view that is used to indicate the on-going progress of a long running operation. Some Oracle functions, such as parallel execution and Server Managed Recovery, use rows in this view to indicate the status of, for example, a database backup.
Applications may use the SET_SESSION_LONGOPS procedure to advertise information on the progress of application specific long running tasks so that the progress can be monitored by way of the V$SESSION_LONGOPS view.
Syntax
DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS (
   rindex      IN OUT BINARY_INTEGER,
   slno        IN OUT BINARY_INTEGER,
   op_name     IN     VARCHAR2       DEFAULT NULL,
   target      IN     BINARY_INTEGER DEFAULT 0,
   context     IN     BINARY_INTEGER DEFAULT 0,
   sofar       IN     NUMBER         DEFAULT 0,
   totalwork   IN     NUMBER         DEFAULT 0,
   target_desc IN     VARCHAR2       DEFAULT 'unknown target',
   units       IN     VARCHAR2       DEFAULT NULL)  

set_session_longops_nohint constant BINARY_INTEGER := -1;
Parameters
Table 22-7 SET_SESSION_LONGOPS Procedure Parameters
ParameterDescription
rindexA token which represents the v$session_longops row to update. Set this to set_session_longops_nohint to start a new row. Use the returned value from the prior call to reuse a row.
slnoSaves information across calls to set_session_longops: It is for internal use and should not be modified by the caller.
op_nameSpecifies the name of the long running task. It appears as the OPNAME column of v$session_longops. The maximum length is 64 bytes.
targetSpecifies the object that is being worked on during the long running operation. For example, it could be a table ID that is being sorted. It appears as the TARGET column of v$session_longops.
contextAny number the client wants to store. It appears in the CONTEXT column of v$session_longops.
sofarAny number the client wants to store. It appears in the SOFAR column of v$session_longops. This is typically the amount of work which has been done so far.
totalworkAny number the client wants to store. It appears in the TOTALWORK column of v$session_longops. This is typically an estimate of the total amount of work needed to be done in this long running operation.
target_descSpecifies the description of the object being manipulated in this long operation. This provides a caption for the target parameter. This value appears in the TARGET_DESC field of v$session_longops. The maximum length is 32 bytes.
unitsSpecifies the units in which sofar and totalwork are being represented. It appears as the UNITS field of v$session_longops. The maximum length is 32 bytes.
Example
This example performs a task on 10 objects in a loop. As the example completes each object, Oracle updates V$SESSION_LONGOPS on the procedure's progress.
DECLARE
        rindex    BINARY_INTEGER;
        slno      BINARY_INTEGER;
        totalwork number;
        sofar     number;
        obj       BINARY_INTEGER;
 
      BEGIN
        rindex := dbms_application_info.set_session_longops_nohint;
        sofar := 0;
        totalwork := 10;
 
        WHILE sofar < 10 LOOP
          -- update obj based on sofar
          -- perform task on object target
 
          sofar := sofar + 1;
          dbms_application_info.set_session_longops(rindex, slno,
            "Operation X", obj, 0, sofar, totalwork, "table", "tables");
        END LOOP;
      END;

SENTENCIAS SQL PARA VALIDAR LOS PROCESOS EN EJECUCION
SELECT SQL_TEXT,MODULE,ACTION
FROM V$SQLAREA
WHERE SQL_TEXT = 'SELECT OWNER,COUNT(*) FROM ALL_OBJECTS GROUP BY OWNER ORDER BY OWNER'

SELECT sql_text, disk_reads, module, action 
FROM v$sqlarea 
WHERE module like 'DBA%'

jueves, 3 de septiembre de 2020

CREATE USER CON ROLE SYSDBA DINAMICO

 set define on 

prompt 'Digite el nombre de usuario:' "&&USERNAME"

CREATE USER "&USERNAME" PROFILE "DBA" IDENTIFIED BY 0r1cl310g PASSWORD EXPIRE DEFAULT TABLESPACE "USERS" TEMPORARY TABLESPACE "TEMP" ACCOUNT UNLOCK;


GRANT ADMINISTER ANY SQL TUNING SET TO "&USERNAME" ;

GRANT ADMINISTER DATABASE TRIGGER TO "&USERNAME" ;

GRANT DBA TO "&USERNAME" ;

GRANT ADMINISTER SQL TUNING SET TO "&USERNAME" ;

GRANT ADVISOR TO "&USERNAME" ;

GRANT ALTER ANY INDEX TO "&USERNAME" ;

GRANT ALTER ANY INDEXTYPE TO "&USERNAME" ;

GRANT ALTER ANY MATERIALIZED VIEW TO "&USERNAME" ;

GRANT ALTER ANY PROCEDURE TO "&USERNAME" ;

GRANT ALTER ANY SEQUENCE TO "&USERNAME" ;

GRANT ALTER ANY TABLE TO "&USERNAME" ;

GRANT ALTER ANY TRIGGER TO "&USERNAME" ;

GRANT ALTER DATABASE TO "&USERNAME" ;

GRANT ALTER SESSION TO "&USERNAME" ;

GRANT ALTER SYSTEM TO "&USERNAME" ;

GRANT ALTER TABLESPACE TO "&USERNAME" ;

GRANT ALTER USER TO "&USERNAME" ;

GRANT ANALYZE ANY TO "&USERNAME" ;

GRANT ANALYZE ANY DICTIONARY TO "&USERNAME" ;

GRANT BACKUP ANY TABLE TO "&USERNAME" ;

GRANT BECOME USER TO "&USERNAME" ;

GRANT CREATE ANY DIRECTORY TO "&USERNAME" ;

GRANT CREATE DATABASE LINK TO "&USERNAME" ;

GRANT CREATE JOB TO "&USERNAME" ;

GRANT CREATE PROFILE TO "&USERNAME" ;

GRANT CREATE ROLE TO "&USERNAME" ;

GRANT CREATE PUBLIC DATABASE LINK TO "&USERNAME" ;

GRANT CREATE PUBLIC SYNONYM TO "&USERNAME" ;

GRANT CREATE SESSION TO "&USERNAME" ;

GRANT EXECUTE ANY PROCEDURE TO "&USERNAME" ;

GRANT EXPORT FULL DATABASE TO "&USERNAME" ;

GRANT FLASHBACK ANY TABLE TO "&USERNAME" ;

GRANT GRANT ANY OBJECT PRIVILEGE TO "&USERNAME" ;

GRANT GRANT ANY PRIVILEGE TO "&USERNAME" ;

GRANT GRANT ANY ROLE TO "&USERNAME" ;

GRANT IMPORT FULL DATABASE TO "&USERNAME" ;

GRANT MANAGE TABLESPACE TO "&USERNAME" ;

GRANT RESTRICTED SESSION TO "&USERNAME" ;

GRANT SELECT ANY DICTIONARY TO "&USERNAME" ;

GRANT SELECT ANY SEQUENCE TO "&USERNAME" ;

GRANT SELECT ANY TABLE TO "&USERNAME" ;

GRANT "DBA" TO "&USERNAME" ;

GRANT "EXECUTE_CATALOG_ROLE" TO "&USERNAME" ;

GRANT "EXP_FULL_DATABASE" TO "&USERNAME" ;

GRANT "GATHER_SYSTEM_STATISTICS" TO "&USERNAME" ;

GRANT "IMP_FULL_DATABASE" TO "&USERNAME" ;

GRANT "MGMT_USER" TO "&USERNAME" ;

GRANT "OEM_ADVISOR" TO "&USERNAME" ;

GRANT "OEM_MONITOR" TO "&USERNAME" ;

GRANT "SELECT_CATALOG_ROLE" TO "&USERNAME" ;


PRIVILEGIOS V$SESSION

 SQL> GRANT SELECT ON V_$SESSION TO DBO;

martes, 25 de agosto de 2020

tamano tablespaces

 set serveroutput on size 10000

clear breaks

clear computes

clear columns

set pagesize 50

set linesize 300

set heading on


PROMPT TAMAÑO TABLESPACES ...


column tablespace_name heading 'Tablespace' justify left format a20 truncated

column tbsize heading 'Size|(Mb) ' justify left format 9,999,999.99

column tbused heading 'Used|(Mb) ' justify right format 9,999,999.99

column tbfree heading 'Free|(Mb) ' justify right format 9,999,999.99

column tbusedpct heading 'Used |% ' justify left format a8

column tbfreepct heading 'Free |% ' justify left format a8

break on report

compute sum label 'Totals:' of tbsize tbused tbfree on report

select t.tablespace_name, round(a.bytes,2) tbsize,

nvl(round(c.bytes,2),'0') tbfree,

nvl(round(b.bytes,2),'0') tbused,

to_char(round(100 * (nvl(b.bytes,0)/nvl(a.bytes,1)),2)) || '%' tbusedpct,

to_char(round(100 * (nvl(c.bytes,0)/nvl(a.bytes,1)),2)) || '%' tbfreepct

from dba_tablespaces t,

(select tablespace_name, round(sum(bytes)/1024/1024,2) bytes

from dba_data_files

group by tablespace_name

union

select tablespace_name, round(sum(bytes)/1024/1024,2) bytes

from dba_temp_files

group by tablespace_name ) a,

(select e.tablespace_name, round(sum(e.bytes)/1024/1024,2) bytes

from dba_segments e

group by e.tablespace_name

union

select tablespace_name, sum(max_size) bytes

from v$sort_segment

group by tablespace_name) b,

(select f.tablespace_name, round(sum(f.bytes)/1024/1024,2) bytes

from dba_free_space f

group by f.tablespace_name

union

select tmp.tablespace_name, (sum(bytes/1024/1024) - sum(max_size)) bytes

from dba_temp_files tmp, v$sort_segment sort

where tmp.tablespace_name = sort.tablespace_name

group by tmp.tablespace_name) c

where

t.tablespace_name = a.tablespace_name (+)

and t.tablespace_name = b.tablespace_name (+)

and t.tablespace_name = c.tablespace_name (+)

order by t.tablespace_name

/

TAMANO TABLAS

select owner,table_name,avg_row_len,num_rows,
round(sum(num_rows*avg_row_len)) as bytes, 
round(sum(num_rows*avg_row_len/1024),2) as kilobytes,
round(sum(num_rows*avg_row_len/1024/1024),2) as megabytes,
round(sum(num_rows*avg_row_len/1024/1024/1024),2) as gigabytes
--round(sum(num_rows*avg_row_len/1024/1024/1024/1024),2) as terabytes
from dba_tables
where num_rows > 0
group by owner,table_name,avg_row_len,num_rows
order by gigabytes desc



VALIDAR FORMATO ENDIAN

SQL> select * from v$transportable_platform

SQL> select tp.endian_format from v$transportable_platform tp, v$database sp where tp.platform_name = sp.platform_name

sábado, 25 de julio de 2020

PARAMETROS FLASHBACK DATABASE

SQL> select open_mode,log_mode,flashback_on from v$database;

OPEN_MODE      LOG_MODE   FLASHBACK_ON
-------------------- ------------ ------------------
READ WRITE      ARCHIVELOG   NO

SQL> 


SQL> show parameter db_flashback;

NAME      TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target      integer 1440
SQL> 

sábado, 18 de julio de 2020

Backup and Restore of ASM Metadata in Oracle 11gR2 (md_backup and md_restore)


Backup and Restore of ASM Metadata in Oracle 11gR2 (md_backup and md_restore)
ASMCMD utility was introduced in Oracle 10g and offered some basic features for navigation, search, monitoring and management, for full description see the docs here. In Oracle 11gR1 the asmcmd functionality was extended to include ability to backup existing disk groups metadata among other new 11g features, for full information refer to the docs here. In Oracle 11gR2 with the introduction of the ACFS the ASMCMD functionality was further extended see here. In Oracle 11gR2 ASMCMD can be used to perform almost all of the activities that used to be performed from sqlplus prompt previously and both sqlplus and asmcmd can be used interchangeably. In this article I will demo how to backup a disk group using md_backup command and use md_restore to obtain the SQL statements to recreate the disk groups and all the dependencies such as templates, aliases, directories and disk group attributes.
The syntax of md_backup in Oracle 11gR2 is as follow.
ASMCMD> md_backup
usage: md_backup backup_file [-G diskgroup [,diskgroup,…]]
help: help md_backup
ASMCMD>
The syntax of md_restore is as follow.
ASMCMD> md_restore
usage: md_restore backup_file [–silent][–full|–nodg|–newdg -o ‘old_diskgroup:new_diskgroup [,…]’][-S sql_script_file] [-G ‘diskgroup [,diskgroup…]’]

md_backup /tmp/backup_ASM.bcp -G data,dgdup,dgdup1,dgdup2,prim,sec

The backed diskgroup metadata can be directly restored upon failure of the disk or we can have asmcmd generate a script and later use the script to generate the disk groups and all of the dependencies from sqlplus.

md_restore /tmp/backup_ASM.bcp –full -S /tmp/ASM_diskgroup.sql


ASMCMD>  md_backup backup.bck -G data,fra


jueves, 16 de julio de 2020

RMAN BACKUP ARCHIVELOG DELETE INPUT - BACKUP ARCHIVELOG ALL NOT BACKED UP

[oracle@localhost ~]$ rman target /

Recovery Manager: Release 12.1.0.1.0 - Production on Thu Jul 16 20:58:48 2020

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ACME (DBID=2033062067)

RMAN> backup archivelog all delete input;

Starting backup at 16-JUL-20
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=96 RECID=92 STAMP=1045765588
input archived log thread=1 sequence=97 RECID=93 STAMP=1045765746
input archived log thread=1 sequence=98 RECID=94 STAMP=1045775298
input archived log thread=1 sequence=99 RECID=95 STAMP=1045778863
input archived log thread=1 sequence=100 RECID=96 STAMP=1045796445
input archived log thread=1 sequence=101 RECID=97 STAMP=1045832437
input archived log thread=1 sequence=102 RECID=98 STAMP=1045855635
input archived log thread=1 sequence=103 RECID=99 STAMP=1045862756
input archived log thread=1 sequence=104 RECID=100 STAMP=1045865866
input archived log thread=1 sequence=105 RECID=101 STAMP=1045915239
input archived log thread=1 sequence=106 RECID=102 STAMP=1045937427
input archived log thread=1 sequence=107 RECID=103 STAMP=1045937613
input archived log thread=1 sequence=108 RECID=104 STAMP=1045947407
input archived log thread=1 sequence=109 RECID=105 STAMP=1045947539
channel ORA_DISK_1: starting piece 1 at 16-JUL-20
channel ORA_DISK_1: finished piece 1 at 16-JUL-20
piece handle=+FRA/ACME/BACKUPSET/2020_07_16/annnf0_tag20200716t205900_0.267.1045947543 tag=TAG20200716T205900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: deleting archived log(s)
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_14/thread_1_seq_96.264.1045765587 RECID=92 STAMP=1045765588
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_14/thread_1_seq_97.279.1045765745 RECID=93 STAMP=1045765746
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_14/thread_1_seq_98.289.1045775295 RECID=94 STAMP=1045775298
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_14/thread_1_seq_99.265.1045778813 RECID=95 STAMP=1045778863
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_15/thread_1_seq_100.263.1045796439 RECID=96 STAMP=1045796445
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_15/thread_1_seq_101.260.1045832433 RECID=97 STAMP=1045832437
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_15/thread_1_seq_102.272.1045855633 RECID=98 STAMP=1045855635
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_15/thread_1_seq_103.300.1045862755 RECID=99 STAMP=1045862756
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_15/thread_1_seq_104.301.1045865821 RECID=100 STAMP=1045865866
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_16/thread_1_seq_105.302.1045915235 RECID=101 STAMP=1045915239
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_16/thread_1_seq_106.303.1045937425 RECID=102 STAMP=1045937427
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_16/thread_1_seq_107.294.1045937613 RECID=103 STAMP=1045937613
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_16/thread_1_seq_108.266.1045947405 RECID=104 STAMP=1045947407
archived log file name=+FRA/ACME/ARCHIVELOG/2020_07_16/thread_1_seq_109.273.1045947539 RECID=105 STAMP=1045947539
Finished backup at 16-JUL-20

Starting Control File and SPFILE Autobackup at 16-JUL-20
piece handle=+FRA/ACME/AUTOBACKUP/2020_07_16/s_1045947576.273.1045947577 comment=NONE
Finished Control File and SPFILE Autobackup at 16-JUL-20

RMAN> 


RMAN> BACKUP ARCHIVELOG ALL NOT BACKED UP;

Starting backup at 21-JUL-20
current log archived
using channel ORA_DISK_1
skipping archived logs of thread 1 from sequence 73 to 93; already backed up
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=94 RECID=90 STAMP=1046378942
channel ORA_DISK_1: starting piece 1 at 21-JUL-20
channel ORA_DISK_1: finished piece 1 at 21-JUL-20
piece handle=+FRA/ACME/BACKUPSET/2020_07_21/annnf0_tag20200721t204902_0.300.1046378943 tag=TAG20200721T204902 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 21-JUL-20

Starting Control File and SPFILE Autobackup at 21-JUL-20
piece handle=+FRA/ACME/AUTOBACKUP/2020_07_21/s_1046378943.301.1046378945 comment=NONE
Finished Control File and SPFILE Autobackup at 21-JUL-20

RMAN>