红联Linux门户
Linux帮助

新手安装postgreSQL后无法连接服务器

发布时间:2016-05-28 16:25:21来源:linux网站作者:explore

系统:Linux Deepin 15.1
postgreSQL:9.5.1
pgAdmin Ⅲ:1.22.0


使用新立得安装postgreSQL和pgAdminⅢ之后,打开pgAdmin需新建服务器。
打开新建服务器窗口后,名称可以随意填写,主机可以填localhost,端口默认5432,维护数据库默认postgres。
但用户名和密码无论咋填都无法连接服务器。


原因:新安装的postgreSQL里默认有一个数据库postgres,也有一个默认用户postgres,但该用户没有密码,而pgAdmin连接服务器必需填写密码。


解决方法:可以使用命令行窗口登录postgres数据库,然后修改用户postgres的密码。或者新建一个postgreSQL的用户,在设置密码。我采用的是第二种方案,步骤如下:
1、新建postgreSQL用户

sudo /bin/bash
# you should be root now 
su postgres
# you are postgres now
createuser --interactive
#createuser会提示你建立一个新用户,在这里我建立了一个用户test

2、修改密码

#登录数据库postgres
sudo -u postgres psql postgres
#登录后使用\password命令修改test的密码
postgres=# \password test

3、打开pgAdmin,新建服务器,填入刚刚设置的用户名和密码即可。


本文永久更新地址:http://www.linuxdiyf.com/linux/21040.html