在进行远程备份或者登录时要手工输入密码,总是一件麻烦的事情。不过PG提供了一个简单的方法,那就是用密码文件的方式。这点PG和GP是相同的。

Linux下密码文件可在home路径下新建一个名为.pgpass的文件或者引用一个PGPASSFILE文件。

Windows下密码文件一般放的位置是%APPDATA%\postgresql\pgpass.conf,

比如C:\Documents and Settings\Administrator\Application Data\postgresql

密码文件有一个约定格式:

# regular syntax
#hostname:port:database:username:password

示例:

客户端IP:172.25.30.1

服务端IP:172.25.30.88  DB:test  User:chenlq   PWD:chenlq

首先在客户端创建密码文件

[postgres@localhost ~]$ vi /home/postgres/.pgpass

然后给个只读权限即可。

[postgres@localhost ~]$ chmod 400 .pgpass
[postgres@localhost ~]$ ls -al .pgpass
-r-------- 1 postgres postgres 93 03-07 15:25 .pgpass

然后往该文件中加服务端的连接信息

172.25.30.88:2012:test:chenlq:chenlq

[postgres@localhost ~]$ more .pgpass
# regular syntax
#hostname:port:database:username:password
172.25.30.88:2012:test:chenlq:chenlq

接下来在服务端的访问控制文件(pg_hba.conf)中也添加客户端的一些信息

host   test       chenlq             172.25.30.1/32          md5

在服务端没有reload的时候我们发现,客户端连接时是要求输入密码的,

[postgres@localhost ~]$ psql -h 172.25.30.88 -d test -U chenlq

Password for user chenlq:

reload一下

pg_ctl reload -D $PGDATA

 

客户端重新登录,OK了,不用输密码了。

[postgres@localhost ~]$ psql -h 172.25.30.88  -d test -U chenlq

psql (9.1.2)
Type "help" for help.

test=#

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐