We're trying to get the timezone data updated on a Windows Postgres install without having to update the server installation.
Background: Our application is using Postgres' built in timezone information and relies on accurate data. Therefore updating Postgres is is not the solution as timezone data is changing too often.
Is there a way to import / update IANA's timezone data into Postgres?
Finally I figured it out. For anyone having similar needs:
Get yourself cygwin, and run: make TOPDIR=$HOME/tzdir install in order to get the compiled time zone data. Copy that into the share\timezone directory of your postgres install. Restart postgres and off you go!
Related
I'm working on trying to setup my local database with some mock data to work with. We have a development AWS account with a postgres database. I would like to create a backup of it, export it to my local computer, and restore to my local postgres database.
I've been trying to find how to do this online, but everything I'm finding is on how to backup to AWS and to restore back to AWS. I tried creating a snapshot and exporting it via S3 - but the snapshot doesn't produce a sql file to restore from like I was expecting.
If anyone can point me in the right direction I would very much appreciate it :)
I am afraid that the only chance you have is pg_dump/pg_restore.
Even if Amazon lets you get your hands on its file system backups, which I doubt, they may be of little use to you, since Amazon runs modified versions of PostgreSQL and you cannot be sure that the physical file format is identical to PostgreSQL.
I have a postgresql database that I deploy scripts to using flyway. I use the maven flyway plugin to launch the database build against the target database. In that build I have scripts that do things like:
create table my_table(
my_date_time timestamp with time zone not null
);
insert into my_table(my_date_time)
select '2000-01-01';
The postgresql database timezone is set to UTC. My client machine (that runs the maven/flyway build) is running CEST (UTC+2:00).
When the scripts run, the database interprets the string literal above as '1999-12-31 22:00:00+00:00' and writes that to storage.
It seems that the jdbc client connection created by flyway is not setting its client timezone to UTC, but is taking the timstamp string and interpreting it as '2000-01-01 00:00:00+02:00'.
How can I set the client timezone on the jdbc connection created by flyway to UTC? Is there a setting that can be placed in my flyway.conf file?
If I change my local machine timezone to UTC the problem goes away, but I'd rather not do that on my development workstation.
A colleague suggested the following
mvn -Duser.timezone=UTC flyway:migrate
Instead of just giving it a date, which postgres has to interpret, it would be better to fully specify the timestamp:
insert into my_table(my_date_time)
select '2000-01-01T00:00:00+00';
If that is not possible, you could try running mvn with -Duser.timezone=UTC but fully specifying the timestamp is the better option as it leaves no room for misinterpretation or misconfiguration.
Another way is to set session timezone in migration script itself
SET timezone TO 'UTC';
i use flyway CLI in a script. so setting correct timezone to the corresponding environment variable before executing flyway command works for me:
export TZ=GMT
I used following commands to change timezone in my Ubuntu 16.04 server
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime and tzselect
After typing date I get the correct datetime.
But on mongodb when I print time of recently added document by res.ops[0]._id.getTimestamp() I still get the datetime prior to the timezone change.
I restarted mongodb and the server itself. But still no change. And I am using node.js as backend.
You need to save the time as UTC and then on the server side get the document with time and apply to it your wanted timezone. That way you decouple timezones from your data.
I have a timestamp column 'submitted_on' with default as now().
I have set the heroku TZ to my zone and added a php user ini with the same timezone.
But the database is still using UTC timezone. I see this when I ran this sql:
show timezone;
Is there a fix? Or this is how heroku databases work? Also I'm using free dynos.
Setting a TZ config var only affects the Dynos environment, as the database is located on a different machine, it has no effect.
Generally speaking, you should always keep servers clocks running on UTC, store all times in UTC, and perform any timezone/locale changes in your application framework.
The parameter timezone is determined when the database cluster is created.
You can either change the value in postgresql.conf, or you can use ALTER SYSTEM as a superuser to change the value.
I don't know if Heroku allows you either of these options.
I started using the jOra eclipse plugin. The plugin seems pretty robust and I'm hoping to stop using SQLDeveloper for 95% of my database needs.
Many of our tables have columns of type TIMESTAMP with LOCAL TIME ZONE. I can connect to the oracle DB using a jdbc string and the plugin seems to function very well. However, when I try to update one of these TIMESTAMP with LOCAL TIME ZONE values, I get a sql exception: java.sql.SQLException: connection session time zone was not set.
Does anyone know how I can set the time zone through the jdbc connection url? jOra doesn't seem to support adding custom connection properties, so the connection URL is really my only option.
Update: Running version 1.0.1, which I believe is the latest version.
Update2: Apparently I can perform an update statement in the sql worksheet just fine, just can't use their detail browser interface to update.
What version do you use? According to their release notes this issue was already fixed in 0.9.0. Consider upgrading. If still in vain, I'd report a bug over there, they seem to maintain it well enough.
After you connect to the DB, try running:
ALTER SESSION SET time_zone='+01:00';
Alternatively you could create a system trigger:
CREATE OR REPLACE TRIGGER setSessionTZ
AFTER LOGON ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET time_zone=''+01:00''';
END;