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

+1 vote
ago in Clojure CLI by
edited ago 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!

ago 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?

1 Answer

+1 vote
ago by
selected ago 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

ago 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.
...