Home php教程 php手册 何清除MSSQL事务日志文件

何清除MSSQL事务日志文件

Jun 06, 2016 pm 08:00 PM
mssql php affairs document log Clear

三种方法: 1、删除LOG 1):分离数据库企业管理器->服务器->数据库->右键->分离数据库 2):删除LOG文件 3):附加数据库企业管理器->服务器->数据库->右键->附加数据库 此法生成新的LOG,大小只有500多K 再将此数据库设置自动收缩 2、清空日

三种方法:
  
1、删除LOG
  
   1):分离数据库企业管理器->服务器->数据库->右键->分离数据库    
   2):删除LOG文件    
   3):附加数据库企业管理器->服务器->数据库->右键->附加数据库
  
   此法生成新的LOG,大小只有500多K

   再将此数据库设置自动收缩
  
2、清空日志
  
   DUMP TRANSACTION 库名 WITH NO_LOG
  
   再:企业管理器 -- 右键你要压缩的数据库 -- 所有任务 -- 收缩数据库 -- 收缩文件 -- 选择日志文件 -- 在收缩方式里选择收缩至XXM,这里会给出一个允许收缩到的最小M数,直接输入这个数,确定就可以了
  
3、如果想以后不让它增长
  
   企业管理器->服务器->数据库->属性->事务日志->将文件增长限制为2M


关于Sql server数据库日志满的快速解决办法

先提供一种复杂的方法压缩日志及数据库文件如下:

1.清空日志
    DUMP   TRANSACTION   库名   WITH   NO_LOG  
2.截断事务日志:
    BACKUP LOG 数据库名 WITH NO_LOG
3.收缩数据库文件(如果不压缩,数据库的文件不会减小
    企业管理器--右键你要压缩的数据库--所有任务--收缩数据库--收缩文件
     --选择日志文件--在收缩方式里选择收缩至XXM,这里会给出一个允许收缩到的最小M数,直接输入这个数,确定就可以了
     --选择数据文件--在收缩方式里选择收缩至XXM,这里会给出一个允许收缩到的最小M数,直接输入这个数,确定就可以了
    也可以用SQL语句来完成
    --收缩数据库
    DBCC SHRINKDATABASE(客户资料)
    --收缩指定数据文件,1是文件号,可以通过这个语句查询到:select * from sysfiles
    DBCC SHRINKFILE(1)
4.为了最大化的缩小日志文件(如果是sql 7.0,这步只能在查询分析器中进行)
    a.分离数据库:
     企业管理器--服务器--数据库--右键--分离数据库
    b.在我的电脑中删除LOG文件
    c.附加数据库:
     企业管理器--服务器--数据库--右键--附加数据库
    此法将生成新的LOG,大小只有500多K
    或用代码:
    下面的示例分离 pubs,然后将 pubs 中的一个文件附加到当前服务器。
    a.分离
    exec sp_detach_db @dbname = 'pubs'
    b.删除日志文件
    c.再附加
    exec sp_attach_single_file_db @dbname = 'pubs',
       @physname = 'c:/Program Files/Microsoft SQL Server/MSSQL/Data/pubs.mdf'
5.为了以后能自动收缩,做如下设置:
    企业管理器--服务器--右键数据库--属性--选项--选择"自动收缩"
    --SQL语句设置方式:
    exec sp_dboption '数据库名', 'autoshrink', 'TRUE'
6.如果想以后不让它日志增长得太大
    企业管理器--服务器--右键数据库--属性--事务日志
     --将文件增长限制为xM(x是你允许的最大数据文件大小)
    --SQL语句的设置方式:
    alter database 数据库名 modify file(name=逻辑文件名,maxsize=20)
特别注意:
    请按步骤进行,未进行前面的步骤,请不要做后面的步骤
    否则可能损坏你的数据库.
    一般不建议做第4,6两步
    第4步不安全,有可能损坏数据库或丢失数据
    第6步如果日志达到上限,则以后的数据库处理会失败,在清理日志后才能恢复.

另外提供一种更简单的方法,本人屡试不爽,建议大家使用。
更简单的方法:
    1。右建数据库属性窗口--故障还原模型--设为简单
    2。右建数据库所有任务--收缩数据库
    3。右建数据库属性窗口--故障还原模型--设为大容量日志记录


backup log xzfw_v7_maogang with NO_LOG;  
backup log xzfw_v7_maogang with TRUNCATE_ONLY;  
DBCC SHRINKDATABASE(xzfw_v7_maogang); 


2、用Transact-SQL 命令压缩数据库
可以使用DBCC SHRINKDATABASE 和DBCC SHRINKFILE 命令来压缩数据库。其中DBCC SHRINKDATABASE 命令对数据库进行压缩,DBCC SHRINKFILE 命令对数据库中指定的文件进行压缩。

(1) DBCC SHRINKDATABASE
DBCC SHRINKDATABASE 命令语法如下:
DBCC SHRINKDATABASE (database_name [, target_percent]
[, {NOTRUNCATE | TRUNCATEONLY}] )
各参数说明如下:


target_percent 指定将数据库压缩后,未使用的空间占数据库大小的百分之几。如果指定的百分比过大,超过了压缩前未使用空间所占的比例,则数据库不会被压缩。并且压缩后的数据库不能比数据库初始设定的容量小。
NOTRUECATE
将数据库缩减后剩余的空间保留在数据库,中不返还给操作系统。如果不选择此选项,则剩余的空间返还给操作系统。
TRUNCATEONLY
将数据库缩减后剩余的空间返还给操作系统。使用此命令时SQL Server 将文件缩减到最后一个文件分配,区域但不移动任何数据文件。选择此项后,target_percent 选项就无效了。
例6-14: 压缩数据库mytest 的未使用空间为数据库大小的20%。
dbcc shrinkdatabase (mytest, 20)
运行结果如下:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

(2) DBCC SHRINKFILE
DBCC SHRINKFILE 命令压缩当前数据库中的文件。其语法如下:
DBCC SHRINKFILE ( {file_name | file_id }
{ [, target_size] |
[, {EMPTYFILE | NOTRUNCATE | TRUNCATEONLY}] } )
各参数说明如下:

 

file_id
指定要压缩的文件的鉴别号(Identification number, 即ID)。文件的ID 号可以通过 FILE_ID()函数或如本章前面所讲述的Sp_helpdb 系统存储过程来得到。
target_size
指定文件压缩后的大小。以MB 为单位。如果不指定此选项,SQL Server 就会尽最大可能地缩减文件。
EMPTYFILE
指明此文件不再使用,将移动所有在此文件中的数据到同一文件组中的其它文件中去。执行带此参数的命令后,此文件就可以用ALTER DATABASE 命令来删除了。
其余参数NOTRUNCATE 和TRUNCATEONLY 与DBCC SHRINKDATABASE 命令中的含义相同。
例6-15: 压缩数据库mydb 中的数据库文件mydb_data2 的大小到1MB。 use mydb dbcc shrinkfile (mydb_data2, 1)

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles