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

Cannot refresh materialized view with npgsql #111892

Closed
rutkowskii opened this issue Oct 6, 2023 · 4 comments
Closed

Cannot refresh materialized view with npgsql #111892

rutkowskii opened this issue Oct 6, 2023 · 4 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@rutkowskii
Copy link

rutkowskii commented Oct 6, 2023

Cockroach version: v21.2.7 (x86_64-unknown-linux-gnu, built 2022/03/14 16:37:26, go1.16.6)
Npgsql version: 7.0.4

Each attempt to refresh a materialized view via Npgsql:

 var cs =_dbConnectionStringProvider.ConnectionString("StateDb") +";POOLING=FALSE";

        await using (NpgsqlConnection conn = new NpgsqlConnection(cs))
        {
            await conn.OpenAsync();

            // Ensure that the connection is not in a transaction
            using (var cmd = new NpgsqlCommand(@"refresh materialized view ""V_view""", conn))
            {
                await cmd.ExecuteNonQueryAsync();
            }
        }

Causes an exception:

Npgsql.PostgresException (0x80004005): 25000: cannot refresh view in an explicit transaction
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|233_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at FleetManager.StateDb.Model.Commands.MaterializedViewsRefresher.ExecuteRefreshSql(FormattableString fs) in /home/ec2-user/buildAgent/work/a60a8c1d7e1070c6/src/FleetManager.StateDb.Model/Commands/MaterializedViewsRefresher.cs:line 77
   at FleetManager.StateDb.Model.Commands.MaterializedViewsRefresher.ExecuteRefreshSql(FormattableString fs) in /home/ec2-user/buildAgent/work/a60a8c1d7e1070c6/src/FleetManager.StateDb.Model/Commands/MaterializedViewsRefresher.cs:line 79
   at FleetManager.StateDb.Model.Commands.MaterializedViewsRefresher.RunCore(FormattableString cmd) in /home/ec2-user/buildAgent/work/a60a8c1d7e1070c6/src/FleetManager.StateDb.Model/Commands/MaterializedViewsRefresher.cs:line 55
  Exception data:
    Severity: ERROR
    SqlState: 25000
    MessageText: cannot refresh view in an explicit transaction
    File: refresh_materialized_view.go
    Line: 34
    Routine: RefreshMaterializedView

Running the same query: refresh materialized view ""V_view" via command line client works just fine.
I cannot easily update Cockroach server to the latest version here, maybe there are workarounds possible?

Jira issue: CRDB-32118

@rutkowskii rutkowskii added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Oct 6, 2023
@blathers-crl
Copy link

blathers-crl bot commented Oct 6, 2023

Hello, I am Blathers. I am here to help you get the issue triaged.

It looks like you have not filled out the issue in the format of any of our templates. To best assist you, we advise you to use one of these templates.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Oct 6, 2023
@yuzefovich yuzefovich added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed X-blathers-untriaged blathers was unable to find an owner labels Oct 12, 2023
@yuzefovich
Copy link
Member

The error message says cannot refresh view in an explicit transaction, so perhaps you need to specify some config option to not use the "explicit" transactions (i.e. avoid the tool to send BEGIN; and COMMIT;).

@rafiss
Copy link
Collaborator

rafiss commented Oct 17, 2023

Also, I saw that you're using v21.2.7 of CockroachDB. That version is no longer supported. Does the issue still happen with a newer version? v23.1.11 is the newest. https://www.cockroachlabs.com/docs/releases/

@rafiss
Copy link
Collaborator

rafiss commented Oct 24, 2023

#87271 fixed this behavior, but the fix is only in v22.1 or later. You will need to upgrade to avoid the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
No open projects
Archived in project
Development

No branches or pull requests

3 participants