Post

FATAL: Invalid TimeZone in PostgreSQL and How I Fixed It

FATAL: Invalid TimeZone in PostgreSQL and How I Fixed It

Fixing PostgreSQL TimeZone Issues in Spring Boot

While working with PostgreSQL in a Spring Boot application, I ran into this error: FATAL: invalid value for parameter “TimeZone”: “Asia/Calcutta”

It turns out this happens due to two main reasons: the database timezone or the JVM timezone.


1. PostgreSQL Database TimeZone Issue

To check the timezone of your database:

  1. Open CMD or PowerShell and login to your database:
1
psql -U <user_name> -d <database_name>

Run:

1
SHOW timezone;

If the output shows “Asia/Calcutta”, that’s the cause.

How to Fix

a) Change timezone for current session:

1
SET TIMEZONE='Asia/Kolkata';
1
SHOW timezone;

b) Change timezone permanently for the database:

1
ALTER DATABASE your_db_name SET timezone TO 'Asia/Kolkata';
1
SHOW timezone;

2. JVM TimeZone Issue

Sometimes the JVM itself uses Asia/Calcutta, causing the JDBC connection to fail.

Check JVM timezone in a Spring Boot test:

1
2
3
4
@Test
void printJVMTimezone() {
    System.out.println(TimeZone.getDefault().getID());
}

If the output shows “Asia/Calcutta”, you need to fix the JVM timezone.

How to Fix JVM TimeZone

Run PowerShell as Administrator:

1
setx JAVA_TOOL_OPTIONS "-Duser.timezone=Asia/Kolkata" /M

You should see:

1
SUCCESS: Specified value was saved.

Re-run your test, and now the output will show Asia/Kolkata.

✅ Key Takeaways

  • Newer versions of PostgreSQL replaced Asia/Calcutta with Asia/Kolkata, causing timezone errors in modern setups.
  • Both database and JVM timezones must be consistent.
  • Fixing this prevents Spring Boot startup failures related to JDBC timezone settings.
This simple change saved me hours of debugging!

This post is licensed under CC BY 4.0 by the author.