0

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.

qpdpQ
  • 21
  • 2

1 Answers1

1

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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263