Skip to content

Commit 778bb00

Browse files
authored
Allow configuring a custom user agent for DuckDB (#989)
1 parent 46790bf commit 778bb00

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

docs/settings.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ Allows mixed transactions between DuckDB and PostgreSQL. This experimental setti
147147
- **Default**: `false`
148148
- **Access**: General
149149

150+
### `duckdb.custom_user_agent`
151+
152+
Appends a custom string to the DuckDB user agent (this is appended after `pg_duckdb`).
153+
154+
- **Default**: `""` (empty string)
155+
- **Access**: Superuser-only
156+
150157
## File System and Storage
151158

152159
### `duckdb.temporary_directory`

include/pgduckdb/pgduckdb_guc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ extern char *duckdb_extension_directory;
2727
extern char *duckdb_max_temp_directory_size;
2828
extern char *duckdb_default_collation;
2929
extern char *duckdb_azure_transport_option_type;
30+
extern char *duckdb_custom_user_agent;
3031
} // namespace pgduckdb

src/pgduckdb_duckdb.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ DuckDBManager::Initialize() {
100100
std::filesystem::create_directories(duckdb_extension_directory);
101101

102102
duckdb::DBConfig config;
103-
config.SetOptionByName("custom_user_agent", "pg_duckdb");
103+
std::string user_agent = "pg_duckdb";
104+
if (!IsEmptyString(duckdb_custom_user_agent)) {
105+
user_agent += " ";
106+
user_agent += duckdb_custom_user_agent;
107+
}
108+
config.SetOptionByName("custom_user_agent", user_agent);
104109
config.SetOptionByName("default_null_order", "postgres");
105110

106111
SET_DUCKDB_OPTION(allow_unsigned_extensions);

src/pgduckdb_guc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ char *duckdb_extension_directory = MakeDirName("extensions");
141141
char *duckdb_max_temp_directory_size = strdup("");
142142
char *duckdb_default_collation = strdup("");
143143
char *duckdb_azure_transport_option_type = strdup("");
144+
char *duckdb_custom_user_agent = strdup("");
144145

145146
void
146147
InitGUC() {
@@ -243,6 +244,9 @@ InitGUC() {
243244
"Set the azure_transport_option_type for DuckDB Azure extension. Can be used to "
244245
"workaround issue #882: https://github.com/duckdb/pg_duckdb/issues/882",
245246
&duckdb_azure_transport_option_type, PGC_SUSET);
247+
248+
DefineCustomDuckDBVariable("duckdb.custom_user_agent", "Additional user agent string to append to 'pg_duckdb'",
249+
&duckdb_custom_user_agent, PGC_SUSET);
246250
}
247251

248252
#if PG_VERSION_NUM < 160000

0 commit comments

Comments
 (0)