ODBV3 and ASM


04.10.2018
by Kamil Stawiarski

At Trivadis Performance Days 2018 (awesome event by the way) I promised to deliver ODBV3 with support for ASM – and here it is! 🙂

https://github.com/ora600pl/odbv

To use it, you have to have access to a user at ASM level with at least SYSDBA privilege. In the connect string you don’t have to add AS SYSDBA as it is added for you automatically.

Here you can see a sample usage:

Let’s see a sample code for reading from ASM:

ASM.Exec("begin dbms_diskgroup.getfileattr(:1, :2, :3, :4); end;", fname,
			sql.Out{Dest: &ftype},
			sql.Out{Dest: &fsize},
			sql.Out{Dest: &fblock})
		blocks = int64(fsize)

As you can see, we are using a "hidden" DBMS_DISKGROUP package.
ASM is a variable containing a handle to ASM connection:

ASM, err := sql.Open("goracle", connSysdba)

In the beginning, we have to obtain file attributes, based on the file name.
After that, we can open a file. Please mind that fsize is returned not in bytes but in blocks.

ASM.Exec("begin dbms_diskgroup.open(:1, 'r', :2, :3, :4, :5, :6); end;", fname, ftype, fblock,
			sql.Out{Dest: &fhandle},
			sql.Out{Dest: &fblock2},
			sql.Out{Dest: &fsize2})

OPEN will give us a file handle, that we can use to read a block from file:

var block_data_s string
for i := int64(0); i < blocks; i++ {
	_, err := ASM.Exec("begin dbms_diskgroup.read(:1, :2, :3, :4); end;", fhandle, i+1, block_size,
	                    sql.Out{Dest: &block_data_s})
	if err != nil {
		log.Panic(err)
	}

	blockBytes, _ := hex.DecodeString(block_data_s)
}

In the end, we have to close a file.

ASM.Exec("begin dbms_diskgroup.close(:1) end;", fhandle)

Have fun 😉
Kamil.


Contact us

Database Whisperers sp. z o. o. sp. k.
al. Jerozolimskie 200, 3rd floor, room 342
02-486 Warszawa
NIP: 5272744987
REGON:362524978
+48 508 943 051
+48 661 966 009
info@ora-600.pl

Newsletter Sign up to be updated