SQL Server query fails in newer version with "VIEW DATABASE PERFORMANCE STATE permission denied" error, despite only requiring "VIEW DEFINITION" permission

Hamza Mohammad 0 Reputation points
2024-09-02T05:47:17.2866667+00:00

I'm running a query in Synapse using the following tables: sys.query_store_plan, sys.query_store_query, and sys.query_store_query_text. This query executes successfully on SQL Server version 12.00.2531 with only the VIEW DEFINITION permission granted to the user via:
GRANT VIEW DEFINITION ON DATABASE::<database_name> TO <username>;

I am using the same exact query mentioned in the docs:

https://video2.skills-academy.com/en-us/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store?view=azuresqldb-current&preserve-view=true

SELECT Txt.query_text_id, Txt.query_sql_text, Pln.plan_id, Qry.*, RtSt.*
FROM sys.query_store_plan AS Pln
INNER JOIN sys.query_store_query AS Qry
    ON Pln.query_id = Qry.query_id
INNER JOIN sys.query_store_query_text AS Txt
    ON Qry.query_text_id = Txt.query_text_id
INNER JOIN sys.query_store_runtime_stats RtSt
ON Pln.plan_id = RtSt.plan_id;

However, when running the same query on synapse that is using SQL Server version 12.00.5624 with VIEW DEFINITION permission granted already, it fails with the following error:
2024-09-01 11:03:20.656 [main] ERROR c.Logging$GlobalExceptionHandler - Uncaught exception in thread 'main': 'com.microsoft.sqlserver.jdbc.SQLServerException: VIEW DATABASE PERFORMANCE STATE permission denied in database 'test'

This permission is required to access the DMVs but we are not accessing DMVs here. The above tables mentioned

What could be the cause of this discrepancy in required permissions between the two SQL Server versions?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,858 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,672 questions
{count} votes

2 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 26,706 Reputation points
    2024-09-02T06:10:44.83+00:00

    Hi @Hamza Mohammad

    The above tables mentioned

    Actually, they are not tables, they are system catalog views. See: Query Store catalog views.

    And the VIEW DATABASE STATE permission is required to use these views.

    See this doc: sys.query_store_plan (Transact-SQL).

    What could be the cause of this discrepancy in required permissions between the two SQL Server versions?

    Please double check the permission of these two different users.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. Erland Sommarskog 110.3K Reputation points
    2024-09-02T06:34:40.6033333+00:00

    I don't think there is no difference. Both in Synapse and Azure SQL Database, you need the permission VIEW DATABASE PERFORMANCE STATE to view Query Store data. Try this in Azure SQL Database:

    CREATE USER tempuser WITHOUT LOGIN
    GRANT VIEW DEFINITION TO tempuser
    go
    EXECUTE AS USER = 'tempuser'
    go
    SELECT Txt.query_text_id, Txt.query_sql_text, Pln.plan_id, Qry.*, RtSt.*
    FROM sys.query_store_plan AS Pln
    INNER JOIN sys.query_store_query AS Qry
        ON Pln.query_id = Qry.query_id
    INNER JOIN sys.query_store_query_text AS Txt
        ON Qry.query_text_id = Txt.query_text_id
    INNER JOIN sys.query_store_runtime_stats RtSt
    ON Pln.plan_id = RtSt.plan_id;
    go
    REVERT
    go
    DROP USER tempuser
    

    I would guess you are confused about the permissions of your test user in Azure SQL Databases. Presumably, the user is member of a role with the required permissions.


Your answer

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