I connect to postgres by placing the following in a file on a remote server, opening over tramp, and executing:

(setq sql-connection-alist
         (sql-product 'postgres)
         (sql-server "localhost")
         (sql-user "postgres")
         (sql-password "postgres")
         (sql-database "my_db")
         (sql-port 5432))

;; emac25:
(sql-set-product-feature 'postgres :prompt-regexp "^.*=# ")

(defun sql-connect-preset (name)
  "Connect to a predefined SQL connection listed in `sql-connection-alist'"
  (eval `(let ,(cdr (assoc name sql-connection-alist))
    (noflet ((sql-get-login (&rest what)))
      (sql-product-interactive sql-product)))))

(sql-connect-preset 'pool-my_db)

If I execute the same script in the context of a different remote server, it just switches to the buffer for my first session. Is there a way to open subsequent SQL sessions in a new buffer so I can have multiple remote sql shells open at the same time?

  • What about renaming the SQL buffer before a further connection? Rename e.g. with rename-uniquely. (Wild guess, 100% untested.) – Marco Wahl Oct 7 '17 at 18:40
  • Thanks @MarcoWahl but didn't work. – EoghanM Oct 8 '17 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.