Home Database Mysql Tutorial SQLServer日志文件清除方法

SQLServer日志文件清除方法

Jun 07, 2016 pm 03:51 PM
sqlserver Discover document method log Clear system

近日,因发现某系统SQLServer数据库的日志文件较大,需要对其进行清理。本来以为是个很简单的事情,SQL Server Management Studio中有现成的菜单功能,点两下鼠标就行了。但在实际操作中却发现不起作用。因为涉及到数据,担心误操作导致不可挽回的损失,所以

近日,因发现某系统SQLServer数据库的日志文件较大,需要对其进行清理。本来以为是个很简单的事情,SQL Server Management Studio中有现成的菜单功能,点两下鼠标就行了。但在实际操作中却发现不起作用。因为涉及到数据,担心误操作导致不可挽回的损失,所以还是上网研究了一下,并单独测试没问题后,才敢对实际数据库下手。

具体的操作过程应该是这样的:

一、挑一个夜深人静的时候,先备份一下数据库。

夜深人静之时,系统一般会比较空闲,可能从容地下手,有数据库备份,万一第二天早上发现有问题,至少可以恢复到昨天的工作点,风险比较小。

二、打开SQL Server Management Studio(SSMS),打开查询页面,执行以下SQL语句:

DUMP TRANSACTION [数据库名] WITH   NO_LOG
Copy after login

该语句的作用是清空指定数据库的日志。

三、在SSMS中相应数据库名称下点右键,菜单中选择“任务-收缩-文件”,在打开的“收缩文件”窗口中,文件类型选择“日志”,并选择相应的日志文件名(如果有多个可选的话),在“收缩操作”项下有3个可选项:

1、释放未使用的空间。

会把文件中未使用的空间释放给操作系统,将将文件收缩到最后分配的区。这个选项感觉作用不大,因为要考虑清理日志文件时,它已经是很大了,分配的空间当然也都是用掉的。

2、在释放未使用的空间前重新组织页,将文件收缩到(需设置文件大小);

这种方法等效于执行指定目标文件大小的:DBCC SHRINKFILE。必须在后面的文本框中输入日志文件的大小,可以为0。

3、通过将数据迁移到同一文件组中的其它文件来清空文件。

此方法相当于执行带EMPTYFILE选项的DBCC SHRINKFILE。

这里我选择使用了第2个选项。

当然,这里只是提供了一种可成功实现的实用方法。对于更复杂的应用场景,需要对DUMP TRANSACTION和DBCC SHRINKFILE有深入的了解,具体可以研究的微软的相关文档。



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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

How to solve the problem that the object named already exists in the sqlserver database How to solve the problem that the object named already exists in the sqlserver database Apr 05, 2024 pm 09:42 PM

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

How to check sqlserver port number How to check sqlserver port number Apr 05, 2024 pm 09:57 PM

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

See all articles