您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_dboption

语法


sp_dboption [<dbname>, <optname>, <optvalue>[, <dockpt>]]

参数

<dbname>

是要在其中设置选项的数据库的名称。必须使用 master 来执行带参数的 sp_dboption(即更改数据库选项)。但是,您不能更改 master 数据库中的选项设置。

<optname>

是要设置的选项的名称。SAP ASE 服务器可以识别属于选项名称一部分的任何唯一字符串。如果选项名是关键字或含有嵌入的空格或标点符号,则请用引号将选项名引起来。

可以一次打开多个数据库选项。不能在用户定义的事务中更改数据库选项。

<optvalue>

是设置的值。true 将打开该选项,false 将关闭该选项。

<dockpt>

指定 sp_dboption 是否对 <dbname> 执行 checkpoint 命令。缺省值为 1,表示自动执行 checkpoint。可以通过手动执行 checkpoint 命令来对 <dbname> 运行 checkpoint。

示例

示例 1

显示数据库选项列表:


sp_dboption

Settable database options

 database_options
 ------------------------
abort on low memory
abort tran on log full
allow incremental dumps
allow nulls by default
allow wide dol rows
async log service
auto identity
auto imrs partition tuning
dbo use only
ddl in tran
deallocate first text page
deferred table allocation
delayed commit
enforce dump tran sequence
erase residual data
full logging for all
full logging for alter table
full logging for reorg rebuild
full logging for select into
identity in nonunique index
no chkpt on recovery
no free space acctg
read only
scratch database
select into/bulkcopy/pllsort
single user
trunc log on chkpt
trunc. log on chkpt.
unique auto_identity index

示例 2

将数据库 pubs2 设置为只读:


1> use pubs2
2> go
1> master..sp_dboption pubs2, "read", true
2> go

Database option 'read only' turned ON for database 'pubs2'.
Running CHECKPOINT on database 'pubs2' for option 'read only' to take effect.
(return status = 0) 

read 字符串在所有可用数据库选项中唯一确定 read only 选项。请注意,应使用引号将关键字 read 引起来。

示例 3

使数据库 pubs2 重新变为可写,但通过为 <dockpt> 选项指定 0,您可以看到消息 “Run the CHECKPOINT command in the database that was changed”:


1> use pubs2
2> go
1> master..sp_dboption pubs2, "read", false, 0
2> go

Database option 'read only' turned OFF for database 'pubs2'.
Run the CHECKPOINT command in the database that was changed.
(return status = 0) 

若要在 pubs2 上手动执行检查点,请输入:


1> checkpoint
2> go

示例 4

允许对 pubs2 中的表进行 select into、bcp 和并行排序操作。select into 字符串在所有可用数据库选项中唯一确定 select into/bulkcopy 选项:


use pubs2
go
master..sp_dboption pubs2, "select into", true
go

⚠️

因为有嵌入的空格,所以需要用引号将选项引起来。

示例 5

自动在 mydb 中创建的新表中定义 10 位的 IDENTITY 列。如果在创建新表时未指定主键、unique 约束或 IDENTITY 列,则将在每个这样的新表中定义 IDENTITY 列 SYB_IDENTITY_COL:


use mydb 
go
master..sp_dboption mydb, "auto identity", true
go

示例 6

自动在 mydb 表的索引键中包括 IDENTITY 列,但前提条件是这些表已经具有了 IDENTITY 列。在表上创建的所有索引都是内部唯一的:


use master 
go 
sp_dboption mydb, "identity in nonunique index", true 
go 
use mydb 
go

示例 7

自动为 pubs2 中的新表包括带有唯一非聚簇索引的 IDENTITY 列:


use master 
go 
sp_dboption pubs2, "unique auto_identity index", true 
go 
use pubs2 
go

示例 8

在指定的数据库中设置异步日志服务 (ALS),启用用户日志高速缓存和日志写入器线程。


sp_dboption "mydb", "async log service", true
use mydb

示例 9

在指定的数据库中禁用 ALS:

sp_dboption "mydb", "async log service", false

use mydb

示例 10

对 big_db 强制执行转储事务序列:


sp_dboption 'big_db', 'enforce dump tran sequence',
true

示例 11

在 mydb 中对 select into 和 alter table 启用完全日志记录:

create database 命令创建 mydb:


create database mydb on datadev=20 log on logdev=10
go

CREATE DATABASE: allocating 10240 logical pages (20.0 megabytes) on disk
'datadev' (10240 logical pages requested).
CREATE DATABASE: allocating 5120 logical pages (10.0 megabytes) on disk
'logdev' (5120 logical pages requested).
Database 'mydb' is now online.

在 mydb 中对 select into 启用完全日志记录选项:


sp_dboption "mydb", "full logging for select into", "true"
go

Database option 'full logging for select into' turned ON for database 
'mydb'.
Running CHECKPOINT on database 'mydb' for option 'full logging for select 
into' to take effect.
(return status = 0)

在 mydb 中对 alter table 启用完全日志记录选项:


sp_dboption "mydb", "full logging for alter table", "true"
go

Database option 'full logging for alter table' turned ON for database 
'mydb'.
Running CHECKPOINT on database 'mydb' for option 'full logging for alter 
table' to take effect.
(return status = 0)

运行 sp_helpdb 可显示 mydb 的设置:


sp_helpdb mydb
go

 name db_size owner dbid created      durability status
 ---- ------- ----- ---- ------------ --------- -----------------------
 mydb 30.0 MB  sa      5 Dec 16, 2010 full       full logging for select
                                                 into/alter table

(1 row affected)
 device_fragments size    usage      created             free kbytes
----------------- ------- ---------- ------------------- --------------
 datadev          20.0 MB data only  Dec 16 2010 6:08PM  18696
 logdev           10.0 MB log only   Dec 16 2010 6:08PM  not applicable

--------------------------------------------------------------
log only free kbytes = 10184
(return status = 0)
1>

示例 12

启用累计转储的备份和恢复:


sp_dboption mydb, "allow incremental dumps", true 

示例 13

对 pubs2 启用延迟表创建:


sp_dboption pubs2, "deferred table allocation", true

示例 14

对于这两个示例,启用在数据库级别删除残留数据的语法为:


sp_dboption <dbname>, "erase residual data", true

第一个示例使用以下两个表:


create table t1 (col1 int) with erase residual data on
create table t2 (col1 int) with erase residual data off

⚠️

sp_dboption 过程要求对 “erase residual data” 使用引号,但 create table … with erase residual data on | off 不使用引号。对 create table 使用引号会造成语法错误。

由于删除残留数据的选项是在数据库级别设置的,因此对于表 t1 该选项为启用,所以对 t1 执行 drop table 和 truncate table 命令都会导致清除其页面中的所有残留数据。

但是,由于创建表 t2 时使用了了 erase residual data off 子句,所以其 erase residual data 选项为显示禁用。即使在数据库级别将“erase residual data”选项设置为 true,也不会删除残留数据。因此,即使在对 t2 表运行 drop table 和 truncate table 后,残留数据仍将保留:


create database db1
go
sp_dboption db1, "erase residual data", true
go
use db1
go
create table t1 (col int)
go
insert t1 values ...
go
create table t2 (col1 int, col2 char(10)) with erase residual data off
go
truncate table t1
go
drop table t1
go
truncate table t2
go
drop table t2
go

第二个示例使用以下语法:


create database db1
go
use db1
go
create table t1 (col int)
go
sp_dboption db1, "erase residual data", true
go
create table t2 (col1 int, col2 char(10))
go
create table t3 (col1 int, col2 char(10)) with erase residual data off
go
truncate table t1
go
truncate table t2
go
truncate table t3
go

表 t1 未显式设置 erase residual data off,但是在数据库级别进行了设置,因此在运行 truncate table t1 时会删除 t1 中的残留数据。

表 t2 设置为 erase residual data,因为该选项是在数据库级别设置的。因此,运行 truncate table t2 时将删除 t2 中的残留数据。

表 t3 显式标记为 erase residual data off,因此即使 sp_dboption 将“erase residual data”设置为 true,SAP ASE 运行 truncate table t3 时也不会删除残留数据。

示例 15

在 NULL 更新后释放第一个文本页:


sp_dboption mydb, "deallocate first text page", true

示例 16

配置自动显示并为启用 IMRS 的表重新启用 IMRS 使用。


sp_dboption mydb, "auto imrs partition tuning", true

用法

  • 在数据库级别启用 "erase residual data" 设置时,任何会导致释放的操作之后都会清理其页面。缺省情况下禁用此选项

  • 无法更改 master 数据库选项设置。

  • 如果为 <optname> 输入了一个不明确的值,则会显示一条错误消息。例如,两个数据库选项分别为 dbo use only 和 read only。使用“only”作为 <optname> 参数的值将产生一条消息,因为它与两个名称都匹配。将显示与所给的字符串匹配的完整名称,以便可以查看如何使 i<optname> 更具体。

  • 若要显示数据库选项列表,请在 master 数据库中执行不带参数的 sp_dboption。

  • 若要得到关于特定数据库中设置的数据库选项的报告,请执行 sp_helpdb。

  • 如果用 sp_dboption 为同一个数据库同时设置了 no chkpt on recovery 选项和 trunc log on chkpt 选项,则前者将禁用后者。在 trunc log on chkpt 设置为缺省值 on 的 tempdb 数据库中出现这种冲突的可能性非常大。

  • 数据库所有者或系统管理员可通过对 model 执行 sp_dboption 来为所有新数据库设置或取消设置特定的数据库选项。

  • 执行完 sp_dboption 之后,直到在为其更改选项的数据库中发出 checkpoint 命令之后,所进行的更改才会生效。

    另请参见:

  • alter table、checkpoint、create default、create index、create procedure、create rule、create schema、create table、create trigger、create view、drop default、drop index、drop procedure、drop rule、drop table、drop trigger、drop view、grant、revoke、select,均位于《参考手册:命令》

  • 有关数据库选项的详细信息,请参见《系统管理指南》。

  • 以及《实用程序指南》 中的 bcp

    a 在启用 IMRS 的表上使用 sp_dboption。

    b 有时,在未提高性能的情况下,启用 IMRS 的表会消耗大量的行存储高速缓存。启用 auto imrs partition tuning 时,服务器从内部监控对数据的事务工作量访问,并禁用它们的行存储使用。但是,禁用行存储使用可稍后通过使用行存储优化。服务器监控这些情况,如果发现通过在行存储中存储数据而提高工作量性能,则可重新启用行存储使用。

    c 例如,极少更新的表可能最初在行存储中装载数据。但是,由于表很少更新,因此这样做可能不会提高性能,反而浪费分区的行存储高速缓存。启用 auto imrs partition tuning 时,服务器禁用分区上的这些更新的行存储使用。

  • 使用 sp_imrs 或 monIMRSPartitionActivity 监控表以查看服务器决定禁用 IMRS 使用的时间。例如:

    
    sp_imrs 'show', 'effectiveness', 'imrscache'
    
    CacheName DBName     ObjectName  PartitionName       DisabledRowTypes 
    --------- ---------  ---------   ------------------  ------------------
    imrscache      mydb         t1                   p1            Migrated
    

  • 不可以在启用 snapshot isolation 的表上使用 auto imrs partition tuning(继续使用行存储)而不考虑它们的工作量访问,提供在针对这些表发出的所有 DML 的行存储中创建版本所需的快照隔离。

  • 禁用 auto imrs partition tuning 之后,服务器无法做出任何新的内部决策,以在数据库分区上为不同操作禁用或重新启用行存储。但是,在启用 auto imrs partition tuning 之前的任何决策均可应用于确定行存储是否用于分区上的操作。

    完全日志记录和 sp_dboption

    缺省情况下,select into、某些类型的 alter table 和 reorg rebuild 在最少日志记录模式下运行。在执行这些命令之前,首先将 select into/bulk copy 数据库选项设置为 true,以便 SAP ASE 服务器能够中断转储序列,即执行防止有能力使用 dump transaction 的操作。

    使用 full logging for [select into | alter table | reorg rebuild | all] 参数时,该命令会在完全日志记录模式下运行。先前设置的任何 select into/bulk copy 值均与目前在完全日志记录模式下运行的命令无关。

    不支持对快速 bcp 和并行排序启用完全日志记录,除非将 select into/bulk copy 设置为 true,否则无法执行完全日志记录。

    将操作设置为在完全日志记录模式下运行之后,便可像执行其它完全日志记录操作那样对这些操作运行 dump transaction/load transaction 命令以及进行恢复。

    以下是对缺省情况下以最少日志记录模式运行的命令执行完全日志记录的语法:

    
    sp_dboption <dbname>, "full logging for 
    	[select into | alter table | reorg rebuild | all]",
    	true | false
    

    其中:

    
    full logging for select into – 要使 select into proxy table 在完全日志记录模式下运行,请在托管实际表的远程服务器上将“full logging for select into”选项设置为 true。如果在托管实际表的服务器上将 full logging for select into 选项设置为 false,该命令将在此数据库中以最少日志记录模式执行,并且转储事务序列将中断。
    
    pll create index – 在并行排序结束后启用完全日志记录。在循环分区表上创建聚簇索引时需要并行排序。
    
    full logging for alter table – 对以下需要数据移动的这些 alter table 版本启用完全日志记录:
    
    </li></ul><ul><li><code>alter table add <column> not null
    
    
  • alter table drop <column> not null
  • alter table modify <datatype> of not null <column>
  • alter table partition alter table 的其它变体已在完全日志记录模式下执行。

⚠️

如果通过 alter table lock 在全页锁定表与数据页锁定表/数据行锁定表这些锁定方案之间进行切换,则需要移动数据,但 full logging for alter table 不支持此行为。