使用spring boot时如何将密码传递给pg_dump
我正在尝试在 Spring boot 中备份 Postgres 数据库,但出现此错误:
2022-03-10 21:17:57.751 INFO 8132 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-10 21:17:59.097 ERROR 8132 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The server requested SCRAM-based authentication, but no password was provided.
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:770) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:163) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:215) ~[postgresql-42.3.1.jar:42.3.1]
并且我的代码如下所示:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
String currentDate = df.format(new Date());
String command = String.format("pg_dump --no-privileges --no-owner postgres -f " +
"src/main/java/com/application/backend/backup/logs/"+currentDate+".sql");
Process process = Runtime.getRuntime().exec(command);
谁能告诉我在哪里可以在命令行中添加密码? 我的密码是 123456。
提前非常感谢您的任何建议。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置 PGPASSWORD 环境变量。有关在 Javascript 中设置环境变量的示例,请参阅此问题。
另一种选择是创建密码文件。
You can se the
PGPASSWORD
environment variable. See for example this question about setting environment variables in Javascript.The other alternative is to create a password file.