Skip to content

Detect that we are connected with Aurora, and avoid running snapshot code with Aurora in general #140

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

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/include/postgres_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace duckdb {

enum class PostgresInstanceType { POSTGRES, AURORA };

struct PostgresVersion {
PostgresVersion() {
}
Expand All @@ -22,6 +24,7 @@ struct PostgresVersion {
idx_t major_v = 0;
idx_t minor_v = 0;
idx_t patch_v = 0;
PostgresInstanceType type_v = PostgresInstanceType::POSTGRES;

inline bool operator<(const PostgresVersion &rhs) const {
if (major_v < rhs.major_v) {
Expand Down
5 changes: 4 additions & 1 deletion src/postgres_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ void PostgresConnection::Execute(const string &query) {
}

PostgresVersion PostgresConnection::GetPostgresVersion() {
auto result = Query("SHOW server_version;");
auto result = Query("SELECT CURRENT_SETTING('server_version'), (SELECT COUNT(*) FROM pg_settings WHERE name LIKE 'rds%')");
auto version = PostgresUtils::ExtractPostgresVersion(result->GetString(0, 0));
if (result->GetInt64(0, 1) > 0) {
version.type_v = PostgresInstanceType::AURORA;
}
return version;
}

Expand Down
10 changes: 7 additions & 3 deletions src/postgres_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ static void PostgresGetSnapshot(PostgresVersion version, PostgresBindData &bind_
unique_ptr<PostgresResult> result;
// by default disable snapshotting
bind_data.snapshot = string();
if (version.type_v == PostgresInstanceType::AURORA) {
return;
}
// reader threads can use the same snapshot
auto &con = bind_data.connection;
// pg_stat_wal_receiver was introduced in PostgreSQL 9.6
Expand Down Expand Up @@ -275,11 +278,12 @@ static unique_ptr<LocalTableFunctionState> GetLocalState(ClientContext &context,
}
local_state->column_ids = input.column_ids;

if (!bind_data.read_only) {
if (bind_data.read_only && bind_data.max_threads > 1) {
local_state->connection = PostgresScanConnect(bind_data.dsn, bind_data.snapshot);
} else {
// if we have made other modifications in this transaction we have to use the main connection
// alternatively, if we are only using a single thread to scan, we use the current connection as well
local_state->connection = PostgresConnection(bind_data.connection.GetConnection());
} else {
local_state->connection = PostgresScanConnect(bind_data.dsn, bind_data.snapshot);
}
local_state->filters = input.filters.get();
if (bind_data.pages_approx == 0 || bind_data.requires_materialization) {
Expand Down