方式
- pg_hba.conf设置配置文件
- 环境变量PGPASSWORD
- .pgpass文件
.pgpass
touch ~/.pgpass创建文件
chmod 600 ~/.pgpass修改文件权限
| 字段 | 你的值 | 含义 |
|---|---|---|
| 1. hostname | 127.0.0.1 | 数据库服务器的 主机名或IP地址 |
| 2. port | 6677 | PostgreSQL 监听的 端口号 |
| 3. database | * | 数据库名(* 表示任意数据库) |
| 4. username | postgres | 连接时使用的 数据库用户名 |
| 5. password | 123456 | 对应用户的 密码 |
# 格式hostname:port:database:username:passwordecho "127.0.0.1:6677:*:postgres:123456" >> ~/.pgpass
echo "127.0.0.1:5432:*:postgres:66666" >> ~/.pgpass
echo "localhost:6677:*:postgres:123456" >> ~/.pgpass
echo "localhost:5432:*:postgres:66666" >> ~/.pgpass