diff --git a/src/metabase/db/spec.clj b/src/metabase/db/spec.clj
index 68f9acd5a39f2b19d40232fedd2505c4d04a1b1d..ba09f511f30a30c3e95a5cc7c1d5c70e958d7267 100644
--- a/src/metabase/db/spec.clj
+++ b/src/metabase/db/spec.clj
@@ -3,9 +3,9 @@
   Only databases that are supported as application DBs should have functions in this namespace;
   otherwise, similar functions are only needed by drivers, and belong in those namespaces."
   (:require [clojure.string :as str]
+            [medley.core :as m]
             [ring.util.codec :as codec]))
 
-
 (defn h2
   "Create a database specification for a h2 database. Opts should include a key
   for :db which is the path to the database file."
@@ -18,11 +18,14 @@
          (dissoc opts :db)))
 
 (defn- remove-required-keys [db-spec & more-keys]
-  (apply dissoc db-spec (concat [:host :port :db :user :password :additional-options]
+  (apply dissoc db-spec (concat [:host :port :db :dbname :user :password :additional-options]
                                 more-keys)))
 
+(defn- purge-nil-values [m]
+  (m/remove-kv (fn [k v] (or (nil? k) (nil? v))) m))
+
 (defn- make-subname [host port db extra-connection-params]
-  (let [query-params (codec/form-encode extra-connection-params)]
+  (let [query-params (codec/form-encode (purge-nil-values extra-connection-params))]
     (str "//" host ":" port "/" db (when-not (str/blank? query-params)
                                      (str "?" query-params)))))
 
diff --git a/test/metabase/db/spec_test.clj b/test/metabase/db/spec_test.clj
new file mode 100644
index 0000000000000000000000000000000000000000..fcbe3584b34fb809a770f71550f336bb74a0e510
--- /dev/null
+++ b/test/metabase/db/spec_test.clj
@@ -0,0 +1,36 @@
+(ns metabase.db.spec-test
+  (:require [expectations :refer :all]
+            [metabase.db.spec :refer :all]))
+
+(defn- default-pg-spec [db]
+  {:classname "org.postgresql.Driver", :subprotocol "postgresql",
+   :subname (format "//localhost:5432/%s?OpenSourceSubProtocolOverride=true" db)})
+
+;; Basic minimal config
+(expect
+  (default-pg-spec "metabase")
+  (postgres {:host "localhost"
+             :port 5432
+             :db   "metabase"}))
+
+;; Users that don't specify a `:dbname` (and thus no `:db`) will use the user's default, we should allow that
+(expect
+  (assoc (default-pg-spec "") :dbname nil)
+  (postgres {:host   "localhost"
+             :port   5432
+             :dbname nil
+             :db     nil}))
+
+;; We should be tolerant of other random nil values sneaking through
+(expect
+  (assoc (default-pg-spec "") :dbname nil, :somethingrandom nil)
+  (postgres {:host            "localhost"
+             :port            5432
+             :dbname          nil
+             :db              nil
+             :somethingrandom nil}))
+
+;; Not specifying any of the values results in defaults
+(expect
+  (default-pg-spec "")
+  (postgres {}))