关于连接PostgreSQL时提示 FATAL: password authentication fail
关于连接PostgreSQL时提示FATAL:passwordauthenticationfailedforuser"连接用户名"的解决方法 ALTERROLEpostbbs SUPERUSER VALIDUNTIL'1970-01-0100:00:00'; 三、采用密码文件认证,但里面的密码是错误的,则会出现如下的提示 [postgres@pgsqldb-masterbin]$cat/home/postgres/.pgpass 127.0.0.1:5432:*:postgres:1234 [postgres@pgsqldb-masterbin]$psql-h127.0.0.1-Upostgres-dpostgres psql:FATAL:passwordauthenticationfailedforuser"postgres" passwordretrievedfromfile"/home/postgres/.pgpass" 解决方法 1、修改.pgpass文件,将密码修改正确,注意,linux下.pgpass的访问权限要设置成0600 2、如果用户无法修改密码文件,则连接时加-W,强制输入密码 [postgres@pgsqldb-masterbin]$psql-h127.0.0.1-Upostgres-dpostgres-W Passwordforuserpostgres: psql(9.2.3) Type"help"forhelp. postgres=# 四、低级错误,用户名不存在 [postgres@pgsqldb-masterbin]$psql-h127.0.0.1-Uposgres-dpostgres-W Passwordforuserposgres: psql:FATAL:passwordauthenticationfailedforuser"posgres" [postgres@pgsqldb-masterbin]$psql-h127.0.0.1-UpostGres-dpostgres-W PasswordforuserpostGres: psql:FATAL:passwordauthenticationfailedforuser"postGres" 这样的大头虾错误不看清楚往往更难发现,注意用户名也是区分大小写的 五、修改了用户密码采用md5加密的用户名 [postgres@pgsqldb-masterbin]$psql-h127.0.0.1-Upostgres-dpostgres-W Passwordforuserpostgres: psql(9.2.3) Type"help"forhelp. postgres=#alterrolepostbbswithENCRYPTEDpassword'123'; ALTERROLE postgres=#alterrolepostgreswithENCRYPTEDpassword'123'; ALTERROLE postgres=#SELECTrolname,rolpasswordFROMpg_authid; rolname|rolpassword ----------+------------------------------------- postbbs|md5514d208ad0f8842c176b4836992f1cbb postgres|md59df270eb52907fff723d9b8b7436113a (2rows) 密码一样都是"123"不同用户名,生成的md5编码也是不样的 postgres=#alterrolepostbbsrenametopostbbs_1; NOTICE:MD5passwordclearedbecauSEOfrolerename ALTERROLE postgres=#SELECTrolname,rolpasswordFROMpg_authid; rolname|rolpassword -----------+------------------------------------- postgres|md59df270eb52907fff723d9b8b7436113a postbbs_1| (2rows) 因为MD5加密的口令使用角色名字作为加密的盐粒,所以,如果口令是MD5加密的,那么给一个用户改名会清空其口令 更详细的说明http://www.postgresql.org/docs/9.2/static/sql-alterrole.html postgres=#cpostgrespostbbs_1 Passwordforuserpostbbs_1: FATAL:passwordauthenticationfailedforuser"postbbs_1" Previousconnectionkept 由于密码清空,所以也就无法认证 postgres=#alterrolepostbbs_1withUNENCRYPTEDpassword'123'; ALTERROLE postgres=#SELECTrolname,rolpasswordFROMpg_authid; rolname|rolpassword -----------+------------------------------------- postgres|md59df270eb52907fff723d9b8b7436113a postbbs_1|123 (2rows) postgres=#alterrolepostbbs_1renametopostbbs; ALTERROLE postgres=#SELECTrolname,rolpasswordFROMpg_authid; rolname|rolpassword ----------+------------------------------------- postgres|md59df270eb52907fff723d9b8b7436113a postbbs|123 (2rows) postgres=#cpostgrespostbbs Passwordforuserpostbbs: Youarenowconnectedtodatabase"postgres"asuser"postbbs". postgres=> 采用明码密码存储的话,修改前后密码保持不变,所以可以认证 所以修改MD5加密认证用户名时应采用这样的做法,这一点本人认为有些不友好,因为原来md5密码我们是不知道明文的 postgres=>cpostgrespostgres Passwordforuserpostgres: Youarenowconnectedtodatabase"postgres"asuser"postgres". postgres=#alterrolepostbbsrenametopostbbs_1; ALTERROLE postgres=#alterrolepostbbs_1withpassword'123'; ALTERROLE postgres=# 六、一台主机上将了多个不同port的Postgresql服务,连接时指向的port不正确 [postgres@pgsqldb-masterbin]$psql-h192.168.1.100-Upostgres-dpostgres Passwordforuserpostgres: psql:FATAL:passwordauthenticationfailedforuser"postgres" 默认的5432port里面的用户postgres密码不是123 [postgres@pgsqldb-masterbin]$psql-h192.168.1.100-Upostgres-dpostgres-p9240 Passwordforuserpostgres: psql(9.2.3,server9.2.4) Type"help"forhelp. postgres=# port为9240的用户postgres密码才是123 这样的错误也是属于比较大头虾的错误 本文转自:http://www.myexception.cn/operating-system/1348177.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |