Postgresql docker timezone

PostgreSQL Docker Timezone:

When running PostgreSQL in a Docker container, you can configure the timezone in the container to match your desired timezone. By default, the timezone used is UTC (Coordinated Universal Time). However, you might want to set a different timezone based on your application’s requirements or the location of your users.

To set the timezone in a PostgreSQL Docker container, you can use environment variables. Here’s an example of setting the timezone to “America/New_York”:

    
docker run -e TZ=America/New_York -e POSTGRES_PASSWORD=mysecretpassword -d postgres
    
  

In the above command, the “-e TZ=America/New_York” flag is used to set the timezone to “America/New_York”. You can replace this value with your desired timezone. Additionally, the “-e POSTGRES_PASSWORD=mysecretpassword” flag is used to set the password for the PostgreSQL user.

Once the container is running with the desired timezone configuration, you can connect to the PostgreSQL database and verify the timezone settings. Here’s an example using the psql command-line tool:

    
docker exec -it [CONTAINER_ID] psql -U postgres
    
  

After connecting to the PostgreSQL database, you can check the current timezone by running the following SQL query:

    
SELECT current_setting('timezone');
    
  

The above query will return the current timezone setting. If everything is configured correctly, it should reflect the timezone you set when starting the Docker container.

Leave a comment