Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure CLI by
edited by

Hello, I have an issue when trying to connect to a recent (v18) postgresql database using next-jdbc. Whenever I try to execute a query I get the following error:

FATAL: invalid value for parameter "TimeZone": "America/Buenos_Aires"

This is my sample code:

(ns app.core
  (:require [next.jdbc :as jdbc]))

(def db
  {:dbtype   "postgresql"
   :dbname   "app"
   :host     "localhost"
   :port     5432
   :user     "app"
  :password "app"})

(def ds (jdbc/get-datasource db))

(defn -main []
  (println "My TZ:")
  (println (java.time.ZoneId/systemDefault))

  (println "Query:")
  (println (jdbc/execute! ds ["select current_timestamp"])))

It prints the following text:

My TZ:
#object[java.time.ZoneRegion 0x5a917723 America/Buenos_Aires]
Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (QueryExecutorImpl.java:2993).
FATAL: invalid value for parameter "TimeZone": "America/Buenos_Aires"

Debian 13, which is the OS the postgres docker image is based on, has "deprecated" some timezones and moved them to legacy package. And it no longer accepts the default Windows timezone (unless the package is installed by modifying the docker image).

I know I can set the JVM timezone when running the program:

clj -J"-Duser.timezone=America/Argentina/Buenos_Aires" -M -m app.core
My TZ:
#object[java.time.ZoneRegion 0x7e4579c7 America/Argentina/Buenos_Aires]
Query:
[{:current_timestamp #inst "2026-10-29T13:12:23.223933000-00:00"}]

which works but it's cumbersome.

Is there a file I can use to set default JVM options? like jvm.option? I also tried with :jvm-opts inside deps.edn but I don't really understand how aliases work.

Thanks!

by
Ok, I can "activate" an alias with the -M option: `clj -Mdev -m app.core`. Is there a way to alter the "default" alias?

2 Answers

+1 vote
by
selected by
 
Best answer

There is no "default" alias or way to set the JVM options for all executions (there are lots of reasons you might run the CLI to do something other than run your own program). You can create an alias with :jvm-opts and use clj -M:dev -m app.core.

Or if you want to do something separate in the terminal, https://clojure.org/reference/clojure_cli#env_vars covers all the env vars that are relevant - here that would be export JAVA_OPTS=-Duser.timezone=America/Argentina/Buenos_Aires

by
Ok. I guess the best approach is having some configuration file for the app and set the timezone before using it for accessing the DB.

After building a JAR I would face the same issue where either explicit command-line arguments or environment variables are needed.
0 votes
ago by

Alex's answer covers the main options. Two additions that helped in a similar setup:

First, you don't have to put the alias in every project's deps.edn. Aliases defined in your user-level ~/.clojure/deps.edn are available in every project, so you can define a :dev alias with :jvm-opts ["-Duser.timezone=America/Argentina/Buenos_Aires"] once there, and then run clj -M:dev -m app.core in any project.

Second, for the JAR case you mentioned in your comment, neither deps.edn nor -J applies, because you are no longer going through the CLI. The JVM itself reads JDK_JAVA_OPTIONS, so launching with JDK_JAVA_OPTIONS=-Duser.timezone=America/Argentina/Buenos_Aires java -jar app.jar works without changing anything inside the JAR.

One more thing worth considering: don't let the database depend on the JVM's default time zone at all. If you set the time zone explicitly on the connection, for example with SET TIME ZONE 'America/Argentina/Buenos_Aires' after connecting, a machine with a different default zone can't break the connection again.

...