使用spring boot时如何将密码传递给pg_dump

发布于 2025-01-13 05:37:56 字数 1328 浏览 5 评论 0 原文

我正在尝试在 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。

提前非常感谢您的任何建议。

I'm trying to make a backup of my Postgres database in Spring boot But I got this error:

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]

and my code looks like this:

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);

Can anyone tell me where can I add my password in my command line?
My password is 123456.

Thanks a lot in advance for any suggestion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2025-01-20 05:37:56

您可以设置 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文