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

First try with role reset #427

Merged
merged 5 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ impl Server {
if self.needs_cleanup {
warn!("Server returned with session state altered, discarding state");
self.query("DISCARD ALL").await?;
self.query("RESET ROLE;").await?;
atanner27 marked this conversation as resolved.
Show resolved Hide resolved
atanner27 marked this conversation as resolved.
Show resolved Hide resolved
self.needs_cleanup = false;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/ruby/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@

expect(processes.primary.count_query("DISCARD ALL")).to eq(10)
end

it "Resets server roles correctly" do
10.times do
conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user"))
conn.async_exec("SET SERVER ROLE to 'primary'")
conn.async_exec("SELECT 1")
conn.async_exec("SET statement_timeout to 5000")
conn.close
end

expect(processes.primary.count_query("RESET ROLE;")).to eq(10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we ALTER ROLE sharding_user ROLE TO <new role> to simulate the same error we saw in production?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the error, if you're willing to share. I'm not too familiar with RESET USER.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levkk we had 2 users in the DB, lets call them A and B.

We had run ALTER ROLE A SET ROLE B, which has the effect of running SET ROLE B after you open a connection with username A. We had configured pgbouncer and pgcat to both connect with username A.

When we run create table on pgbouncer, it was owned by B due to this config.

When we run create table on pgcat, a previous query had run DISCARD ALL in the pgcat server connection, and then the table was owned by A. We found that we could run RESET ROLE to fix it back to SET ROLE b after a DISCARD ALL was run.

Our permissions were all configured with assuming B owns the tables, so when we started creating tables with A as the owner after switching to pgcat, we had some errors.

atanner27 marked this conversation as resolved.
Show resolved Hide resolved
end
end

context "transaction mode" do
Expand Down