远程备份或者登录时总要手工输入密码,导致效率很低。

postgresql可以通过密码文件来实现”无钥验证“。

在用户的根目录下,需要创建一个.pgpass文件,并将权限设置为0600,就可以实现了。

 

文件的格式如下:

hostname:port:database:username:password

 

演示:

1.psql登入

[postgres@oradbca ~]$ cd
[postgres@oradbca ~]$ touch .pgpass
[postgres@oradbca ~]$ vi .pgpass 
192.168.1.11:5432:postgres:postgres:postgres
[postgres@oradbca ~]$ chmod 600 .pgpass 
[postgres@oradbca ~]$ psql -h 192.168.1.11 -p 5432 -d postgres -U postgres
psql (9.3.4)
Type "help" for help.

postgres=# 

 

2.pg_dump备份

pg_dump -d postgres -h 192.168.1.11 -p 5532 -U postgres >back.dmp

 

3.pg_basebackup同步

在使用pg_basebackup时需要在.pgpass中增加一行 replication类型的

192.168.1.11:5432:replication:repuser:repuser

[postgres@oradbca ~]$ pg_basebackup -D /u01/pgdata -Fp -Xs -v -P -h 192.168.1.11 -p 5432 -U repuser
transaction log start point: 0/1A000028 on timeline 1
pg_basebackup: starting background WAL receiver
37929/37929 kB (100%), 2/2 tablespaces                                         
transaction log end point: 0/1A0000F0
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: base backup completed