microsoft / microsoft/sqlmanagementobjects
SMO, CREATE DATABASE: doesn't always replicate file/filegroups accurately.
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 143
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Imagine a database on server A, with several files: PRIMARY DATA, LOG, and additional DATA files belonging to a filegroup. Now imagine you have server B. You want to swap the DATA/LOG drives from server A, to server B, for example, to do a "quick" OS/SQL upgrade (obviously, in a virtual/cloud environment). So: you prepare a new server, flip the drives, and voila.
Before moving the volumes you need to pre-create the database on server B, such that when you flip volumes and boot the SQL Server B, the database is known, and goes ONLINE (yes, I am aware of other db-scoped attributes, login mappings, etc.), but bear with me. :-)
Then, you use SMO/Database to script the database create. It builds the CREATE DATABASE and adds all of the necessary files.
Then, you swap the volumes, boot server B -- and sometimes . . . . you get an error, something like:
2023-05-25 10:30:18.060 spid27s An unexpected file id was encountered. File id 3 was expected but 7 was read from "E:\MSSQL\DATA\blah_5_new.mdf". Verify that files are mapped correctly in sys.master_files. ALTER DATABASE can be used to correct the mappings.
What we found, is that SMO isn't "accurately" building the CREATE DATABASE statement. It adds all files into one statement. That is incorrect (in this case, at least). What it should be doing, is building CREATE DATABASE for the primary DATA and LOG files, and then using a combination of ALTER DATABASE {database} ADD FILE (or REMOVE FILE), to match the fileId values, and more importantly to introduce required "gaps" into the fileId values.
We wrote such code to solve this problem. Was wondering if SMO should be "fixed" too, if deemed a bug? Admittedly, if you're just moving random databases between machines this logic is necessary, but if you're moving ALL databases on a machine, then it comes into play.
Thanks!
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
CREATE DATABASE ステートメントを生成する SMO Database のスクリプト処理パスから開始し、次に、primary、log、および追加の filegroup のファイルに fileId 値の欠落があるケースを再現します。生成されたスクリプトを、必要な CREATE DATABASE と ALTER DATABASE ADD FILE または REMOVE FILE 操作と比較します。ボリュームを移動してサーバーを起動した後も、スクリプト化されたデータベースが元のファイル マッピングを保持していれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, sql
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100