+(defmethod database-create (connection-spec (type (eql :postgresql)))
+ (destructuring-bind (host name user password) connection-spec
+ (declare (ignore password))
+ (let ((asdf::*verbose-out* (make-string-output-stream)))
+ (unwind-protect
+ (let* ((status (asdf:run-shell-command
+ "su -c ~A createdb -h~A ~A"
+ user
+ (if host host "localhost")
+ name))
+ (result (get-output-stream-string asdf::*verbose-out*)))
+
+ (if (search "database creation failed: ERROR:" result)
+ (error 'clsql-access-error
+ :connection-spec connection-spec
+ :database-type type
+ :error
+ (format nil "database-create failed: ~s" result))
+ t))
+ (close asdf::*verbose-out*)))))
+
+(defmethod database-destroy (connection-spec (type (eql :postgresql)))
+ (destructuring-bind (host name user password) connection-spec
+ (declare (ignore password))
+ (let ((asdf::*verbose-out* (make-string-output-stream)))
+ (unwind-protect
+ (let* ((status (asdf:run-shell-command
+ "su -c ~A dropdb -h~A ~A"
+ user
+ (if host host "localhost")
+ name))
+ (result (get-output-stream-string asdf::*verbose-out*)))
+
+ (if (search "database removal failed: ERROR:" result)
+ (error 'clsql-access-error
+ :connection-spec connection-spec
+ :database-type type
+ :error
+ (format nil "database-destroy failed: ~s" result))
+ t))
+ (close asdf::*verbose-out*)))))
+
+
+(defmethod database-probe (connection-spec (type (eql :postgresql)))
+ (destructuring-bind (host name user password) connection-spec
+ (let ((database (database-connect (list host "template1" user password)
+ type)))
+ (unwind-protect
+ (find name (database-query "select datname from pg_database"
+ database :auto)
+ :key #'car :test #'string-equal)
+ (database-disconnect database)))))