Skip to content

Commit 09aee86

Browse files
committed
Add lock to Postgres connection
1 parent 51974e7 commit 09aee86

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/include/postgres_connection.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ struct IndexInfo;
2424

2525
struct OwnedPostgresConnection {
2626
explicit OwnedPostgresConnection(PGconn *conn = nullptr);
27+
OwnedPostgresConnection(const OwnedPostgresConnection &) = delete;
28+
OwnedPostgresConnection &operator=(const OwnedPostgresConnection &) = delete;
2729
~OwnedPostgresConnection();
2830

2931
PGconn *connection;
32+
mutex connection_lock;
3033
};
3134

3235
class PostgresConnection {

src/postgres_connection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ PGresult *PostgresConnection::PQExecute(const string &query) {
6868
}
6969

7070
unique_ptr<PostgresResult> PostgresConnection::TryQuery(const string &query, optional_ptr<string> error_message) {
71+
lock_guard<mutex> guard(connection->connection_lock);
7172
auto result = PQExecute(query.c_str());
7273
if (ResultHasError(result)) {
7374
if (error_message) {

test/sql/storage/attach_show_all_tables.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# name: test/sql/storage/attach_secret.test
1+
# name: test/sql/storage/attach_show_all_tables.test
22
# description: Test attaching using a secret
33
# group: [storage]
44

0 commit comments

Comments
 (0)