Share via

PS vs sys.databases

Mikhail Firsov 1,881 Reputation points
2022-07-21T08:12:44.18+00:00

Hello,

I use daily db reports that are created in PowerShell and noted that the output of LogReuseWaitStatus is not always the same as that of log_reuse_wait_desc:

1) $dbname = Get-SQLDatabase
ForEach ($db in $dbname)
{
Write-Output "$($db.Name), $($db.Status), ..., $($db.LogReuseWaitStatus)" >> C:\REPORTS\SQL\SQL-DB.txt
}

2) SELECT D.name,
D.log_reuse_wait_desc
FROM sys.databases AS D

223004-02.png

As you see the Nothing and LogBackup are the same for both methods while Other in PS may mean Availability Replica in TSQL and 13 may mean OLDEST_Page.

I expected that both PS and TSQL would return the same output... - is that distinction by design?

Regards,
Michael

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

  1. Erland Sommarskog 134K Reputation points MVP Volunteer Moderator
    2022-07-21T08:29:10.43+00:00

    Checking the documentation for sys.databases, I see that 13 is indeed OLDEST_PAGE, so in this case PS has the same thing - it just doesn't have the translation correct.

    I also see that for log_resuse_wait there are two meanings for the value 9:
    9 = An Always On Availability Groups secondary replica is applying transaction log records of this database to a corresponding secondary database.
    9 = Other (Transient)

    So again, this seems to be due to that the PS module is doing it's own translation rather than relying on log_reuse_wait_desc.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Mikhail Firsov 1,881 Reputation points
    2022-07-21T08:39:24.133+00:00

    Thank you very much, ErlandSommarskog!

    Regards,
    Michael

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.