Is it possible to set the timezone for one schema? Do not want to set Postgresql(v.12) server level.
Please suggest if any ways to this.
-
I'd just like to add some context as to why this is an important question. A schema is generally assumed to be a canonical, serialised representation of the database. However a schema loses some of that reliability if its timestamp column values aren't guaranteed to match the timezone of the server. Hence why being able to specify the data's timezone in a schema is a legitimate question.tombh– tombh2023年05月10日 14:28:19 +00:00Commented May 10, 2023 at 14:28
2 Answers 2
No.
You can either set the timezone at database level, or at session level (... or directly when accessing a date-like datatype, using the at time zone
construct).
From the documentation:
The TimeZone configuration parameter can be set in the file
postgresql.conf
, or in any of the other standard ways described in Chapter 19. There are also some special ways to set it:
The SQL command
SET TIME ZONE
sets the time zone for the session. This is an alternative spelling ofSET TIMEZONE TO
with a more SQL-spec-compatible syntax.The
PGTZ
environment variable is used by libpq clients to send aSET TIME ZONE
command to the server upon connection.
-
You should add that it can be set on the user level. Perhaps that solves the OP's unknown problem.Laurenz Albe– Laurenz Albe2020年05月23日 13:39:14 +00:00Commented May 23, 2020 at 13:39
-
Please share the commands or settings to set at database level.Venkat– Venkat2020年05月23日 23:02:23 +00:00Commented May 23, 2020 at 23:02
-
@Venkat: the documentation that I linked in my answer explains how to do that.GMB– GMB2020年05月23日 23:05:35 +00:00Commented May 23, 2020 at 23:05
-
Thanks. The ALTER DATABASE command allows global settings to be overridden on a per-database basis. [ ALTER SYSTEM command provides a SQL-accessible means of changing global defaults; it is functionally equivalent to editing postgresql.conf. The ALTER ROLE command allows both global and per-database settings to be overridden with user-specific values.]Venkat– Venkat2020年05月24日 00:16:04 +00:00Commented May 24, 2020 at 0:16
I was able to change the timezone of a schema (permanently) with:
set timezone to 'UTC';
Reconnecting and/or restarting my postgresql
service shows the setting remained. Confirm with: show timezone;
or select now();
Switch to schema2 with: \c schema2
I'm using Postgres 12 on Ubuntu.