microsoft / microsoft/sqlmanagementobjects
SMO, CREATE DATABASE: doesn't always replicate file/filegroups accurately.
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 143
- Fork
- 28
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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!
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziare dal percorso di scripting di SMO Database che produce istruzioni CREATE DATABASE, quindi riprodurre il caso con file dei filegroup primario, di log e aggiuntivi contenenti lacune nei relativi valori di fileId. Confrontare lo script generato con le operazioni CREATE DATABASE e ALTER DATABASE ADD FILE o REMOVE FILE richieste. Il lavoro è completato quando il database sottoposto a scripting conserva le mappature dei file originali dopo lo spostamento dei volumi e l'avvio del server.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, sql
- Ambito
- databases
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100