南美海獅

首页 » 常识 » 常识 » postgresql客户端非交互连接方
TUhjnbcbe - 2021/1/21 17:05:00
如何治疗白癜风偏方 http://baidianfeng.39.net/a_yufang/131031/4282864.html

一般postgresql数据库,通过客户端工具(pgdump,psql等)连接,默认会通过交互的方式输入密码(配置md5认证方式),例如:

[postgres

localhost~]$psql-Ubackup-dpostgres-p--host..56.Passwordforuserbackup:psql(9.6.20)Type"help"forhelp.postgres=

但是在shell脚本自动化场景中(获取数据库信息,数据导入导出,备份恢复等)

以交互方式传递密码难以实现,那么如何实现非交互方式的脚本调用呢?

本次测试脚本:

[postgres

localhostpostgresql]$cattest.sh#!/bin/bashecho`psql-Ubackup-dpostgres-p--host..56.-c"selectversion()"`

在不进行任何处理的情况下,需要交互传递密码:

[postgres

localhostpostgresql]$shtest.shPasswordforuserbackup:

本文汇总三个非交互方式:

非交互方法1:

1
查看完整版本: postgresql客户端非交互连接方