Friday 11 September 2009

Linux : add additonal disk as a logical volume

# Add new disk as a logical volume

# Create partition
fdisk -l

fdisk /dev/sdb
n-1-rtn-rtn

# Create a physical volume
pvcreate /dev/sdb1
pvdisplay

# Create a virtual group VolGroup01
vgcreate VolGroup01 /dev/sdb1

# Get PE size from vgdisplay
vgdisplay
 Total PE              4094


# Create a logical volume
lvcreate -n vol01 -l 4094 VolGroup01
lvdisplay

mkfs.ext3 /dev/VolGroup01/vol01

# Add to fstab
vi /etc/fstab
/dev/VolGroup01/vol01    /u01         ext3    defaults        0 0

mount /u01


Thursday 10 September 2009

BOXI : Restore to point in time with oracle

  • Shut down services on lonmisapp01
  • Restore database to point in time before deletion
    Export ORACLE_SID=MISDB1
  • Identify required sequence number from alert log
    139776 (8:04 am)
  • Disable dataguard
    dgmgrl<br />DGMGRL> connect sys<br />DGMGRL> show configuration<br />DGMGRL> disable configuration<br />
  • Run rman nocatalog
    connect target<br />shutdown immediate<br />startup mount<br /><br />run {<br />	set until sequence 139776;<br />	restore database;<br />	recover database;<br />	}<br /><br />alter database open;<br />
  • Restore file store to point in time before deletion - safe to use last full backup
    cd /u04/oradata/backup/MISDB1/BO-filestore<br />tar xvfz lonmisapp01_BO_FILESTORE_20090910012217_20426.tgz<br /><br />mv /u04/boxi/lonmisapp01/FileStore /u04/boxi/lonmisapp01/FileStore_Old<br />mv ./u04/boxi/lonmisapp01/FileStore /u04/boxi/lonmisapp01/FileStore<br /><br />chown -R root: /u04/boxi/lonmisapp01/FileStore<br />
  • Restart services on lonmisapp01 and test


Oracle : Refresh the dataguard instance and re-enable

  • Disable dataguard on primary
    dgmgrl
    DGMGRL> connect sys
    DGMGRL> show configuration
    DGMGRL> disable configuration
  • Shutdown standby in sqlplus
    alter database recover managed standby database cancel
      shudown immediate
  • Clear out standby data files
    cd /u04/oradata/STANDBYDB/<br />rm *.dbf<br />
  • Create backup of primary control file and then shut down primary in sqlplus
    alter database create standby controlfile as '/tmp/stnd_controlfile.bkp';<br />shutdown immediate;<br />
  • Copy control file to standby and then all data files (NOT archive logs, redo logs, standby logs)
    scp /tmp/stnd_controlfile.bkp oracle@greoemdb01:/u04/oradata/MISDG1<br />cd /u04/oradata/PRIMARYDB/<br />scp * oracle@greoemdb01:/u04/oradata/STABDBYDB<br />
  • Startup standby in sqlplus
    startup mount<br />alter database recover managed standby database disconnect;<br />
  • Startup primary in sqlplus
    startup <br />
  • Re-enable dataguard configuration in dgmgrl
    dgmgrl<br />DGMGRL> connect sys<br />DGMGRL> show configuration<br />DGMGRL> enable configuration<br />
  • Check db logs on both sides!

Note
  • did not need to create standby logs as they already exist on the primary (and so are referenced in the control file (possibly) ) 
  • did not need to rename any files on the standby as the DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT params are both set correctly


Wednesday 9 September 2009

Oracle : 11GR2 - File Watchers

Trigger scheduler jobs when a glob-matched file is created in a directory

BEGIN
DBMS_SCHEDULER.CREATE_FILE_WATCHER(
FILE_WATCHER_NAME => 'EOD_FILE_WATCHER',
DIRECTORY_PATH => '?/eod_reports',
FILE_NAME => 'eod*.txt',
CREDENTIAL_NAME => 'WATCH_CREDENTIAL',
DESTINATION => NULL,
ENABLED => FALSE);
END;
/

SELECT file_watcher_name, destination, directory_path, file_name, credential_name
FROM dba_scheduler_file_watchers;

<a href="http://download.oracle.com/docs/cd/E11882_01/server.112/e10595/scheduse005.htm#CIABIEJA">Ref</a>


Oracle : 11GR2 - IGNORE_ROW_ON_DUPKEY_INDEX Hint

Silently ignore new rows that violate a single unique index. 
  • The IGNORE_ROW_ON_DUPKEY_INDEX hint applies only to single-table INSERT operations. It is not supported for UPDATE, DELETE, MERGE, or multitable insert operations.
  • IGNORE_ROW_ON_DUPKEY_INDEX causes the statement to ignore a unique key violation for a specified set of columns or for a SINGLE specified index.
  • When a unique key violation is encountered, a row-level rollback occurs and execution resumes with the next input row.
  • As with all hints, a syntax error in the hint causes it to be silently ignored. The result will be that ORA-00001 will be caused, just as if no hint were used.
Ref

Bulk operations?
Multiple rows with same UK being inserted - which get in - arbitrary ?

Oracle : 11GR2 - Recursive subqueries for hierarchy traversal

Recursive Subquery Example
===========================
WITH
  reports_to_101 (eid, emp_last, mgr_id, reportLevel) AS
  (
     SELECT employee_id, last_name, manager_id, 0 reportLevel
     FROM employees
     WHERE employee_id = 101
   UNION ALL
     SELECT e.employee_id, e.last_name, e.manager_id, reportLevel+1
     FROM reports_to_101 r /* MAGIC IS HERE */
         ,employees e
     WHERE r.eid = e.manager_id
  )
SELECT eid, emp_last, mgr_id, reportLevel
FROM reports_to_101
ORDER BY reportLevel, eid;

       EID EMP_LAST                      MGR_ID REPORTLEVEL
---------- ------------------------- ---------- -----------
       101 Kochhar                          100           0
       108 Greenberg                        101           1
       200 Whalen                           101           1
       203 Mavris                           101           1
       204 Baer                             101           1
       205 Higgins                          101           1
       109 Faviet                           108           2
       110 Chen                             108           2
       111 Sciarra                          108           2
       112 Urman                            108           2
       113 Popp                             108           2
       206 Gietz                            205           2

Ref


Oracle : 11GR2 - LISTAGG - the long missing string concatentation built-in

Finally

LISTAGG Example
===============
SELECT department_id "Dept.",
  LISTAGG(last_name, '; ')
   WITHIN GROUP (ORDER BY hire_date) "Employees"
   FROM employees
   GROUP BY department_id;

Dept. Employees
------ ------------------------------------------------------------
    10 Whalen
    20 Hartstein; Fay
    30 Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares
    40 Mavris
    50 Kaufling; Ladwig; Rajs; Sarchand; Bell; Mallin; Weiss; Davie
       s; Marlow; Bull; Everett; Fripp; Chung; Nayer; Dilly; Bissot
       ; Vollman; Stiles; Atkinson; Taylor; Seo; Fleaur; Matos; Pat
       el; Walsh; Feeney; Dellinger; McCain; Vargas; Gates; Rogers;
        Mikkilineni; Landry; Cabrio; Jones; Olson; OConnell; Sulliv
       an; Mourgos; Gee; Perkins; Grant; Geoni; Philtanker; Markle
    60 Austin; Pataballa; Lorentz; Ernst; Hunold
    70 Baer

  • Throws a ORA-01489: result of string concatenation is too long is > 4000 chars ! -
  • No way to suppress (?) so need to avoid
with base_data as (
select
table_name,
sum(length(table_name)) over (order by table_name)
  + row_number () over (order by table_name)        tot_length
from dba_tables
where 1=1
and owner = 'SYS'
order by table_name
)
select
listagg(table_name,';') within group (order by table_name)
from base_data b
where tot_length < 4000

Ref



Oracle : 11GR2 - Selected new features

Drawn from the 11GR2 New features doc

Definitely Interesting
1.2.2.4 IGNORE_ROW_ON_DUPKEY_INDEX Hint for INSERT Statement
1.3.1.1 Analytic Functions 2.0
1.3.1.2 Recursive WITH Clause
1.3.2.2 Preprocessing Data for ORACLE_LOADER Access Driver in External Tables
1.5.2.1 E-mail Notification
1.5.2.2 File Watcher
1.5.2.4 Remote Database Jobs
1.5.3.1 Data Pump Legacy Mode

Possibly Interesting
1.2.3.2 Configurable Real-Time Query Apply Lag Limit
1.9.2.3 Automatic Patching of Time Stamp With Time Zone Data
1.3.4.2 Minimal Effort Parallel Execution - Auto Degree of Parallelism (DOP) and Queuing
1.9.2.10 Enable Sampling for Active Data Guard
1.9.2.12 Global Oracle RAC ASH Report + ADDM Backwards Compatibility

RAC - Possibly Interesting
1.4.1.6 Grid Plug and Play (GPnP)
1.4.1.7 Oracle Restart
1.4.1.10 Role-Separated Management
1.4.1.13 Enterprise Manager-Based Clusterware Resource Management
1.4.1.14 Enterprise Manager Provisioning for Oracle Clusterware and Oracle Real Application Clusters
1.4.1.17 Configuration Assistant Support for Removing Oracle RAC Installations
1.4.1.18 Oracle Universal Installer Support for Removing Oracle RAC Installations
1.4.1.22 Out-of-Place Oracle Clusterware Upgrade
1.4.1.26 SRVCTL Support for Single-Instance Database in a Cluster

Definitely Interesting

1.2.2.4 IGNORE_ROW_ON_DUPKEY_INDEX Hint for INSERT Statement
With INSERT INTO TARGET...SELECT...FROM SOURCE, a unique key for some to-be-inserted rows may collide with existing rows. The IGNORE_ROW_ON_DUPKEY_INDEX allows the collisions to be silently ignored and the non-colliding rows to be inserted. A PL/SQL program could achieve the same effect by first selecting the source rows and by then inserting them one-by-one into the target in a block that has a null handler for the DUP_VAL_ON_INDEX exception. However, the PL/SQL approach would take effort to program and is much slower than the single SQL statement that this hint allows.
This hint improves performance and ease-of-programming when implementing an online application upgrade script using edition-based redefinition.

1.3.1.1 Analytic Functions 2.0
New and enhanced analytical functions are introduced in this release. A new ordered aggregate, LISTAGG, concatenates the values of the measure column. The new analytic window function NTH_VALUE (a generalization of existing FIRST_VALUE and LAST_VALUE functions) gives users the functionality of retrieving an arbitrary (or nth) record in a window.
The LAG and LEAD functions are enhanced with the IGNORE NULLS option.
The new and enhanced SQL analytical functions allow more complex analysis in the database, using (simpler) SQL specification and providing better performance.
See Also:
Oracle Database Data Warehousing Guide for details

1.3.1.2 Recursive WITH Clause
The SQL WITH clause has been extended to enable formulation of recursive queries.
Recursive WITH clause complies with the American National Standards Institute (ANSI) standard. This makes Oracle ANSI-compatible for recursive queries.
See Also:
Oracle Database SQL Language Reference for details

1.3.2.2 Preprocessing Data for ORACLE_LOADER Access Driver in External Tables
The syntax for the ORACLE_LOADER access driver is extended in this release to allow specification of a program to preprocess the data files that are read for the external table. The access parameters can specify the name of a directory object and the name of an executable file in that directory object. When the access driver needs to read data from a file, it creates a process that runs the specified program, passing in the name of the data file. The output from the program is passed into the access driver which parses the data into records and columns.
The initial use of this feature is by a customer who needs to load data that is stored in compressed files. The user specifies the name of the program used to decompress the file as part of the access parameters. The access driver reads the output of the decompression program.
Large customers want to load data from compressed files which requires less disk space and uses the I/O bandwidth between the disk and memory more efficiently.

1.5.2.1 E-mail Notification
Oracle Database 11g Release 2 (11.2) users can now get e-mail notifications on any job activity.
This feature improves efficiency by enabling users to be notified of any job activity that is of interest to them without having to constantly monitor the job.

1.5.2.2 File Watcher
File watcher enables jobs to be triggered when a file arrives on a given machine.
This feature improves efficiency and ease-of-use. Jobs with file dependencies are automatically triggered when the specified file is received instead of constantly monitoring for the file.

1.5.2.4 Remote Database Jobs
This feature enables users to run PL/SQL blocks or stored procedures that reside in a remote database as a job.
This is a key feature for Enterprise Manager scheduling. It improves efficiency and ease-of-use by enabling job scheduling in a distributed environment to be managed centrally.

1.5.3.1 Data Pump Legacy Mode
Data Pump Legacy Mode provides backward compatibility for scripts and parameter files used for original Export and Import scripts.
This feature enables users to continue using original Export and Import scripts with Data Pump Export and Import. Development time is reduced as new scripts do not have to be created.

Possibly Interesting

1.2.3.2 Configurable Real-Time Query Apply Lag Limit
A physical standby database can be open for read-only access while redo apply is active only if the Oracle Active Data Guard option is enabled. This capability is known as real-time query.
The new STANDBY_MAX_DATA_DELAY session parameter can be used to specify a session-specific apply lag tolerance, measured in seconds, for queries issued by non-administrative users to a physical standby database that is in real-time query mode.
This capability allows queries to be safely offloaded from the primary database to a physical standby database, because it is possible to detect if the standby database has become unacceptably stale.

1.9.2.3 Automatic Patching of Time Stamp With Time Zone Data
Time stamp with time zone data could become stale in the database tables when the time zone version file is updated. Today, users have to manually fix the affected data. This feature updates the system and user data transparently with minimal downtime and provides automatic and transparent patching of time stamp with time zone data whenever a time zone file is updated.
Also, when a server time zone version is patched, all of the clients that communicate with the server need to be patched as well. With this feature, OCI, JDBC, Pro*C, and SQL*Plus clients can now continue to work with the server without having to update their client-side files.
This new feature provides automatic and transparent patching of time stamp with time zone data whenever a time zone file is updated.

1.3.4.2 Minimal Effort Parallel Execution - Auto Degree of Parallelism (DOP) and Queuing
When activated, Oracle determines the optimal degree of parallelism (DOP) for any given SQL operation based on the size of the objects, the complexity of a statement, and the existing hardware resources.

1.9.2.10 Enable Sampling for Active Data Guard
Active Session History (ASH) is now available on standby systems.
Having ASH data available on standby systems for Data Guard environments allows customers to troubleshoot performance problems specific to their standby environments.

1.9.2.12 Global Oracle RAC ASH Report + ADDM Backwards Compatibility
The Active Session History (ASH) report now includes cluster-wide information, greatly enhancing it's utility in identifying and troubleshooting performance issues that span nodes for a cluster database.

RAC - Possibly Interesting

1.4.1.6 Grid Plug and Play (GPnP)
Grid Plug and Play (GPnP) eliminates per-node configuration data and the need for explicit add and delete nodes steps. This allows a system administrator to take a template system image and run it on a new node with no further configuration. This removes many manual operations, reduces the opportunity for errors, and encourages configurations that can be changed easily. Removal of the per-node configuration makes the nodes easier to replace, because they do not need to contain individually-managed state.
Grid Plug and Play reduces the cost of installing, configuring, and managing database nodes by making their per-node state disposable. It allows nodes to be easily replaced with regenerated state.

1.4.1.7 Oracle Restart
Oracle Restart improves the availability of your single-instance Oracle database. Oracle Restart automatically restarts the database instance, the Automatic Storage Management (ASM) instance, the listener, and other components after a hardware or software failure or whenever your database host computer restarts. Server Control (SRVCTL) is the command line interface to manage Oracle processes that are managed by Oracle Restart on a standalone server.
This feature provides improved reliability and automated management of a single-instance Oracle database and the management of any process or application running on the database server.

1.4.1.10 Role-Separated Management
Role-separated management for Oracle Clusterware allows certain administrative tasks to be delegated to different people, representing different roles in the company. It is based on the idea of a clusterware administrator. The administrator may grant administrative tasks on a per resource basis. For example, if two databases are placed into the same cluster, the clusterware administrator can manage both databases in the cluster. But, the clusterware administrator may decide to grant different administrative privileges to each DBA responsible for one of those databases.
Role-separated management allows multiple applications and databases to share the same cluster and hardware resources, but ensures that different administration groups do not interfere with each other

1.4.1.13 Enterprise Manager-Based Clusterware Resource Management
New in this release is an Enterprise Manager graphical user interface (GUI) to manage various Oracle Clusterware resources with full lifecycle support. In addition to allowing the creation and configuration of resources within Oracle Clusterware, it also helps to monitor and manage resources once deployed in the cluster.
Using Oracle Enterprise Manager as a GUI to monitor and manage various Oracle Clusterware resources eases the daily management in high availability environments.

1.4.1.14 Enterprise Manager Provisioning for Oracle Clusterware and Oracle Real Application Clusters
Enterprise Manager provisioning introduces procedures to easily scale up or scale down Oracle Clusterware and Oracle Real Application Clusters.
Ease-of-implementation and management for a clustered database environment can be achieved through utilizing the terprise Manager provisioning framework.

1.4.1.17 Configuration Assistant Support for Removing Oracle RAC Installations
Database Configuration Assistant (DBCA), Database Upgrade Assistant (DBUA), and Net Configuration Assistant (NETCA) have been updated to support the complete deinstallation and deconfiguration of Oracle RAC databases and listeners.
This support improves the manageability of an Oracle RAC environment through automation of deinstallation and deconfiguration of Oracle RAC databases.

1.4.1.18 Oracle Universal Installer Support for Removing Oracle RAC Installations
The installer can clean up a failed Oracle Clusterware installation or upgrade of an environment prior to reattempting the operation. This ensures that the reattempted operation is done over a clean environment, thereby eliminating the chances of errors related to environmental inconsistencies.
Easily cleaning up an environment provides improved Oracle RAC manageability and deployment.

1.4.1.22 Out-of-Place Oracle Clusterware Upgrade
A new version of Oracle Clusterware is now installed into a separate home from the current installation. This reduces the downtime required to upgrade a node in the cluster and facilitate the provisioning of clusters within an enterprise.
The benefit is a reduction in planned outage time required for cluster upgrades which assists in meeting availability service levels. This also makes it easier to provide a standard installation across the enterprise.

1.4.1.26 SRVCTL Support for Single-Instance Database in a Cluster
Using SRVCTL, you can register a single-instance database to be managed by Oracle Clusterware. Once registered, Oracle Clusterware starts, stops, monitors, and restarts the database instance.
This feature provides an improved management interface which makes it easy to provide higher availability for single-instance databases that are running on a server that is part of a cluster.

Fini



Thursday 3 September 2009

Oracle: Exporting Grid Control Repository Database

Resolve EXP-00079 EXP-00056 (exp) and ORA-28112 (expdp) Errors when Exporting Grid Control Repository Database using Traditional Export or Datapump Export (1oG+)

grant exempt access policy to EXPORTING_USER;




Oracle : Archivelog mode 2

# For RAC bring down other instances
srvctl stop instance -d NTPDB1 -i NTPDB12

# On remaining instance
alter system set log_archive_dest_1='location=/u02/volntpdblogs01/oradata/NTPDB1/archive' scope=spfile
alter system set log_archive_format='%t_%s_%r.dbf' scope=spfile
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
ALTER SYSTEM SWITCH LOGFILE;

# For RAC bring back other instances
srvctl start instance -d NTPDB1 -i NTPDB12


Tuesday 1 September 2009

Oracle : Drop corrupt AQ tables

alter session set events '10851 trace name context forever, level 2';

This disables ORA-24005 message then table can be dropped using conventional SQL DROP