你use tempdb
sp_dropsegment 'default',tempdb,master
sp_dropsegment system,tempdb,master
sp_dropsegment logsegment,tempdb,master
后,
sp_helpdb tempdb
select db_name(dbid),segmap,lstart,size,vstart,pad,unreservedpgs
from sysusages
where dbid=2
贴出来
如果第一行中segmap为0,就ok
一般情况下数据库装好之后,都要给tempdb增加空间,因为在用户数据库中的很多插入,删除等操作需要用到tempdb数据库作为临时存储空间,所以要增大他的空间,否则可能你的事务不能执行
sybase 临时数据库
缺省情况下,tempdb数据库是放置在master设备上,容量为2M,而临时数据库是活动最为平凡的数据库常常被用来排序、创建临时表、重格式化等操作,所以tempdb的优化应该受到特别的关注。本篇文章目的在于使你掌握临时数据库的优化策略以及临时表的优化使用。本文中,你将以调整临时库的位置开始,有步骤的完成临时数据库的优化,并在此过程中了解到优化临时数据库和临时表的一些方法和规则。
实验环境的要求:你应具有系统管理员的权限,系统中有auths和article表。
步骤:
第一步:调整临时库的位置
tempdb数据库缺省放在master设备上,将临时数据库发在分离的设备上是更可取的。
1) 初始化一个用来存放临时数据库的设备
disk init
name="tempdb_dev",
physname="d:\sybase\example\tempdb.dat",
vdevno=13,
size=15360
(注意:如果将tempdb数据库放在多个设备上,需初始化多个数据库设备)
2)将临时数据库扩展到该一个设备上
alter database tempdb on tempdb_dev=30
3)打开tempdb数据库,从段上删除master设备
sp_dropsegment "default",tempdb,master
sp_dropsegment logsegment,tempdb,master
4)发出如下命令,检查default段中是否不再包含master设备
select dbid,name,segmap from sysusages,sysdevices
where sysdevices.low<=syusages.size+vstart
and sysdevices.high>;=sysusages.size+vstart-1
and dbid=2
and(status=2 or status=3)
说明:若将临时数据库放在多个磁盘设备上,可以更好的利用并行查询特性来提高查询性能。
第二步:将临时数据库与高速缓冲进行绑定。
由于临时表的创建、使用,临时数据库会频繁地使用数据缓存,所以应为临时数据库创建高速缓存,从而可以使其常驻内存并有助于分散I/O:
1、创建命名高速缓存
sp_cacheconfig “tempdb_cache","10m","mixed"
2、重新启动server
3、捆绑临时数据库到tempdb_cache高速缓存
sp_bindcache “tempdb_cache", tempdb
4、若有大的I/O,配置内存池
第三步:优化临时表
大多数临时表的使用是简单的,很少需要优化。但需要对临时表进行复杂的访问则
应通过使用多个过程或批处理来把表的创建和索引分开。以下两种技术可以改善临时表的优化
slash; 在临时表上创建索引
1) 临时表必须存在
2) 统计页必须存在(即不能在空表上创建索引)
slash; 把对临时表的复杂的使用分散到多个批处理或过程中,以便为优化器提供信息
下面的这个过程需要进行优化:
create proc base_proc
as
select * into #huge_result from auths
select * from article, #huge_result where article.author_code=
#huge_result.author_code and sex="0"
使用两个过程可以得到更好的性能
1)create proc base_proc
as
select *
into #huge_result
from auths
exec select_proc
2) create proc select_proc
as
select * from article,#huge_result
where article.author_code=#huge_result.author_code and sex="0"
说明:在同一个存储过程或批处理中,创建并使用一个表时,查询优化器无法决定这个表的大小。
结论:通过本实验我们知道,临时数据库经过优化可以极大的提高系统性能。实际工作中,必须考虑具体应用的情况,需长时间经验的积累。
11) 怎样利用脚本自动关闭sybase数据库
http://www.chinaunix.net/cgi-bin/bbs/topic.cgi?forum=10&topic=1484&show=180
不知你什么平台,如果是unix,ksh
#!/bin/ksh
LOGIN="`whoami`"
if [ "${LOGIN}" != "sybase" ]; then
echo "`basename $0`: You should login as 'sybase'\n"
exit 0
fi
echo "\n\n"
{
isql -Usa -P -Syourservername >; /dev/null 2>;&1 <
go
shutdown SYB_BACKUP
go
shutdown
go
ISQL
}
12) 请教存储过程动态使用表
http://www.chinaunix.net/cgi-bin/bbs/topic.cgi?forum=10&topic=1488&show=180
你指动态sql
要12.0版本以上才支持
CREATE PROCEDURE dbo.mytt
(@c varchar(25))
AS
BEGIN
declare @cc varchar(25)
select @cc = "select * from " + @c
exec (@cc)
END
13) sybase中的跨库操作
http://www.chinaunix.net/cgi-bin/bbs/topic.cgi?forum=10&topic=1489&show=150
假如本机server为loc_server,远程server为re_server
在这两个server 各自的interface文件里都必须有定义
sp_configure "allow remote access"是否为1;
在本机server上:
sp_addserver re_server
sp_addserver loc_server,LOCAL --->;这样你select @@servername就有东西
在remote server 上:
sp_addserver loc_server
sp_addserver re_server,LOCAL
在2个server 上
sp_addremotelogin ......
检查这两个参数
number of remote sites
number of remote connections .
然后:
如果isql从loc_server 到rs_server
connect to rs_server
disconnect
rs_server...sp_who在loc_server上执行rs_server 上的sp_who
没有评论:
发表评论