DBCC 收缩文件给出错误

发布于 2024-08-24 15:41:32 字数 233 浏览 5 评论 0原文

我正在尝试使用 DBCC SHRINKFILE(db_2.ldf) 缩小我的日志文件,这是日志文件的名称,

它每次都会给我错误:

8985,16 级,州 1,第 1 线 无法在 sys.database_files 中找到数据库 db 的文件“FIelD”。该文件不存在或已被删除。

你能建议我能做什么来解决它吗?

I am trying to shrink my log file using DBCC SHRINKFILE(db_2.ldf), which is the name for log file

It gives me error every time:

8985, Level 16, State 1, Line 1
Could not locate file 'FIelD' for database db in sys.database_files. The file either does not exist, or was dropped.

Can you please suggest what can I do to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

挽手叙旧 2024-08-31 15:41:33

文件名应该是逻辑文件名而不是物理文件名。在“文件”选项卡上的“数据库属性”中查找您尝试收缩的文件的逻辑名称,并使用该名称。

The file name should be the logical file name and not the physical file name. Look in the Database properties, on the Files tab for the Logical Name of the file you are trying to shrink, and use that name.

寒尘 2024-08-31 15:41:33

您是否在包含您要收缩的日志的数据库上下文中运行它?在运行 DBCC 命令之前确保您有正确的 USE 语句

Are you running it in the context of the database that has the log you are trying to shrink? Make sure you have the right USE statement before running DBCC commands

从﹋此江山别 2024-08-31 15:41:33

这里有同样的问题,解决方案是重命名逻辑文件以匹配数据库名称。下面是一个查询逻辑文件名然后执行文件重命名的示例:

-- retrieve the logical files for the current db
SELECT [name] AS logical_file FROM sys.database_files df

-- rename the logical file (to match the database name)
ALTER DATABASE YourDB
MODIFY FILE (NAME = 'LogicalFile1', NEWNAME='NewLogicalFile1')
GO

ALTER DATABASE YourDB
MODIFY FILE (NAME = 'LogicalFile2', NEWNAME='NewLogicalFile2')
GO

两次更改的原因是每个数据库通常有两个文件关联,即数据文件和日志文件。

Had the same problem over here, the solution was to rename the logical file to match the database name. Below is an example to query the logical file names and then perform a rename of the files:

-- retrieve the logical files for the current db
SELECT [name] AS logical_file FROM sys.database_files df

-- rename the logical file (to match the database name)
ALTER DATABASE YourDB
MODIFY FILE (NAME = 'LogicalFile1', NEWNAME='NewLogicalFile1')
GO

ALTER DATABASE YourDB
MODIFY FILE (NAME = 'LogicalFile2', NEWNAME='NewLogicalFile2')
GO

The reason for the two alters is that there are usually two files associated with each database, the data file and the log file.

百善笑为先 2024-08-31 15:41:33

下面的命令有效。但我没有看到它减小尺寸。我在运行之后和运行之前看到相同的大小。你能告诉我我可能错过了什么吗?

fileid  groupid size    maxsize     growth  status  perf name filename 
2           0   1048    268435456      10   1048642 0           PrimaryLogFileName

谢谢

The command below worked. However I don't see it reducing the size. I see the same size after and before running it. Can you please let me know what I might have missed.

fileid  groupid size    maxsize     growth  status  perf name filename 
2           0   1048    268435456      10   1048642 0           PrimaryLogFileName

Thanks

浴红衣 2024-08-31 15:41:33

从 SQL 管理工作室
右键单击数据库名称,任务,收缩,数据库
Ctrl+Shift+N(或新查询窗口的脚本操作)

生成以下内容:

USE [DataBaseName]

DBCC SHRINKDATABASE(N'DataBaseName' )

From SQL Management Studio
Right click the database name, Tasks, Shrink, Database
Ctrl+Shift+N (or Script Action to New Query Window)

Generates the following:

USE [DataBaseName]
GO
DBCC SHRINKDATABASE(N'DataBaseName' )
GO

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文