昨天网上一网友说,由于他同事误将“max server memory”设置为10M后,SQL Server数据库登录不了,当时我简单测试了一下,今天有空就顺手将整个过程整理一下,记录在此。

在SSMS的UI界面设置“max server memory”,即使你设置为10M大小,但是它会“悄悄”默认修改为128M,你用Profile跟踪或者设置后会发现,它偷偷“修改”了你的设置值(改为了128M),

  1. EXEC sys.sp_configure N'max server memory (MB)', N'128'

  1. GO

  1. RECONFIGURE WITH OVERRIDE

  1. GO

  1.  

  1. Configuration option 'max server memory (MB)' changed from 4096 to 128. Run the RECONFIGURE statement to install.

如果你没有注意这些细节,或者不信这个事情,那么也可以用脚本测试一下,如下所示,它提示你这个值(10M)不是一个有效值。

当你对“max server memory”做了错误设置后,那么基本上,任何查询或连接都会出现类似下面这样的错误:

  1. An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

  1.  

  1. ------------------------------

  1. There is insufficient system memory in resource pool 'internal' to run this query. (Microsoft SQL Server, Error: 701)

  1.  

  1.  

  1.  

  1.  

  1.  

  1.  

  1. ------------------------------

  1. ADDITIONAL INFORMATION:

  1.  

  1. A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - 远程主机强迫关闭了一个现有的连接。) (Microsoft SQL Server, Error: 10054)

  1.  

  1. For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=10054&LinkId=20476

  1.  

  1. ------------------------------

  1. 远程主机强迫关闭了一个现有的连接。

你检查数据库的错误日志,就会发现有很多额外信息,摘抄部分如下:

  1. .........................................................

  1. .........................................................

  1. 2019-12-24 10:15:32.84 spid53      There is insufficient system memory in resource pool 'internal' to run this query.

  1. 2019-12-24 10:15:52.88 spid53      Error: 18056, Severity: 20, State: 29. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.

  1. 2019-12-24 10:15:55.89 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.

  1. 2019-12-24 10:16:12.70 Server       Failed allocate pages: FAIL_PAGE_ALLOCATION 1

  1. 2019-12-24 10:16:12.70 Server  

  1.  

  1. Process/System Counts                         Value

  1. ---------------------------------------- ----------

  1. Available Physical Memory                6614454272

  1. Available Virtual Memory                 140726213148672

  1. Available Paging File                    7776440320

  1. Working Set                                95432704

  1. Percent of Committed Memory in WS               100

  1. Page Faults                                   57030

  1. System physical memory high                       1

  1. System physical memory low                        0

  1. Process physical memory low                       1

  1. Process virtual memory low                        0

  1. 2019-12-24 10:16:12.70 Server     

  1. Memory Manager                                   KB

  1. ---------------------------------------- ----------

  1. VM Reserved                                10652776

  1. VM Committed                                  57972

  1. Locked Pages Allocated                        86472

  1. Large Pages Allocated                             0

  1. Emergency Memory                               1024

  1. Emergency Memory In Use                          16

  1. Target Committed                             131072

  1. Current Committed                            144448

  1. Pages Allocated                               84176

  1. Pages Reserved                                    0

  1. Pages Free                                        0

  1. Pages In Use                                 144432

  1. Page Alloc Potential                         -19912

  1. NUMA Growth Phase                                 2

  1. Last OOM Factor                                   1

  1. Last OS Error                                     0

  1. 2019-12-24 10:16:12.70 Server     

  1. Memory node Id = 0                               KB

  1. ---------------------------------------- ----------

  1. VM Reserved                                10652712

  1. VM Committed                                  57952

  1. Locked Pages Allocated                        86472

  1. Pages Allocated                               84176

  1. Pages Free                                        0

  1. Target Committed                             131048

  1. Current Committed                            144424

  1. Foreign Committed                                 0

  1. Away Committed                                    0

  1. Taken Away Committed                              0

  1. 2019-12-24 10:16:12.70 Server     

  1. Memory node Id = 64                              KB

  1. ---------------------------------------- ----------

  1. VM Reserved                                       0

  1. VM Committed                                     20

  1. Locked Pages Allocated                            0

  1. 2019-12-24 10:16:12.70 Server     

  1. MEMORYCLERK_SQLGENERAL (node 0)                  KB

  1. ---------------------------------------- ----------

  1. .........................................................

  1. .........................................................

要解决这个问题,你需要关闭数据库服务, 然后以单用户模式+最小配置启动数据库实例,然后去修改max server memory参数。 关闭数据库过程中如果遇到一些问题,可以通过重启服务器解决问题(这个要根据具体实际情况决定,有时候不会遇到问题,有时候会遇到一些问题,例如net stop mssqlserver命令卡住,出现service_state[MSSQLSERVER]): Stop pending)

注意:如果以单用户模式启动,然后以sqlcmd去连接数据库,就会出现下面错误,所以必须以单用户模式+最小配置启动数据库实例

  1. EXEC sys.sp_configure 'max server memory (MB)',4096;  #根据实际情况设置内存大小。

  1.  

  1. RECONFIGURE

  1.  

  1. GO

然后重启SQL Server实例,问题就解决了。 当然你也可以还原master库的备份到其它测试数据库,然后用还原后master数据库的相关文件替换当前数据库master的相关文件来解决问题。但是那样会相对麻烦,没有这种方法简便、有效!

C:\Windows\system32>net stop mssqlserver

The SQL Server (MSSQLSERVER) service is stopping.

The SQL Server (MSSQLSERVER) service was stopped successfully.

C:\Windows\system32>net start mssqlserver

The SQL Server (MSSQLSERVER) service is starting.

The SQL Server (MSSQLSERVER) service was started successfully.

SQL Server误设置max server memory处理小结的更多相关文章

  1. 限制sqlserver最大内存后无法连接-EXEC sp_configure max server memory

    在sql server 中设置了过小的 "max server memory"最大内存后,sqlserver可启动,但是无法连接. 网络上流行的"sqlserver 内存 ...

  2. max server memory

    MS SQL Server 2008 R2,主要是用作ERP的数据库,但它的内存使用率非常高: 经查资料,原来数据库有默认的情况之下,使用内存时它是尽可能使用完有效内存.如果你不想这样,你可以手动分配 ...

  3. DAC重置max server memory

    15:44 2014-01-24 08R2,一次通过GUI更改'最大服务器内存(MB)'为16MB,errorlog显示信息如下 :: . Run the RECONFIGURE statement ...

  4. SQL Server数据库与max degree of parallelism参数

    我们今天主要向大家讲述的是SQL Server数据库中的max degree of parallelism参数,当 SQL Server 数据库在具N个微处理器或是 CPU 的计算机上运行时,它将为每 ...

  5. Sharepoint 性能之SQL Server内存设置

    In this article, let's understand the Minimum and Maximum server memory settings of SQL Server. The ...

  6. 设置Proxy Server和SQL Server实现互联网上的数据库安全

    ◆首先,我们需要了解一下SQL Server在WinSock上定义协议的步骤: 1. 在”启动”菜单上,指向”程序/Microsoft Proxy Server”,然后点击”Microsoft Man ...

  7. 将 SQL Server 实例设置为自动启动(SQL Server 配置管理器)

    本主题说明如何使用 SQL Server 配置管理器在 SQL Server 2012 中将 SQL Server 实例设置为自动启动. 在安装过程中,SQL Server 通常配置为自动启动. 如果 ...

  8. SQL Server数据库设置自动备份策略

    一. 简单介绍 SQL Server自带的维护计划是一个非常有用的维护工具,能够完成大部分的数据库的维护任务. 数据库的备份也是日常工作中非常重要的一个环节.备份的方法非常的多. 今天给大家介绍最简单 ...

  9. SQL server已经设置为单用户模式,还是无法做分离、属性设置等操作

    https://www.cnblogs.com/xingyunqiu/p/10336938.html SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数 ...

随机推荐

  1. postman之设置关联

    接口关联(上一个接口的返回参数作为下一个接口的入参使用): 一:在第一个接口的test点击Response body:JSON value check和set an environment varia ...

  2. 从底层入手,解析字节码增强和Btrace应用

    这篇文章聊下字节码和相关的应用. 1.机器码和字节码 机器码(machine code),学名机器语言指令,有时也被称为原生码(Native Code),是电脑的CPU可直接解读的数据. 通常意义上来 ...

  3. SELinux 和 iptables 开启关闭

    SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制(MAC)系统.对于目前可用的 Linux安全模块来说,SELinux 是功能最全面,而且测试最充分的,它是在 20 年的 MA ...

  4. 珠峰-buffer-流事件

    #### Buffer // 字符串的二进制转10进制 let r = parseInt('11111111', 2); console.log(r); // 打印 255 // Number类型转为 ...

  5. gcd综合

    问题: 如果正整数大于了1000有什么影响? 1.递推式gcd: int gcd(int a,int b) { ) { int c=a%b; a=b; b=c; } return a; } 2.递归式 ...

  6. K8S集群入门:运行一个应用程序究竟需要多少集群?

    如果你使用Kubernetes作为应用程序的操作平台,那么你应该会遇到一些有关使用集群的方式的基本问题: 你应该有多少集群? 它们应该多大? 它们应该包含什么? 本文将深入讨论这些问题,并分析你所拥有 ...

  7. C#设计模式学习笔记:(17)中介者模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7966240.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第五个模式--中 ...

  8. pycharm(迅雷下载链接)

    pycharm2020迅雷下载链接: https://download.jetbrains.com/python/pycharm-professional-2019.3.3.exe?_ga=2.146 ...

  9. MySql数据库精简与绿色启动

    1.下载MYSQL的zip包,解压ZIP包 版本低的相对需要的空间少,最好能在mysql-5.6以下,我测试的最高5.6版本为mysql-5.6.46,主要是里面有my.ini文件,高于5.6的版本里 ...

  10. Centos7内核版安装nginx环境问题及解决方法

    错误信息:./configure: error: C compiler cc is not found解决方案:yum -y install gcc gcc-c++ autoconf automake ...