Apr 15 2013

Oracle Database Gateways 11g R2 (11.2) Installation and Configuration for heterogeneous connection from Oracle to Microsoft SQL database

Category: 11g,Databaseittichai @ 5:33 pm

Installation

Install the Oracle Database Gateways 11g R2 (11.2). See the screen snapshots of the installation here.

Configuration

  • During the installation, the following+ default initialization parameter file is created:
[ORACLE_DG_HOME]\dg4msql\admin\initdg4msql.ora
dg4msql = Database gateway for Microsoft SQL Server. 
If you choose a different database option, use the appropriate path name.
  • Copy initdg4msql.ora to a new file init[MSSQL].ora.
[MSSQL] can be any meaningful name easier to refer to, for example, mssqlsale. 
The filename will be in the format of init[MSSQL].ora.
copy initdg4msql.ora initmssqlsale.ora
  • Modify newly created file initmssqlsale.ora and modify or add the MS SQL server & database name.
# This is a customized agent init file that contains the HS parameters
# that are needed for the Database Gateway for Microsoft SQL Server
#
# HS init parameters
#
HS_FDS_CONNECT_INFO=[SERVERNAME]//DATABASENAME
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
  • Modify the listener.ora file. This can be that of the existing listener or new listener. Add SID_DESC to the appropriate place in the listener.ora file.
         (SID_DESC=
            (SID_NAME=[MSSQL])
            (ORACLE_HOME=[ORACLE_DG_HOME])
            (PROGRAM=[DRIVER])
         )
[MSSQL] =  Name of the new configuration file excluding the init and .ora.
For example, if the file name is initmssqlsale.ora, the [MSSQL] will be only mssqlsale.
[ORACLE_DG_HOME] = Oracle Database Gateway Home. This is NOT listener home.
[DRIVER] = dg4msql for Microsoft SQL Server

Sample:

 
LISTENER =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = DGHOST)(PORT = 1521))
      )
    )

SID_LIST_LISTENER = 
   (SID_LIST=
     (SID_DESC=
            (SID_NAME=mssqlsale)
            (ORACLE_HOME=D:\product\11.2.0\tg_1)
            (PROGRAM=dg4msql)
      )
    )
 )
  • Restart or reload the listener.
  • Validate using lsnrctl status.
C:\>lsnrctl status
LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production
:
:
Services Summary...
Service "mssqlsale" has 1 instance(s).
 Instance "mssqlsale", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
  • On different Oracle database where we’d like to connect to this MS SQL database, create a new database link. The new database link will point to the the host where the gateway is installed.
create database link dblink_mssqlsale connect to "username" identified by "password"
using '
     (DESCRIPTION=
        (ADDRESS=(PROTOCOL=tcp)(HOST=DGHOST)(PORT=1521))
        (CONNECT_DATA=(SID=mssqlsale))
        (HS=OK)
     )';
DGHOST = Host where the Oracle Database Gateway is installed.
mssqlsale = SID name mentioned in the listener.ora.
  • Try to query for a table.
select count(*) from information_schema.tables@dblink_mssqlsale;
 COUNT(*)
----------
 26

Add more MS SQL databases

  • Repeat the above steps starting with copying the sample file into a new init file, and updating it with an appropriate host and database name.
copy initdg4msql.ora to initmssqlhr.ora
  • Update the listener.ora.
  (SID_LIST=
     (SID_DESC=
            (SID_NAME=mssqlsale)
            (ORACLE_HOME=D:\product\11.2.0\tg_1)
            (PROGRAM=dg4msql)
     )
     (SID_DESC=
            (SID_NAME=mssqlhr)
            (ORACLE_HOME=D:\product\11.2.0\tg_1)
            (PROGRAM=dg4msql)
     )
  )
  • Restart or reload listener. Check using lsnrctl status.


Jan 21 2013

How long did Oracle materialized view refresh run?

Category: Database,Materialized Viewsittichai @ 9:38 am

The LAST_REFRESH_DATE column of the DBA_MVIEWS or the LAST_REFRESH column of the DBA_MVIEW_REFRESH_TIMES indicates the start refresh time. But what if we’d like to find out how long the refresh of the materialized view really takes. Well, we can query the DBA_MVIEW_ANALYSIS.

For Complete Refresh, the refresh duration will be in the FULLREFRESHTIM column of the DBA_MVIEW_ANALYSIS. For Fast Refresh duration, it will be in the INCREFRESHTIM column.

Both values are in seconds.

SELECT mview_name, last_refresh_date, fullrefreshtim, increfreshtim
FROM dba_mview_analysis
WHERE owner='JOHN';

MVIEW_NAME               LAST_REFRESH_DATE      FULLREFRESHTIM INCREFRESHTIM
------------------------ ---------------------- -------------- -------------
MV_CHANGE_HISTORY        07-JAN-13 04.36.58 PM               0            36
MV_ITEM_HISTORY          07-JAN-13 04.36.58 PM               0             9

This shows that the recent refresh of the MV_CHANGE_HISTORY and MV_ITEM_HISTORY are the fast refreshes for 36 and 9 seconds respectively.

Put in one query to calculate and display the end time.

SELECT 
   mview_name,
   last_refresh_date "START_TIME",
   CASE
      WHEN fullrefreshtim <> 0 THEN
         LAST_REFRESH_DATE + fullrefreshtim/60/60/24
      WHEN increfreshtim <> 0 THEN
         LAST_REFRESH_DATE + increfreshtim/60/60/24
      ELSE
         LAST_REFRESH_DATE
   END "END_TIME",
   fullrefreshtim,
   increfreshtim
FROM all_mview_analysis
WHERE owner='JOHN';

MVIEW_NAME              START_TIME             END_TIME               FULLREFRESHTIM INCREFRESHTIM
----------------------- ---------------------- ---------------------- -------------- -------------
MV_CHANGE_HISTORY       07-JAN-13 04.36.58 PM  07-JAN-13 04.37.34 PM               0            36
MV_ITEM_HISTORY         07-JAN-13 04.36.58 PM  07-JAN-13 04.37.07 PM               0             9

Reference: How To Calculate MVIEW Refresh Duration? What Does DBA_MVIEWS.LAST_REFRESH_DATE and DBA_MVIEW_REFRESH_TIMES.LAST_REFRESH Indicate? [ID 1513554.1]

Tags: , , , ,


Aug 10 2012

Create Google Tasks by sending email to Google GMail Address

Category: Programming,Toolittichai @ 7:59 am

I use Google Tasks for a quick to-do list. It has clean interface and is easy to use. On desktop or laptop machine, it is built-in to Google Mail for quick access. On smartphones, many to-do apps including Tasks N Todos sync with Google tasks.

The neat thing is that in the Google Mail, you can add Gmail messages into the task list very easily by selecting the messages and then using More Actions > Add to Tasks. What if you want to add email messages from other mails like that from work, or Yahoo Mail, etc., it doesn’t seem that there is a straightforward way to do so.

I found this web log on the automated email-to-task with Google Apps Script by DJ Adams. The Google Apps Script is able to parse the email with a specific filtered label and create a task automatically. Let’s give it a try.

The overall process is as follows:

  • Two new Gmail labels will be created – newtask and newtaskdone. When a new email is arrived, the filter will label it with newtask. Once the script processes this email, it will be re-labeled to newtaskdone so it won’t be processed again.
  • To make sure that only specified emails – not all – are processed, one of the hidden features of Gmail will be used. The filter will look for only +task@gmail.com (such as ittichai+task@gmail.com) in the TO address to apply new label. Read this on how to use “+” (plus ) or “.” (dot) in your Gmail address.
  • The Apps Script will be created from Google Spreadsheet. The original post is to use only the email’s subject for the task’s title but I modified codes a bit to include the email’s body to be the task’s body as well.
  • One of the important things is to integrate the script with Google API so it will be allowed to use the Google Tasks’ API service and content.
  • Schedule it to run with a needed interval. I’m doing it every 30 minutes. Note that there is a courtesy limit of 5,000 requests per day. But this should be more than enough for a normal use.

Courtesy Limit of Tasks API

  • Now just simply forward all emails to+task@gmail.com if you want to add them into the task list. It should show up in the Google Tasks within your specified interval.

All step-by-step instructions can be found at my wiki site.

Tags: , , , , , ,


Jul 06 2012

Resizing the filesystem using Logical Volume Manager within Oracle Linux

Category: Linux,OSittichai @ 8:53 pm

Oftentimes we all run into the situation where the file system is full (or almost full) and need more space. This expansion task seems to be a lot easier when using the Logical Volume Manager (LVM) in Oracle Linux.

  • Review the current size.
[root@ol6 ~]# df -H
Filesystem                 Size   Used  Avail Use% Mounted on
/dev/mapper/vg_ol6-lv_root 27G    22G   3.8G  86% /
tmpfs                      1.3G   209M   1.1G  17% /dev/shm
/dev/sda1                  508M    97M   385M  21% /boot
Downloads                  750G   172G   578G  23% /media/sf_Downloads

Plan to add 30G to the root file system.

  • Create a partition on the newly-added disk.
[root@ol6 ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x0c04311f.
Changes will remain in memory only, until you decide to write them.

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916): 
Using default value 3916

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
  •  Create a physical volume on top of it.
[root@ol6 ~]# pvcreate /dev/sdf1
  Writing physical volume data to disk "/dev/sdf1"
  Physical volume "/dev/sdf1" successfully created
  • Review the current volume. Note that currently there is no free extends (noted by zero value of the “Free PE / Size”).
[root@ol6 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_ol6
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               29.51 GiB
  PE Size               4.00 MiB
  Total PE              7554
  Alloc PE / Size       7554 / 29.51 GiB
 Free PE / Size 0 / 0  
  VG UUID               2e2VHd-Mb3D-Uz0G-4Yec-tbfe-f3cI-7cvpby
  • Extend this volume with a new disk.
[root@ol6 ~]# vgextend vg_ol6 /dev/sdf1
  Volume group "vg_ol6" successfully extended
  • Check the volume again. The “Free PE / Size” is now 30G.
[root@ol6 ~]# vgdisplay
--- Volume group ---
VG Name vg_ol6
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 59.50 GiB
PE Size 4.00 MiB
Total PE 15233
Alloc PE / Size 7554 / 29.51 GiB
Free PE / Size 7679 / 30.00 GiB
VG UUID 2e2VHd-Mb3D-Uz0G-4Yec-tbfe-f3cI-7cvpby
  • Now let’s review the logical volume.
[root@ol6 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_ol6/lv_root
  LV Name                lv_root
  VG Name                vg_ol6
  LV UUID                rd2d4X-vqE8-xENi-clCz-Oa0T-0R6X-RFCBDq
  LV Write Access        read/write
  LV Creation host, time , 
  LV Status              available
  # open                 1
 LV Size 25.10 GiB
  Current LE             6426
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_ol6/lv_swap
  LV Name                lv_swap
  VG Name                vg_ol6
  LV UUID                xM3Blz-wvpG-IUfF-WhWc-EHoI-I0xG-oeV1IR
  LV Write Access        read/write
  LV Creation host, time , 
  LV Status              available
  # open                 1
  LV Size                4.41 GiB
  Current LE             1128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

We want to add additional 30G into the existing /dev/vg_ol6/lv_root. So the total size will be 55.1GB.

  • We can extend the logical volume to the needed size.
[root@ol6 ~]# lvextend -L 55.10G /dev/vg_ol6/lv_root
  Rounding size to boundary between physical extents: 55.10 GiB
  Extending logical volume lv_root to 55.10 GiB
  Insufficient free space: 5120 extents needed, but only 5119 available

You may have to adjust the size if the initial specified size is too large.

[root@ol6 ~]# lvextend -L 55G /dev/vg_ol6/lv_root
  Extending logical volume lv_root to 55.00 GiB
  Logical volume lv_root successfully resized
  • Now finally you can extend the file system.
[root@ol6 ~]# resize2fs /dev/vg_ol6/lv_root 55G
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_ol6/lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 4
Performing an on-line resize of /dev/vg_ol6/lv_root to 14417920 (4k) blocks.
The filesystem on /dev/vg_ol6/lv_root is now 14417920 blocks long.
  • The file system is resized while the system is still on-line.
[root@ol6 ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_ol6-lv_root
55G 22G 33G 39% /
tmpfs 1.3G 209M 1.1G 17% /dev/shm
/dev/sda1 508M 97M 385M 21% /boot
Downloads 750G 172G 578G 23% /media/sf_Downloads

References:

Tags: , , , , , , ,


Next Page »