set blank password for PostgreSQL user

安稳与你 提交于 2019-12-02 14:50:02
nate c

You're barking up the wrong tree trying to fix this with createuser. If you care to check the man page for createuser it will tell you that login will fail if you really need a password and set --no-password. createuser actually just creates a user. It does not decide how the user will have to authenticate.

Authentication is handled mainly in pg_hba.conf, which decides whether or not to require passwords at login. I've never run PostgreSQL on OS X. On Linux, my distro's stock conf looks like this:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     ident
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

I would make sure you have something like the first line for for development access. Note: psql will try to connect with a unix socket if there is no --host option set. The second line would be used if you try to connect with psql --host localhost

Rather than creating a user with no password, create a .pgpass file with the password in to have it automatically supplied. This will be respected by all applications that use libpq to connect, which is practically all of them except the JDBC driver and the .NET driver.

The additional way (I prefere it) to change user's password for PG user is to login to postgres console (as a postgres user on a local pc), and issue SQL request:

$ sudo -u postgres psql -w

# ALTER USER postgres WITH PASSWORD '';
postgres=# ALTER USER postgres WITH PASSWORD '';
NOTICE:  empty string is not a valid password, clearing password
ALTER ROLE
postgres=# 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!