I change parameter timezone and log_timezone in postgresql.conf by this doc:
https://www.postgresql.org/docs/current/datatype-datetime.html
From documenttaion: The TimeZone configuration parameter can be set in the file postgresql.conf
timezone = 'Europe/Moscow'
log_timezone = 'Europe/Moscow'
File postgresql.conf i could changed in docker.
But parameter timezone don’t change in database by this sql:
SELECT * FROM pg_settings where name like '%timezone%' or name = 'TimeZone';
timezone parameter is ‘UTC’ now. Why???
And log_timezone changed! What is it?!
My postgresql is in docker.
postgresql version: PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1)
Thanks.
3
Answers
Tin of course. The config was applied on the server. This is my intellij idea client changing timezone purely for himself. I check
in psql console and pgadmin. It is normal time with my timezone. Thanks everybody
Note that the parameter
timezone
could (and should!) be overridden in the database session to set the appropriate session time zone. To see if your parameter value is frompostgresql.conf
or was set somewhere else, querypg_settings
:Changes in postgresql.conf take effect only if they are there before the database loads it – it’s read on startup. To re-load them, you’ll need to restart or run
pg_reload_conf()
. This one’s fine but some settings do require a full restart, which you need to check on case-by-case basis.Mind that what you’re trying to do sets the cluster-wide default – all connections to all databases on this cluster will assume this time zone, but they are all free to set their own. All defaults take effect at the start of each session, so all ongoing sessions will disregard all changes after that and cannot be forced to change their settings from the outside – they need to either re-connect for changes to apply, or apply them on their own.
Postgresql.conf
andalter system set
affect defaults on cluster,alter database set
on db,alter [role|user] set
on role level. When session starts, it can open by issuing its ownset
orset_config()
, which will override all those settings and there’s no (built-in) way to revoke anyone’s right toset
.Demo at db<>fiddle:
This changes the default, without affecting current settings:
Same: change to role-level default doesn’t affect ongoing session(s):
Only
set
command orset_config()
function can affect the session, from the inside.(
set local
andset_config('name','value',true)
makes the setting go back to what it was before the transaction after it ends)set session
andset_config('name','value',false)
keeps the setting after the transaction even if it was issued inside it: