Could not allocate space for object sys.sysfiles1.sysfiles1 in database

一、 问题描述

给数据库添加数据文件时遇到了一个奇怪的报错:

Could not allocate space for object 'sys.sysfiles1'.'sysfiles1' in database 'dbname' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.

检查各磁盘均有剩余空间超过100G,新增的数据文件也没有设上限,怎么就没法分配空间了?

网上搜索文章发现是跟mdf这个文件有关

To add space to the primary filegroup requires some free space in the first MDF file. Adding just 1MB to the MDF file allowed the addition of another (NDF) file without error.

检查mdf大小,发现确实离上限还有11M,但是因为每次自动扩展设置是100M,到达了上限不能再扩了。

二、 解决方法

  • 改小mdf文件自动扩展设置(例如1M),让它能自动扩展
  • 改大mdf文件上限,让它能自动扩展

三、 报错原因详解

sys.sysfiles1是一个特殊的系统表,用于存储数据库中各数据文件的位置。这个表中的数据被限制死只能存在mdf文件中而不能到其他ndf文件中(不能理解为啥要这么设计...)。该报错是因为:每当新增数据文件时会往里插入一行数据,此时mdf文件刚好没有空间了,而自动扩展100M又到达了mdf文件设置的上限,只能报错无法分配空间。

以下是文章中的原文:

sys.sysfiles1 is a system table, usually hidden away from view, which holds information about all files in the database. It makes sense that this file would be restricted to living in the .mdf - the first file of the PRIMARY file group, and cannot move to other files in the PRIMARY filegroup (after all, if you stored information about which files are in the database inside another file in the database...)

From that error message, you're unable to even add a new row to sys.sysfiles1, whether for the PRIMARY filegroup, or adding a new one.

If you  need to make room in the .mdf file, you have some options - if you can grow the file by a couple of MB, do so. Alternatively, BACKUP FIRST (goes without saying!), and either drop some old tables (where the data is originally in the .mdf), or create a backup copy of them into another database, or into a new table (which will be on your autogrowing .ndf file). You can then drop the original table. If you copied the table into the same database, you can rename the new table to match the old name, and your database will still be working. You should then have enough room in the .mdf to add your new file.

参考

Adding space to PRIMARY filegroup · What Did I Learn Today

Error: "PRIMARY filegroup is full" when adding databse file

This error message typically occurs when the Java Virtual Machine (JVM) is unable to allocate the required amount of memory for the application. The JVM is responsible for managing the memory allocation for Java applications. There are several possible reasons why the JVM may not be able to allocate the required amount of memory. Here are some common causes and possible solutions: 1. Insufficient memory: The JVM may not have enough available memory on the system to allocate the requested heap size. You can try increasing the memory available to the JVM by setting the -Xmx flag to a higher value. For example, you can set -Xmx2g to allocate 2GB of memory. 2. 32-bit JVM limitation: If you are running a 32-bit JVM, it may not be able to allocate more than 2GB of memory. In this case, you can try running a 64-bit JVM instead. 3. Conflicting memory settings: If you have conflicting memory settings in your application or in the JVM startup parameters, it can cause the JVM to fail to allocate the required memory. You can try removing any conflicting settings or adjusting them to ensure they do not conflict. 4. Other system resource limitations: There may be other system resource limitations, such as disk space or CPU usage, that are preventing the JVM from allocating the required memory. You can try freeing up resources or adjusting the application to use fewer resources. Overall, the solution to this error message will depend on the specific cause. By identifying and addressing the underlying cause, you can resolve the issue and allow your Java application to run successfully.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hehuyi_In

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值