Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to connect to a PostgreSQL DB thru Emacs using the sql-mode. I start Emacs, command M-x sql-postgres and it prompts for User, Database and Server but not for the password. An empty buffer opens and whatever I write, I get:

the Password for user james:
psql: FATAL:  password authentication failed for user "james"

I can login using psql, though. I'm running GNU Emacs 24.4.1 in Linux Antergos, PostgreSQL is 9.3.5.

Thanks..

share|improve this question

2 Answers 2

I solved this temporarily by creating a .pgpass file where I stored my connection credentials. I am not comfortable with that and would like a solution that requires inputing the password at login.

share|improve this answer

Edit: This answer is invalid. The sql-*-login-params variables and associated customize widgets are generalised across all database types, and not all options are applicable to all databases. In the case of postgres and psql, you cannot supply the password itself as part of the command line, which means that Emacs can't read the password in the minibuffer and incorporate it into the psql command. This is why the password option is disabled by default. Using an alternative (such as a .pgpass file) would seem to be necessary.

Original answer follows:

M-x customize-option RET sql-postgres-login-params RET

Tick the "password" option, and apply the change.

share|improve this answer
    
I get [no match]. –  James Brown Nov 5 '14 at 8:39
    
Sorry for being unclear. There is no match for sql-postgres-login-params. –  James Brown Nov 5 '14 at 9:21
    
It's available as of Emacs 24.1. Do make sure the library is actually loaded first (e.g. call M-x sql-postgres), or Emacs won't know about it. –  phils Nov 5 '14 at 9:25
    
I see. Now it prompts for the password and all the other credentials but I still get the psql: FATAL: password authentication failed for user "james". I triple checked and psql still works fine by itself. –  James Brown Nov 5 '14 at 9:34
    
Ah. Ok, this was all a red herring :/ The customize interface is generalised across all databases; but not all (non-default) options apply to all databases. Where applicable, passwords are read by Emacs and then used in the command line. psql doesn't allow the password to be supplied as part of the command, however, so there's no way for Emacs to use this approach here. Hence passwords are disabled by default, and you possibly do need to use some other approach. –  phils Nov 5 '14 at 10:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.