简体   繁体   English

bacpac还原到SQL Server的内存使用情况

[英]Memory usage for bacpac restore to SQL server

I have just restored a .bacpac file into a local SQL server instance (64b v12.0.4213), the backup is from an azure sql instance. 我刚刚将.bacpac文件还原到本地SQL Server实例(64b v12.0.4213)中,备份是从Azure SQL实例中进行的。

It failed a few times with an OOM exception. 由于OOM异常,它几次失败。 I switched off everything on my machine and by the end of the restore the SQL server service instance was consuming 13GB of memory from a 700MB file! 我关闭了计算机上的所有设备,并且在还原结束时,SQL Server服务实例从700MB的文件中消耗了13GB的内存!

The restore luckily finished, but it seems the memory is not being freed up/garbage collected. 幸运的是,还原已完成,但是似乎内存没有被释放/回收。 It's still sitting at 12GB as I write this. 在我撰写本文时,它仍然位于12GB。

Is it a known issue? 这是一个已知问题吗? Is there any way I can restore a .bacpac and select a table to ignore? 有什么办法可以恢复.bacpac并选择要忽略的表? You can to do this with a normal data restore, the most offensive table was a dbo.[Logs] table, obvs. 您可以通过正常的数据恢复来做到这一点,最令人反感的表是dbo。[Logs]表,obvs。

I had the same issue; 我遇到过同样的问题; amending the memory available to the server had no impact. 修改服务器可用的内存没有影响。

For me the resolution was to use the command line (PowerShell) to perform the import. 对我来说,解决方法是使用命令行(PowerShell)执行导入。

[string]$myBacpac = 'c:\temp\myBacpac123.bacpac'
[string]$connectionString = 'Data Source=.;Initial Catalog=MyNewCatalog; Integrated Security=true;'
[string]$action = 'Import'

[string[]]$commandParameters = @(
    "/Action:`"$action`"" 
    "/SourceFile:`"$myBacpac`"" 
    "/TargetConnectionString:`"$connectionString`""
)
[string]$LatestSqlPackage = Get-Item 'C:\*\Microsoft SQL Server\*\DAC\bin\sqlpackage.exe' | %{get-command $_}| sort version -Descending | select -ExpandProperty source -First 1
if ($LatestSqlPackage) {
    Write-Verbose "Found: $LatestSqlPackage" 
    & $LatestSqlPackage $commandParameters
} else {
    Write-Error "Could not find SqlPackage.exe"
}

On my first attempt I received an error regarding an unsupported model version: 第一次尝试时,我收到关于不支持的模型版本的错误:

Importing to database 'MyNewCatalog' on server '.'. 导入到服务器“。”上的数据库“ MyNewCatalog”。 Creating deployment plan Initializing deployment SqlPackage.exe : * Error importing database:Could not read schema model header information from package. 创建部署计划初始化部署SqlPackage.exe: *导入数据库时​​出错:无法从包中读取架构模型头信息。 At line:1 char:1 + & $sqlPackage /Action:Import /SourceFile:"c:\\temp\\myBacpac123.bacpac" /T ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (* Error impor...n from package.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError The model version '3.5' is not supported. 在第1行:char:1 +&$ sqlPackage / Action:导入/SourceFile:"c:\\temp\\myBacpac123.bacpac“ / T ... + ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo:未指定:(*包中的错误不正确... :字符串 )[],RemoteException + FullyQualifiedErrorId:NativeCommandError不支持模型版本'3.5'。

For that error I followed the guidance here: https://stackoverflow.com/a/40541210/361842 ; 对于该错误,我遵循此处的指导: https : //stackoverflow.com/a/40541210/361842 ; ie installed Microsoft SQL Server Data-Tier Application Framework (16.4) . 即安装了Microsoft SQL Server Data-Tier Application Framework (16.4) On rerunning all was successful. 在重新运行时,一切都成功了。

To configure SQL Server's use of memory, open SQL Server Management Studio, connect to the server, right-click on the server in the Object Explorer window, click properties, and then click on the Memory tab of the Server Properties window. 若要配置SQL Server的内存使用,请打开SQL Server Management Studio,连接到服务器,在“对象资源管理器”窗口中右键单击服务器,单击“属性”,然后单击“服务器属性”窗口的“内存”选项卡。

As for the bacpac, you can't select which tables to restore during an import operation, but you can select which tables are exported. 至于bacpac,您无法选择在导入操作期间要还原的表,但是可以选择导出的表。 You can use SqlPackage.exe's export command with the /p:TableData parameter to specify which tables should be included in the bacpac. 您可以将SqlPackage.exe的export命令与/ p:TableData参数一起使用,以指定应在bacpac中包含哪些表。 There's unfortunately no way to just specify which tables should be excluded. 不幸的是,没有办法仅指定应排除哪些表。 =^/ = ^ /

SqlPackage.exe documentation is available here: https://msdn.microsoft.com/en-us/hh550080(v=vs.103).aspx SqlPackage.exe文档可在此处获得: https ://msdn.microsoft.com/zh-cn/hh550080(v=vs.103).aspx

Neither of the other answers worked for me, what did work was closing and restarting SSMS . 没有其他答案对我有用 ,所做的工作是关闭并重新启动SSMS This sounds like a silly suggestion, but I'd previously been running some large queries which must've caused memory issues. 这听起来像是一个愚蠢的建议,但是我以前一直在运行一些大型查询,这些查询肯定会导致内存问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM