Skip to content

Commit f0fc700

Browse files
authored
Merge pull request #347 from Mytherin/issue341
Fix #341: add mutex to querying using Postgres connection
2 parents 9ea169b + 09aee86 commit f0fc700

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
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) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# name: test/sql/storage/attach_show_all_tables.test
2+
# description: Test attaching using a secret
3+
# group: [storage]
4+
5+
require postgres_scanner
6+
7+
require-env POSTGRES_TEST_DATABASE_AVAILABLE
8+
9+
statement ok
10+
PRAGMA enable_verification
11+
12+
statement ok
13+
ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES)
14+
15+
statement ok
16+
USE s
17+
18+
statement ok
19+
SHOW ALL TABLES

0 commit comments

Comments
 (0)