Found a temporary solution to this problem.
According to psql man page:
-W, --password
Force psql to prompt for a password before connecting to a database. This option is never essential, since psql will automatically prompt for a password if the server demands password authentication. However, psql will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
So, connecting to postgres database through psql when a connection needs a password will ever prompt for a password in a buffer.
A temporary solution might be set the -w
option on psql call to not ask for a password. Then, it gets the password from the ~/.pgpass
file. This file has 0600 permissions so it is insecure. But works for me right now.
In the .emacs
file:
(custom-set-variables '(sql-postgres-options (quote ("-P" "pager=off" "-w"))))
A better solution might be using ssl certificates, which I will explore.
Thank you all for your help.