DisCopy


Wednesday, 11 January 2012

sp__deviceinfo

sp__deviceinfo
This procedure displays the information of devices.

Input Parameters:
  • min_space – lists all the devices with the specified size of minimum free space on the device in MBs.
  • dev_name - name of the device or devices matchs the pattern.

Usage Examples:
  • sp__freedevice - displays the information of all the devices.
  • sp__freedevice 100,’User_Data’ - displays all the devices like User_Data1, User_Data2  etc., with >= 100MB free space.

create procedure sp__deviceinfo @min_space int = null, @dev_name varchar(64) = null
as
begin
declare @numpgsmb integer /* Number of 'virtual' Pages in MegaBytes */
select @numpgsmb = (1048576 / @@maxpagesize)
select "phyname"=convert(varchar(64), d.phyname),
"name"=convert(varchar(32),d.name),
"d_size"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb),
"d_used"=convert(varchar(6), sum(u.size / @numpgsmb)) ,
"d_free"=((1 + d.high - d.low) / @numpgsmb) - sum(u.size / @numpgsmb),
vdevno=d.low/power(2,24) & 255
into #device_tbl
from master..sysusages u, master..sysdevices d
where u.vstart between d.low and d.high
and d.status & 2 = 2
group by d.name

select
vdevno=low/power(2,24) & 255,
"Physical Name"=convert(varchar(40), d.phyname),
"Device Name"=convert(varchar(28),d.name),
"Size"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb),
"Used"=convert(varchar(6),0),
"Free"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb)
from master..sysdevices d
where d.name not in (select tmp.name from # device _tbl tmp)
and d.status & 2 = 2
and ( @min_space is null or ((1 + d.high - d.low) / @numpgsmb) >= @min_space )
and ( @dev_name is null or d.phyname like @dev_name or d.name like @dev_name)
union
select vdevno , phyname , name , d_size , d_used , convert(varchar(6), d_free)
from # device_ tbl
where ( @min_space is null or d_free >= @min_space )
and ( @dev_name is null or phyname like @dev_name or name like @dev_name)
order by 1
end
go

More Info of sysdevices:

sysdevices contains one row for each tape dump device, disk dump device, disk for databases, and disk partition for databases. There are four entries in sysdevices in the Adaptive Server distribution media: one for the master device (for databases), one for a disk dump device, and two for tape dump devices.

The columns for sysdevices are:

NameDatatypeDescription
low int Not used for dump devices – block offset of virtual page in 2K bytes
high int Block offset of last virtual page in 2K bytes
status smallint Bitmap indicating type of device, default, and mirror status
cntrltype smallint Controller type:
  • Database device=0
  • Disk dump device or streaming tape=2
  • Tape dump device=3 – 8
name sysname Logical name of dump device or database device
phyname varchar(127)Name of physical device
mirrornamevarchar(127) nullName of mirror device
vdevnointDevice identification number
crdatedatetime nullDate on which the device was added
resizedatedatetime nullDate on which disk resize was most recently run for this device
status2intAdditional status bits for this device



Bit representations for the status column.
DecimalHex Status
10x01Default disk
20x02Physical disk
40x04Not used – logical disk
80x08Skip header
160x10Dump device
320x20Serial writes
640x40Device mirrored
1280x80Reads mirrored
2560x100Secondary mirror side only
5120x200Mirror enabled
10240x400Master device is mirrored
20480x800Used internally – mirror disabled
40960x1000Used internally – primary device must be unmirrored
81920x2000Used internally – secondary device must be unmirrored
163840x4000UNIX file device uses dsync setting (writes occur directly to physical media)


sysusages

sysusages contains one row for each disk allocation piece assigned to a database. Each database contains a specified number of database (logical) page numbers.  The create database command checks sysdevices and sysusages to find available disk allocation pieces. One or more contiguous disk allocation pieces are assigned to the database, and the mapping is recorded in sysusages.

The columns for sysusages are:

NameDatatypeDescription
dbidsmallintDatabase ID
segmapintBitmap of possible segment assignments
lstartintFirst database (logical) page number
sizeintNumber of contiguous database (logical) pages
vstartintStarting virtual page number
padsmallint nullUnused
unreservedpgsint nullFree space not part of an allocated extent
crdatedatetime nullCreation date
vdevnointDevice identification number


No comments:

Post a Comment