<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>System engineer</title>
    <link>https://99lib.tistory.com/</link>
    <description></description>
    <language>ko</language>
    <pubDate>Sun, 28 Jun 2026 00:59:08 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>99iberty</managingEditor>
    <item>
      <title>[스크랩] SQL SERVER 스키마란?</title>
      <link>https://99lib.tistory.com/687</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;DB내 어떤 구조로 데이터가 저장되는가를 나타내는 데이터베이스 구조&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://truepia.tistory.com/167&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://truepia.tistory.com/167&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1659883085489&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;[SQL2005] 스키마(Schema) 이해&quot; data-og-description=&quot;SQL 서버 2005에서 데이터베이스에 테이블, 뷰, 저장프로시저와 같은 개체를 만들면 스키마(Schema)안에 만들어 집니다. SQL 서버 2000과 달라진 부분이기 때문에 SQL 서버 2000 사용자 분들이 이것에 대&quot; data-og-host=&quot;truepia.tistory.com&quot; data-og-source-url=&quot;https://truepia.tistory.com/167&quot; data-og-url=&quot;https://truepia.tistory.com/167&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/XsKpP/hyPmbwWN3R/o9ju0GnY7lwn4HCmO0rY21/img.jpg?width=443&amp;amp;height=116&amp;amp;face=0_0_443_116,https://scrap.kakaocdn.net/dn/mDdAa/hyPmkUX1eM/31pPDzvTqhx98VDQva6Byk/img.jpg?width=443&amp;amp;height=116&amp;amp;face=0_0_443_116,https://scrap.kakaocdn.net/dn/bW2peA/hyPmbwWN19/LTe2VQvyOVwuffT67FNwy1/img.jpg?width=400&amp;amp;height=300&amp;amp;face=0_0_400_300&quot;&gt;&lt;a href=&quot;https://truepia.tistory.com/167&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://truepia.tistory.com/167&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/XsKpP/hyPmbwWN3R/o9ju0GnY7lwn4HCmO0rY21/img.jpg?width=443&amp;amp;height=116&amp;amp;face=0_0_443_116,https://scrap.kakaocdn.net/dn/mDdAa/hyPmkUX1eM/31pPDzvTqhx98VDQva6Byk/img.jpg?width=443&amp;amp;height=116&amp;amp;face=0_0_443_116,https://scrap.kakaocdn.net/dn/bW2peA/hyPmbwWN19/LTe2VQvyOVwuffT67FNwy1/img.jpg?width=400&amp;amp;height=300&amp;amp;face=0_0_400_300');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;[SQL2005] 스키마(Schema) 이해&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;SQL 서버 2005에서 데이터베이스에 테이블, 뷰, 저장프로시저와 같은 개체를 만들면 스키마(Schema)안에 만들어 집니다. SQL 서버 2000과 달라진 부분이기 때문에 SQL 서버 2000 사용자 분들이 이것에 대&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;truepia.tistory.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;SQL 서버 2005에서 데이터베이스에 테이블, 뷰, 저장프로시저와 같은 개체를 만들면 스키마(Schema)안에 만들어 집니다. SQL 서버 2000과 달라진 부분이기 때문에 SQL 서버 2000 사용자 분들이 이것에 대해 많이 혼란스러워합니다. 스키마에 대해 살펴보도록 하겠습니다.&lt;/p&gt;
&lt;pre class=&quot;angelscript&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;1. 스키마란&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;스키마는 데이터베이스 개체에 대한 네임스페이스(Namespace) 입니다. 즉 데이터베이스 개체가 갖는 고유한 이름을 결정지어주게 됩니다. 스키마는 데이터베이스 안에서 고유해야 하기 때문에 데이터베이스의 모든 개체는 다음과 같은 형식의 고유한 이름을 갖게 됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Server.Database.Schema.Object&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;SQL 서버 2000에서는 Server.Database.Owner.Object와 같은 형식으로 이름이 결정되었습니다. 하지만 SQL 서버 2005에서는 개체의 소유자(Owner)가 아닌 스키마를 사용해 개체의 이름에서 소유자 부분을 분리시켰습니다. 이렇게 함으로써 얻어지는 이점이 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;1) 개체의 소유자와는 상관없이 스키마를 이용해 개체를 그룹화 하여 관리에 효율을 꾀할 수 있습니다.&lt;br /&gt;2) 권한 관리의 경우 개체 개별 적으로 권한을 허용하지 않고 스키마에 권한을 허용하면 스키마에 포함된 모든 개체에 대해 자동으로 권한을 줄 수 있어 권한 관리가 효율적입니다.&lt;br /&gt;3) 소유자 계정을 삭제하기 위해 소유자가 소유한 개테의 소유자를 변경하거나 개체를 삭제할 필요가 없습니다. SQL 서버 2000에서는 개체를 소유한 소유자의 계정을 삭제 할 수 없었습니다.&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;SQL 서버 2005의 예제 데이터베이스인 AdventureWorks 데이터베이스는 다음과 같은 스키마를 가지고 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;- HumanResources&lt;br /&gt;- Person&lt;br /&gt;- Production&lt;br /&gt;- Purchasing&lt;br /&gt;- Sales&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Management Studio에서 AdventureWorks 데이터베이스의 테이블 부분을 확장하면 위 스키마로 시작된 테이블들을 확인 할 수 있습니다.&lt;/p&gt;
&lt;pre class=&quot;angelscript&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;2. dbo 스키마&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;dbo 스키마는 모든 데이터베이스에 포함되어 있는 특수한 스키마입니다. 데이터베이스의 사용자 계정은 기본 스키마를 갖게 됩니다. 그리고 이 사용자가 테이블을 만들면 그 테이블은 사용자의 기본 스키마에 포함되게 됩니다. 예를 들어 기본 스키마가 Sales 인 사용자 계정이 Customer 테이블을 만들면 Sales.Customer와 같은 이름을 갖게 됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;dbo 스키마는 별도의 기본 스키마가 지정되지 않은 사용자 계정의 기본 스키마가 됩니다. 만일 기본 스키마가 별도로 지정되지 않은 사용자 계정이 Orders 테이블을 만들면 기 테이블은 dbo.Orders 라는 이름을 갖게 됩니다.&lt;/p&gt;
&lt;pre class=&quot;angelscript&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;3. 스키마 만들기&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;스키마는 SQL Server Management Studio 또는 CREATE SCHEMA 문을 이용해 만들 수 있습니다.&lt;/p&gt;
&lt;table class=&quot;script&quot; style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; width=&quot;580&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;USE AdventureWorks&lt;br /&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;b&gt;CREATE SCHEMA&lt;/b&gt; Sales&lt;br /&gt;GO&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위 예제 에서는 AdventureWorks 데이터베이스에 Sales 스키마를 만들고 있습니다. 만일 AdventureWorks 데이터베이스에 Jane 이라는 사용자 계정이 있다고 가정한다면 다음과 같이 같이 Jane의 기본 스키마를 Sales로 지정 할 수 있습니다.&lt;/p&gt;
&lt;table class=&quot;script&quot; style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; width=&quot;580&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;USE AdventureWorks&lt;br /&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span&gt;ALTER USER Jane WITH &lt;b&gt;DEFAULT_SCHEMA&lt;/b&gt; = Sales&lt;br /&gt;GO&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이러한 작업은 Management Studio에서도 가능합니다.&lt;/p&gt;
&lt;pre class=&quot;angelscript&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;4. 스키마 삭제&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;스키마 삭제는 SQL Server Management Studio 또는 DROP SCHEMA 문을 이용하여 할 수 있습니다.&lt;/p&gt;
&lt;table class=&quot;script&quot; style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; width=&quot;580&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;USE AdventureWorks&lt;br /&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;b&gt;DROP SCHEMA&lt;/b&gt; Sales&lt;br /&gt;GO&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=&quot;7&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;5. 개체 이름 확인 과정&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;데이터베이스에 여러 개의 스키마가 있다면 개체 이름 확인은 단순하지 않습니다. 하지만 기본 스키마에 대해 정확히 파악하고 있다면 이 부분을 쉽게 이해 할 수 있습니다. 만일 데이터베이스에 다음과 같이 Person, Sales, dbo 스키마가 있다고 가정하겠습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class=&quot;imageblock center&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/1652291049BDB3FD7A&quot; width=&quot;443&quot; height=&quot;116&quot; /&gt;&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그리고 Person 스키마에는 Contact 테이블이 dbo 스키마에는 ErrorLog 테이블이 존재하고 있습니다. 물론 Sales 스키마에도 몇몇 테이블이 존재하고 있습니다. 이 상황에서 다음의 예에서 어떻게 개체를 찾게 되는지 확인을 해보도록 하겠습니다.&lt;/p&gt;
&lt;pre class=&quot;inform7&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;[예제1] 기본 스키마가 Person인 사용자 Lance가 다음 쿼리 문을 수행 &lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;SELECT * FROM Contact&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;개체 이름에 스키마가 생략되어 있으면 SQL 서버는 쿼리 문을 수행하는 사용자의 기본 스키마에서 해당 테이블을 찾게 됩니다. Lance의 기본 스키마가 Person이므로 위 쿼리 문 수행을 위해 SQL 서버는 Person.Contact 테이블을 찾게 됩니다. 그리고 Person.Contact 테이블에 존재하므로 &lt;b&gt;결과를 리턴&lt;/b&gt;해 줍니다.&lt;/p&gt;
&lt;pre class=&quot;angelscript&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;[예제2] 기본 스키마가 Sales 인 사용자 Anders가 다음 세 개의 쿼리 문을 수행&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;SELECT * FROM Person.Contact&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Anders의 기본 스키마가 Sales 이지만 쿼리 문에 Person.Contact이라고 스키마가 지정되어 개체 이름을 사용했으므로 SQL 서버는 Person.Contact 테이블을 찾게 됩니다. 그리고 Person.Contact 테이블이 존재하므로 &lt;b&gt;결과를 리턴&lt;/b&gt;해 줍니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;SELECT * FROM ErrorLog&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 경우 개체 이름에 스키마가 생략되어 있으므로 SQL 서버는 쿼리 문을 수행하는 사용자의 기본 스키마에서 해당 테이블을 찾게 됩니다. Anders의 기본 스키마가 Sales이므로 Sales.ErrorLog 테이블을 찾게 됩니다. 하지만 Sales 스키마에는 ErrorLog 테이블이 없습니다. SQL 서버는 여기서 포기 하지 않고 dbo 스키마에 ErrorLog 테이블이 있는지 찾습니다. 즉 dbo.ErrorLog 테이블을 찾습니다. 그리고 dbo.ErrorLog 테이블이 있으므로 그 &lt;b&gt;결과를 리턴&lt;/b&gt;해 줍니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;SELECT * FROM Contact&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;역시 개체 이름에 스키마가 생략되어 있으므로 SQL 서버는 쿼리 문을 수행하는 사용자의 기본 스키마에서 해당 테이블을 찾게 됩니다. Anders의 기본 스키마가 Sales이므로 Sales.Contact 테이블을 찾습니다. 하지만 Sales 스키마에는 Contact 테이블이 없으므로 Sales.Contact 테이블 찾기는 실패합니다. SQL 서버는 이어서 dbo.Contact 테이블을 찾습니다. dbo 스키마에도 Contact 테이블이 없으므로 찾기에 실패합니다. 결국 이 쿼리 문은 개체를 찾지 못해&lt;b&gt; 에러를 발생&lt;/b&gt;시킵니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;정리 하면, 사용자의 기본 스키마에 속한 개체나 dbo 스키마에 속한 개체는 스키마를 생략해도 개체를 찾을 수 있으나, 그 외의 스키마에 속한 개체를 찾기 위해서는 개체 이름 앞에 스키마를 정확히 포함시켜주어야 한다는 것입니다. 가장 좋은 방법은 개체 이름 앞에 항상 스키마를 포함시키는 습관을 갖는 것입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;&lt;b&gt;&lt;span&gt;6. 정리&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;일반적으로 스키마라고 하면 테이블의 구조를 이야기 합니다. 하지만 SQL 서버 2005에서는 다른 의미를 가지고 있습니다. 스키마는 관리 및 보안을 위해 유익한 기능을 제공하고 있으며, SQL 서버 2005를 사용하려면 꼭 이해하고 있어야 하는 개체입니다. 본 강좌에서 다 다루지 못한 부분은 온라인 설명서를 통해 명확히 이해 하시는게 좋을것 같습니다.&lt;/p&gt;
&lt;pre id=&quot;code_1659883094009&quot; class=&quot;cs&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;[출처] 디비누리&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;출처: &lt;a href=&quot;https://truepia.tistory.com/167&quot;&gt;https://truepia.tistory.com/167&lt;/a&gt; [진실세상을 꿈꾸며:티스토리]&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://smok95.tistory.com/151&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://smok95.tistory.com/151&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1659883107242&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;[펌] SQL Server 사용자와 스키마 개념&quot; data-og-description=&quot;SQL Server 2005 온라인 설명서(2007년 9월) 사용자와 스키마 분리 업데이트: 2007년 2월 1일 SQL Server 2005부터 각 개체는 데이터베이스 스키마에 속해 있습니다. 데이터베이스 스키마는 데이터베이스 사&quot; data-og-host=&quot;smok95.tistory.com&quot; data-og-source-url=&quot;https://smok95.tistory.com/151&quot; data-og-url=&quot;https://smok95.tistory.com/151&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/diwxb1/hyPmhRtNRQ/0KiGSvIyyYxsA8tCjHzDk1/img.png?width=800&amp;amp;height=800&amp;amp;face=0_0_800_800,https://scrap.kakaocdn.net/dn/bJvIYV/hyPl8NMuif/DXhruOUpgCHMyjiUUcMeaK/img.png?width=800&amp;amp;height=800&amp;amp;face=0_0_800_800&quot;&gt;&lt;a href=&quot;https://smok95.tistory.com/151&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://smok95.tistory.com/151&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/diwxb1/hyPmhRtNRQ/0KiGSvIyyYxsA8tCjHzDk1/img.png?width=800&amp;amp;height=800&amp;amp;face=0_0_800_800,https://scrap.kakaocdn.net/dn/bJvIYV/hyPl8NMuif/DXhruOUpgCHMyjiUUcMeaK/img.png?width=800&amp;amp;height=800&amp;amp;face=0_0_800_800');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;[펌] SQL Server 사용자와 스키마 개념&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;SQL Server 2005 온라인 설명서(2007년 9월) 사용자와 스키마 분리 업데이트: 2007년 2월 1일 SQL Server 2005부터 각 개체는 데이터베이스 스키마에 속해 있습니다. 데이터베이스 스키마는 데이터베이스 사&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;smok95.tistory.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)?redirectedfrom=MSDN&quot;&gt;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)?redirectedfrom=MSDN&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;figure id=&quot;og_1659883128534&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;website&quot; data-og-title=&quot;사용자와 스키마 분리&quot; data-og-description=&quot;사용자와 스키마 분리 아티클 12/15/2008 읽는 데 12분 걸림 이 문서의 내용 --&amp;gt; 업데이트: 2006년 12월 12일 SQL Server 2005부터 각 개체는 데이터베이스 스키마에 속해 있습니다. 데이터베이스 스키마는 &quot; data-og-host=&quot;docs.microsoft.com&quot; data-og-source-url=&quot;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)?redirectedfrom=MSDN&quot; data-og-url=&quot;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/bdzUnd/hyPmipjJsJ/mbUt3ehjcMGMezjwOGa9Hk/img.png?width=400&amp;amp;height=400&amp;amp;face=0_0_400_400&quot;&gt;&lt;a href=&quot;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)?redirectedfrom=MSDN&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://docs.microsoft.com/ko-kr/previous-versions/sql/sql-server-2005/ms190387(v=sql.90)?redirectedfrom=MSDN&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/bdzUnd/hyPmipjJsJ/mbUt3ehjcMGMezjwOGa9Hk/img.png?width=400&amp;amp;height=400&amp;amp;face=0_0_400_400');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;사용자와 스키마 분리&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;사용자와 스키마 분리 아티클 12/15/2008 읽는 데 12분 걸림 이 문서의 내용 --&amp;gt; 업데이트: 2006년 12월 12일 SQL Server 2005부터 각 개체는 데이터베이스 스키마에 속해 있습니다. 데이터베이스 스키마는&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;docs.microsoft.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/687</guid>
      <comments>https://99lib.tistory.com/687#entry687comment</comments>
      <pubDate>Sun, 7 Aug 2022 23:39:07 +0900</pubDate>
    </item>
    <item>
      <title>Understanding Logging and Recovery in SQL Server</title>
      <link>https://99lib.tistory.com/686</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392031(v=msdn.10)?redirectedfrom=MSDN&quot;&gt;SQL Server: Understanding Logging and Recovery in SQL Server | Microsoft Docs&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1658155583713&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;website&quot; data-og-title=&quot;SQL Server: Understanding Logging and Recovery in SQL Server&quot; data-og-description=&quot;Table of contents Article 10/04/2016 21 minutes to read In this article --&amp;gt; SQL Server Understanding Logging and Recovery in SQL Server Paul S. Randal At a Glance: How logging and recovery function in SQL Server How the transaction log works and what you n&quot; data-og-host=&quot;docs.microsoft.com&quot; data-og-source-url=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392031(v=msdn.10)?redirectedfrom=MSDN&quot; data-og-url=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392031(v=msdn.10)&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/EqtM8/hyO809L41P/d5Tlj9zdGMnTJNcvrEa0UK/img.png?width=400&amp;amp;height=400&amp;amp;face=0_0_400_400&quot;&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392031(v=msdn.10)?redirectedfrom=MSDN&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392031(v=msdn.10)?redirectedfrom=MSDN&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/EqtM8/hyO809L41P/d5Tlj9zdGMnTJNcvrEa0UK/img.png?width=400&amp;amp;height=400&amp;amp;face=0_0_400_400');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;SQL Server: Understanding Logging and Recovery in SQL Server&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;Table of contents Article 10/04/2016 21 minutes to read In this article --&amp;gt; SQL Server Understanding Logging and Recovery in SQL Server Paul S. Randal At a Glance: How logging and recovery function in SQL Server How the transaction log works and what you n&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;docs.microsoft.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;At a Glance:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;How logging and recovery function in SQL Server&lt;/li&gt;
&lt;li&gt;How the transaction log works and what you need to know about managing it&lt;/li&gt;
&lt;li&gt;Recovery models and their effect on logging&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;contents&quot; data-ke-size=&quot;size26&quot;&gt;Contents&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;What Is Logging?&lt;br /&gt;What Is Recovery?&lt;br /&gt;The Transaction Log&lt;br /&gt;Recovery Models&lt;br /&gt;Wrapping Up&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Some of the most misunderstood parts of SQL Server are its logging and recovery mechanisms. The fact that the transaction log exists and can cause problems if not managed correctly seems to confound many &quot;involuntary DBAs.&quot; Why is it possible for the transaction log to grow unbounded? Why does it sometimes take so long for the database to come online after a system crash? Why can't logging be turned off completely? Why can't I recover my database properly? Just what is the transaction log and why is it there?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;These are all questions I see repeatedly on SQL Server forums and newsgroups, so in this article I want to provide an overview of the logging and recovery system and explain why it is such an integral part of the SQL Server Storage Engine. I will explain the architecture of the transaction log and how the three recovery models available for a database can change the behavior of the transaction log and the logging process itself. Along the way, I'll also provide some links to resources covering transaction log management best practices.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;What Is Logging?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Logging and recovery are not concepts that are unique to SQL Server&amp;mdash;all commercial relational database management systems (RDBMSs) must have them to support the various ACID properties of transactions. ACID stands for Atomicity, Consistency, Isolation, and Durability, which are the fundamental properties of a transaction-processing system (such as an RDBMS). You can read more about this in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://msdn.microsoft.com/library/aa719484&quot; data-linktype=&quot;external&quot;&gt;ACID Properties section of the MSDN Library&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Video (no longer available)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Paul Randal demonstrates the importance of managing your transaction log properly in the full recovery model, and he shows you techniques for doing so in SQL Server.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Operations in an RDBMS are logged (or recorded) at the physical and logical level in terms of what happens in the storage structures of the database. Each change to the storage structures has its own log record, which describes the structure being changed and what the change was. This is done in such a way that the change can be replayed or reversed, if necessary. The log records are stored in a special file called the transaction log&amp;mdash;I will describe this in more detail later, but for now you can think of it as a sequential-access file.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A set of one or more such changes can be (and in fact, always are) grouped together in a transaction&amp;mdash;which provides the basic unit of making changes (atomicity) to a database as far as users, application developers, and DBAs are concerned. A transaction either succeeds (committing) or fails/is canceled (rolling back). In the first case, the operations that form the transaction are guaranteed to be reflected in the database. In the second case, the operations are guaranteed not to be reflected in the database.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transactions in SQL Server are either explicit or implicit. An explicit transaction is one where the user or application issues a BEGIN TRANSACTION T-SQL statement, signaling the start of a group of related changes by that session. An explicit transaction succeeds when a COMMIT TRANSACTION statement is issued, signaling the successful completion of the group of changes. If a ROLLBACK TRANSACTION statement is issued instead, all changes made by that session since the BEGIN TRANSACTION statement was issued are reverted (rolled back) and the transaction is aborted. A transaction rollback could also be forced by an external event, such as the database running out of disk space or a server crash, as I will explain later.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;An implicit transaction is one where the user or application does not explicitly issue a BEGIN TRANSACTION statement before issuing a T-SQL statement. However, given that all changes to the database must be transactional, the Storage Engine will automatically start a transaction under the covers. When the T-SQL statement completes, the Storage Engine automatically commits the transaction that it started to wrap around the user's statement.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;You might think that this is not necessary because a single T-SQL statement won't generate a large number of changes to the storage structures of the database, but consider something like an ALTER INDEX REBUILD statement. Although this statement can't be contained within an explicit transaction, it could generate an enormous number of changes to the database. So there must be some mechanism for ensuring that if something does go wrong (the statement is canceled, for instance), all of the changes are properly reversed.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;As an example, consider what happens when a single table row is updated in an implicit transaction. Imagine a simple heap table with an integer column c1 and a char column c2. The table has 10,000 rows, and a user submits an update query as follows:&lt;/p&gt;
&lt;div id=&quot;code-try-0&quot; data-bi-name=&quot;code-header&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&lt;span&gt;Copy&lt;/span&gt;
&lt;div aria-hidden=&quot;true&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;UPDATE SimpleTable SET c1 = 10 WHERE c2 LIKE '%Paul%';
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The following operations take place:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;The data pages from SimpleTable are read from disk into memory (the buffer pool) so they can be searched for matching rows. It turns out that three data pages hold five rows that match the WHERE clause predicate.&lt;/li&gt;
&lt;li&gt;The Storage Engine automatically starts an implicit transaction.&lt;/li&gt;
&lt;li&gt;The three data pages and five data rows are locked to allow the updates to occur.&lt;/li&gt;
&lt;li&gt;The changes are made to the five data records on the three data pages in memory.&lt;/li&gt;
&lt;li&gt;The changes are also recorded in log records in the transaction log on disk.&lt;/li&gt;
&lt;li&gt;The Storage Engine automatically commits the implicit transaction.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Note that I didn't list a step where the three updated data pages are written back out to disk. This is because they don't yet need to be; as long as the log records describe the changes are on disk in the transaction log, then the changes are protected. If the pages need to be subsequently read or changed again, then the most up-to-date copy of the page is already in memory, just not on disk (yet). The data pages will be written out to disk when the next checkpoint operation occurs or if the memory that they use in the buffer pool is required for another page image.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Checkpoints exist for two reasons&amp;mdash;to batch up write I/Os to improve performance and to reduce the time required for crash recovery. In terms of performance, if a data page were forced out to disk each time it was updated, the number of write I/Os occurring on a busy system could easily overwhelm the I/O subsystem. It's better to periodically write out dirty pages (pages that have been changed since being read from disk) than to write out pages immediately as they are changed. I'll discuss the recovery aspect of checkpoints in a moment.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;One common misconception about checkpoints is that they only write out pages with changes from committed transactions. This is not true&amp;mdash;a checkpoint always writes out all dirty pages, regardless of whether the transaction that changed a page has committed or not.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Write-ahead logging is the mechanism wherein the log records describing a change are written to disk before the changes themselves are written. It provides the durability part of the ACID properties. As long as the log records describing changes are on disk, in the event of a crash, the log records (and hence the changes themselves) can be recovered and the effects of the transaction are not lost.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;What Is Recovery?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Looking for SQL Server Tips?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For tips on SQL Server, visit the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd391795(v=msdn.10)&quot; data-linktype=&quot;relative-path&quot;&gt;TechNet Magazine SQL Server Tips&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;page.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For more Tips on other products, visit the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://technet.microsoft.com/en-us/magazine/dd310316.aspx&quot; data-linktype=&quot;external&quot;&gt;TechNet Magazine Tips index&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Logging exists to support a variety of operations in SQL Server. It ensures that if a crash occurs, a committed transaction will be correctly reflected in the database after the crash. It ensures that an uncommitted transaction will be correctly rolled back and not reflected in the database after a crash. It ensures that it is possible to cancel an in-flight transaction and have all its operations rolled back. It allows a backup copy of the transaction log to be taken so that a database can be restored and the transaction log backups replayed to bring the database to a specific point in time with transactional consistency. And it supports features that rely on reading the transaction log, such as replication, database mirroring, and change data capture.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The majority of these uses of logging involve a mechanism called recovery. Recovery is the process of having the changes described in log records replayed or reverted in the database. Replaying log records is called the REDO (or roll forward) phase of recovery. Reverting log records is called the UNDO (or roll back) phase of recovery. In other words, recovery will make sure that a transaction and all its constituent log records are either redone or undone.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The simple form of recovery is when a single transaction is canceled, in which case it is undone and there is no net effect on the database. The most complex form is crash recovery&amp;mdash;when SQL Server crashes (for whatever reason) and the transaction log must be recovered to bring the database to a transactionally consistent point. This means that all transactions that were committed at the time of the crash must be rolled forward to ensure their effects are persisted in the database. And all in-flight transactions that had not committed at the time of the crash must be rolled back to ensure their effects are not persisted in the database.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This is because there is no facility for a transaction in SQL Server to continue after a crash. Thus, if the effects of a partially complete transaction were not rolled back, the database would be left in an inconsistent state (possibly even structurally corrupt, depending on what the transaction was in the middle of doing).&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;So how does recovery know what to do? All recovery processes depend on the fact that each log record is stamped with a log sequence number (LSN). A log sequence number is an ever-increasing, three-part number that uniquely defines the position of a log record within the transaction log. Each log record in a transaction is stored in sequential order within the transaction log and contains the transaction ID and the LSN of the previous log record for the transaction. In other words, each operation that is recorded as part of the transaction has a &quot;link&quot; back to the operation that immediately preceded it.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For the simple case of a single transaction being rolled back, the recovery mechanism can easily and quickly follow the chain of logged operations from the most recent operation back to the first operation and undo the effects of the operations in the opposite order from which they occurred. The database pages that were affected by the transaction are either still in the buffer pool or on disk. In either case, the image of the page that is available is guaranteed to be one where the effect of the transaction is reflected on the page and must be undone.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;During crash recovery, the mechanism is more complicated. The fact that database pages are not written to disk when a transaction commits means that there is no guarantee that the set of database pages on disk accurately reflects the set of changes described in the transaction log&amp;mdash;either for committed or uncommitted transactions. However, there is one final piece of the puzzle that I haven't mentioned yet&amp;mdash;all database pages have a field in their page header (a 96-byte portion of the 8192-byte page that contains metadata about the page) that contains the LSN of the last log record that affected the page. This allows the recovery system to decide what to do about a particular log record that it must recover:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;For a log record from a committed transaction where the database page has an LSN equal to or greater than the LSN of the log record, nothing needs to be done. The effect of the log record has already been persisted on the page on disk.&lt;/li&gt;
&lt;li&gt;For a log record from a committed transaction where the database page has an LSN less than the LSN of the log record, the log record must be redone to ensure the transaction effects are persisted.&lt;/li&gt;
&lt;li&gt;For a log record from an uncommitted transaction where the database page has an LSN equal to or greater than the LSN of the log record, the log record must be undone to ensure the transaction effects are not persisted.&lt;/li&gt;
&lt;li&gt;For a log record from an uncommitted transaction where the database page has an LSN less than the LSN of the log record, nothing needs to be done. The effect of the log record was not persisted on the page on disk and as such does not need to be undone.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Crash recovery reads through the transaction log and ensures that all effects of all committed transactions are persisted in the database, and all effects of all uncommitted transactions are not persisted in the database&amp;mdash;the REDO and UNDO phases, respectively. Once crash recovery completes, the database is transactionally consistent and available for use.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I mentioned earlier that one of the uses of a checkpoint operation is to reduce the amount of time that crash recovery takes. By periodically flushing out all dirty pages to disk, the number of pages that have changed because of committed transactions but whose images are not on disk is reduced. This, in turn, reduces the number of pages that need to have REDO recovery applied during crash recovery.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The Transaction Log&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Crash recovery is only possible if the transaction log is intact. In fact, the transaction log is the most important part of the database&amp;mdash;it's the only place where all changes to the database are guaranteed to be described in the event of a crash.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If the transaction log is missing or damaged after a crash, then crash recovery cannot complete, leading to a suspect database. In that case, the database must be restored from backups or recovered using less desirable options, such as emergency mode repair. (These procedures are beyond the scope of this article but will be covered in depth in articles later in the year.)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The transaction log is a special file that each database must have to function correctly. It holds the log records that are produced from logging and is used to read them again during recovery (or any of the other uses of logging I've already mentioned). As well as the space occupied by the log records themselves, a transaction will also reserve space in the transaction log for any potential log records required if the transaction were to be canceled and required to roll back. This accounts for the behavior you may observe where, say, a transaction that updates 50MB of data in the database may actually require 100MB of transaction log space.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;When a new database is created, the transaction log is essentially empty. As transactions occur, log records are written sequentially to the transaction log, which means there is no performance gain from creating multiple transaction log files&amp;mdash;a very common misconception. The transaction log will use each log file in turn.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Log records for concurrent transactions can be interspersed in the transaction log. Remember that log records for a single transaction are linked by their LSNs, so there is no need for all log records for a transaction to be grouped together in the log. LSNs can almost be thought of as a timestamp.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The physical architecture of the transaction log is shown in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;Figure 1&lt;/b&gt;. It is split internally into smaller chunks called virtual log files (or VLFs). These are simply an aid to easier internal management of the transaction log. When a VLF becomes full, logging automatically proceeds to use the next VLF in the transaction log. You might think that eventually the transaction log will run out of space, but this is where the transaction log is so different from data files.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;121&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/lq5ZL/btrHAHZ4nud/gglFwesLLx8Z7gDvsCUXC0/img.gif&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/lq5ZL/btrHAHZ4nud/gglFwesLLx8Z7gDvsCUXC0/img.gif&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/lq5ZL/btrHAHZ4nud/gglFwesLLx8Z7gDvsCUXC0/img.gif&quot; srcset=&quot;https://blog.kakaocdn.net/dn/lq5ZL/btrHAHZ4nud/gglFwesLLx8Z7gDvsCUXC0/img.gif&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;500&quot; height=&quot;121&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;121&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Figure 1&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;Physical architecture of the transaction log&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The transaction log is really a circular file&amp;mdash;as long as the log records at the start of the transaction log have been truncated (or cleared). Then when logging reaches the end of the transaction log, it wraps around to the start again and begins overwriting what was there before.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;So how do log records get truncated so the space they occupied can be reused? A log record is no longer needed in the transaction log if all of the following are true:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;The transaction of which it is part has committed.&lt;/li&gt;
&lt;li&gt;The database pages it changed have all been written to disk by a checkpoint.&lt;/li&gt;
&lt;li&gt;The log record is not needed for a backup (full, differential, or log).&lt;/li&gt;
&lt;li&gt;The log record is not needed for any feature that reads the log (such as database mirroring or replication).&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A log record that is still needed is called active, and a VLF that has at least one active log record is also called active. Every so often, the transaction log is checked to see whether all the log records in a full VLF are active or not; if they are all inactive, the VLF is marked as truncated (meaning the VLF can be overwritten once the transaction log wraps). When a VLF is truncated, it is not overwritten or zeroed in any way&amp;mdash;it is just marked as truncated and can then be reused.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This process is called log truncation&amp;mdash;not to be confused with actually shrinking the size of the transaction log. Log truncation never changes the physical size of the transaction log&amp;mdash;only which portions of the transaction log are active or not.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;Figure 2&lt;/b&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;shows the transaction log from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;Figure 1&lt;/b&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;after truncation has occurred.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;120&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/bPAqnu/btrHEzeUu94/kQPHTNhDludhy7GASY5KyK/img.gif&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/bPAqnu/btrHEzeUu94/kQPHTNhDludhy7GASY5KyK/img.gif&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/bPAqnu/btrHEzeUu94/kQPHTNhDludhy7GASY5KyK/img.gif&quot; srcset=&quot;https://blog.kakaocdn.net/dn/bPAqnu/btrHEzeUu94/kQPHTNhDludhy7GASY5KyK/img.gif&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;500&quot; height=&quot;120&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;120&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Figure 2&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;The transaction log after log truncation&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Active VLFs make up the logical log&amp;mdash;the portion of the transaction log that contains all the active log records. The database itself knows where crash recovery should start reading log records within the active portion of the log&amp;mdash;the start of the oldest active transaction in the log, the MinLSN (this is stored in the database boot page).&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Crash recovery does not know where to stop reading log records, so it continues until it reaches a zeroed section of the transaction log (if the transaction log has not yet wrapped) or a log record whose parity bits do not fit the sequence from the previous log record.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;As VLFs become truncated and new ones become active, the logical log moves within the physical transaction log file and eventually should wrap around to the start again, as shown in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;Figure 3&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;189&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/Gd5Pb/btrHBA7rnqF/oLe3tpEAOILyKk1ayeTRd1/img.gif&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/Gd5Pb/btrHBA7rnqF/oLe3tpEAOILyKk1ayeTRd1/img.gif&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/Gd5Pb/btrHBA7rnqF/oLe3tpEAOILyKk1ayeTRd1/img.gif&quot; srcset=&quot;https://blog.kakaocdn.net/dn/Gd5Pb/btrHBA7rnqF/oLe3tpEAOILyKk1ayeTRd1/img.gif&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;500&quot; height=&quot;189&quot; data-origin-width=&quot;500&quot; data-origin-height=&quot;189&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Figure 3&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;The circular nature of the transaction log&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The check whether log truncation can take place under either of the following circumstances:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;When a checkpoint occurs in the SIMPLE recovery model or in other recovery models when a full backup has never been taken. (This implies that a database will remain in a pseudo-SIMPLE recovery model after being switched out of SIMPLE until a full database backup occurs.)&lt;/li&gt;
&lt;li&gt;When a log backup completes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Remember that log truncation may not be possible because of the many reasons a log record must remain active. When log truncation cannot occur, the VLFs cannot be truncated and eventually the transaction log has to grow (or another transaction log file be added). Excessive transaction log growth can cause performance problems through a phenomenon known as VLF fragmentation. Removing VLF fragmentation can sometimes lead to a dramatic improvement in the performance of log-related activities.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For more information on this, see Kimberly Tripp's blog post &quot;&lt;a href=&quot;https://sqlskills.com/blogs/kimberly/post/8-steps-to-better-transaction-log-throughput.aspx&quot; data-linktype=&quot;external&quot;&gt;8 Steps to Better Transaction Log Throughput&lt;/a&gt;.&quot; Kimberly discusses best practices pertaining to transaction log capacity planning, management, and performance improvements&amp;mdash;it's well worth reading!&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;There are two common issues that can prevent log truncation:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;A long-running active transaction. The entire transaction log since the first log record from the oldest active transaction can never be truncated until that transaction commits or aborts.&lt;/li&gt;
&lt;li&gt;Switching to the FULL recovery model, taking a full backup, and then never taking any log backups. The entire transaction log will remain active, waiting to be backed up by a log backup.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For a complete list of factors and instructions on how to determine what is preventing log truncation, see the SQL Server Books Online topic &quot;&lt;a href=&quot;https://msdn.microsoft.com/library/ms345414&quot; data-linktype=&quot;external&quot;&gt;Factors that Can Delay Log Truncation&lt;/a&gt;.&quot; I've also created a video demonstration that shows the effect of uncontrolled transaction log growth and how to remove VLF fragmentation&amp;mdash;check out this video screencast (and previous screencasts on SQL topics) at&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://technetmagazine.com/videos&quot; data-linktype=&quot;external&quot;&gt;technetmagazine.com/videos&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If the transaction log does grow to capacity and cannot grow any further, then error 9002 will be reported and you will need to take steps to provide more space, such as growing the log file, adding another log file, or removing any impediment to the log being truncated.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Under no circumstances should you delete the transaction log, try to rebuild it using undocumented commands, or simply truncate it using the NO_LOG or TRUNCATE_ONLY options of BACKUP LOG (which have been removed in SQL Server 2008). These options will either cause transactional inconsistency (and more than likely corruption) or remove the possibility of being able to properly recover the database.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For more information on how to troubleshoot a full transaction log, check out the Books Online topic &quot;&lt;a href=&quot;https://msdn.microsoft.com/library/ms175495&quot; data-linktype=&quot;external&quot;&gt;Troubleshooting a Full Transaction Log (Error 9002)&lt;/a&gt;.&quot;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Recovery Models&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;As you can see, the behavior of the transaction log depends in part on the recovery model the database is using. There are three recovery models available, and they all have an effect on transaction log behavior or how operations are logged or both.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The FULL recovery model means that every part of every operation is logged, which is called being fully logged. Once a full database backup has been taken in the FULL recovery model, the transaction log will not automatically truncate until a log backup is taken. If you do not want to make use of log backups and the ability to recover a database to a specific point in time, do not use the FULL recovery model. However, if you wish to use database mirroring, then you have no choice, as it only supports the FULL recovery model.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The BULK_LOGGED recovery model has the same transaction log truncation semantics as the FULL recovery model but allows some operations to be partially logged, which is called being minimally logged. Examples are an index rebuild and some bulk-load operations&amp;mdash;in the FULL recovery model the entire operation is logged.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;But in the BULK_LOGGED recovery model only the allocation changes are logged, which drastically reduces the number of log records produced and, in turn, reduces the potential for transaction log growth. For more information on minimally logged operations, see the Books Online section &quot;&lt;a href=&quot;https://msdn.microsoft.com/library/ms191244&quot; data-linktype=&quot;external&quot;&gt;Operations that Can Be Minimally Logged&lt;/a&gt;.&quot;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Finally, the SIMPLE recovery model actually has the same logging behavior as the BULK_LOGGED recovery, but the transaction log truncation semantics are quite different. Log backups are not possible in the SIMPLE recovery model, which means the log can be truncated (as long as nothing else is holding log records active) when a checkpoint occurs. There are pros and cons to each of these recovery models in terms of which backups are possible (or needed) and the ability to recover to various points in time (I will cover this in another article later this year).&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Wrapping Up&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This article has really been a more academic explanation of how a critical part of SQL Server works. I hope I've managed to clear up any misconceptions you might have had. If this is your first introduction to logging and recovery, these are the key points I'd like you to take away from this article:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;Do not create multiple log files, as it will not lead to a performance gain.&lt;/li&gt;
&lt;li&gt;Be aware of the recovery model your database is using and the effect it has on the transaction log&amp;mdash;especially around whether it can automatically truncate or not when a checkpoint occurs.&lt;/li&gt;
&lt;li&gt;Be aware of the potential for transaction log growth, the factors that can lead to it, and how to get it back under control.&lt;/li&gt;
&lt;li&gt;Know where to look for help when troubleshooting a full transaction log.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;On my blog, I have a lot more information about the transaction log and factors that affect it&amp;mdash;see my blog post category&quot;&lt;a href=&quot;https://sqlskills.com/blogs/paul/category/transaction-log.aspx&quot; data-linktype=&quot;external&quot;&gt;Transaction Log&lt;/a&gt;&quot; for more details. The various Books Online topics concerning the transaction log are also very good&amp;mdash;starting with&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://msdn.microsoft.com/library/ms345583&quot; data-linktype=&quot;external&quot;&gt;Transaction Log Management&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/686</guid>
      <comments>https://99lib.tistory.com/686#entry686comment</comments>
      <pubDate>Mon, 18 Jul 2022 23:46:53 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] Lock 확인, 조치방법</title>
      <link>https://99lib.tistory.com/685</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://sagittariusof85s.tistory.com/124&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://sagittariusof85s.tistory.com/124&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1658155104466&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;[MS-SQL]락(LOCK)관리하기&quot; data-og-description=&quot;DB를 사용하다보면 떨어질 수 없는 것이 LOCK 관리입니다. DB를 쓸 때 자주 발생하는 것이 LOCK이며, 최소한으로 발생되고 최대한 빠르게 처리가 되도록 해야 하는 것이 LOCK입니다. 그래서 이번에는 &quot; data-og-host=&quot;sagittariusof85s.tistory.com&quot; data-og-source-url=&quot;https://sagittariusof85s.tistory.com/124&quot; data-og-url=&quot;https://sagittariusof85s.tistory.com/124&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/bQnpr4/hyO8PmTtJE/yKZ9AKfo41eDUTUZi9fK2K/img.png?width=430&amp;amp;height=322&amp;amp;face=0_0_430_322,https://scrap.kakaocdn.net/dn/cpvkO6/hyO8QsxNvQ/EbfHNsmc1jA1idjcqHcKxk/img.png?width=430&amp;amp;height=322&amp;amp;face=0_0_430_322,https://scrap.kakaocdn.net/dn/bkDkMU/hyO8Z36l2E/BvCFAkezrFSqElP5iXkZO0/img.png?width=900&amp;amp;height=272&amp;amp;face=0_0_900_272&quot;&gt;&lt;a href=&quot;https://sagittariusof85s.tistory.com/124&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://sagittariusof85s.tistory.com/124&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/bQnpr4/hyO8PmTtJE/yKZ9AKfo41eDUTUZi9fK2K/img.png?width=430&amp;amp;height=322&amp;amp;face=0_0_430_322,https://scrap.kakaocdn.net/dn/cpvkO6/hyO8QsxNvQ/EbfHNsmc1jA1idjcqHcKxk/img.png?width=430&amp;amp;height=322&amp;amp;face=0_0_430_322,https://scrap.kakaocdn.net/dn/bkDkMU/hyO8Z36l2E/BvCFAkezrFSqElP5iXkZO0/img.png?width=900&amp;amp;height=272&amp;amp;face=0_0_900_272');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;[MS-SQL]락(LOCK)관리하기&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;DB를 사용하다보면 떨어질 수 없는 것이 LOCK 관리입니다. DB를 쓸 때 자주 발생하는 것이 LOCK이며, 최소한으로 발생되고 최대한 빠르게 처리가 되도록 해야 하는 것이 LOCK입니다. 그래서 이번에는&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;sagittariusof85s.tistory.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DB를 사용하다보면&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;떨어질 수 없는 것이 LOCK 관리입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DB를 쓸 때 자주 발생하는 것이&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;LOCK이며,&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;최소한으로 발생되고&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;최대한 빠르게 처리가 되도록 해야 하는 것이&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;LOCK입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그래서 이번에는 LOCK 을&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;확인하고&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;조치하는 방법에 대해서 정리를 해보고자 합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;1. LOCK 확인하기&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;SQL SERVER에서는&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;락을 확인 하는 방법이&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;여러가지가 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그 중 제가 아는 것은 3가지 방법이 있어서&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그 3가지 방법에 대해&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;모두 정리를 해보고자 합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;1-1. SP_LOCK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MS-SQL에서 제공하는&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;시스템 프로시저가 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이를 이용해서 확인할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;함수는 SP_LOCK입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;사용방법은 다음과 같습니다.&lt;/p&gt;
&lt;pre class=&quot;abnf&quot;&gt;&lt;code&gt;EXEC SP_LOCK;
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 작성하여&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;돌리면 됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러면 결과는 다음과 같습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;430&quot; data-origin-height=&quot;322&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/ebGtds/btrHDz7xnFe/IPpyNEAG8ATc9us7zk5Qmk/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/ebGtds/btrHDz7xnFe/IPpyNEAG8ATc9us7zk5Qmk/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/ebGtds/btrHDz7xnFe/IPpyNEAG8ATc9us7zk5Qmk/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FebGtds%2FbtrHDz7xnFe%2FIPpyNEAG8ATc9us7zk5Qmk%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;430&quot; height=&quot;322&quot; data-origin-width=&quot;430&quot; data-origin-height=&quot;322&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러면 Mode값이&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;X인 SPID가 있다면&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;해당 세션이 락 걸린 세션입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;1-2. SP_WHO2&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;또한, SQL SERVRVER에서 제공하는&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;또 다른 시스템프로시저가 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;SP_WHO2 입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위 프로시저를 이용해서도&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;LOCK이 걸린 정보를 확인할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;쿼리는 다음과 같습니다.&lt;/p&gt;
&lt;pre class=&quot;abnf&quot;&gt;&lt;code&gt;EXEC SP_WHO2;
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 돌리면 결과는 다음과 같습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;900&quot; data-origin-height=&quot;272&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/sY23g/btrHEeB4Qpg/fFN7IUPkbIh049RHpmMRE0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/sY23g/btrHEeB4Qpg/fFN7IUPkbIh049RHpmMRE0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/sY23g/btrHEeB4Qpg/fFN7IUPkbIh049RHpmMRE0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FsY23g%2FbtrHEeB4Qpg%2FfFN7IUPkbIh049RHpmMRE0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;900&quot; height=&quot;272&quot; data-origin-width=&quot;900&quot; data-origin-height=&quot;272&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 결과가 나옵니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 곳에서 BlkBy 컬럼에 값이 있으면&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Lock을 걸고 있는&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;프로세스의 spid값입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;1-3.&amp;nbsp;SYS.sysprocesses&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;내부 시스템 테이블을 이용해서도&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;확인할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;테이블은&amp;nbsp;SYS.sysprocesses 입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;쿼리는 다음과 같습니다.&lt;/p&gt;
&lt;pre class=&quot;n1ql&quot;&gt;&lt;code&gt;SELECT * FROM SYS.sysprocesses WHERE blocked &amp;gt; 0;
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 쿼리를 작성하여 돌리면 되십니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러면 결과는 다음과 같습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;900&quot; data-origin-height=&quot;109&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/cF104T/btrHEe9UPND/FqWCkCORGzCiDe1CIFunw0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/cF104T/btrHEe9UPND/FqWCkCORGzCiDe1CIFunw0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/cF104T/btrHEe9UPND/FqWCkCORGzCiDe1CIFunw0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcF104T%2FbtrHEe9UPND%2FFqWCkCORGzCiDe1CIFunw0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;900&quot; height=&quot;109&quot; data-origin-width=&quot;900&quot; data-origin-height=&quot;109&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;blocked에 값이 있으면&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;락이 걸린 것입니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;저는 테스트서버이고,&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그렇다보니 락 걸린 것이 없어서&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;안나오네요.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;2. 쿼리 확인&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;해당 프로세스의 쿼리를&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;확인해 보는 것이 좋습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;정확하게 무슨 쿼리에서 락이 걸린 것인지 알 수 있고,&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;추후 튜닝을 통해&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;락이 안걸릴 수 있도록&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;조치할 수도 있으니&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;확인이 필요합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;확인 방법은 다음과 같습니다.&lt;/p&gt;
&lt;pre class=&quot;abnf&quot;&gt;&lt;code&gt;dbcc inputbuffer ( 75 );
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 쿼리를 작성하여 돌리면 되십니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러면 결과는 다음과 같습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;585&quot; data-origin-height=&quot;77&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/Lbnzb/btrHFQU08Kd/1vozJjxjtv2am9VSN0JLpk/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/Lbnzb/btrHFQU08Kd/1vozJjxjtv2am9VSN0JLpk/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/Lbnzb/btrHFQU08Kd/1vozJjxjtv2am9VSN0JLpk/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FLbnzb%2FbtrHFQU08Kd%2F1vozJjxjtv2am9VSN0JLpk%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;585&quot; height=&quot;77&quot; data-origin-width=&quot;585&quot; data-origin-height=&quot;77&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;저는 테스트로&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;락 걸리지 않은 다른 프로세스의&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;spid값을 넣었습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그래도 저렇게 쿼리가 나오는 것을 확인할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이렇게 쿼리 정보를 확인해놓는 것이&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;좋습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span&gt;3. kill&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이제 종료를 시켜야 합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;종료 시키는 것은 매우 간단합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;방법은 다음과 같습니다.&lt;/p&gt;
&lt;pre class=&quot;bash&quot;&gt;&lt;code&gt;kill SPID
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위처럼 하면 됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러면 해당 세션이 종료가 됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DB를 사용하면서&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;락은 떨어질래야 떨어질 수는 없습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;다만, 최소한으로 발생하도록 하여&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DB의 성능을 높여주는 것이 중요합니다.&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/685</guid>
      <comments>https://99lib.tistory.com/685#entry685comment</comments>
      <pubDate>Mon, 18 Jul 2022 23:38:52 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] 오픈 트랜잭션 쿼리가 있는 DB 찾아보기</title>
      <link>https://99lib.tistory.com/684</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.overtop.co.kr/139&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://www.overtop.co.kr/139&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1658155011906&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;오픈 트랜잭션 쿼리가 있는 데이터베이스 찾아보기&quot; data-og-description=&quot;현재 오픈된 트랜잭션이 어느 데이터베이스에 있는지 찾는 방법은 여러 가지 있다. 이 활성화된 세션을 찾아야 블로킹세션을 찾을 수 있다. 아래와 같이 세션 2개를 열어서 확인해보자 -- session #&quot; data-og-host=&quot;www.overtop.co.kr&quot; data-og-source-url=&quot;https://www.overtop.co.kr/139&quot; data-og-url=&quot;https://www.overtop.co.kr/139&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/Y2YmV/hyO7u5KcTU/zrPuq5Z58GGR6uGKYQfbKK/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220,https://scrap.kakaocdn.net/dn/gseJX/hyO8V8sFRF/goABQAZLbnrEggkQj7fzG1/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220,https://scrap.kakaocdn.net/dn/bMBXg6/hyO7EUOfZO/ZlLLZkxqkI7FHVebaXHNaK/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220&quot;&gt;&lt;a href=&quot;https://www.overtop.co.kr/139&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://www.overtop.co.kr/139&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/Y2YmV/hyO7u5KcTU/zrPuq5Z58GGR6uGKYQfbKK/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220,https://scrap.kakaocdn.net/dn/gseJX/hyO8V8sFRF/goABQAZLbnrEggkQj7fzG1/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220,https://scrap.kakaocdn.net/dn/bMBXg6/hyO7EUOfZO/ZlLLZkxqkI7FHVebaXHNaK/img.png?width=222&amp;amp;height=220&amp;amp;face=0_0_222_220');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;오픈 트랜잭션 쿼리가 있는 데이터베이스 찾아보기&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;현재 오픈된 트랜잭션이 어느 데이터베이스에 있는지 찾는 방법은 여러 가지 있다. 이 활성화된 세션을 찾아야 블로킹세션을 찾을 수 있다. 아래와 같이 세션 2개를 열어서 확인해보자 -- session #&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;www.overtop.co.kr&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;현재 오픈된 트랜잭션이 어느 데이터베이스에 있는지 찾는 방법은 여러 가지 있다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 활성화된 세션을 찾아야 블로킹세션을 찾을 수 있다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;아래와 같이 세션 2개를 열어서 확인해보자&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;-- session #1 tempdb 를 열고 실제 데이터베이스는 TD 에 있는 테이블을 업데이트 하고 있다.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;use&lt;/span&gt; tempdb &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;go&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;begin&lt;/span&gt; &lt;span&gt;tran &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;update&lt;/span&gt; A &lt;span&gt;set&lt;/span&gt; diff &lt;span&gt;=&lt;/span&gt; &lt;span&gt;'1'&lt;/span&gt; &lt;span&gt;from&lt;/span&gt; td&lt;span&gt;.&lt;/span&gt;[dbo]&lt;span&gt;.&lt;/span&gt;[results] a &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;-- rollback &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;-- session #2&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;use&lt;/span&gt; tempdb &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;go&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;DBCC&lt;/span&gt; OPENTRAN &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;세션#1에서 tempdb를 오픈하고 Update를 하지만 실제는 TD 를 하고 있는 것을 찾아야 된다. &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;SELECT&lt;/span&gt; spid&lt;span&gt;,&lt;/span&gt; &lt;span&gt;dbid&lt;/span&gt; &lt;span&gt;FROM&lt;/span&gt; &lt;span&gt;SYS&lt;span&gt;.&lt;span&gt;SYSPROCESSES&lt;/span&gt; &lt;span&gt;WHERE&lt;/span&gt; OPEN_TRAN =&lt;/span&gt; 1 &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;select&lt;/span&gt; &lt;span&gt;db_name&lt;span&gt;(&lt;/span&gt;2&lt;span&gt;)&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;현재 세션정보를 보면 tempdb 로 확인이 된다. 혹시나 오픈된 데이터베이스가 tempdb로 착각하면 안된다. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/21138C4455F64E6501&quot; /&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;SELECT&lt;/span&gt; &lt;span&gt;*&lt;/span&gt; &lt;span&gt;FROM&lt;/span&gt; &lt;span&gt;SYS&lt;span&gt;.&lt;span&gt;DM_TRAN_SESSION_TRANSACTIONS&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/24143C3B55F64E6617&quot; /&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;위에서는 정말 잘못된 데이터베이스를 찾을수 있다. 실수하기 좋은 예이다. &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;실제 오픈 트랜잭션이 발생중인 데이터베이스를 찾으려면 sp_lock 으로 확인해보자. &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;sp_lock&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;select&lt;/span&gt; &lt;span&gt;db_name&lt;span&gt;(&lt;/span&gt;9&lt;span&gt;)&lt;/span&gt; &lt;span&gt;as&lt;/span&gt; DBName &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;/*&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;DBName&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;TD&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;*/&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;use&lt;/span&gt;&lt;span&gt; TD &lt;/span&gt;&lt;span&gt;&amp;ndash;&lt;/span&gt;&lt;span&gt; 실제 오픈 트랜잭션이 있는 데이터베이스에서 DBCC OPENTRAN을 수행해야 결과를 볼 수 있다 &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;go&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;DBCC&lt;/span&gt; OPENTRAN &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;/*&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; SQL Server 실행 시간: &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; CPU 시간 = 0ms, 경과 시간 = 0ms&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;SQL Server 구문 분석 및 컴파일 시간: &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; CPU 시간 = 0ms, 경과 시간 = 0ms.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;데이터베이스 'TD'의 트랜잭션 정보입니다.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;가장 오래 전에 활성화된 트랜잭션:&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; SPID(서버 프로세스 ID): 54&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; UID(사용자 ID) : -1&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; 이름 : user_transaction&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; LSN : (43:56:5)&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; 시작 시간 : 09 14 2015 1:27:39:913PM&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt; SID : 0x010500000000000515000000301322d263e67671bfb9b84833150000&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;&lt;span&gt;DBCC 실행이 완료되었습니다. DBCC에서 오류 메시지를 출력하면 시스템 관리자에게 문의하십시오.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;*/&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;출처: &lt;a href=&quot;https://www.overtop.co.kr/139&quot;&gt;https://www.overtop.co.kr/139&lt;/a&gt; [AWSin:티스토리]&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://dallasdbas.com/dbcc-opentran-simplified/&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1658155265210&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;Examples of how to use DBCC Opentran&quot; data-og-description=&quot;Simple description of how to use DBCC Opentran&quot; data-og-host=&quot;dallasdbas.com&quot; data-og-source-url=&quot;https://dallasdbas.com/dbcc-opentran-simplified/&quot; data-og-url=&quot;https://dallasdbas.com/dbcc-opentran-simplified/&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/nOb3U/hyO7zlDfE8/gc6rHUOKZdswfVQPOG9Au0/img.png?width=300&amp;amp;height=65&amp;amp;face=0_0_300_65&quot;&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://dallasdbas.com/dbcc-opentran-simplified/&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/nOb3U/hyO7zlDfE8/gc6rHUOKZdswfVQPOG9Au0/img.png?width=300&amp;amp;height=65&amp;amp;face=0_0_300_65');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;Examples of how to use DBCC Opentran&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;Simple description of how to use DBCC Opentran&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;dallasdbas.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;n my&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://dallasdbas.com/top-10-sql-server-functions-every-dba-should-know-by-heart/&quot;&gt;Top 10 SQL Server Functions post&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;awhile back, I listed&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-opentran-transact-sql&quot;&gt;DBCC OPENTRAN&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;as one of the top 3, and for good reason.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;An Open transaction may simply be something that has not finished yet, or someone issued a BEGIN TRAN without a corresponding COMMIT or ROLLBACK. &amp;nbsp;Or as we will see at the end, replication is having issues.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;You can use this against any database with minimal syntax and get back solid information very quickly.&lt;/p&gt;
&lt;div&gt;
&lt;div id=&quot;highlighter_114301&quot;&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/#&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div&gt;1&lt;/div&gt;
&lt;div&gt;2&lt;/div&gt;
&lt;div&gt;3&lt;/div&gt;
&lt;div&gt;4&lt;/div&gt;
&lt;div&gt;5&lt;/div&gt;
&lt;div&gt;6&lt;/div&gt;
&lt;div&gt;7&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div&gt;
&lt;div&gt;--connect to sample db&lt;/div&gt;
&lt;div&gt;use MyDatabase&lt;/div&gt;
&lt;div&gt;go&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;--as generic as this command gets and still runs:&lt;/div&gt;
&lt;div&gt;DBCC OPENTRAN&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Result if nothing is open:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;No active open transactions.&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If I start and execute a DML (insert, update or delete) transaction with BEGIN TRAN and leave out the corresponding COMMIT, I get:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transaction information for database &amp;lsquo;SmallData_BigLog&amp;rsquo;.&lt;u&gt;Oldest&lt;/u&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;active transaction:&lt;br /&gt;SPID (server process ID): 64&amp;nbsp;&amp;lt;&amp;mdash;&amp;mdash;&amp;mdash;&amp;ndash;&lt;br /&gt;UID (user ID) : -1&lt;br /&gt;Name : user_transaction&lt;br /&gt;LSN : (637:4620:1)&lt;br /&gt;Start time : Apr 1 2017 4:59:02:307PM&lt;br /&gt;SID : 0x0105000000000005150000004893a0845595b6fef515cd5de9030000&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Now, if I open a second&amp;nbsp;transaction (in a new query window) and execute any DML statement without the COMMIT, and then run DBCC OPENTRAN again, I get:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transaction information for database &amp;lsquo;SmallData_BigLog&amp;rsquo;.&lt;u&gt;Oldest&lt;/u&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;active transaction:&lt;br /&gt;SPID (server process ID): 64&amp;nbsp;&amp;lt;&amp;mdash;&amp;mdash;&amp;mdash;&amp;ndash;&lt;br /&gt;UID (user ID) : -1&lt;br /&gt;Name : user_transaction&lt;br /&gt;LSN : (637:4620:1)&lt;br /&gt;Start time : Apr 1 2017 4:59:02:307PM&lt;br /&gt;SID : 0x0105000000000005150000004893a0845595b6fef515cd5de9030000&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Yes&amp;hellip;the same output, as this is just showing the ONE oldest transaction.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I can run a query to show that there are two SPIDs with open transactions:&lt;/p&gt;
&lt;div&gt;
&lt;div id=&quot;highlighter_938219&quot;&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/#&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div&gt;1&lt;/div&gt;
&lt;div&gt;2&lt;/div&gt;
&lt;div&gt;3&lt;/div&gt;
&lt;div&gt;4&lt;/div&gt;
&lt;div&gt;5&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div&gt;
&lt;div&gt;--&lt;/div&gt;
&lt;div&gt;SELECT spid, blocked,[dbid],last_batch,open_tran&lt;/div&gt;
&lt;div&gt;FROM master.sys.sysprocesses&lt;/div&gt;
&lt;div&gt;WHERE open_tran &amp;lt;&amp;gt; 0&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;879&quot; data-origin-height=&quot;191&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/brikTF/btrHDcreObj/BxIgAMXdpNAMIriTp9Q22k/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/brikTF/btrHDcreObj/BxIgAMXdpNAMIriTp9Q22k/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/brikTF/btrHDcreObj/BxIgAMXdpNAMIriTp9Q22k/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbrikTF%2FbtrHDcreObj%2FBxIgAMXdpNAMIriTp9Q22k%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;531&quot; height=&quot;115&quot; data-origin-width=&quot;879&quot; data-origin-height=&quot;191&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If I COMMIT spid 64 and re-run DBCC OPENTRAN, the SPID changes to the second transaction I started:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transaction information for database &amp;lsquo;SmallData_BigLog&amp;rsquo;.Oldest active transaction:&lt;br /&gt;SPID (server process ID): 52 &amp;nbsp;&amp;lt;&amp;mdash;&amp;mdash;&amp;mdash;&amp;ndash;&lt;br /&gt;UID (user ID) : -1&lt;br /&gt;Name : user_transaction&lt;br /&gt;LSN : (637:9603:1)&lt;br /&gt;Start time : Apr 1 2017 5:11:20:830PM&lt;br /&gt;SID : 0x0105000000000005150000004893a0845595b6fef515cd5de9030000&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If I COMMIT spid 52 and re-run DBCC OPENTRAN along with checking sysprocesses for open_tran &amp;lt;&amp;gt; 0 I get:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;No active open transactions.&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.spid blocked dbid last_batch open_tran&lt;br /&gt;&amp;mdash;&amp;mdash; &amp;mdash;&amp;mdash;- &amp;mdash;&amp;mdash; &amp;mdash;&amp;mdash;&amp;mdash;&amp;mdash;&amp;mdash;&amp;mdash;&amp;mdash;&amp;ndash; &amp;mdash;&amp;mdash;&amp;mdash;(0 row(s) affected)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Now, all of that was just running DBCC OPENTRAN by itself. &amp;nbsp;There are additional options:&lt;/p&gt;
&lt;div&gt;
&lt;div id=&quot;highlighter_925851&quot;&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/#&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div&gt;1&lt;/div&gt;
&lt;div&gt;2&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div&gt;
&lt;div&gt;--specify dbname, dbid or 0 for the current database&lt;/div&gt;
&lt;div&gt;DBCC OPENTRAN (SmallData_BigLog)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;You will get results in the same format as the previous examples.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;You can suppress all messages, regardless of if a transaction is open or not (but I have no idea why this would help you&amp;hellip;)&lt;/p&gt;
&lt;div&gt;
&lt;div id=&quot;highlighter_395396&quot;&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/#&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div&gt;1&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div&gt;
&lt;div&gt;DBCC OPENTRAN (0) with no_infomsgs&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Result:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Command(s) completed successfully.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If you needed to periodically capture the oldest transaction, in order to review later, use WITH TABLERESULTS:&lt;/p&gt;
&lt;div&gt;
&lt;div id=&quot;highlighter_840771&quot;&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://dallasdbas.com/dbcc-opentran-simplified/#&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div&gt;1&lt;/div&gt;
&lt;div&gt;2&lt;/div&gt;
&lt;div&gt;3&lt;/div&gt;
&lt;div&gt;4&lt;/div&gt;
&lt;div&gt;5&lt;/div&gt;
&lt;div&gt;6&lt;/div&gt;
&lt;div&gt;7&lt;/div&gt;
&lt;div&gt;8&lt;/div&gt;
&lt;div&gt;9&lt;/div&gt;
&lt;div&gt;10&lt;/div&gt;
&lt;div&gt;11&lt;/div&gt;
&lt;div&gt;12&lt;/div&gt;
&lt;div&gt;13&lt;/div&gt;
&lt;div&gt;14&lt;/div&gt;
&lt;div&gt;15&lt;/div&gt;
&lt;div&gt;16&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div&gt;
&lt;div&gt;-- TableResults only shows the oldest open tran&lt;/div&gt;
&lt;div&gt;-- useful running in a loop to load the oldest&lt;/div&gt;
&lt;div&gt;-- tran over time.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;--create a temp table&lt;/div&gt;
&lt;div&gt;CREATE TABLE #OpenTranStatus (&lt;/div&gt;
&lt;div&gt;ActiveTransaction varchar(25),&lt;/div&gt;
&lt;div&gt;Details sql_variant&lt;/div&gt;
&lt;div&gt;);&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;-- Execute the command, putting the results in the table.&lt;/div&gt;
&lt;div&gt;INSERT INTO #OpenTranStatus&lt;/div&gt;
&lt;div&gt;EXEC ('DBCC OPENTRAN (SmallData_BigLog) with tableresults')&lt;/div&gt;
&lt;div&gt;SELECT * FROM #OpenTranStatus&lt;/div&gt;
&lt;div&gt;DROP TABLE #OpenTranStatus&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In the above, you could create a user table instead of a temp table of course&amp;hellip;it depends on your needs.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;One more particularly useful item you may see when running DBCC OPENTRAN by itself:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transaction information for database &amp;lsquo;Music&amp;rsquo;.Replicated Transaction Information:&lt;br /&gt;Oldest distributed LSN : (37:143:3)&lt;br /&gt;Oldest non-distributed LSN : (37:144:1)&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If your database is participating in Replication as a Publisher, this may show up when running OPENTRAN, but it doesn&amp;rsquo;t necessarily mean that the transaction is actually open. &amp;nbsp;I set this up and stopped the Replication Log Reader and Distribution agent jobs. &amp;nbsp; I then added some data to a published table (article) and ran DBCC OPENTRAN to get the above result. &amp;nbsp;Note that there are two lines with LSN information in them (no SPIDs)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I then ran the Log Reader Agent job and got back:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Transaction information for database &amp;lsquo;Music&amp;rsquo;.Replicated Transaction Information:&lt;br /&gt;Oldest distributed LSN : (37:157:3)&lt;br /&gt;Oldest non-distributed LSN :&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;(0:0:0)&lt;/span&gt;&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I have verified that new records I inserted have been read by the log reader, AND distributed to the subscriber(s). &amp;nbsp;This means that while you are seeing&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Oldest distributed LSN : (37:157:3)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;There is not an error&amp;hellip;just info.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If you have non-distributed LSNs, there is something to troubleshoot in the replication process which is way outside the scope of this post. &amp;nbsp;A non-distributed replicated transaction/LSN CAN cause some huge Log file growth, and need to be investigated. &amp;nbsp;If this happens frequently, use the TABLERESULTS option to log to a regular table and alert on it.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Hopefully this gives you some insight into various ways to use DBCC OPENTRAN as well as use cases for the various options. &amp;nbsp;90% of the time I run this, it is due to application transactions timing out, or log file growth issues.&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/684</guid>
      <comments>https://99lib.tistory.com/684#entry684comment</comments>
      <pubDate>Mon, 18 Jul 2022 23:37:00 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] Lazy Log Truncation - Clearing of SQL transaction log VLF status deferred</title>
      <link>https://99lib.tistory.com/683</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/lazy-log-truncation-clearing-of-sql-transaction-log-vlf-status/ba-p/370499&quot;&gt;Lazy Log Truncation - Clearing of SQL transaction log VLF status deferred - Microsoft Tech Community&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1658154957601&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;Lazy Log Truncation - Clearing of SQL transaction log VLF status deferred&quot; data-og-description=&quot;First published on MSDN on Jun 27, 2013 I came across an oddity in the transaction log when I was testing Availability Group backup scenarios which really had me confused.&amp;nbsp; It required some help from my colleague Denzil and a few others to figure out what&quot; data-og-host=&quot;techcommunity.microsoft.com&quot; data-og-source-url=&quot;https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/lazy-log-truncation-clearing-of-sql-transaction-log-vlf-status/ba-p/370499&quot; data-og-url=&quot;https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/lazy-log-truncation-clearing-of-sql-transaction-log-vlf-status/ba-p/370499&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/w2MnN/hyO8OIgsZ1/9VCMddgNFExNWMZNE4viH0/img.jpg?width=650&amp;amp;height=229&amp;amp;face=0_0_650_229,https://scrap.kakaocdn.net/dn/WGeck/hyO8QlMTH6/IVlCfIYmqiC4toEb5vZyK0/img.jpg?width=654&amp;amp;height=233&amp;amp;face=0_0_654_233,https://scrap.kakaocdn.net/dn/wCecw/hyO8SjA5tc/LeXRPMqF5CUOi3b3TEmExk/img.jpg?width=654&amp;amp;height=240&amp;amp;face=0_0_654_240,https://scrap.kakaocdn.net/dn/tqrPB/hyO8XZvT4J/Aq44OeI7eBWU5nDKeNONNk/img.jpg?width=650&amp;amp;height=229&amp;amp;face=0_0_650_229&quot;&gt;&lt;a href=&quot;https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/lazy-log-truncation-clearing-of-sql-transaction-log-vlf-status/ba-p/370499&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/lazy-log-truncation-clearing-of-sql-transaction-log-vlf-status/ba-p/370499&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/w2MnN/hyO8OIgsZ1/9VCMddgNFExNWMZNE4viH0/img.jpg?width=650&amp;amp;height=229&amp;amp;face=0_0_650_229,https://scrap.kakaocdn.net/dn/WGeck/hyO8QlMTH6/IVlCfIYmqiC4toEb5vZyK0/img.jpg?width=654&amp;amp;height=233&amp;amp;face=0_0_654_233,https://scrap.kakaocdn.net/dn/wCecw/hyO8SjA5tc/LeXRPMqF5CUOi3b3TEmExk/img.jpg?width=654&amp;amp;height=240&amp;amp;face=0_0_654_240,https://scrap.kakaocdn.net/dn/tqrPB/hyO8XZvT4J/Aq44OeI7eBWU5nDKeNONNk/img.jpg?width=650&amp;amp;height=229&amp;amp;face=0_0_650_229');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;Lazy Log Truncation - Clearing of SQL transaction log VLF status deferred&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;First published on MSDN on Jun 27, 2013 I came across an oddity in the transaction log when I was testing Availability Group backup scenarios which really had me confused.&amp;nbsp; It required some help from my colleague Denzil and a few others to figure out what&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;techcommunity.microsoft.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;First published on MSDN on Jun 27, 2013&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I came across an oddity in the transaction log when I was testing Availability Group backup scenarios which really had me confused.&amp;nbsp; It required some help from my colleague Denzil and a few others to figure out what was going on.&amp;nbsp; This adventure taught us about Lazy Log Truncation.&amp;nbsp; This is not new to SQL 2012 as it also exists in SQL 2008R2 (and possibly prior), but only when a database is being mirrored or participating in an Availability Group.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For more on VLF&amp;rsquo;s and transaction log architecture:&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms179355(v=SQL.105).aspx&quot;&gt;Transaction Log Physical Architecture&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Before getting into the oddity that Lazy Log Truncation brings into play, let&amp;rsquo;s first look at what you normally see in the transaction log as it is filled and truncated.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I started off creating a database with a fixed log file size of 100MB in full recovery model.&amp;nbsp; I have this all in the attached script for you to try on your own as well. Once that is set up, take a full database backup to get full recovery model going.&amp;nbsp; Then run DBCC LOGINFO to show you the current VLFs in the database.&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;USE [LLTTest]
GO
DBCC LOGINFO --you see here that there are 8 VLFs with 1 that has a status of 2
GO
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;650&quot; data-origin-height=&quot;229&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/coN7N1/btrHEYlr0Uh/sLm1OQXdsqeD9CI5zyklZ1/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/coN7N1/btrHEYlr0Uh/sLm1OQXdsqeD9CI5zyklZ1/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/coN7N1/btrHEYlr0Uh/sLm1OQXdsqeD9CI5zyklZ1/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcoN7N1%2FbtrHEYlr0Uh%2FsLm1OQXdsqeD9CI5zyklZ1%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;650&quot; height=&quot;229&quot; data-origin-width=&quot;650&quot; data-origin-height=&quot;229&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The status value of 2 means that it is the active portion of the log, meaning that it contains data that needs to be backed up in order for that VLF to be able to be used again.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Next we will do some work in the database that will generate a little log activity.&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;CREATE TABLE test1 (myvarchar VARCHAR(5000))
GO
INSERT INTO test1
VALUES (replicate('*', 5000)) GO 5000
DELETE
FROM test1
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Now take a look at DBCC LOFINGO again and you can see that more of the VLFs contain active transaction log data.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;654&quot; data-origin-height=&quot;233&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/q6xqD/btrHCo6JySX/kvWxP1FB52S4jd61rQXkuk/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/q6xqD/btrHCo6JySX/kvWxP1FB52S4jd61rQXkuk/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/q6xqD/btrHCo6JySX/kvWxP1FB52S4jd61rQXkuk/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fq6xqD%2FbtrHCo6JySX%2FkvWxP1FB52S4jd61rQXkuk%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;654&quot; height=&quot;233&quot; data-origin-width=&quot;654&quot; data-origin-height=&quot;233&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Next, we take a backup of the transaction log in order to clear out all the full VLFs and run DBCC LOGINFO again. Note that FSeqNo 35 is still marked as active.&amp;nbsp; This is because only full VLFs that do not contain log records for active transactions or records needed for replication (mirroring, CDC, replication, etc) are truncated. Also note that there must always be at least 1 active VLF.&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;BACKUP LOG [LLTTest] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\LLTTest.bak'
WITH NOFORMAT
	,NOINIT
	,NAME = N'LLTTest-Transaction Log Backup'
	,SKIP
	,NOREWIND
	,NOUNLOAD
	,STATS = 10
GO
DBCC LOGINFO --after the tlog backup all but one of the VLFs are inactive (status 0)
GO
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;654&quot; data-origin-height=&quot;240&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/ZZNwr/btrHCXgN0Pu/X60MY4OkcKV1y4EXmaWEO1/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/ZZNwr/btrHCXgN0Pu/X60MY4OkcKV1y4EXmaWEO1/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/ZZNwr/btrHCXgN0Pu/X60MY4OkcKV1y4EXmaWEO1/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FZZNwr%2FbtrHCXgN0Pu%2FX60MY4OkcKV1y4EXmaWEO1%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;654&quot; height=&quot;240&quot; data-origin-width=&quot;654&quot; data-origin-height=&quot;240&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This is exactly what you would expect to see, no surprises here.&amp;nbsp;&amp;nbsp;&amp;nbsp; When it becomes interesting is when you do this same test against a database participating in an Availability Group.&amp;nbsp; For the sake of keeping this blog entry from being too long, I am not showing you how to add this db to an availability group, but you can do so on your own using the GUI tools.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;After adding this database to an availability group, there was no change to the output of DBCC LOGINFO, but one interesting thing to note is that the DBCC LOGINFO output will be identical across all the replicas when everything is synchronized.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Now, we are doing to do the same work we did before to put some activity in the transaction log.&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;INSERT INTO test1
VALUES (replicate('*', 5000)) GO 5000
GO
DELETE
FROM test1
GO
DBCC LOGINFO --Nothing special here, you can see more active VLFs
GO
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This looks similar to what we saw before, it is just that different VLFs are being used and the activity rolled over to the beginning of the log file since I have the file set to a fixed size (to make this easier to demo).&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;660&quot; data-origin-height=&quot;245&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/zV7Ep/btrHDcEJp87/TACbkQ5fIrrMzJkRK5ueIK/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/zV7Ep/btrHDcEJp87/TACbkQ5fIrrMzJkRK5ueIK/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/zV7Ep/btrHDcEJp87/TACbkQ5fIrrMzJkRK5ueIK/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FzV7Ep%2FbtrHDcEJp87%2FTACbkQ5fIrrMzJkRK5ueIK%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;660&quot; height=&quot;245&quot; data-origin-width=&quot;660&quot; data-origin-height=&quot;245&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Now we will backup the transaction log to truncate the VLFs, right?&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;BACKUP LOG [LLTTest] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\LLTTest.bak'
WITH NOFORMAT
	,NOINIT
	,NAME = N'LLTTest-Transaction Log Backup'
	,SKIP
	,NOREWIND
	,NOUNLOAD
	,STATS = 10
GO
DBCC LOGINFO
GO
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;ACK! The status didn't clear to 0 on any of the VLFs?! The DBCC LOGINFO output did not change at all. The replica is fully synchronized, so we know it is not due to data not being at all the replicas. The transaction log backup file does contain data, so are those VLFs cleared out or not?&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;652&quot; data-origin-height=&quot;227&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/dADgSf/btrHCoeBtT1/02AneVTwWKWKJGnrkDd990/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/dADgSf/btrHCoeBtT1/02AneVTwWKWKJGnrkDd990/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/dADgSf/btrHCoeBtT1/02AneVTwWKWKJGnrkDd990/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdADgSf%2FbtrHCoeBtT1%2F02AneVTwWKWKJGnrkDd990%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;652&quot; height=&quot;227&quot; data-origin-width=&quot;652&quot; data-origin-height=&quot;227&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If we do work again, what will happen?&amp;nbsp; We think the transaction log was just backed up so there should be plenty of free space right? Running DBCC SQLPERF ('LOGSPACE') confirms that.&amp;nbsp; So what will happen?&amp;nbsp; Will the transaction log fill and return an error? This seems very confusing.&amp;nbsp; Well let's give it a shot!&lt;/p&gt;
&lt;pre class=&quot;sql&quot;&gt;&lt;code&gt;INSERT INTO test1
VALUES (replicate('*', 5000)) GO 5000
DELETE
FROM test1
	--Spoiler Alert:  IT WORKS!!
GO
DBCC LOGINFO
GO
&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;You can see that FSeqNo 32-35 have been replaced with 40-43.&amp;nbsp; Even though the VLFs were still considered active, they were able to be reused since they were part of the previous transaction log backup.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;657&quot; data-origin-height=&quot;237&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/yfT5K/btrHDzNfqNI/w9CHhpBFFW1vaBNq0TxoD1/img.jpg&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/yfT5K/btrHDzNfqNI/w9CHhpBFFW1vaBNq0TxoD1/img.jpg&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/yfT5K/btrHDzNfqNI/w9CHhpBFFW1vaBNq0TxoD1/img.jpg&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FyfT5K%2FbtrHDzNfqNI%2Fw9CHhpBFFW1vaBNq0TxoD1%2Fimg.jpg&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;657&quot; height=&quot;237&quot; data-origin-width=&quot;657&quot; data-origin-height=&quot;237&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;We noticed that in a mirroring or Availability Group scenario, Lazy Log Truncation marks the VLFs for truncation, but it does not actually truncate the log unless those VLFs are necessary.&amp;nbsp; Why is this done?&amp;nbsp; Well, the primary log truncation has to retain log which may be in use at any of the secondaries. When adding a replica, this aids in minimizing the number of transaction log backups that must be restored in order to get the replica transaction log at the same point as the primary.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Is this something that you need to be aware of?&amp;nbsp; Not really, but we thought it was an interesting tidbit about how Availability Groups and mirroring have had so much thought put into them.&amp;nbsp; We also didn&amp;rsquo;t want you to be concerned if you happened to notice that a lot of your VLFs are marked as active when you think they have been backed up and should be truncated.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Lisa Gardner&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;ndash; Premier Field Engineer&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/683</guid>
      <comments>https://99lib.tistory.com/683#entry683comment</comments>
      <pubDate>Mon, 18 Jul 2022 23:36:13 +0900</pubDate>
    </item>
    <item>
      <title>Linux VM root로 로그인하기</title>
      <link>https://99lib.tistory.com/682</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;$ sudo su -&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;# vim /etc/ssh/sshd_config&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;#LoginGraceTime&amp;nbsp;2m &lt;br /&gt;#PermitRootLogin&amp;nbsp;prohibit-password &lt;br /&gt;&lt;span style=&quot;background-color: #f3c000;&quot;&gt;&lt;b&gt;PermitRootLogin&amp;nbsp;yes&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;#StrictModes&amp;nbsp;yes &lt;br /&gt;#MaxAuthTries&amp;nbsp;6 &lt;br /&gt;#MaxSessions&amp;nbsp;10&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;저장&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;# systemctl restart sshd&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Windows/Azure</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/682</guid>
      <comments>https://99lib.tistory.com/682#entry682comment</comments>
      <pubDate>Tue, 14 Dec 2021 23:29:39 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] Understanding MariaDB Architecture</title>
      <link>https://99lib.tistory.com/681</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://mariadb.com/kb/en/understanding-mariadb-architecture/&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1636035756314&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;Understanding MariaDB Architecture&quot; data-og-description=&quot;An overview of MariaDB server architecture, especially where it differs from SQL Server.&quot; data-og-host=&quot;mariadb.com&quot; data-og-source-url=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/&quot; data-og-url=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/&quot; data-og-image=&quot;&quot;&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url();&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;Understanding MariaDB Architecture&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;An overview of MariaDB server architecture, especially where it differs from SQL Server.&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;mariadb.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Understanding MariaDB Architecture&lt;/h1&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;Contents&lt;/h3&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#storage-engines&quot;&gt;Storage Engines&lt;/a&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#innodb&quot;&gt;InnoDB&lt;/a&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#primary-key-and-indexes&quot;&gt;Primary Key and Indexes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#tablespaces&quot;&gt;Tablespaces&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#transaction-logs&quot;&gt;Transaction Logs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#innodb-buffer-pool&quot;&gt;InnoDB Buffer Pool&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#innodb-background-threads&quot;&gt;InnoDB Background Threads&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#checksums-and-doublewrite-buffer&quot;&gt;Checksums and Doublewrite Buffer&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#aria&quot;&gt;Aria&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#databases&quot;&gt;Databases&lt;/a&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#system-databases&quot;&gt;System Databases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#default-database&quot;&gt;Default Database&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#the-binary-log&quot;&gt;The Binary Log&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#plugins&quot;&gt;Plugins&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#thread-pool&quot;&gt;Thread Pool&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#configuration&quot;&gt;Configuration&lt;/a&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#configuration-files&quot;&gt;Configuration Files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#dynamic-and-static-variables&quot;&gt;Dynamic and Static Variables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#scope&quot;&gt;Scope&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#syntax&quot;&gt;Syntax&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#setting-system-variables-with-startup-parameters&quot;&gt;Setting System Variables with Startup Parameters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#debugging-configuration&quot;&gt;Debugging Configuration&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#status-variables&quot;&gt;Status Variables&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB architecture is partly different from the architecture of traditional DBMSs, like SQL Server. Here we will examine the main components that a new MariaDB DBA needs to know. We will also discuss a bit of history, because this may help understand MariaDB philosophy and certain design choices.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This section is an overview of the most important components. More information is included in specific sections of this migration guide, or in other pages of the MariaDB Knowledge Base (see the links scattered over the text).&lt;/p&gt;
&lt;h2 id=&quot;storage-engines&quot; data-ke-size=&quot;size26&quot;&gt;Storage Engines&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB was born from the source code of MySQL, in 2008. Therefore, its history begins with MySQL.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MySQL was born at the beginning of the 90s. Back in the days, if compared to its existing competitors, MySQL was lightweight, simple to install, easy to learn. While it had a very limited set of features, it was also fast in certain common operations. And it was open source. These characteristics made it suitable to back the simple websites that existed at that time.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The web evolved rapidly, and the same happened to MySQL. Being open source helped a lot in this respect, because the community needed functionalities that weren&amp;rsquo;t supported at that time.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MySQL was probably the first database system to support a&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/storage-engines/&quot;&gt;pluggable storage engine architecture&lt;/a&gt;. Basically, this means that MySQL knows very little about creating or populating a table, reading from it, building proper indexes and caches. It just delegated all these operations to a special plugin type called a storage engine.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;One of the first plugins developed by third parties was&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#innodb&quot;&gt;InnoDB&lt;/a&gt;. It is very fast, and it adds two important features that are not otherwise supported: transactions and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/foreign-keys/&quot;&gt;foreign keys&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Note that when MariaDB asks a storage engine to write or read a row, the storage engine could theoretically do anything. This led to the creation of very interesting alternative engines, like&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/blackhole/&quot;&gt;BLACKHOLE&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;(which doesn&amp;rsquo;t write or read any data, acting like the /dev/null file in Linux), or&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/connect/&quot;&gt;CONNECT&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;(which can read and write to files written in many different formats, or remote DBMSs, or some other special data sources).&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Nowadays InnoDB is the default MariaDB storage engine, and it is the best choice for most use cases. But for particular needs, sometimes using a different storage engine is desirable. In case of doubts about the best storage engine to use for a specific case, check the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/choosing-the-right-storage-engine/&quot;&gt;Choosing the Right Storage Engine&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;page.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;When we create a table, we specify its storage engine or use the default one. It is possible to convert an existing table to another storage engine, though this is a blocking operation which requires a complete table copy. Third-party storage engines can also be installed while MariaDB is running.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Note that it is perfectly possible to use tables with different storage engines in the same transaction (even if some engines are not transactional). It is even possible to use different engines in the same query, for example with JOINs and subqueries.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The default storage engine can be changed by changing the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/#default_storage_engine&quot;&gt;default_storage_engine&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;variable. A different default can be specified for temporary tables by setting&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/#default_tmp_storage_engine&quot;&gt;default_tmp_storage_engine&lt;/a&gt;. MariaDB uses&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-storage-engine/&quot;&gt;Aria&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;for system tables and temporary tables created internally to store the intermediate results of a query.&lt;/p&gt;
&lt;h3 id=&quot;innodb&quot; data-ke-size=&quot;size23&quot;&gt;InnoDB&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;It is worth spending some more words here about&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb/&quot;&gt;InnoDB&lt;/a&gt;, the default storage engine.&lt;/p&gt;
&lt;h4 id=&quot;primary-key-and-indexes&quot; data-ke-size=&quot;size20&quot;&gt;Primary Key and Indexes&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB primary keys are always the equivalent of SQL Server clustered indexes. In other words, an InnoDB table is always ordered by the primary key.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If an InnoDB table doesn't have a user-defined primary key, the first&lt;span&gt;&amp;nbsp;&lt;/span&gt;UNIQUE&lt;span&gt;&amp;nbsp;&lt;/span&gt;index whose columns are all&lt;span&gt;&amp;nbsp;&lt;/span&gt;NOT NULL&lt;span&gt;&amp;nbsp;&lt;/span&gt;is used as a primary key. If there is no such index, the table will have a&lt;span&gt;&amp;nbsp;&lt;/span&gt;clustered index. The terminology here can be a bit confusing for SQL Server and other DBMS users. A clustered index in InnoDB is a 6 bytes value that is added to the table. This index and its values are completely invisible to the users. It's important to note that clustered indexes are governed by a global mutex that greatly reduces their scalability.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Secondary indexes are ordered by the columns that are part of the index, and contain a reference to each entry's corresponding primary key value.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Some consequences of these design choices are the following:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;For performance reasons, a primary key value should be inserted in order. In other words, the last inserted value should be the highest. This order is normally followed when inserting values into an&lt;span&gt;&amp;nbsp;&lt;/span&gt;AUTO_INCREMENT&lt;span&gt;&amp;nbsp;&lt;/span&gt;primary key. The reason is that inserting values in the middle of an ordered data structure is slower, unless they fit into existing holes. If we insert primary key values randomly, InnoDB often has to rearrange pages to make some room for the new data.&lt;/li&gt;
&lt;li&gt;A big primary keys means that all secondary indexes are also big.&lt;/li&gt;
&lt;li&gt;A query by primary key will require a single search. A query on a secondary index that also reads columns not contained in the index will require one search on the index, plus one more search for each row that satisfies the index condition.&lt;/li&gt;
&lt;li&gt;We shouldn't explicitly include the primary key in a secondary index. If we do so, the primary key column will be duplicated in the index.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;tablespaces&quot; data-ke-size=&quot;size20&quot;&gt;Tablespaces&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For InnoDB, a&lt;span&gt;&amp;nbsp;&lt;/span&gt;tablespace&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a file containing data (not a file group as in SQL Server). The types of tablespaces are:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-tablespaces/&quot;&gt;System tablespace&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-file-per-table-tablespaces/&quot;&gt;File-per-table tablespaces&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-temporary-tablespaces/&quot;&gt;Temporary tablespaces&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The system tablespace is stored in the file&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibdata. It contains information used by InnoDB internally, like rollback segments, as well as some system tables. Historically, the system tablespace also contained all tables created by the user. In modern MariaDB versions, a table is created in the system tablespace only if the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-variables/#innodb_file_per_table&quot;&gt;innodb_file_per_table&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;system variable is set to 0 at the moment of the table creation. By default, innodb_file_per_table is 1.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Tables created while&lt;span&gt;&amp;nbsp;&lt;/span&gt;innodb_file_per_table=1&lt;span&gt;&amp;nbsp;&lt;/span&gt;are written into their own tablespace. These are&lt;span&gt;&amp;nbsp;&lt;/span&gt;.ibd&lt;span&gt;&amp;nbsp;&lt;/span&gt;files.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Starting from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/what-is-mariadb-102/&quot;&gt;MariaDB 10.2&lt;/a&gt;, temporary tables are written into temporary tablespaces, which means&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibtmp*&lt;span&gt;&amp;nbsp;&lt;/span&gt;files. Previously, they were created in the system tablespace or in file-per-table tablespaces according to the value of&lt;span&gt;&amp;nbsp;&lt;/span&gt;innodb_file_per_table, just like regular tables. Temporary tablespaces, if present, are deleted when MariaDB starts.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;It is important to remember that tablespaces can never shrink&lt;/b&gt;. If a file-per-table tablespace grows too much, deleting data won't recover space. Instead, a new table must be created and data needs to be copied. Finally, the old table will be deleted. If the system tablespace grows too much, the only solution is to move data into a new MariaDB installation.&lt;/p&gt;
&lt;h4 id=&quot;transaction-logs&quot; data-ke-size=&quot;size20&quot;&gt;Transaction Logs&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In SQL Server, the transaction log contains both the undo log and the redo log. Usually we have only one transaction log.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In MariaDB the undo log and the redo log are stored separately. By default, the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-redo-log/&quot;&gt;redo log&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is written to two files, called&lt;span&gt;&amp;nbsp;&lt;/span&gt;ib_logfile0&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;ib_logfile1. The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-undo-log/&quot;&gt;undo log&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;by default is written to the&lt;span&gt;&amp;nbsp;&lt;/span&gt;system tablespace, which is in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibdata1&lt;span&gt;&amp;nbsp;&lt;/span&gt;file. However, it is possible to write it in separate files in a specified directory.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB provides no way to inspect the contents of the transaction logs. However, it is possible to inspect the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/understanding-mariadb-architecture/#the-binary-log&quot;&gt;binary log&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB transaction logs are written in a circular fashion: their size is normally fixed, and when the end is reached, InnoDB continues to write from the beginning. However, if very long transactions are running, InnoDB cannot overwrite the oldest data, so it has to expand the log size instead.&lt;/p&gt;
&lt;h4 id=&quot;innodb-buffer-pool&quot; data-ke-size=&quot;size20&quot;&gt;InnoDB Buffer Pool&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB doesn't have a central buffer pool. Each storage engine may or may not have a buffer pool. The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-buffer-pool/&quot;&gt;InnoDB buffer pool&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is typically assigned a big amount of memory. See&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/mariadb-memory-allocation/&quot;&gt;MariaDB Memory Allocation&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB has no extension like the SQL Server buffer pool extension.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A part of the buffer pool is called the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-change-buffering/&quot;&gt;change buffer&lt;/a&gt;. It contains dirty pages that have been modified in memory and not yet flushed.&lt;/p&gt;
&lt;h4 id=&quot;innodb-background-threads&quot; data-ke-size=&quot;size20&quot;&gt;InnoDB Background Threads&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB has background threads that take care of flushing dirty pages from the change buffer to the tablespaces. They don't directly affect the latency of queries, but they are very important for performance.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://mariadb.com/kb/en/show-engine-innodb-status/&quot;&gt;SHOW ENGINE InnoDB STATUS&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;shows information about them in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;BACKGROUND THREAD&lt;span&gt;&amp;nbsp;&lt;/span&gt;section. They can also be seen using the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/performance-schema-threads-table/&quot;&gt;threads&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;table, in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/performance-schema/&quot;&gt;performance_schema&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB flushing is similar to&lt;span&gt;&amp;nbsp;&lt;/span&gt;lazy writes&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;checkpoints&lt;span&gt;&amp;nbsp;&lt;/span&gt;in SQL Server. It has no equivalent for&lt;span&gt;&amp;nbsp;&lt;/span&gt;eager writing.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For more information, see&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-page-flushing/&quot;&gt;InnoDB Page Flushing&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-purge/&quot;&gt;InnoDB Purge&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;checksums-and-doublewrite-buffer&quot; data-ke-size=&quot;size20&quot;&gt;Checksums and Doublewrite Buffer&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB pages have checksums. After writing pages to disk, InnoDB verifies that the checksums match. The checksum algorithm is determined by&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-variables/#innodb_checksum_algorithm&quot;&gt;innodb_checksum_algorithm&lt;/a&gt;. Check the variable documentation for its consequences on performance, backward compatibility and encryption.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In case of a system crash, hardware failure or power outage, a page could be half-written on disk. For some pages, this causes a disaster. Therefore, InnoDB writes essential pages to disk twice. A backup copy of the new page version is written first. Then, the old page is overwritten. The backup copies are written into a file called the&lt;span&gt;&amp;nbsp;&lt;/span&gt;doublewrite buffer.&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;If an event prevents the first page from being written, the old version of the page will still be available.&lt;/li&gt;
&lt;li&gt;If an event prevents the old page from being completely overwritten by its new version, the page can still be recovered using the doublewrite buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The doublewrite buffer can disabled using the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-variables/#innodb_doublewrite&quot;&gt;innodb_doublewrite&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;variable, but this usually doesn't bring big performance benefits. The doublewrite buffer location can be changed with&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-variables/#innodb_doublewrite_file&quot;&gt;innodb_doublewrite_file&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;aria&quot; data-ke-size=&quot;size23&quot;&gt;Aria&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Even if we only create InnoDB tables, we use Aria indirectly, in two ways:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;For system tables.&lt;/li&gt;
&lt;li&gt;For internal temporary tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Aria is a non-transactional storage engine. By default it is crash-safe, meaning that all changes to data are written and fsynced to a write-ahead log and can always be recovered in case of a crash.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Aria caches indexes into the pagecache. Data are not directly cached by Aria, so it's important that the underlying filesystem caches reads and writes.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The pagecache size is determined by the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-system-variables/#aria_pagecache_buffer_size&quot;&gt;aria_pagecache_buffer_size&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;system variable. To know if it is big enough we can check the proportion of free pages (the ratio between&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_blocks_used&quot;&gt;Aria_pagecache_blocks_used&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_blocks_unused&quot;&gt;Aria_pagecache_blocks_unused&lt;/a&gt;) and the proportion of cache misses (the ratio between&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_read_requests&quot;&gt;Aria_pagecache_read_requests&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_reads&quot;&gt;Aria_pagecache_reads&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The proportion of dirty pages is the ratio between&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_blocks_used&quot;&gt;Aria_pagecache_blocks_used&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-status-variables/#aria_pagecache_blocks_not_flushed&quot;&gt;Aria_pagecache_blocks_not_flushed&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;tells us if the log file is big enough.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The size of Aria log is determined by&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/aria-system-variables/#aria_pagecache_buffer_size&quot;&gt;aria_log_file_size&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;databases&quot; data-ke-size=&quot;size26&quot;&gt;Databases&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB does not support the concept of schema. In MariaDB SQL,&lt;span&gt;&amp;nbsp;&lt;/span&gt;schema&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;schemas&lt;span&gt;&amp;nbsp;&lt;/span&gt;are synonyms for&lt;span&gt;&amp;nbsp;&lt;/span&gt;database&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;databases.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;When a user connects to MariaDB, they don't connect to a specific database. Instead, they can access any table they have permissions for. There is however a concept of&lt;span&gt;&amp;nbsp;&lt;/span&gt;default database, see below.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A database is a container for database objects like tables and views. A database serves the following purposes:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;A database is a namespace.&lt;/li&gt;
&lt;li&gt;A database is a logical container to separate objects.&lt;/li&gt;
&lt;li&gt;A database has a default&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/character-sets/&quot;&gt;character set&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and collation, which are inherited by their tables.&lt;/li&gt;
&lt;li&gt;Permissions can be assigned on a whole database, to make permission maintenance simpler.&lt;/li&gt;
&lt;li&gt;Physical data files are stored in a directory which has the same name as the database to which they belong.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;system-databases&quot; data-ke-size=&quot;size23&quot;&gt;System Databases&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB has the following system databases:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/the-mysql-database-tables/&quot;&gt;mysql&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is for internal use only, and should not be read or written directly.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/information-schema/&quot;&gt;information_schema&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;contains all information that can be found in SQL Server's information_schema and more. However, while SQL Server's&lt;span&gt;&amp;nbsp;&lt;/span&gt;information_schema&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a schema containing information about the local database, MariaDB's&lt;span&gt;&amp;nbsp;&lt;/span&gt;information_schema&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a database that contains information about all databases.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://mariadb.com/kb/en/performance-schema/&quot;&gt;performance_schema&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;contains information about MariaDB runtime. It is disabled by default. Enabling it requires setting the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/performance-schema-system-variables/#performance_schema&quot;&gt;performance_schema&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;system variable to 1 and restarting MariaDB.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;default-database&quot; data-ke-size=&quot;size23&quot;&gt;Default Database&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;When a user connects to MariaDB, they can optionally specify a default database. A default database can also be specified or changed later, with the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/use/&quot;&gt;USE&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;command.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Having a default database specified allows one to specify tables without specifying the name of the database where they are located. If no default database is specified, all table names must be fully qualified.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For example, the two following snippets are equivalent:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;FROM&lt;/span&gt; &lt;span&gt;my_database&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;my_table&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- is equivalent to:&lt;/span&gt; &lt;span&gt;USE&lt;/span&gt; &lt;span&gt;my_database&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;FROM&lt;/span&gt; &lt;span&gt;my_table&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Even if a default database is specified, tables from other databases can be accessed by specifying their fully qualified names:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #60a0b0;&quot;&gt;-- this query joins my_database.my_table to your_database.your_table&lt;/span&gt; &lt;span&gt;USE&lt;/span&gt; &lt;span&gt;my_database&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span&gt;m&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;FROM&lt;/span&gt; &lt;span&gt;my_table&lt;/span&gt; &lt;span&gt;m&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;JOIN&lt;/span&gt; &lt;span&gt;your_database&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;your_table&lt;/span&gt; &lt;span&gt;y&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;ON&lt;/span&gt; &lt;span&gt;m&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;xyz&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span&gt;y&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;xyz&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB has the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/database/&quot;&gt;DATABASE()&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function to determine the current database:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;DATABASE&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Stored procedures and triggers don't inherit a default database from the session, nor by a caller procedure. In that context, the default database is the database which contains the procedure.&lt;span&gt;&amp;nbsp;&lt;/span&gt;USE&lt;span&gt;&amp;nbsp;&lt;/span&gt;can be used to change it. The default database will only be valid for the rest of the procedure.&lt;/p&gt;
&lt;h2 id=&quot;the-binary-log&quot; data-ke-size=&quot;size26&quot;&gt;The Binary Log&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Different tables can be built using different storage engines. It is important to note that not all engines are transactional, and that different engines implement the transaction logs in different ways. For this reason, MariaDB cannot replicate data from a master to a slave using an equivalent of SQL Server transactional replication.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Instead, it needs a global mechanism to log the changes that are applied to data. This mechanism is the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/binary-log/&quot;&gt;binary log&lt;/a&gt;, often abbreviated to binlog.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The binary log can be written in the following formats:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;STATEMENT logs SQL statements that modify data;&lt;/li&gt;
&lt;li&gt;ROW logs a reference to the rows that have been modified, if any (usually it&amp;rsquo;s the primary key), and the new values that have been added or modified, in a binary format.&lt;/li&gt;
&lt;li&gt;MIXED is a combination of the above formats. It means that ROW is used for statements that can safely be logged in this way (see below), and STATEMENT is used in other cases. This is the default format from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/what-is-mariadb-102/&quot;&gt;MariaDB 10.2&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In most cases, STATEMENT is slower because the SQL statement needs to be re-executed by the slave, and because certain statements may produce a different result in the slave (think about queries that use LIMIT without ORDER BY, or the CURRENT_TIMESTAMP() function). But there are exceptions, and besides, DDL statements are always logged as STATEMENT to avoid flooding the binary log. Therefore, the binary log may well contain both ROW and STATEMENT entries.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;See&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/binary-log-formats/&quot;&gt;Binary Log Formats&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The binary log allows:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;replication, if enabled on the master;&lt;/li&gt;
&lt;li&gt;promoting a slave to a master, if enabled on that slave;&lt;/li&gt;
&lt;li&gt;incremental backups;&lt;/li&gt;
&lt;li&gt;seeing data as they were in a point of time in the past (&lt;a href=&quot;https://mariadb.com/kb/en/flashback/&quot;&gt;flashback&lt;/a&gt;);&lt;/li&gt;
&lt;li&gt;restoring a backup and re-appling the binary log, with the exception of a data change which caused problems (human mistake, application bug, SQL injection);&lt;/li&gt;
&lt;li&gt;Capture Data Changes (CDC), by streaming the binary log to technologies like Apache Kafka.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If you don't plan to use any of these features on a server, it is possible to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/replication-and-binary-log-system-variables/#log_bin&quot;&gt;disable&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;the binary log to slightly improve the performance.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The binary log can be inspected using the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/mysqlbinlog/&quot;&gt;mysqlbinlog&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;utility, which comes with MariaDB. Enabling or disabling the binary log requires restarting MariaDB.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;See also&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/mariadb-replication-overview-for-sql-server-users/&quot;&gt;MariaDB Replication Overview for SQL Server Users&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/mariadb-backups-overview-for-sql-server-users/&quot;&gt;MariaDB Backups Overview for SQL Server Users&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;for a better understanding of how the binary log is used.&lt;/p&gt;
&lt;h2 id=&quot;plugins&quot; data-ke-size=&quot;size26&quot;&gt;Plugins&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Storage engines are a special type of&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/plugins/&quot;&gt;plugin&lt;/a&gt;. But others exist. For example, plugins can add authentication methods, new features, SQL syntax, functions, informative tables, and more.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A plugin may add some server variables and some status variables. Server variables can be used to configure the plugin, and status variables can be used to monitor its activities and status. These variables generally use the plugin's name as a prefix. For example InnoDB has a server variable called innodb_buffer_pool_size to configure the size of its buffer pool, and a status variable called Innodb_pages_read which indicates the number of memory pages read from the buffer pool. The category&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/system-variables/&quot;&gt;system variables&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;of the MariaDB Knowledge Base has specific pages for system and status variables associated with various plugins.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Many plugins are installed by default, or available but not installed by default. They can be installed or uninstalled at runtime with SQL statements, like&lt;span&gt;&amp;nbsp;&lt;/span&gt;INSTALL PLUGIN,&lt;span&gt;&amp;nbsp;&lt;/span&gt;UNINSTALL PLUGIN&lt;span&gt;&amp;nbsp;&lt;/span&gt;and others; see&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/plugin-sql-statements/&quot;&gt;Plugin SQL Statements&lt;/a&gt;. 3rd party plugins can be made available for installation by simply copying them to the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/#plugin_dir&quot;&gt;plugin_dir&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;It is important to note that different plugins may have different maturity levels. It is possible to prevent the installation of plugins we don&amp;rsquo;t consider production-ready by setting the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/#plugin_maturity&quot;&gt;plugin_maturity&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;system variable. For plugins that are distributed with MariaDB, the maturity level is determined by the MariaDB team based on the bugs reported and fixed.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Some plugins are developed by 3rd parties. Even some 3rd party plugins are included in MariaDB official distributions - the ones available on mariadb.org.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;In MariaDB every authorization method (including the default one) is provided by an&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/authentication-plugins/&quot;&gt;authentication plugin&lt;/a&gt;. A user can be required to use a certain authentication plugin. This gives us much flexibility and control. Windows users may be interested in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/authentication-plugin-gssapi/&quot;&gt;gsapi&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;(which supports Windows authentication, Kerberos and NTLM) and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/authentication-plugin-named-pipe/&quot;&gt;named_pipe&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;(which uses named pipe impersonation).&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Other plugins that can be very useful include&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/user-statistics/&quot;&gt;userstat&lt;/a&gt;, which includes statistics about resources and table usage, and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/metadata_lock_info/&quot;&gt;METADATA_LOCK_INFO&lt;/a&gt;, which provides information about metadata locks.&lt;/p&gt;
&lt;h2 id=&quot;thread-pool&quot; data-ke-size=&quot;size26&quot;&gt;Thread Pool&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB supports&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/thread-pool/&quot;&gt;thread pool&lt;/a&gt;. It works differently on UNIX and on Windows. On Windows, it is enabled by default and its implementation is quite similar to SQL Server. It uses the Windows native CreateThreadpool API.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If we don't use the thread pool, MariaDB will use its traditional method to handle connections. It consists of using a dedicated thread for each client connection. Creating a new thread has a cost in terms of CPU time. To mitigate this cost, after a client disconnects, the thread may be preserved for a certain time in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/#thread_cache_size&quot;&gt;thread cache&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Whichever connection method we use, MariaDB has a maximum number of simultaneous connections, which can be changed at runtime. When the limit is reached, if more clients try to connect they will receive an error. This prevents MariaDB from consuming all the server resources and freezing or crashing. See&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/handling-too-many-connections/&quot;&gt;Handling Too Many Connections&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;configuration&quot; data-ke-size=&quot;size26&quot;&gt;Configuration&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB has many settings that control the server behavior. These can be set up when starting mysqld (&lt;a href=&quot;https://mariadb.com/kb/en/mysqld-options/&quot;&gt;mysqld options&lt;/a&gt;), and the vast majority are also accessible as&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/&quot;&gt;server system variables&lt;/a&gt;. These can be classified in these ways:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;b&gt;Dynamic&lt;/b&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;or&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;static&lt;/b&gt;;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Global&lt;/b&gt;,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;session&lt;/b&gt;, or both.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Note that server system variables are not to be confused with&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/user-defined-variables/&quot;&gt;user-defined variables&lt;/a&gt;. The latter are not used for MariaDB configuration.&lt;/p&gt;
&lt;h3 id=&quot;configuration-files&quot; data-ke-size=&quot;size23&quot;&gt;Configuration Files&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB can use several&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/configuring-mariadb-with-option-files/&quot;&gt;configuration files&lt;/a&gt;. Configuration files are searched in several locations, including in the user directory, and if present they all are read and used. They are read in a consistent order. These locations depend on the operating system; see&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#default-option-file-locations&quot;&gt;Default Option File Locations&lt;/a&gt;. It is possible to tell MariaDB which files it should read; see&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#global-options-related-to-option-files&quot;&gt;Global Options Related to Option Files&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;On Linux, by default the configuration files are called&lt;span&gt;&amp;nbsp;&lt;/span&gt;my.cnf. On Windows, by default the configuration files can be called&lt;span&gt;&amp;nbsp;&lt;/span&gt;my.ini&lt;span&gt;&amp;nbsp;&lt;/span&gt;or&lt;span&gt;&amp;nbsp;&lt;/span&gt;my.cnf. The former is more common.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If a variable is mentioned multiple times in different files, the occurrence that is read last will overwrite the others. Similarly, if a variable is mentioned several times in a single file, the occurrence that is read last overwrites the others.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The contents of each configuration file are organized by&lt;span&gt;&amp;nbsp;&lt;/span&gt;option groups. MariaDB Server and client programs read different groups. The read groups also depend on the MariaDB version. See&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#option-groups&quot;&gt;Option Groups&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;for the details. Most commonly, the&lt;span&gt;&amp;nbsp;&lt;/span&gt;[server]&lt;span&gt;&amp;nbsp;&lt;/span&gt;or&lt;span&gt;&amp;nbsp;&lt;/span&gt;[mysqld]&lt;span&gt;&amp;nbsp;&lt;/span&gt;groups are used to contain all server configuration. The&lt;span&gt;&amp;nbsp;&lt;/span&gt;[client-server]&lt;span&gt;&amp;nbsp;&lt;/span&gt;group can be used for options that are shared by the server and the clients (like the port to use), to avoid repeating those variables multiple times.&lt;/p&gt;
&lt;h3 id=&quot;dynamic-and-static-variables&quot; data-ke-size=&quot;size23&quot;&gt;Dynamic and Static Variables&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Dynamic variables have a value that can be changed at runtime, using the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/set/&quot;&gt;SET&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;SQL statement. Static variables have a value that is decided at startup (see below) and cannot be changed without a restart.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/&quot;&gt;Server System Variables&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;page states if variables are dynamic or static.&lt;/p&gt;
&lt;h3 id=&quot;scope&quot; data-ke-size=&quot;size23&quot;&gt;Scope&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A global system variable is one that affects the general behavior of MariaDB. For example&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/innodb-system-variables/#innodb_buffer_pool_size&quot;&gt;innodb_buffer_pool_size&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;determines the size of the InnoDB buffer pool, which is used by read and write operations, no matter which user issued them. A session system variable is one that affects MariaDB behavior for the current connection; changing it will not affect other connected users, or future connections from the current user.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A variable could exist in both the global and session scopes. In this case, the session value is what affects the current connection. When a user connects, the current global value is copied to the session scope. Changing the global value afterward will not change existing connections.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-system-variables/&quot;&gt;Server System Variables&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;page states the scope of each variable.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Global variables and some session variables can only be modified by a user with the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/grant/#global-privileges&quot;&gt;SUPER&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;privilege (typically root).&lt;/p&gt;
&lt;h3 id=&quot;syntax&quot; data-ke-size=&quot;size23&quot;&gt;Syntax&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;To see the value of a system variable:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #60a0b0;&quot;&gt;-- global variables:&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@@&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;global&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;variable_name&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- session variables:&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@@&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;session&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;variable_name&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- or just use the shortcut:&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@@&lt;/span&gt;&lt;span&gt;variable_name&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;A longer syntax, which is mostly useful to get multiple variables, makes use of the same pattern syntax that is used by the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/like/&quot;&gt;LIKE&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;operator:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #60a0b0;&quot;&gt;-- global variables whose name starts with 'innodb':&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;GLOBAL&lt;/span&gt; &lt;span&gt;VARIABLES&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- session variables whose name starts with 'innodb':&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SESSION&lt;/span&gt; &lt;span&gt;VARIABLES&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span&gt;VARIABLES&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;To modify the global or session value of a dynamic variable:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@@&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;global&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;variable_name&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'new '&lt;/span&gt;&lt;span&gt;value&lt;/span&gt;&lt;span style=&quot;color: #4070a0;&quot;&gt;';&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;SET @@session.variable_name = '&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'value'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Notice that if we modify a global variable in this way, the new value will be lost at server restart. For this reason we probably want to change the value in the configuration file too.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For further information see:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/set/&quot;&gt;SET&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;statement.&lt;/li&gt;
&lt;li&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/show-variables/&quot;&gt;SHOW VARIABLES&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;statement.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;setting-system-variables-with-startup-parameters&quot; data-ke-size=&quot;size23&quot;&gt;Setting System Variables with Startup Parameters&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;System variables can be set at server startup without writing their values into a configuration file. This is useful if we want a value to be set once, until we change it or restart MariaDB. Values passed in this way override values written in the configuration files.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The general rule is that every global variable can be passed as an argument of&lt;span&gt;&amp;nbsp;&lt;/span&gt;mysqld&lt;span&gt;&amp;nbsp;&lt;/span&gt;by prefixing its name with&lt;span&gt;&amp;nbsp;&lt;/span&gt;--&lt;span&gt;&amp;nbsp;&lt;/span&gt;and by replacing every occurrence of&lt;span&gt;&amp;nbsp;&lt;/span&gt;_&lt;span&gt;&amp;nbsp;&lt;/span&gt;with&lt;span&gt;&amp;nbsp;&lt;/span&gt;-&lt;span&gt;&amp;nbsp;&lt;/span&gt;in its name.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;For example, to pass&lt;span&gt;&amp;nbsp;&lt;/span&gt;bind_address&lt;span&gt;&amp;nbsp;&lt;/span&gt;as a startup argument:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;mysqld&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;--bind-address=127.0.0.1&lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&quot;debugging-configuration&quot; data-ke-size=&quot;size23&quot;&gt;Debugging Configuration&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Mistyping a variable can prevent MariaDB from starting. We cannot set a variable that doesn't exist in the MariaDB version in use. In these cases, an error is written in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/error-log/&quot;&gt;error log&lt;/a&gt;.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Having several configuration files and configuration groups, as well as being able to pass variables as command-line arguments, brings a lot of flexibility but can sometimes be confusing. When we are unsure about which values will be used, we can run:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;mysqld&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;--print-defaults&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;status-variables&quot; data-ke-size=&quot;size26&quot;&gt;Status Variables&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB status variables and some system tables allow external tools to monitor a server, building graphs on how they change over time, and allow the user to inspect what is happening inside the server.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://mariadb.com/kb/en/server-status-variables/&quot;&gt;Status variables&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;cannot be directly modified by the user. Their values indicate how MariaDB is operating. Their scope can be:&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;b&gt;Global&lt;/b&gt;, meaning that the value is about some MariaDB activity.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Session&lt;/b&gt;, meaning that the value measures activities taking place in the current session.&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Many status variables exist in both scopes. For example,&lt;a href=&quot;https://mariadb.com/kb/en/server-status-variables/#cpu_time&quot;&gt;Cpu_time&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;at global level indicates how much time the CPU was used by the MariaDB process (including all user sessions and all the background threads). At session level, it indicates how much time the CPU was used by the current session.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The status variables created by a plugin, usually, use the plugin name as a prefix.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/show-status/&quot;&gt;SHOW STATUS&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;statement prints the values of the status variables that match a certain pattern.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #60a0b0;&quot;&gt;-- Show all InnoDB global status variables&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;GLOBAL&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- Show all InnoDB session status variables&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SESSION&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'innodb%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #60a0b0;&quot;&gt;-- Show global variables that contain the &quot;size&quot; substring:&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;GLOBAL&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'%size%'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Some status variables values are reset when&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://mariadb.com/kb/en/flush/#flush-status&quot;&gt;FLUSH STATUS&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is executed. A possible use:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;DELIMITER&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;||&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;BEGIN&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;NOT&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;ATOMIC&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@&lt;/span&gt;&lt;span&gt;i&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span&gt;WHILE&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@&lt;/span&gt;&lt;span&gt;i&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;60&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;DO&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SHOW&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;GLOBAL&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;LIKE&lt;/span&gt; &lt;span style=&quot;color: #4070a0;&quot;&gt;'Com_select'&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span&gt;FLUSH&lt;/span&gt; &lt;span&gt;STATUS&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;DO&lt;/span&gt; &lt;span&gt;SLEEP&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;SET&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@&lt;/span&gt;&lt;span&gt;i&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;@&lt;/span&gt;&lt;span&gt;i&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;END&lt;/span&gt; &lt;span&gt;WHILE&lt;/span&gt;&lt;span&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;END&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;||&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MariaDB</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/681</guid>
      <comments>https://99lib.tistory.com/681#entry681comment</comments>
      <pubDate>Thu, 4 Nov 2021 23:22:52 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] MariaDB에서 테이블스페이스란?</title>
      <link>https://99lib.tistory.com/680</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://hobogi.tistory.com/entry/MariaDB%EC%97%90%EC%84%9C-%ED%85%8C%EC%9D%B4%EB%B8%94%EC%8A%A4%ED%8E%98%EC%9D%B4%EC%8A%A4%EB%9E%80&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://hobogi.tistory.com/entry/MariaDB%EC%97%90%EC%84%9C-%ED%85%8C%EC%9D%B4%EB%B8%94%EC%8A%A4%ED%8E%98%EC%9D%B4%EC%8A%A4%EB%9E%80&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Oracle DBA로 익숙해져 있어서 그런지, MariaDB에서의 Tablespace가 명확히 와닿지 않는다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;오라클은 흔히 알다시피 논리적 개념으로 1개의 테이블스페이스에 1개 이상의 데이터파일들이 매핑될 수 있다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;분명 오라클처럼 Tablespace는 존재하는 것 같은데 MariaDB의 테이블스페이스는 어떻게 다를까?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;우리가 트랜잭션을 제대로 관리하기 위해 쓰는 기본 데이터베이스 엔진은 InnoDB이므로 InnoDB에서의 테이블스페이스에 대해 정리해보고자 한다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB 스토리지 엔진을 사용하는 테이블은 &quot;테이블스페이스&quot;라는 데이터파일 디스크에 기록된다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;각 테이블스페이스는 하나 이상의 InnoDB, 테이블과 관련된 인덱스 데이터를 포함할 수가 있다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB에서는 아래와 같이 크게 3가지로 테이블스페이스를 분류 할 수 있다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- InnoDB SYSTEM 테이블스페이스&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- InnoDB file-per-table 테이블스페이스&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- InnoDB Temporary 테이블스페이스&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB의 아키텍쳐 측면에서 보면 아래 그림과 같다.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;amp;amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcBUBtF%2FbtqDeU9EFvE%2FL7dmFJs9StfEf5wfJgyHMk%2Fimg.png&quot; data-filename=&quot;innodb-architecture5.7.png&quot; data-origin-width=&quot;700&quot; data-origin-height=&quot;537&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/bArfE9/btrjXFJhz0N/9kX9CcTWL6TngCdWkJpGq0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/bArfE9/btrjXFJhz0N/9kX9CcTWL6TngCdWkJpGq0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/bArfE9/btrjXFJhz0N/9kX9CcTWL6TngCdWkJpGq0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcBUBtF%2FbtqDeU9EFvE%2FL7dmFJs9StfEf5wfJgyHMk%2Fimg.png&quot; data-filename=&quot;innodb-architecture5.7.png&quot; data-origin-width=&quot;700&quot; data-origin-height=&quot;537&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/cBUBtF/btqDeU9EFvE/L7dmFJs9StfEf5wfJgyHMk/img.png&quot; data-lightbox=&quot;lightbox&quot; data-alt=&quot;mysql 5.7에서의 innodb architecture&quot;&gt;&lt;/span&gt;mysql 5.7에서의 innodb architecture&lt;/p&gt;
&lt;hr contenteditable=&quot;false&quot; data-ke-type=&quot;horizontalRule&quot; data-ke-style=&quot;style5&quot; /&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;* InnoDB SYSTEM 테이블스페이스 :&amp;nbsp;&lt;/h3&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;내용&lt;/h3&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;b&gt;크기 변경&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;InnoDB SYSTEM 테이블스페이스 내의 시스템 테이블&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB가 시스템과 관련된 정보를 특정 테이블이 아닌 전체로 저장해야하는 경우, 기록하는 특정 파일이 바로 시스템 테이블스페이스이다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;기본적으로&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibdata1파일이며 데이터 디렉토리에&lt;span&gt;&amp;nbsp;위치한&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;파일이다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;(datadir 또는&lt;span&gt;&amp;nbsp;&lt;/span&gt;innodb_data_home_dir 시스템 변수로 정의 됨&lt;span&gt;&amp;nbsp;&lt;/span&gt;)&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB는 시스템 테이블스페이스를 사용하여 데이터 딕셔너리, 버퍼의 변경분, undo log를 저장한다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;innodb_data_file_path 시스템 변수를 설정하여&lt;span&gt;&amp;nbsp;&lt;/span&gt;시스템&lt;span&gt;&amp;nbsp;&lt;/span&gt;테이블스페이스 파일 이름, 크기 및 기타 옵션을 정의할 수 있다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;이 시스템 변수는 커맨드라인 인수로&lt;span&gt;&amp;nbsp;&lt;/span&gt;mysqld에서 지정&lt;span&gt;&amp;nbsp;&lt;/span&gt;하거나&lt;span&gt;&amp;nbsp;&lt;/span&gt;옵션 파일&lt;span&gt;&amp;nbsp;&lt;/span&gt;의 서버 그룹에서&lt;span&gt;&amp;nbsp;&lt;/span&gt;지정할 수 있다&lt;span&gt;&amp;nbsp;&lt;/span&gt;.&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;예를 들면 다음과 같다.&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;&lt;span&gt;[mariadb]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;innodb_data_file_path = ibdata1 : 50M : autoextend&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 시스템 변수의 기본값은&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibdata1 file이자, 최소 크기&lt;span&gt;&amp;nbsp;&lt;/span&gt;12M,&lt;span&gt;&amp;nbsp;&lt;/span&gt;autoextend 속성이 활성화된 상태이다.&lt;/p&gt;
&lt;h2 id=&quot;changing-sizes&quot; data-ke-size=&quot;size26&quot;&gt;크기 변경&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB는 기본적으로&lt;span&gt;&amp;nbsp;&lt;/span&gt;ibdata1 시스템 테이블스페이스의&lt;span&gt;&amp;nbsp;&lt;/span&gt;파일에&lt;span&gt;&amp;nbsp;&lt;/span&gt;12M을 할당한다.&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;보통은&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;충분하지만 충분하지 않을수도 있다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;MariaDB를 사용하다 보면 시스템 테이블 공간에 대한 할당이 너무 작거나 디스크에 비해 너무 커질 수도 있다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;다행히 나중에 크기를 조정할 수 있다.&lt;/p&gt;
&lt;h3 id=&quot;increasing-the-size&quot; data-ke-size=&quot;size23&quot;&gt;크기 늘리기&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;innodb_data_file_path시스템 변수를&lt;span&gt;&amp;nbsp;&lt;/span&gt;설정하여&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;각 파일의 크기를 정의 할 수 있다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;더 큰 시스템 테이블스페이스가 필요한 경우&lt;span&gt;&amp;nbsp;&lt;/span&gt;autoextend옵션을 마지막 값에&lt;span&gt;&amp;nbsp;&lt;/span&gt;추가하면 된다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;&lt;span&gt;[mariadb]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;innodb_data_file_path = ibdata1 : 12M; ibdata2 : 50M :&lt;span&gt;&amp;nbsp;&lt;/span&gt;autoextend&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 구성에서 시스템 테이블스페이스가 지정한 크기보다 초과하여 할당하게 되면 InnoDB는 파일 크기를 늘린다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;autoextend옵션은&lt;span&gt;&amp;nbsp;&lt;/span&gt;innodb_autoextend_increment 시스템 변수를&lt;span&gt;&amp;nbsp;&lt;/span&gt;설정할 수 있다.&lt;/p&gt;
&lt;h3 id=&quot;decreasing-the-size&quot; data-ke-size=&quot;size23&quot;&gt;크기 감소&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB 시스템 테이블스페이스의 크기를 줄이는 과정은 크기를 늘리는 것보다 조금 더 복잡하다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB를 사용하면 테이블스페이스 파일 자체에서 데이터를 제거할 수 없다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;대신 테이블스페이스 파일 자체를 삭제 한 다음, 백업에서 데이터베이스를 복원해야 한다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;백업 유틸리티 mysqldump는 데이터베이스를 재생성하는 데 필요한 SQL문이 포함된 백업 파일을 생성한다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;결과적으로, 최소 데이터로 데이터베이스를 복원한다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;mysqldump를 사용해서&lt;span&gt;&amp;nbsp;&lt;/span&gt;(mysql 데이터베이스의 시스템 테이블을 포함하여 모든 InnoDB 데이터베이스 테이블)&amp;nbsp;백업합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;information_schema를 사용하면 사용중인 것을 찾을 수 있습니다.&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;SELECT&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;TABLE_NAME&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;FROM&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;INFORMATION_SCHEMA&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;TABLES&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;WHERE&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;TABLE_SCHEMA&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;=&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;'mysql'&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;AND&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;ENGINE&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;=&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;'InnoDB'&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB 만 사용하는 경우 모든 데이터베이스와 테이블을 쉽게 백업 할 수 있습니다.&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$ mysqldump -u root -p --all-databases &amp;gt; full-backup.sql&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그런 다음 MariaDB 서버를 중지하고 InnoDB 테이블 스페이스 파일을 제거합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;데이터 디렉토리 또는 InnoDB의 데이터를 홈 디렉토리에서 모든 ibdata와&lt;span&gt;&amp;nbsp;&lt;/span&gt;ib_log 파일들을 삭제하십시요.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;(확장자가 .ibd, .frm과 같은 모든 파일들)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 작업이 완료되면 서버를 다시 시작하고 덤프 파일을 가져옵니다.&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$ mysql -u root -p &amp;lt; full-backup.sql&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 data-ke-size=&quot;size26&quot;&gt;&amp;nbsp;&lt;/h2&gt;
&lt;h2 id=&quot;using-raw-disk-partitions&quot; data-ke-size=&quot;size26&quot;&gt;InnoDB 시스템 테이블스페이스 내의 System table들&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB는 InnoDB 시스템 테이블스페이스 내에 시스템 테이블을 생성합니다 :&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;SYS_DATAFILES&lt;/li&gt;
&lt;li&gt;SYS_FOREIGN&lt;/li&gt;
&lt;li&gt;SYS_FOREIGN_COLS&lt;/li&gt;
&lt;li&gt;SYS_TABLESPACES&lt;/li&gt;
&lt;li&gt;SYS_VIRTUAL&lt;/li&gt;
&lt;li&gt;SYS_ZIP_DICT&lt;/li&gt;
&lt;li&gt;SYS_ZIP_DICT_COLS&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;위 테이블은 쿼리할 수 없습니다. 하지만 information_schema 데이터베이스의 INNODB_SYS_TABLES과 같은 테이블에서 확인할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;hr contenteditable=&quot;false&quot; data-ke-type=&quot;horizontalRule&quot; data-ke-style=&quot;style5&quot; /&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;* InnoDB file-per-table 테이블스페이스 :&amp;nbsp;&lt;/h3&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;내용&lt;/h3&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;file-per-table의 위치&lt;/li&gt;
&lt;li&gt;transportable tablespace copy&lt;/li&gt;
&lt;li&gt;테이블 스페이스 암호화&lt;/li&gt;
&lt;li&gt;그 외...&lt;/li&gt;
&lt;/ol&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;InnoDB 스토리지 엔진을&lt;span&gt;&amp;nbsp;&lt;/span&gt;사용하여 테이블을 생성하면&lt;span&gt;&amp;nbsp;&lt;/span&gt;해당 테이블에 기록된 데이터는 파일시스템의 tablespace라는 데이터 파일에 저장됩니다.&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;tablespace file&lt;/span&gt;에는 데이터와 인덱스가 모두 포함됩니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;innodb_file_per_table=ON 설정을 하면, InnoDB는 InnoDB의 테이블 당 한개의 tablespace file을 사용합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;이 때 tablespace file의 확장자는&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;.ibd입니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;innodb_file_per_table=OFF 설정을 하면, InnoDB는 InnoDB의 시스템 테이블스페이스를 모든 테이블에 저장합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MySQL 5.7 이상의 InnoDB 버전은 CREATE TABLESPACE 명령어와&lt;span&gt;&amp;nbsp;general tablespace&lt;/span&gt;라는 유형의 테이블스페이스를 지원합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;하지만 MariaDB 서버의 InnoDB 버전은 CREATE TABLESPACE 명령어와 general tablespace 유형의 테이블스페이스를 지원하지 않습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 id=&quot;file-per-table-tablespace-locations&quot; data-ke-size=&quot;size26&quot;&gt;File-Per-Table 테이블스페이스 위치&lt;/h2&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;기본적으로 InnoDB의 File-Per-Table 테이블스페이스는&lt;span&gt;&amp;nbsp;&lt;/span&gt;datadir 시스템 변수에&lt;span&gt;&amp;nbsp;&lt;/span&gt;의해 정의되는 시스템의 데이터 디렉토리에 위치하게 됩니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;InnoDB 데이터를 다른 스토리지 엔진의 데이터와 별도로 저장하려면&lt;span&gt;&amp;nbsp;&lt;/span&gt;innodb_data_home_dir시스템 변수를&lt;span&gt;&amp;nbsp;&lt;/span&gt;설정하여 이를 변경하십시오.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;전용 경로에 저장해야 하는 특정 테이블 스페이스가 있는 경우&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;테이블 생성시에&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;DATA DIRECTORY 옵션을&lt;span&gt;&amp;nbsp;&lt;/span&gt;사용하여 위치를 설정할 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;예를 들어&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;&lt;span&gt;CREATE&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;TABLE&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;test&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;t1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;id&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;INT&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;PRIMARY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;KEY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;AUTO_INCREMENT&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;name&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;VARCHAR&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;50&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ENGINE&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span&gt;InnoDB&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;DATA&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;DIRECTORY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&quot;/data/contact&quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;데이터 디렉토리를 작성하면&lt;span&gt;&amp;nbsp;&lt;/span&gt;MariaDB는&amp;nbsp;해당 디렉토리 내에 File-Per-Table 테이블스페이스가 생성합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;유닉스 계열 운영체제에서 ls 명령을 사용하여 파일을 볼 수 있습니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;# ls -al /data/contact/test&lt;/span&gt;&lt;br /&gt;&lt;span&gt;drwxrwx--- 2 mysql mysql 4096 Dec 8 18:46 .&lt;/span&gt;&lt;br /&gt;&lt;span&gt;drwxr-xr-x 3 mysql mysql 4096 Dec 8 18:46 ..&lt;/span&gt;&lt;br /&gt;&lt;span&gt;-rw-rw---- 1 mysql mysql 98304 Dec 8 20:41 t1.ibd&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;MariaDB 서버 프로세스 (보통&lt;span&gt;&amp;nbsp;&lt;/span&gt;mysql)를 실행하는 시스템 사용자는 주어진 경로에 대해 쓰기 권한이 있어야 합니다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MariaDB</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/680</guid>
      <comments>https://99lib.tistory.com/680#entry680comment</comments>
      <pubDate>Thu, 4 Nov 2021 23:21:25 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] SQL lock / blocking / dead lock 간단정리</title>
      <link>https://99lib.tistory.com/679</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1626937080750&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;[DB] Lock이란?&quot; data-og-description=&quot;DBMS에서 데이터의 일관성을 보장하기 위한 기본적인 방법인 Lock에 대해서 알아봅니다&quot; data-og-host=&quot;chrisjune-13837.medium.com&quot; data-og-source-url=&quot;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&quot; data-og-url=&quot;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/tSDPr/hyKZmhQsSt/EazWBVvkX2tmbnNqscx1c1/img.png?width=776&amp;amp;height=318&amp;amp;face=0_0_776_318,https://scrap.kakaocdn.net/dn/kdpfp/hyKZgWedZw/DKTHkjJCSXnJ3sh830a5r0/img.png?width=60&amp;amp;height=52&amp;amp;face=0_0_60_52,https://scrap.kakaocdn.net/dn/bxgXrs/hyKZhAPUuH/mCRtCPKg6kvlIhGKhexJm1/img.png?width=60&amp;amp;height=51&amp;amp;face=0_0_60_51&quot;&gt;&lt;a href=&quot;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://chrisjune-13837.medium.com/db-lock-%EB%9D%BD%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-d908296d0279&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/tSDPr/hyKZmhQsSt/EazWBVvkX2tmbnNqscx1c1/img.png?width=776&amp;amp;height=318&amp;amp;face=0_0_776_318,https://scrap.kakaocdn.net/dn/kdpfp/hyKZgWedZw/DKTHkjJCSXnJ3sh830a5r0/img.png?width=60&amp;amp;height=52&amp;amp;face=0_0_60_52,https://scrap.kakaocdn.net/dn/bxgXrs/hyKZhAPUuH/mCRtCPKg6kvlIhGKhexJm1/img.png?width=60&amp;amp;height=51&amp;amp;face=0_0_60_51');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;[DB] Lock이란?&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;DBMS에서 데이터의 일관성을 보장하기 위한 기본적인 방법인 Lock에 대해서 알아봅니다&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;chrisjune-13837.medium.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DBMS에서 데이터의 일관성을 보장하기 위한 기본적인 방법인 Lock에 대해서 알아봅니다.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; width=&quot;700&quot; height=&quot;287&quot; data-origin-width=&quot;776&quot; data-origin-height=&quot;318&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/bZEv8i/btracPCNt1F/uWks8JN9pVknsDDOK359y0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/bZEv8i/btracPCNt1F/uWks8JN9pVknsDDOK359y0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/bZEv8i/btracPCNt1F/uWks8JN9pVknsDDOK359y0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbZEv8i%2FbtracPCNt1F%2FuWks8JN9pVknsDDOK359y0%2Fimg.png&quot; width=&quot;700&quot; height=&quot;287&quot; data-origin-width=&quot;776&quot; data-origin-height=&quot;318&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;h2 id=&quot;a80b&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size26&quot;&gt;Lock이란?&lt;/h2&gt;
&lt;p id=&quot;6ecb&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;데이터의 일관성을 보장하기 위한 방법입니다. 오라클과 같이 고가의 DBMS를 사용하는 이유가 데이터의 무결성과 일관성을 유지하는 능력이 뛰어나기 때문입니다.&lt;/p&gt;
&lt;h2 id=&quot;30d3&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size26&quot;&gt;Lock의 종류는?&lt;/h2&gt;
&lt;p id=&quot;574d&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;Lock은 상황에 따라서 크게 두가지로 나누어 집니다.&lt;/p&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li id=&quot;8ec9&quot; data-selectable-paragraph=&quot;&quot;&gt;Shared Lock(공유 Lock 또는 Read Lock)&lt;/li&gt;
&lt;/ol&gt;
&lt;p id=&quot;aba1&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;보통 데이터를 읽을 때 사용합니다. 원하는 데이터에 lock을 걸었지만 다른 세션에서 읽을 수 있습니다. 공유Lock을 설정한 경우 추가로 공유Lock을 설정할 수 있지만, 배타적 Lock은 설정할 수 없습니다. 즉, 내가 보고 있는 데이터는 다른 사용자가 볼 수 있지만, 변경할 수는 없습니다.&lt;/p&gt;
&lt;p id=&quot;8fd3&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;2. Exclusive Lock(배타적 Lock 또는 Write lock)&lt;/p&gt;
&lt;p id=&quot;e86d&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;보통 데이터를 변경할 때 사용합니&lt;span&gt;&lt;span&gt;다&lt;/span&gt;&lt;/span&gt;. 이름에서 느껴지는 것 처럼 해당 Lock이 해제되기 전까지는, 다른 공유Lock, 배타적Lock을 설정할 수 없습니다. 즉, 읽기 기와 쓰기가 불가능하다는 의미입니다.&lt;/p&gt;
&lt;h2 id=&quot;7c78&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size26&quot;&gt;Blocking ?&lt;/h2&gt;
&lt;p id=&quot;c9cf&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;경합으로 인한 상태인 블로킹에 대하여 알아봅니다.&lt;/p&gt;
&lt;p id=&quot;35e0&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Blocking&lt;/b&gt;&lt;/p&gt;
&lt;p id=&quot;340e&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;블로킹은 Lock들의 경합(Race condition이라고도 합니다)이 발생하여 특정 세션이 작업을 진행하지 못하고 멈춰 선 상태를 의미합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;공유Lock과 배타적Lock&lt;span&gt;&amp;nbsp;&lt;/span&gt;또는&lt;span&gt;&amp;nbsp;&lt;/span&gt;배타적Lock과 배타적Lock끼리 블로킹이 발생할 수 있습니다. 이를 해결하는 방법은 Transaction commit 또는 rollback 뿐입니다.&lt;/p&gt;
&lt;p id=&quot;0cdc&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;경합이 발생할 때, 먼저 Lock을 설정한 트랜젝션을 기다려야하기 때문에, 이런 현상이 반복되면 빠른 서비스를 제공할 수 없습니다.&lt;/p&gt;
&lt;p id=&quot;a2bf&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;해결방안&lt;/b&gt;&lt;/p&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li id=&quot;09c4&quot; data-selectable-paragraph=&quot;&quot;&gt;SQL 문장에 가장 빠르게 실행되도록 리펙토링하는 것이 가장 기본이며 효과적인 방법입니다.&lt;/li&gt;
&lt;li id=&quot;0da1&quot; data-selectable-paragraph=&quot;&quot;&gt;트랜젝션을 가능한 짧게 정의하면 경합을 줄일 수 있습니다.&lt;/li&gt;
&lt;li id=&quot;ebbe&quot; data-selectable-paragraph=&quot;&quot;&gt;동일한 데이터를 동시에 변경하는 작업을 하지 않도록 설계하는 것이 좋습니다. 또한 트랜젝션이 활발한 주간에는 대용량 갱신 작업을 수행하면 안됩니다.&lt;/li&gt;
&lt;li id=&quot;0a84&quot; data-selectable-paragraph=&quot;&quot;&gt;대용량작업이 불가피할 경우, 작업단위를 쪼개거나&lt;span&gt;&amp;nbsp;&lt;/span&gt;lock_timeout을 설정하여 해당 Lock의 최대시간을 설정할 수 있습니다.&lt;/li&gt;
&lt;/ol&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #292929;&quot; data-selectable-paragraph=&quot;&quot;&gt;set lock_timeout 3000&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;5ba4&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size26&quot;&gt;Dead Lock이란?&lt;/h2&gt;
&lt;p id=&quot;607e&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;deadlock은 트랜젝션간의 교착상태를 의미합니다. 두개의 트랜젝션간에 각각의 트랜젝션이 가지고 있는 리소스의 Lock을 획득하려고 할 때 발생합니다.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; width=&quot;576&quot; height=&quot;492&quot; data-origin-width=&quot;60&quot; data-origin-height=&quot;51&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/dmlUce/btq99cEYGtI/PzC328vQ5Fg3HPJTIyXd91/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/dmlUce/btq99cEYGtI/PzC328vQ5Fg3HPJTIyXd91/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/dmlUce/btq99cEYGtI/PzC328vQ5Fg3HPJTIyXd91/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdmlUce%2Fbtq99cEYGtI%2FPzC328vQ5Fg3HPJTIyXd91%2Fimg.png&quot; width=&quot;576&quot; height=&quot;492&quot; data-origin-width=&quot;60&quot; data-origin-height=&quot;51&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;figure class=&quot;imageblock alignCenter&quot; srcset=&quot;https://miro.medium.com/max/276/1*RBAssm3L_5uDG2S-4nTWKg.png 276w, https://miro.medium.com/max/552/1*RBAssm3L_5uDG2S-4nTWKg.png 552w, https://miro.medium.com/max/576/1*RBAssm3L_5uDG2S-4nTWKg.png 576w&quot; width=&quot;576&quot; height=&quot;492&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;751&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/tGn8U/btradIQnXUY/zGdbRZPRDJ9quTR5KpWNn0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/tGn8U/btradIQnXUY/zGdbRZPRDJ9quTR5KpWNn0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/tGn8U/btradIQnXUY/zGdbRZPRDJ9quTR5KpWNn0/img.png&quot; srcset=&quot;https://miro.medium.com/max/276/1*RBAssm3L_5uDG2S-4nTWKg.png 276w, https://miro.medium.com/max/552/1*RBAssm3L_5uDG2S-4nTWKg.png 552w, https://miro.medium.com/max/576/1*RBAssm3L_5uDG2S-4nTWKg.png 576w&quot; width=&quot;576&quot; height=&quot;492&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;751&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Dead Lock Example1&lt;/p&gt;
&lt;p id=&quot;64d2&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;가장 흔히 떠올릴 수 있는 deadlock 상황입니다. 1번 트랜젝션에서 2번 리소스의 잠금을 획득, 2번 트랜젝션에서는 1번 리소스의 잠금을 획득한 상태입니다. 이때, 동시에 상대방의 데이터를 엑세스하려고 할때 기존의 Lock이 해제될 때까지 기다리게 되는 상황입니다.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; width=&quot;570&quot; height=&quot;499&quot; data-origin-width=&quot;60&quot; data-origin-height=&quot;52&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/eaFEHF/btraeyNRNo9/7hJUWs4mMm8IF3uyBuXPmK/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/eaFEHF/btraeyNRNo9/7hJUWs4mMm8IF3uyBuXPmK/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/eaFEHF/btraeyNRNo9/7hJUWs4mMm8IF3uyBuXPmK/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FeaFEHF%2FbtraeyNRNo9%2F7hJUWs4mMm8IF3uyBuXPmK%2Fimg.png&quot; width=&quot;570&quot; height=&quot;499&quot; data-origin-width=&quot;60&quot; data-origin-height=&quot;52&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;figure class=&quot;imageblock alignCenter&quot; srcset=&quot;https://miro.medium.com/max/276/1*oyvzeTR0huqpe8GbVRZX-w.png 276w, https://miro.medium.com/max/552/1*oyvzeTR0huqpe8GbVRZX-w.png 552w, https://miro.medium.com/max/570/1*oyvzeTR0huqpe8GbVRZX-w.png 570w&quot; width=&quot;570&quot; height=&quot;499&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;768&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/cuIx1w/btraetlaqaf/H8YYJe9RKr3fO5WKedbQAK/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/cuIx1w/btraetlaqaf/H8YYJe9RKr3fO5WKedbQAK/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/cuIx1w/btraetlaqaf/H8YYJe9RKr3fO5WKedbQAK/img.png&quot; srcset=&quot;https://miro.medium.com/max/276/1*oyvzeTR0huqpe8GbVRZX-w.png 276w, https://miro.medium.com/max/552/1*oyvzeTR0huqpe8GbVRZX-w.png 552w, https://miro.medium.com/max/570/1*oyvzeTR0huqpe8GbVRZX-w.png 570w&quot; width=&quot;570&quot; height=&quot;499&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;768&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Dead Lock Example2&lt;/p&gt;
&lt;p id=&quot;477b&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;두번째 예는, 1번 트랜젝션이 공유Lock을 설정하고 Sleep에 빠졌습니다. 이때 2번 트랜젝션은 배타적Lock을 설정하려고 할때, 무기한 기다리게되는 교착상태에 빠지게 됩니다.&lt;/p&gt;
&lt;p id=&quot;635f&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;Postgresql에서는 자동적으로 deadlock을 인지하고 교착상태를 해결하기 위하여 하나의 트랜젝션을 취소시킵니다. 그러나, 어떤 트랜젝션이 취소될 지 판단하기는 어렵습니다.&lt;/p&gt;
&lt;h2 id=&quot;5c36&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size26&quot;&gt;Lock Level &amp;amp; Escalation이란?&lt;/h2&gt;
&lt;p id=&quot;7396&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;SQL 명령어에 따라서 Lock의 설정대상이 데이터 row일지 database일지 나누어집니다.&lt;/p&gt;
&lt;ol style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li id=&quot;8dd1&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;b&gt;Row level&lt;/b&gt;, 변경하려는 row에만 lock을 설정하는 것을 의미합니다.&lt;/li&gt;
&lt;li id=&quot;3843&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;b&gt;Page level&lt;/b&gt;, 변경하려는 row가 담긴 데이터 page (또는 인덱스 페이지)에 lock을 설정합니다. 같은 페이지에 속한 row들은 변경작업과 무관하게 모두 lock에 의해 잠깁니다.&lt;/li&gt;
&lt;li id=&quot;34df&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;b&gt;Tabel level&lt;/b&gt;, 테이블과 인덱스에 모두 잠금을 설정합니다.&lt;span&gt;&amp;nbsp;&lt;/span&gt;Select table,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Alter table,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Vacuum,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Refresh,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Index,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Drop,&lt;span&gt;&amp;nbsp;&lt;/span&gt;Truncate&lt;span&gt;&amp;nbsp;&lt;/span&gt;등의 작업에서 해당레벨의 락이 설정됩니다.&lt;/li&gt;
&lt;li id=&quot;8723&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;b&gt;Database level&lt;/b&gt;, 데이터베이스를 복구하거나 스키마를 변경할 때 발생합니다.&lt;/li&gt;
&lt;/ol&gt;
&lt;p id=&quot;1ea1&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Escalation&lt;/b&gt;&lt;/p&gt;
&lt;p id=&quot;1520&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;Lock리소스가 임계치를 넘으면 Lock 레벨이 확장되는 것을 의미합니다. Lock 레벨이 낮을 수록 동시성이 좋아지지만, 관리해야할 Lock이 많아지기 때문에 메모리 효율성은 떨어집니다. 반대로 Lock레벨이 높을 수록 관리리소스는 낮지만, 동시성은 떨어집니다.&lt;/p&gt;
&lt;p id=&quot;c079&quot; data-selectable-paragraph=&quot;&quot; data-ke-size=&quot;size16&quot;&gt;참고링크&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li id=&quot;073f&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;a href=&quot;http://www.sqler.com/320577&quot;&gt;http://www.sqler.com/320577&lt;/a&gt;&lt;/li&gt;
&lt;li id=&quot;2ca4&quot; data-selectable-paragraph=&quot;&quot;&gt;&lt;a href=&quot;https://www.postgresql.org/docs/9.4/explicit-locking.html&quot;&gt;https://www.postgresql.org/docs/9.4/explicit-locking.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
      <category>Database/MS-SQL</category>
      <category>LOCK</category>
      <category>SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/679</guid>
      <comments>https://99lib.tistory.com/679#entry679comment</comments>
      <pubDate>Thu, 22 Jul 2021 15:58:34 +0900</pubDate>
    </item>
    <item>
      <title>[스크랩] Can DBCC SHRINKFILE Cause Blocking in SQL Server?</title>
      <link>https://99lib.tistory.com/678</link>
      <description>&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&lt;/a&gt;&lt;/p&gt;
&lt;figure id=&quot;og_1626936991963&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;article&quot; data-og-title=&quot;Can DBCC SHRINKFILE Cause Blocking in SQL Server? - Brent Ozar Unlimited&amp;reg;&quot; data-og-description=&quot;It sure can. The lock risks of shrinking data files in SQL Server aren&amp;rsquo;t very well documented. Many people have written about shrinking files being a bad regular practice&amp;mdash; and that&amp;rsquo;s totally true. But sometimes you may need to run a one-time operatio&quot; data-og-host=&quot;www.brentozar.com&quot; data-og-source-url=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&quot; data-og-url=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/bSNseX/hyKXQLCKlj/k6ZovRmHiwUsEHAhDCetC0/img.png?width=600&amp;amp;height=81&amp;amp;face=0_0_600_81,https://scrap.kakaocdn.net/dn/dOTFV8/hyKXSQd4oq/B2Kr1Xpuyu4KQRszPdc3R1/img.png?width=1075&amp;amp;height=146&amp;amp;face=0_0_1075_146&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/bSNseX/hyKXQLCKlj/k6ZovRmHiwUsEHAhDCetC0/img.png?width=600&amp;amp;height=81&amp;amp;face=0_0_600_81,https://scrap.kakaocdn.net/dn/dOTFV8/hyKXSQd4oq/B2Kr1Xpuyu4KQRszPdc3R1/img.png?width=1075&amp;amp;height=146&amp;amp;face=0_0_1075_146');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;Can DBCC SHRINKFILE Cause Blocking in SQL Server? - Brent Ozar Unlimited&amp;reg;&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;It sure can. The lock risks of shrinking data files in SQL Server aren&amp;rsquo;t very well documented. Many people have written about shrinking files being a bad regular practice&amp;mdash; and that&amp;rsquo;s totally true. But sometimes you may need to run a one-time operatio&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;www.brentozar.com&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span&gt;Last Updated&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;January 11, 2018&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/author/kendra-little/&quot;&gt;Kendra Little&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/category/development/locking-blocking-and-isolation-levels/&quot;&gt;Locking, Blocking, and Isolation Levels&lt;/a&gt;,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://www.brentozar.com/archive/category/sql-server/&quot;&gt;SQL Server&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2015/04/dbcc-shrinkfile-blocking-locks-in-sql-server/#comments&quot;&gt;36&lt;span&gt;Comments&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;It sure can.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;The lock risks of shrinking data files in SQL Server aren&amp;rsquo;t very well documented. Many people have written about&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2009/08/stop-shrinking-your-database-files-seriously-now/&quot;&gt;shrinking files being a bad regular practice&lt;/a&gt;&amp;mdash; and that&amp;rsquo;s totally true. But sometimes you may need to run a one-time operation if you&amp;rsquo;ve been able to clear out or archive a lot of data. And you might wonder what kind of pains shrinking could cause you.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;One pain it could cause you is blocking and lock waits. It&amp;rsquo;s easy to reproduce, here&amp;rsquo;s how.&lt;/p&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;A Recipe for LCK_M_X Lock&amp;nbsp;Waits and Blocking&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I was able to easily reproduce blocking in my&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2014/01/how-to-query-the-stackexchange-databases/&quot;&gt;restored copy of the StackOverflow database&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;on SQL Server 2014 by doing a few things.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I rebuilt a non-clustered index on the Posts table with this command:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td data-settings=&quot;show&quot;&gt;&lt;span&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;ALTER &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;INDEX&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;[&lt;span style=&quot;color: #002d7a;&quot;&gt;kl_Posts_OwnerUserId_CreationDate&lt;/span&gt;]&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;on &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;Posts &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;REBUILD &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;(&lt;span style=&quot;color: #002d7a;&quot;&gt;ONLINE&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;ON&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;This ate up some space, and gave shrink something to do!&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I then started a data modification and left an open transaction running:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td data-settings=&quot;show&quot;&gt;&lt;span&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;BEGIN &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;TRAN&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;DELETE &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;FROM &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #004ed0;&quot;&gt;Posts &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;where &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ce0000;&quot;&gt;16&lt;/span&gt;;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;And then, in another session, I started to shrink the data file:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td data-settings=&quot;show&quot;&gt;&lt;span&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;DBCC &lt;/span&gt;&lt;span style=&quot;color: #004ed0;&quot;&gt;SHRINKFILE&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;(&lt;span style=&quot;color: #008000;&quot;&gt;'StackOverflow'&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;Behold, Blocking!&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Shrink starts up and slogs its way through things, and soon enough, lock waits appear. This view is from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://twitter.com/adammachanic&quot;&gt;Adam Machanic&lt;/a&gt;&amp;lsquo;s&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://sqlblog.com/files/default.aspx&quot;&gt;sp_WhoIsActive&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; srcset=&quot;https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-600x81.png 600w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-300x41.png 300w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-250x34.png 250w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-130x18.png 130w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits.png 1075w&quot; width=&quot;600&quot; height=&quot;81&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;119&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/ccQVqx/btraidIRzsN/BQu9JDV7fWe4gIaELkXzA0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/ccQVqx/btraidIRzsN/BQu9JDV7fWe4gIaELkXzA0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/ccQVqx/btraidIRzsN/BQu9JDV7fWe4gIaELkXzA0/img.png&quot; srcset=&quot;https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-600x81.png 600w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-300x41.png 300w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-250x34.png 250w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits-130x18.png 130w, https://www.brentozar.com/wp-content/uploads/2015/03/lock-waits.png 1075w&quot; width=&quot;600&quot; height=&quot;81&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;119&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;I&amp;rsquo;ll take LCK_M_X Waits for 15,000, Alex!&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;If I run that with @get_locks=1, I can see details on exactly what lock SHRINKFILE is after:&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td data-settings=&quot;show&quot;&gt;&lt;span&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span&gt;3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;4&lt;/span&gt;&lt;br /&gt;&lt;span&gt;5&lt;/span&gt;&lt;br /&gt;&lt;span&gt;6&lt;/span&gt;&lt;br /&gt;&lt;span&gt;7&lt;/span&gt;&lt;br /&gt;&lt;span&gt;8&lt;/span&gt;&lt;br /&gt;&lt;span&gt;9&lt;/span&gt;&lt;br /&gt;&lt;span&gt;10&lt;/span&gt;&lt;br /&gt;&lt;span&gt;11&lt;/span&gt;&lt;br /&gt;&lt;span&gt;12&lt;/span&gt;&lt;br /&gt;&lt;span&gt;13&lt;/span&gt;&lt;br /&gt;&lt;span&gt;14&lt;/span&gt;&lt;br /&gt;&lt;span&gt;15&lt;/span&gt;&lt;br /&gt;&lt;span&gt;16&lt;/span&gt;&lt;br /&gt;&lt;span&gt;17&lt;/span&gt;&lt;br /&gt;&lt;span&gt;18&lt;/span&gt;&lt;br /&gt;&lt;span&gt;19&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Database &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;StackOverflow&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Lock &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_mode&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;S&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_status&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;GRANT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_count&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #002d7a;&quot;&gt;Objects&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #800080;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;(null)&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Lock &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;resource_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;FILE.FILE_SHRINK&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_mode&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;X&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_status&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;GRANT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_count&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #800080;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;Posts&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;schema_name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;dbo&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Lock &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;resource_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;OBJECT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_mode&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;IX&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_status&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;GRANT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_count&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Lock &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;resource_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;PAGE&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;page_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;index_name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;kl_Posts_OwnerUserId_CreationDate&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_mode&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;X&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_status&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;GRANT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_count&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;3&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #004ed0;&quot;&gt;Lock &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;resource_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;PAGE&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;page_type&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;index_name&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;kl_Posts_OwnerUserId_CreationDate&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_mode&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;X&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_status&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;WAIT&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;request_count&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Locks&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Objects&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;lt&lt;/span&gt;;&lt;span style=&quot;color: #006fe0;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;Database&lt;/span&gt;&lt;span style=&quot;color: #006fe0;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #002d7a;&quot;&gt;gt&lt;/span&gt;;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Yep, it&amp;rsquo;s waiting on a page lock in kl_Posts_OwnerUserId_CreationDate.&lt;/p&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;But How Many Locks did SHRINKFILE Really Need?&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Maybe it needed just a few locks&amp;hellip; right?&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Well, I ran a trace against my session that did that shrinkfile command, and here&amp;rsquo;s the number of locks by database and type that it caught&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignCenter&quot; srcset=&quot;https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks.png 454w, https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks-246x200.png 246w, https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks-130x106.png 130w&quot; width=&quot;454&quot; height=&quot;369&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;715&quot; data-ke-mobilestyle=&quot;widthOrigin&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/DoXmp/btrafNjHTa4/5ZSmRL43FpX5KL2NgXdoC0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/DoXmp/btrafNjHTa4/5ZSmRL43FpX5KL2NgXdoC0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/DoXmp/btrafNjHTa4/5ZSmRL43FpX5KL2NgXdoC0/img.png&quot; srcset=&quot;https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks.png 454w, https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks-246x200.png 246w, https://www.brentozar.com/wp-content/uploads/2015/03/a-few-locks-130x106.png 130w&quot; width=&quot;454&quot; height=&quot;369&quot; data-origin-width=&quot;880&quot; data-origin-height=&quot;715&quot; data-ke-mobilestyle=&quot;widthOrigin&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Lock mode: XTreme&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;And this was a FAST run, except for that blocking!&lt;/p&gt;
&lt;h3 data-ke-size=&quot;size23&quot;&gt;Shrinking files is painful&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;It can actually be worse than this &amp;mdash; on a few runs, I was able to reproduce blocking with SCH_M locks that could cause even nastier blocking chains.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Shrinking is slow, tedious work. It eats CPU, steals your IO, and always takes longer than you want. And if it has work to do and you&amp;rsquo;ve got users or processors modifying that data, lock contention ensues.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;Worst of all, at the end of shrinking a database, nobody will ever thank you. Be careful out there, and&amp;nbsp;if you must run it make sure you don&amp;rsquo;t leave it unattended.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Brent says:&lt;/b&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;whoa, I never even thought about that. Maybe we should design indexes to improve DBCC SHRINKDB speed.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;Erik says:&lt;/b&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;if you do this more than once, I will come find you.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>Database/MS-SQL</category>
      <category>LOCK</category>
      <category>SHRINK</category>
      <category>SQL</category>
      <author>99iberty</author>
      <guid isPermaLink="true">https://99lib.tistory.com/678</guid>
      <comments>https://99lib.tistory.com/678#entry678comment</comments>
      <pubDate>Thu, 22 Jul 2021 15:57:17 +0900</pubDate>
    </item>
  </channel>
</rss>