3

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.

asked May 23, 2020 at 1:43
1
  • 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. Commented May 10, 2023 at 14:28

2 Answers 2

3

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 of SET TIMEZONE TO with a more SQL-spec-compatible syntax.

  • The PGTZ environment variable is used by libpq clients to send a SET TIME ZONE command to the server upon connection.

answered May 23, 2020 at 1:46
4
  • You should add that it can be set on the user level. Perhaps that solves the OP's unknown problem. Commented May 23, 2020 at 13:39
  • Please share the commands or settings to set at database level. Commented May 23, 2020 at 23:02
  • @Venkat: the documentation that I linked in my answer explains how to do that. Commented 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.] Commented May 24, 2020 at 0:16
0

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.

answered Jun 9, 2023 at 0:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.