Sybase DBA User Guide For Beginners
Sybase DBA User Guide For Beginners
It is a humble attempt from our end to welcome the readers into the intriguing
and amazing world of SYBASE. Outmost care has been taken to ensure that it is
easily grasped even by the novices. This document hopefully will become the first
step before you launch yourself into the profession of DATABASE
ADMINISTRATION. Few of the topics have been copied from www.sybase.com.
Contents
What is DBMS/RDBMS?
Duties of DBA
What is Database?
Disk Initialization
10
Segments
11
Thresholds
12
12
13
13
14
Db_options
16
Configuration Parameters
16
Indexes
17
20
20
22
Hit/Miss Diagram
24
26
Page 2
26
Dbcc
27
MDA Tables
28
29
Utilities
29
Troubleshooting
30
31
32
Calculations
33
Sybase Diagram
34
34
Crontab
37
What is DBMS/RDBMS?
A Data Base Management System is a collection of programs that enable users to
create and maintain a database. It can also be said that DBMS is a process of
Page 3
Duties of DBA
The following are some of the duties of a DBA Checking the server status (automate the job in crontab to monitor the server
status).
Ensure that backups happen daily.
Health check for all the databases.
Performance related tasks (automate Update statistics & sp_recompile in
crontab).
Rebooting the servers during maintenance window.
Security Management (adding logins/users with proper approvals from
application/technical leads).
Proactively monitoring the database data & log growth (threshold setup).
Monitoring error logs.
Page 4
Statement Cache
Wash Area
Page 5
MRU
LRU
POOL
What is Database?
Database is collection of data objects (Tables, Views, Stored Procedures,
Functions, Triggers and indexes).
Number of databases that can be created under one adaptive server depends
on the configuration parameter number of databases
All the information regarding databases created in single adaptive server can
be viewed in system table SYSDATABASES and the database space usage in
SYSUSAGES.
Databases are broadly divided into system and user databases.
o System databases are default databases created during adaptive
server installation (master, model, tempdb & sysbsystemprocs) few
system databases are optional and can be created/configured by DBA
(sybsecurity, sybsyntax, DBCC and sybsystemdb). Some of them are
Sybsecurity, sybsystemdb, pubs, sybsyntax, and dbcc.
o User databases can only be created by the system administrator or
whoever has the system administrator privileges. A max of 256
Databases can be created on single adaptive server.
Syntax
Create database database_name
[On {default | database_device} [= size]
[, database_device [= size]]...]
[Log on database_device [= size]
[, database_device [= size]]...]
[With {override | default_location = "pathname"}]
[For {load | proxy_update}]
Options:
With override: must be specified when data and log segments are placed
Defaulton2K pool
Page 7
DATA
4K logical page
size
8K logical page
size
250
506
1018
2042
Global Allocation Map (SYSGAMS system table) records and tracks all the
information of all the AUs in the particular database. SYSGAMS is not
accessible by any user. For every 8GB of disk space a new GAM is created.
Page 8
Lock
A lock can persist for a long period of
time: while a page is being scanned,
while a disk read or network write takes
place, for the duration of a statement,
or for the duration of a transaction
Disk Initialization
Disk initialization is the process of allocating disk space to server. During
initialization adaptive server will divide the new allocated disk into allocation
units and an entry is made in sysdevices system table.
All the information regarding devices connected to the Server, can be viewed
in system table SYSDEVICES.
Device that can be connected to a server was up to 256 till version 12.5, later
got unlimited from version 15.
A disk that is allocated to a server cannot be shared with other servers. Any
number of databases can use a disk as long as they are in the same server,
restricting to a single file system.
Number of devices that can be allocated to the adaptive server depends on
the configuration parameter number of devices
Disk once initialized to the adaptive server can only be dropped when all the
associated databases are dropped
Disk default option for system database has to be turned off.
Syntax
Disk init
Name = "device_name" ,
Physname = "physicalname" ,
[Vdevno = virtual_device_number,]
Size = number_of_blocks
[, vstart = virtual_address
, cntrltype = controller_number]
[, contiguous]
[, dsync = {true | false}]
ASE 15.0
Disk init name = 'dev2',
Physname = '/data/sql_server.dev2',
Page 9
Whenever a user inserts some data it first checks for available pages in the current
extent (OAM) and inserts into it. If not found a new extent is allocated for that object
in the same allocation unit with the help of the allocation page. This extent is
mapped to the OAM of the object. If the extent is not available in the same
allocation unit it checks with GAM for a new allocation unit (available extent),
Page 10
Page 11
Syntax
Creates seg_name in the current database and device name
sp_addsegment seg_name, db_name, device_name: db_name matches to
current database
sp_placeobject segment_name, object_name, db_name: future allocation will
be mapped to new segment. Object name can be table name, or index name,
('tab_name.index_name')
sp_helpsegment seg_name: Displays information about all the segments in
current database. If specified display information about only one segment
which is specified
Sp_dropsegment segment_name,
segment in the current database
db_name,
Page 12
[device_name]:
drops
the
Thresholds
Thresholds monitor the free space in a database and alert the DBA to take
appropriate action to prevent the max usage of the database segments coz if
neglected the server will hang and is users cannot access.
Thresholds can be defined on data and log segments.
Two types of thresholds : System & User
o System level- Last chance Threshold. Usually 18% of log space is
reserved for LCT. LCT threshold limit value cannot be modified and is
set by the adaptive server automatically. We can only modify the
stored procedure Sp_thresholdaction.
o User level- Free chance Threshold. FCT is defined by the user as per
the usage of the database and log segment size.
Sp_thresholdaction sends alert if transaction crosses the LCT.
A max of 256 thresholds can be created for a Database.
All the details regarding the thresholds can be found in SYSTHRESHOLD.
FCTs can be dropped or modified.
Syntax
Sp_addthreshold dbname, segname, free_space, proc_name:
To add a
threshold.
Sp_modifythreshold dbname, segname, free_space [, new_proc_name] [,
new_free_space] [, new_segname]: To modify a given threshold.
Syntax
Create role role_name [with passwd "password"[, {passwd expiration | min
passwd length | max failed_logins} option_value] ]: To create a role.
Sp_addgroup grpname: To create a group.
SYSLOGIN holds the details which allow people to access the Server level.
SYSUSERS holds the details which allow people to access the Databases level.
These two above table are related with the column suid.
Syslogins: Suid, dbname, name, password, srvname, procid.
Sysusers: Suid, uid, gid, name.
Syntax
Sp_addlogin loginame, passwd [, defdb][, deflanguage][, fullname][,
passwdexp]: To create a login with a default database.
Sp_adduser loginame [, name_in_db [, grpname]]: To create a user for a login
for a database.
Page 14
Page 16
Page 17
Db_options
To change the default settings for the database we use database options.
Sp_dboption- displays or changes database options.
List of database options areTable 2 System Tables DB Options
SN
o.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
DB OPTION
abort tran on log full
allow nulls by default
async log service
auto identity
dbo use only
ddl in tran
delayed commit
disable alias access
identity in nonunique
index
no chkpt on recovery
no free space acctg
read only
single user
select
into/bulkcopy/pllsort
trunc log on chkpt
unique auto_identity
index
MASTE
R
MODE
L
TEMPD
B
SYBSYSTEMPRO
CS
No
No
No
No
No
No
No
No
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Configuration Parameters
Config parameter defines the server wide settings and is divided in to static
and dynamic.
All the static configured parameters values are stored in table sysconfigure.
All the dynamic configured parameters values are stored in table
syscurconfigure.
Config values also stored in the <server name>.cfg file and every time you
modify the config values the current <server name>.cfg file will be saved as
<server name>.001 and new config values will be appeared in <server
name>.cfg file.
We cannot start the ASE without valid config file.
Page 18
Page 19
Indexes are created for the faster retrieval of the data. Indexes are preferred
when the total requested records are less than or equal to 5% of total table
rows.
Whenever a new record is inserted into a table with no index, it stored into
the last available page called hot spot. Table without a clustered index is
known a Heap Table.
When there is no index on the table the user requested query will perform the
table scans (scanning each page that is allocated to the object). To avoid
the table scan we prefer indexes.
Indexes can be broadly divided into two types
o Clustered Indexes- There can only one clustered index for a table in
binary tree format. The leaf nodes contain the data itself. Data is
stored in physical order (asc/desc). Total 3 levels (root, intermediate &
data/leaf). Whenever we recreate the clustered index the non-clustered
index (if exists) will be automatically recreated and update statistics
will run on the object automatically (ASE will run internally).
o Nonclustered Indexes- There can be as many as 249 non clustered
indexes for a table. The leaf nodes contain pointers that map to the
actual data. This is the reason why it takes more time for nonclustered
index data. It is logical. Total 4 levels (root, intermediate. Leaf & data).
All the indexes can be found in table sysindexes for a database. Table is
identified by value 0; Clustered index is identified by value 1, where as rest
non clustered indexes are identified from 2 to 249.
Diagrams that explain clearly about clustered and non clustered
index pages.
Page 20
Page 21
Page 22
Page Split(APL)
Overflow Pages
Page 23
Row
Forwarding(DOL)
Page 24
A data-only-locked table is
updated so that it no
longer fits on the page, a
process
called
row
forwarding performs the
following steps:
The row is inserted onto a
different page, and
A pointer to the row ID on
the new page is stored in
the original location for
the row.
Indexes do not need to be
modified when rows are
forwarded. All indexes still
point to the original row
ID.
Syntax
Syntax
Page 25
Table locks
o Intent lock-An intent lock indicates that page-level or row-level locks
are currently held on a table. Adaptive Server applies an intent table
lock with each shared or exclusive page or row lock, so an intent lock
can be either an exclusive lock or a shared lock. Setting an intent lock
prevents other transactions from subsequently acquiring conflicting
table-level locks on the table that contains that locked page. An intent
lock is held as long as page or row locks are in effect for the
transaction.
o Shared lock-This lock is similar to a shared page or lock, except that it
affects the entire table. A create nonclustered index command also
acquires a shared table lock.
o Exclusive lock-This lock is similar to an exclusive page or row lock,
except it affects the entire table. For example, Adaptive Server applies
an exclusive table lock during create clustered index command.
Update and delete statements require exclusive table locks if their
search arguments do not reference indexed columns of the object.
Syslocks contains information about active locks, and built dynamically when
queried by a user. No updates to Syslocks are allowed.
Deadlock can be tuned with two options
o Deadlock checking period specifies the minimum amount of time (in
milliseconds) before Adaptive Server initiates a deadlock check for a
process that is waiting on a lock to be released.
o Deadlock retries specifies the number of times a transaction can
attempt to acquire a lock when deadlocking occurs during an index
page split or shrink.
Spinlock ratio- A spinlock is a simple locking mechanism that prevents a
process from accessing the system resource currently used by another
process. All processes trying to access the resource must wait (or spin) until
the lock is released. If 100 are specified for the spinlock ratio, Adaptive
Server allocates one spinlock for each 100 resources. The number of
spinlocks allocated by Adaptive Server depends on the total number of
resources as well as on the ratio specified. The lower the value specified for
the spinlock ratio, the higher the number of spinlocks.
Page 26
Page 27
Condition
recv sleep
Immediate
send sleep
Immediate
alarm sleep
lock sleep
waiting
on
acquisition
Sleeping
Runnable
Running
Infected
Server
has
serious error
extremely rare
lock
Immediate
killed when it "wakes up", usually
immediate; a few sleeping processes do
not wake up, and require a Server reboot
to clear
a process, such as a
threshold procedure, run
Background
by SQL Server rather than
by a user process
Page 28
Hit/Miss Diagram
During the execution of a query, it goes through many phases, which can
result as a HIT or a MISS depending on the availability of the data in the
cache.
The below diagrams clearly explain the steps involved during HIT or MISS.
Max Memory
Connection Established
Network Handler
Running
Page 29
Max Memory
Connection Established
Network Handler
Sleeping
If
query plan not found
Interface file
ASE
ASE
Running
Configur
Data
Unused
Procedu
User
1.
2.
3.
4.
Backup/Recovery/Refresh/Restore
Recovery- Getting the database to the current state of data from a previously
maintained backup.
Refresh- Loading data from one database to another irrespective of sever.
Restore- Taking the database to a previous state.
Backup- Taking an extra copy of the existing data.
Steps to be followed for test refresh.
Page 31
Dbcc
Database consistency checker (dbcc) checks the logical and physical
consistency of a database and provides statistics, planning, and repair
functionality.
dbcc Tablealloc checks the specified user table to ensure thato All pages are correctly allocated.
o Partition statistics on the allocation pages are correct.
o No page is allocated that is not used.
o All pages are correctly allocated to the partitions in the specified table
and no page is used until allocated.
o No page is used that is not allocated.
dbcc Checkalloc ensures thato All pages are correctly allocated
o Partition statistics on the allocation pages are correct
o No page is allocated that is not used
o All pages are correctly allocated to individual partitions and no page
used until allocated.
o No page is used that is not allocated
Page 32
o
dbcc
o
o
o
o
dbcc
o
o
o
dbcc
o
o
o
o
o
indexalloc checks the specified index to see thatAll pages are correctly allocated.
No page is allocated that is not used.
No page is used that is not allocated.
CheckTable checks the specified table to see thatIndex and data pages are linked correctly.
Indexes are sorted properly.
Pointers are consistent.
All indexes and data partitions are correctly linked.
Data rows on each page have entries in the row-offset table; these
entries match the locations for the data rows on the page.
o Partition statistics for partitioned tables are correct.
Dbcc checkdb runs the same checks as dbcc CheckTable on each table in
the specified database. If you do not give a database name, dbcc checkdb
checks the current database. dbcc checkdb gives similar messages to those
returned by dbcc CheckTable and makes the same types of corrections.
DBCCDB database setup
o Determine Size sp_plan_dbccdb.
o Initialize Disk Devices- Based on size create data and log devices.
o Create dbccdb Database- Create dbccdb on the above created devices.
o Install Stored Procedures- isql -Usa -P -SASESERVER iinstalldbccdb
-odbccdb_error.out.
o Configure Adaptive Server- sp_configure "number of worker processes",
2.
o Create Workspaces.
o Set dbccdb Configuration Parameters.
o Run dbcc checkstorage.
o Evaluate Configurations.
PROXY TABLES
Sp_addserver PROX_<server name>,NULL,<server name that u mention in
interface file>
Sp_addexternlogin PROX_<server name>, <login name in source server>,
<user at remote server>, <password at remote server>
Sp_addobjectdef proxy_<table name>, PROX_<server name>,<remote
database name>,<remote object owner>,<object name>,table
Page 33
MDA Tables
MDA tables provides detailed information about server status, the activity of
each process in the server, the utilization of resources such as data caches,
locks and the procedure cache, and the resource impact of each query thats
run on the server.
Steps that need to be followed during installing MDA tableso Check for sp_configure enable cis and set to 1.
o Add loopback server name alias in master - sp_addserver loopback,
null, @@servername
o Install MDA tables - isql -U sa -P <password> -S<Server Name> i
~/scripts/installmontables
o Assign 'Mon_role' to logins allowed MDA access- grant role Mon_role to
sa
o To test for basic configuration select * from master..monstate
o Assign several configuration parameters like enable monitoring to 1,
sql text pipe active to 1, sql text pipe max messages to 100, plan text
pipe active to 1, plan text pipe max messages to 100, statement pipe
active to 1, statement pipe max messages to 100, errorlog pipe active
to 1, errorlog pipe max messages to 100, deadlock pipe active to 1,
deadlock pipe max messages to 100, wait event timing to 1, process
wait events to 1, object lockwait timing to 1, sql batch capture to 1,
statement statistics active to 1, per object statistics active to 1, max
sql text monitored to 2048
Page 34
Troubleshooting
If server config value has reached the max threshold limit for number of
open databases, number of open objects, number of open indexes,
number of user connections & number of locks. Please follow the steps
below.
Sp_countmetadata- Gives information about the total number of objects like
tables, sps, views, triggers, etc. sp_countmetadata "configname" [, dbname].
Sp_monitorconfig- Gives information about max usage/current max value of
the above mentioned config parameters.
Sp_configure- To reconfigure the parameters with new value.
To check if the port is opened
Telnet <IP ADDRESS> <Port Number>
if the port is opened you will see a blank screen in command prompt....
To abort all the open transactions when log is full- Select LCT_admin(abort,
pid, dbid).
Process to kill the open transactions
a. The PID for the current running transaction can be identified from table
SYSLOGSHOLD.
b. Once the PID is identified, the user details can be found from the table
SYSPROCESSES.
c. Execute dbcc TRACEON (3604): Turning on the trace flag will display
the trace output on console rather than the error log.
Page 35
d. Execute dbcc SQL TEXT (spid) : to view the details of the transaction
e. Execute dbcc TRACEOFF (3604)
f. To Kill Process- kill PID.
To view server status in Unix- showserver, & ps-esf |grep Sybase.
To know server version details- select @@version OR records in error log OR
dataserver v.
To know the current isolation level used by the server- select @@isolation.
For manually clearing shared segments- ipcrm s/m<pid> and verify the
values with <server name>.krg file and once you clear the memory then
delete the <server name>.krg file.
Also check for any active Sybase process ps eaf |grep Sybase. Kill the active
Sybase process related to the particular server.
Memory Jam- It occurs due to the non de-allocation of the shared segments in
the shared memory.
To recover this we have to check out the number of servers running. Later we
have to match the <servername>.krg file with the details available on the
shared segment allocated to the server.
Delete the identified segment by using- ipcrm s<PID>.
Its always a better practice to hold a backup of the <servername>.krg file,
as it is deleted once the server gets shut down.
Point-In-Time Recovery
a. PITR can be done only if a valid full dump of database, transaction log
dumps and the dump of current transaction log (dump tran <db
name> to <file name> with no_truncate, this option will allow to
perform the backup if database device fails.).
b. To do PITR, steps followed are
i.
Restore the full backup
ii.
Restore all the transaction logs in the sequence
iii.
Restore the most recent transaction log which was dumped with
no_truncate option
iv.
Bring the database online.
Extending Temp Database to separate data and log segments
a.
b.
c.
d.
Page 38
Page 39
Page 40
Page 41
Calculations
To find vdev number- Select max (low/16777218) from Master..sysdevices.
Procedure cache size= (max number of concurrent users)*(4+size of largest
plan)*1.25.
Minimum
procedure
cache
size
needed=(number
of
main
procedures)*(Average plan size).
To get a rough estimate of the size of a single stored procedure, view, or
trigger, use: select(count(*) / 8) +1
from sysprocedures where id =
object_id("procedure_name").
number of worker processes = [max parallel degree] X [the number of
concurrent connections wanting to run queries in parallel] X [1.5].
Size of the tempdb = 20% of sum up of all the user databases.
Size of Log disk= 10 % of the data disk of the particular device.
Size of DBCC database- can be found out from sp_plan_dbccdb.
Stored procedure to get the segment usage report
get_segment_space.
txt
Sybase Diagram
Sybase Diagram.doc
Page 43
Page 45
OUTBOUND QUEUE
Sybase DBA
Manual
INBOUND QUEUE
Page 46
Crontab
Job scheduling at UNIX level is done in crontab. All the DBA jobs are
scheduled to run automatically in crontab. Each user on UNIX level has own
crontab and one should have the privilege to add/modify the crontab.
Syntax- crontab [ -e [opens the crontab editor] | -l [lists all the crontab
entries] | -r [removes the crontab file].
Always have the backup for crontab.
Page 47