Wednesday, October 13, 2010

Postgres: createuser failing

A collegue had an issue with createuser not working as expected. ie.


postgres:~$ createuser --createdb --no-createrole -pwprompt openuser
Shall the new role be a superuser? (y/n) y
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.0"?



As they say.. The devil is in the details.. the cause why this was failing was due the the single dash before the pwprompt, which made the command interpret is as the '-p' option. That option expects a decimal number to specify the port number, unfortunately it doesn't complain that the string to number conversion fails, which makes it end up using 0 as the port number.

A nasty time sink bug!