Skip to content

Commit e7397d3

Browse files
committed
Merge branch 'main' of github.com:duckdb/duckdb-postgres
2 parents 73b9a12 + 9c1a5bd commit e7397d3

File tree

8 files changed

+34
-5
lines changed

8 files changed

+34
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ if(WIN32)
9393
postgres/src/port/open.c
9494
postgres/src/port/pgsleep.c
9595
postgres/src/port/system.c
96+
postgres/src/port/dirmod.c
97+
postgres/src/port/win32common.c
9698
postgres/src/port/win32error.c
9799
postgres/src/port/win32ntdll.c
98100
postgres/src/port/win32setlocale.c
@@ -120,10 +122,10 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
120122
message(STATUS "Downloading PostgreSQL source code")
121123
file(
122124
DOWNLOAD
123-
"https://github.com/postgres/postgres/archive/refs/tags/REL_15_2.tar.gz"
125+
"https://github.com/postgres/postgres/archive/refs/tags/REL_15_13.tar.gz"
124126
${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz
125127
SHOW_PROGRESS
126-
EXPECTED_MD5 615ef3fa75d19c46d2dafd6c66ddb5f6
128+
EXPECTED_MD5 106c54e53aca9395354a251eeea914c0
127129
STATUS PG_DOWNLOAD_RESULT)
128130

129131
if(NOT PG_DOWNLOAD_RESULT EQUAL 0)
@@ -137,7 +139,7 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
137139
${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
138140

139141
# Move out of root directory
140-
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp/postgres-REL_15_2
142+
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp/postgres-REL_15_13
141143
${CMAKE_CURRENT_SOURCE_DIR}/postgres)
142144

143145
# Remove the tmp directory

extension_config.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ duckdb_extension_load(tpcds)
1212
duckdb_extension_load(json)
1313

1414
# Any extra extensions that should be built
15-
# e.g.: duckdb_extension_load(json)
15+
# e.g.: duckdb_extension_load(json)

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) {

src/postgres_extension.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ unique_ptr<BaseSecret> CreatePostgresSecretFunction(ClientContext &context, Crea
9292
result->secret_map["password"] = named_param.second.ToString();
9393
} else if (lower_name == "port") {
9494
result->secret_map["port"] = named_param.second.ToString();
95+
} else if (lower_name == "passfile") {
96+
result->secret_map["passfile"] = named_param.second.ToString();
9597
} else {
9698
throw InternalException("Unknown named parameter passed to CreatePostgresSecretFunction: " + lower_name);
9799
}
@@ -109,6 +111,7 @@ void SetPostgresSecretParameters(CreateSecretFunction &function) {
109111
function.named_parameters["user"] = LogicalType::VARCHAR;
110112
function.named_parameters["database"] = LogicalType::VARCHAR; // alias for dbname
111113
function.named_parameters["dbname"] = LogicalType::VARCHAR;
114+
function.named_parameters["passfile"] = LogicalType::VARCHAR;
112115
}
113116

114117
void SetPostgresNullByteReplacement(ClientContext &context, SetScope scope, Value &parameter) {

src/storage/postgres_catalog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ string PostgresCatalog::GetConnectionString(ClientContext &context, const string
9292
new_connection_info += AddConnectionOption(kv_secret, "host");
9393
new_connection_info += AddConnectionOption(kv_secret, "port");
9494
new_connection_info += AddConnectionOption(kv_secret, "dbname");
95+
new_connection_info += AddConnectionOption(kv_secret, "passfile");
9596

9697
connection_string = new_connection_info + connection_string;
9798
} else if (explicit_secret) {

test/sql/storage/attach_json.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ statement ok
1212
PRAGMA enable_verification
1313

1414
statement ok
15-
ATTACH 'dbname=postgresscanner' AS postgres_db (TYPE POSTGRES)
15+
ATTACH 'dbname=postgresscanner' AS postgres_db (TYPE POSTGRES, READ_WRITE)
1616

1717
statement ok
1818
CREATE OR REPLACE TABLE postgres_db.json_tbl AS SELECT '{"a": 42}'::JSON AS json_col
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)