{"id":64823,"date":"2024-10-14T11:58:15","date_gmt":"2024-10-14T03:58:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/64823\/"},"modified":"2024-10-14T11:58:15","modified_gmt":"2024-10-14T03:58:15","slug":"mssql%e5%bf%ab%e9%80%9f%e6%b8%85%e7%90%86log%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88mssql%e6%b8%85%e9%99%a4log%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/64823\/","title":{"rendered":"MSSQL\u5feb\u901f\u6e05\u7406LOG\u7684\u65b9\u6cd5\uff08mssql\u6e05\u9664LOG\uff09"},"content":{"rendered":"<h1 id=\"mssql%e5%bf%ab%e9%80%9f%e6%b8%85%e7%90%86log%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88mssql%e6%b8%85%e9%99%a4log%ef%bc%89-ExYcoUStTW\">MSSQL\u5feb\u901f\u6e05\u7406LOG\u7684\u65b9\u6cd5\uff08mssql\u6e05\u9664LOG\uff09<\/h1>\n<p>\u5728\u4f7f\u7528Microsoft SQL Server\uff08MSSQL\uff09\u6642\uff0c\u65e5\u8a8c\u6a94\u6848\uff08LOG\uff09\u662f\u975e\u5e38\u91cd\u8981\u7684\u7d44\u6210\u90e8\u5206\u3002\u5b83\u5011\u8a18\u9304\u4e86\u6240\u6709\u7684\u4ea4\u6613\u548c\u6578\u64da\u8b8a\u66f4\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6062\u5fa9\u80fd\u529b\u3002\u7136\u800c\uff0c\u96a8\u8457\u6642\u9593\u7684\u63a8\u79fb\uff0c\u9019\u4e9b\u65e5\u8a8c\u6a94\u6848\u53ef\u80fd\u6703\u8b8a\u5f97\u975e\u5e38\u9f90\u5927\uff0c\u4f54\u7528\u5927\u91cf\u7684\u78c1\u789f\u7a7a\u9593\uff0c\u5f71\u97ff\u7cfb\u7d71\u7684\u6027\u80fd\u3002\u56e0\u6b64\uff0c\u5b9a\u671f\u6e05\u7406\u9019\u4e9b\u65e5\u8a8c\u6a94\u6848\u662f\u5fc5\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5e7e\u7a2e\u5feb\u901f\u6e05\u7406MSSQL\u65e5\u8a8c\u7684\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"1-%e7%9e%ad%e8%a7%a3%e6%97%a5%e8%aa%8c%e6%aa%94%e6%a1%88%e7%9a%84%e9%81%8b%e4%bd%9c-ExYcoUStTW\">1. \u77ad\u89e3\u65e5\u8a8c\u6a94\u6848\u7684\u904b\u4f5c<\/h2>\n<p>MSSQL\u7684\u65e5\u8a8c\u6a94\u6848\u4e3b\u8981\u7528\u65bc\u8a18\u9304\u6578\u64da\u5eab\u7684\u4ea4\u6613\u3002\u7576\u6578\u64da\u5eab\u8655\u65bc\u5b8c\u6574\u6062\u5fa9\u6a21\u5f0f\u6642\uff0c\u6240\u6709\u7684\u4ea4\u6613\u90fd\u6703\u88ab\u8a18\u9304\u5728\u65e5\u8a8c\u4e2d\uff0c\u4ee5\u4fbf\u5728\u9700\u8981\u6642\u9032\u884c\u6062\u5fa9\u3002\u9019\u610f\u5473\u8457\uff0c\u9664\u975e\u4f60\u5b9a\u671f\u5099\u4efd\u65e5\u8a8c\uff0c\u5426\u5247\u65e5\u8a8c\u6a94\u6848\u5c07\u4e0d\u6703\u81ea\u52d5\u6e05\u7406\uff0c\u4e26\u4e14\u6703\u4e0d\u65b7\u589e\u9577\u3002<\/p>\n<h2 id=\"2-%e5%ae%9a%e6%9c%9f%e5%82%99%e4%bb%bd%e6%97%a5%e8%aa%8c%e6%aa%94%e6%a1%88-ExYcoUStTW\">2. \u5b9a\u671f\u5099\u4efd\u65e5\u8a8c\u6a94\u6848<\/h2>\n<p>\u6700\u6709\u6548\u7684\u6e05\u7406\u65e5\u8a8c\u6a94\u6848\u7684\u65b9\u6cd5\u662f\u5b9a\u671f\u5099\u4efd\u3002\u900f\u904e\u5099\u4efd\u65e5\u8a8c\uff0cSQL Server\u6703\u81ea\u52d5\u6a19\u8a18\u5df2\u5099\u4efd\u7684\u65e5\u8a8c\u70ba\u53ef\u6e05\u7406\uff0c\u5f9e\u800c\u91cb\u653e\u7a7a\u9593\u3002\u4ee5\u4e0b\u662f\u5099\u4efd\u65e5\u8a8c\u7684\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>BACKUP LOG [\u6578\u64da\u5eab\u540d\u7a31] TO DISK = 'C:Backup\u6578\u64da\u5eab\u540d\u7a31_log.bak'<\/code><\/pre>\n<p>\u5efa\u8b70\u5b9a\u671f\u57f7\u884c\u6b64\u547d\u4ee4\uff0c\u6839\u64da\u696d\u52d9\u9700\u6c42\uff0c\u53ef\u4ee5\u9078\u64c7\u6bcf\u5c0f\u6642\u3001\u6bcf\u5929\u6216\u6bcf\u9031\u9032\u884c\u5099\u4efd\u3002<\/p>\n<h2 id=\"3-%e5%88%87%e6%8f%9b%e5%88%b0%e7%b0%a1%e5%96%ae%e6%81%a2%e5%be%a9%e6%a8%a1%e5%bc%8f-ExYcoUStTW\">3. \u5207\u63db\u5230\u7c21\u55ae\u6062\u5fa9\u6a21\u5f0f<\/h2>\n<p>\u5982\u679c\u4f60\u7684\u6578\u64da\u5eab\u4e0d\u9700\u8981\u5b8c\u6574\u7684\u4ea4\u6613\u65e5\u8a8c\uff0c\u8003\u616e\u5c07\u5176\u6062\u5fa9\u6a21\u5f0f\u5207\u63db\u5230\u7c21\u55ae\u6a21\u5f0f\u3002\u5728\u7c21\u55ae\u6a21\u5f0f\u4e0b\uff0cSQL Server\u6703\u81ea\u52d5\u6e05\u7406\u65e5\u8a8c\u6a94\u6848\uff0c\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u6e1b\u5c11\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\u3002\u5207\u63db\u6062\u5fa9\u6a21\u5f0f\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>ALTER DATABASE [\u6578\u64da\u5eab\u540d\u7a31] SET RECOVERY SIMPLE<\/code><\/pre>\n<p>\u8acb\u6ce8\u610f\uff0c\u9019\u6a23\u505a\u6703\u4f7f\u4f60\u7121\u6cd5\u9032\u884c\u9ede\u6642\u9593\u6062\u5fa9\uff0c\u56e0\u6b64\u5728\u505a\u51fa\u6b64\u6c7a\u5b9a\u4e4b\u524d\uff0c\u8acb\u4ed4\u7d30\u8003\u616e\u3002<\/p>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8dbcc-shrinkfile%e5%91%bd%e4%bb%a4-ExYcoUStTW\">4. \u4f7f\u7528DBCC SHRINKFILE\u547d\u4ee4<\/h2>\n<p>\u5982\u679c\u65e5\u8a8c\u6a94\u6848\u5df2\u7d93\u8b8a\u5f97\u975e\u5e38\u9f90\u5927\uff0c\u53ef\u4ee5\u4f7f\u7528DBCC SHRINKFILE\u547d\u4ee4\u4f86\u7e2e\u5c0f\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\u3002\u9019\u500b\u547d\u4ee4\u6703\u91cb\u653e\u672a\u4f7f\u7528\u7684\u7a7a\u9593\uff0c\u5f9e\u800c\u6e1b\u5c11\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u6b64\u547d\u4ee4\u7684\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>DBCC SHRINKFILE (N'\u6578\u64da\u5eab\u540d\u7a31_log' , 1)<\/code><\/pre>\n<p>\u5728\u57f7\u884c\u6b64\u547d\u4ee4\u4e4b\u524d\uff0c\u78ba\u4fdd\u5df2\u7d93\u5099\u4efd\u4e86\u65e5\u8a8c\u6a94\u6848\uff0c\u4e26\u4e14\u4e86\u89e3\u9019\u53ef\u80fd\u6703\u5f71\u97ff\u6027\u80fd\u3002<\/p>\n<h2 id=\"5-%e7%9b%a3%e6%8e%a7%e6%97%a5%e8%aa%8c%e6%aa%94%e6%a1%88%e7%9a%84%e5%a4%a7%e5%b0%8f-ExYcoUStTW\">5. \u76e3\u63a7\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f<\/h2>\n<p>\u5b9a\u671f\u76e3\u63a7\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\u4f86\u6aa2\u67e5\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\uff1a<\/p>\n<pre><code>SELECT \n    DB_NAME(database_id) AS DatabaseName, \n    Name AS LogicalName, \n    Size * 8 \/ 1024 AS SizeMB \nFROM sys.master_files \nWHERE type_desc = 'LOG'<\/code><\/pre>\n<p>\u900f\u904e\u9019\u4e9b\u6578\u64da\uff0c\u4f60\u53ef\u4ee5\u53ca\u6642\u63a1\u53d6\u884c\u52d5\uff0c\u907f\u514d\u65e5\u8a8c\u6a94\u6848\u904e\u5927\u800c\u5f71\u97ff\u7cfb\u7d71\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ExYcoUStTW\">\u7e3d\u7d50<\/h2>\n<p>\u6e05\u7406MSSQL\u65e5\u8a8c\u6a94\u6848\u662f\u7dad\u8b77\u6578\u64da\u5eab\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u900f\u904e\u5b9a\u671f\u5099\u4efd\u65e5\u8a8c\u3001\u5207\u63db\u6062\u5fa9\u6a21\u5f0f\u3001\u4f7f\u7528DBCC SHRINKFILE\u547d\u4ee4\u4ee5\u53ca\u76e3\u63a7\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u65e5\u8a8c\u6a94\u6848\u7684\u5927\u5c0f\uff0c\u78ba\u4fdd\u7cfb\u7d71\u7684\u7a69\u5b9a\u904b\u884c\u3002\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u7ba1\u7406\u4f60\u7684\u6578\u64da\u5eab\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u4f86\u63d0\u5347\u4f60\u7684\u696d\u52d9\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5feb\u901f\u6e05\u7406MSSQL\u65e5\u5fd7\u7684\u65b9\u6cd5\uff0c\u63d0\u5347\u6570\u636e\u5e93\u6027\u80fd\uff0c\u51cf\u5c11\u5b58\u50a8\u5360\u7528\uff0c\u786e\u4fdd\u7cfb\u7edf\u9ad8\u6548\u8fd0\u884c\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-64823","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/64823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=64823"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/64823\/revisions"}],"predecessor-version":[{"id":64824,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/64823\/revisions\/64824"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=64823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=64823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=64823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}