Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlAgDatabase: Failing when AG is Automatic Seeding #1492

Closed
Jens-Sjolund opened this issue Apr 1, 2020 · 3 comments · Fixed by #1642 or #1666
Closed

SqlAgDatabase: Failing when AG is Automatic Seeding #1492

Jens-Sjolund opened this issue Apr 1, 2020 · 3 comments · Fixed by #1642 or #1666
Labels
bug The issue is a bug.

Comments

@Jens-Sjolund
Copy link

Jens-Sjolund commented Apr 1, 2020

Details of the scenario you tried and the problem that is occurring

When creating a new database and subsequently adding it to an Availability Group (using SqlAgDatabase) there are errors. This occurr when seeding is automatic, bu I have not tried with manual.

Verbose logs showing the problem

PowerShell DSC resource MSFT_SqlAGDatabase failed to execute Set-TargetResource functionality with error mess
age: The operation on the database 'TEST02_2019DSC' failed with the following errors: System.Exception: System
.InvalidOperationException: Executing non-query failed on database 'master'. (SQLCOMMON0046) ---> System.Manag
ement.Automation.MethodInvocationException: Exception calling "ExecuteNonQuery" with "1" argument(s): "Execute
NonQuery failed for Database 'master'. " ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Exe
cuteNonQuery failed for Database 'master'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureExcepti
on: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlExc
eption: The file 'K:\MSSQL\TEST02_2019DSC.mdf' cannot be overwritten. It is being used by database 'TEST02_20
19DSC'.
File 'TEST02_2019DSC' cannot be restored to 'K:\MSSQL\TEST02_2019DSC.mdf'. Use WITH MOVE to identify a valid l
ocation for the file.
The file 'L:\MSSQL\TEST02_2019DSC_log.ldf' cannot be overwritten. It is being used by database 'TEST02_2019DS
C'.
File 'TEST02_2019DSC_log' cannot be restored to 'L:\MSSQL\TEST02_2019DSC_log.ldf'. Use WITH MOVE to identify a
valid location for the file.
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
RESTORE DATABASE is terminating abnormally.

Suggested solution to the issue

Determine whether SEEDING_MODE = AUTOMATIC or MANUAL. Rows 482-567 may not be executed if seeding is automatic.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

    SqlAgDatabase 'AddAGDatabaseMembership'
    {
        ServerName              = $Node.NodeName
        InstanceName            = $ConfigurationData.DataBases.Instance
        DatabaseName            = $ConfigurationData.DataBases.Name
        AvailabilityGroupName   = $ConfigurationData.DataBases.AGName
        BackupPath              = $ConfigurationData.DataBases.BackupPath
        Ensure                  = 'Present'
        ProcessOnlyOnActiveNode = $true
        PsDscRunAsCredential = $SqlAdministratorCredential
    }

insert configuration here

instance of MSFT_SqlAGDatabase as $MSFT_SqlAGDatabase1ref
{
ResourceID = "[SqlAGDatabase]AddAGDatabaseMembership";
PsDscRunAsCredential = $MSFT_Credential10ref;
ServerName = "TS17";
InstanceName = "MSSQLSERVER";
BackupPath = "\\TS07\MSSQL_Backup";
SourceInfo = "D:\DSC\RFS591\SQLDB\CreateDatabase2.3.ps1::118::9::SqlAgDatabase";
DatabaseName = {
"TEST02_2019DSC"
};
AvailabilityGroupName = "TCLUPOC01AG01";
ModuleName = "SqlServerDsc";
ProcessOnlyOnActiveNode = True;
ModuleVersion = "13.4.0";
Ensure = "Present";
ConfigurationName = "CreateSQLDBTemplateConfig";

};

SQL Server edition and version the target node is running

Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)
+
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

SQL Server PowerShell modules present on the target node

Name Version Path


SQLPS 15.0 C:\Program Files (x86)\Microsoft SQL Server\150\Tools\PowerShell\Modules\SQLPS\SQLPS.psd1

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.3564.amd64fre.rs1_release.200303-1942
OsLanguage : en-US
OsMuiLanguages : {en-US}
+
OsName : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsVersion : 1809
WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.17763.1007
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1007
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used

Name Version Path


SqlServerDsc 13.4.0 C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\13.4.0\SqlServerDsc.psd1

@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Apr 1, 2020
@Fiander
Copy link
Contributor

Fiander commented Nov 27, 2020

Working on this one.

@Fiander Fiander mentioned this issue Dec 4, 2020
9 tasks
Fiander added a commit to Fiander/SqlServerDsc that referenced this issue Dec 4, 2020
@johlju johlju added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Dec 5, 2020
johlju pushed a commit that referenced this issue Dec 13, 2020
- SqlAGDatabase
  - Added AutomaticSeeding for this resource. In Set-TargetResource added logic that looks 
    at all replicas of an availability group. When automatic seeding is found, it will use that 
    (issue #1492).
  - Lots of extra tests to check AutomaticSeeding.
  - The parameter `BackupPath` is still needed just in case a database never has been backuped
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Dec 13, 2020
@Jens-Sjolund
Copy link
Author

@Fiander - Great work done! Just tried it and discovered the obligatory typo...
Look at row 450, the variable name 'needsBackup' is wrong. When I changed it the needed backup was made.

@Fiander
Copy link
Contributor

Fiander commented Jan 8, 2021

oops.

i think because on my test system all new databases are backuped to nul with a triger at create time i missed that one.
thank you, will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
3 participants