简体   繁体   English

我们可以从数据库中删除 Memory 优化文件组吗

[英]Can we remove Memory Optimized file group from database

I checked In sql server 2019(15.0.2070.41) and tried to remove with bellow mentioned command:我检查了 sql server 2019(15.0.2070.41) 并尝试使用下面提到的命令删除:

Alter database InMemoryCheckpoint 
Remove file InMemoryCheckpointDF 

Alter database InMemoryCheckpoint 
Remove filegroup InMemoryCheckpointDF

You can't remove a memory-optimized filegroup.您不能删除内存优化文件组。

The following limitations apply to a memory-optimized filegroup:以下限制适用于内存优化文件组:

Once you use a memory-optimized filegroup, you can only remove it by dropping the database.使用内存优化文件组后,只能通过删除数据库来删除它。 In a production environment, it is unlikely that you will need to remove the memory-optimized filegroup.在生产环境中,您不太可能需要删除内存优化文件组。

https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/the-memory-optimized-filegroup?view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/the-memory-optimized-filegroup?view=sql-server-ver15

!!! !!! Please use this method in case of corrupted database that contains memory optimized table (you can't use DBCC check on databases that contains memory optimized tables) !!!如果包含 memory 优化表的数据库损坏,请使用此方法(您不能对包含 memory 优化表的数据库使用 DBCC 检查)!!!

WARNING: This is an unsupported operation.警告:这是不受支持的操作。 There have been reports of unrecoverable log corruption when using this.有报告称使用此功能时日志损坏不可恢复。

It's a hack method and it's risky.这是一种黑客方法,而且有风险。 Microsoft didn't verified this solution Microsoft 未验证此解决方案

Before doing anything take backup在做任何事情之前先备份

1- Delete memory optimized tables 1- 删除 memory 优化表

2- Detach Database 2-分离数据库

3- Create new database with same files without memory optimized filegroup 3-创建具有相同文件的新数据库,但没有 memory 优化文件组

4- Modify database files and change it to detached database (mdf,ldf,ndf) files 4-修改数据库文件并将其更改为分离的数据库(mdf,ldf,ndf)文件

alter database test1 modify file (name='test1' , filename='C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\test.mdf')

alter database test1 modify file (name='test1_log' , filename='C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\test_log.ldf')

5- Now try to to repair database: 5-现在尝试修复数据库:

alter database test1 set emergency

alter database test1 set single_user with ROLLBACK IMMEDIATE;

dbcc checkdb(test1,repair_allow_data_loss)

alter database test1 set multi_user

alter database test1 set online

6- After successfully repair database remove memory optimized filegroup from database 6- 成功修复数据库后,从数据库中删除 memory 优化文件组

ALTER DATABASE [test1] REMOVE FILEGROUP [memory_optimized_filegroup_0]

Follow steps correctly for prevent log corruption正确执行步骤以防止日志损坏

Step 4: Alter log file name must be done correctly Step 5: DBCC is Important to prevent corruption第 4 步:必须正确更改日志文件名 第 5 步:DBCC 对防止损坏很重要

Also for getting best result:也为了获得最佳结果:

Don't use database while doing steps (Insert - Update - Changing Schema)执行步骤时不要使用数据库(插入 - 更新 - 更改架构)

do CHECKPOINT to flush log to data file then shrink log file执行 CHECKPOINT 将日志刷新到数据文件,然后收缩日志文件

you will never have log corruption issue你永远不会有日志损坏问题

Don't forget:不要忘记:

Before using your database do this steps for checking issue:在使用数据库之前,请执行以下步骤来检查问题:

  1. Insert or update 1 row in database在数据库中插入或更新 1 行
  2. Do CHECKPOINT做检查点
  3. Restart server重启服务器

If database got online i think you did all steps correctly else Restore database from backup and forget about removing memory optimized filegroup如果数据库上线,我认为您已正确执行所有步骤,否则从备份中恢复数据库并忘记删除 memory 优化文件组

Used these commands and they worked fine for me:使用了这些命令,它们对我来说很好用:

USE [<dbname>]
GO

ALTER DATABASE [<dbname>]  REMOVE FILE [<filename>]
GO

ALTER DATABASE [<dbname>] REMOVE FILEGROUP [<Group Name>]
GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将普通表上的现有索引移至内存优化文件组? - How can I move an existing index on a normal table to a memory optimized file group? 如何从 MDF 数据库中删除一个主文件? - How can I remove one primary file from an MDF database? 从内存优化表插入物理表 - Insert from memory optimized table to physical table 如何防止内存优化表爆掉 OPT_MEMORY_OPTIMIZED\$HKv2 - How to prevent memory optimized tables from blowing out OPT_MEMORY_OPTIMIZED\$HKv2 我们可以在文件存储而不是在内存中创建临时表吗 - Can we create Temp Tables in File Storage, Not in Memory SQL Server内存优化数据和FILESTREAM数据文件非常大 - SQL Server Memory Optimized Data and FILESTREAM Data File is very large 使用flyway——如何部署memory优化表 - Using flyway - How can memory optimized tables be deployed 将数据从普通表复制到 SSMS(2019) 中的 memory 优化表 - Copying data from a normal table to memory optimized table in SSMS(2019) 我们是否可以分发单个数据库的文件组以驻留在多个服务器上? - Can we distribute the file groups of a single database to reside on multiple servers? 我们可以向 SQL 服务器数据库/表添加注释或 README 文件吗? - Can we add comments or a README file to a SQL Server database/table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM