diff --git a/src/dbup-postgresql/PostgresqlConnectionOptions.cs b/src/dbup-postgresql/PostgresqlConnectionOptions.cs
index e503223..7eb088b 100644
--- a/src/dbup-postgresql/PostgresqlConnectionOptions.cs
+++ b/src/dbup-postgresql/PostgresqlConnectionOptions.cs
@@ -14,9 +14,14 @@ public class PostgresqlConnectionOptions
public X509Certificate2 ClientCertificate { get; set; }
///
- // Custom handler to verify the remote SSL certificate.
- // Ignored if Npgsql.NpgsqlConnectionStringBuilder.TrustServerCertificate is set.
+ /// Custom handler to verify the remote SSL certificate.
+ /// Ignored if Npgsql.NpgsqlConnectionStringBuilder.TrustServerCertificate is set.
///
public RemoteCertificateValidationCallback UserCertificateValidationCallback { get; set; }
+
+ ///
+ /// The database to connect to initially. Default is 'postgres'.
+ ///
+ public string MasterDatabaseName { get; set; } = "postgres";
}
}
diff --git a/src/dbup-postgresql/PostgresqlExtensions.cs b/src/dbup-postgresql/PostgresqlExtensions.cs
index 8a5a77c..6033481 100644
--- a/src/dbup-postgresql/PostgresqlExtensions.cs
+++ b/src/dbup-postgresql/PostgresqlExtensions.cs
@@ -159,7 +159,12 @@ private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase
PostgresqlDatabase(supported, connectionString, logger, options);
}
- private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase supported, string connectionString, IUpgradeLog logger, PostgresqlConnectionOptions connectionOptions)
+ private static void PostgresqlDatabase(
+ this SupportedDatabasesForEnsureDatabase supported,
+ string connectionString,
+ IUpgradeLog logger,
+ PostgresqlConnectionOptions connectionOptions
+ )
{
if (supported == null) throw new ArgumentNullException("supported");
@@ -179,7 +184,7 @@ private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase
throw new InvalidOperationException("The connection string does not specify a database name.");
}
- masterConnectionStringBuilder.Database = "postgres";
+ masterConnectionStringBuilder.Database = connectionOptions.MasterDatabaseName;
var logMasterConnectionStringBuilder = new NpgsqlConnectionStringBuilder(masterConnectionStringBuilder.ConnectionString);
if (!string.IsNullOrEmpty(logMasterConnectionStringBuilder.Password))