You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transmit user's preferred locale to PostgreSQL #685
We can send lc_messages in the startup message to make PostgreSQL emit messages in the user's preferred locale (in Windows or Linux), instead of in its own default locale. The challenge is going to be to translate Windows/Linux/MacOSX locales to PostgreSQL locales...
How many connections are opened by a superuser? It's not secure. Therefore, I think it would be rarely used. Maybe messages should be translated on the client side?
@YohDeadfall can you provide more information? Why would this not be secure, it's just a field in the startup packet which Npgsql sends to PostgreSQL when first connecting. PostgreSQL makes sure that it's a valid locale string, so I don't see any security implication. I also don't understand what superuser has to do with this.
I've read documentation about lc_messages from a wrong section, from client connection defaults which says that the value affects server logs. Therefore, it can be changed by a super user only. So everything's okay now.
@roji I've been investigating a little around this issue and finally think I agree with @YohDeadfall
How many connections are opened by a superuser?
select context from pg_settings where name = 'lc_messages'; returns superusermeaning that while this setting can be "changed while a session is in progress, during a backend startup, using SIGHUP, at Postgres startup, or during code compilation" it can only be changed by superusers (for security reasons indeed).
I've verified on the windows command line that psql "user=SomeNonSuperUser dbname=myDataBase options=--lc_messages=de_DE.UTF-8" (which internally sets lc_messages in the startup message via libpq) fails with psql: FATAL: permission denied to set parameter "lc_messages"
So after all this would be a superuser-connection only feature in which case it doesn't seem very interesting to me.
If we really want to implement it, it actually isn't all that hard.
Just add the following (plus some guards for InvariantCulture) to NpgsqlConnector.WriteStartupMessage() and it will work (for superusers and fail for ordinary users)
One additional problem would the fact that it only works by trial and error as there is no reliable way to detect the locales supported by a server from the client side.
In fact you can set lc_messages to anything you want without getting an error on a windows backend.
Thanks for looking into this @Brar, I didn't realize (and failed to understand from @YohDeadfall's comment) that this is a superuser-only feature. It's quite surprising - the reasoning given is that this setting modifies the language in the log files as well, which is odd (you would have expected it to be a user-facing change only).
in any case, I don't really see any value in implementing this for superuser only. The idea was to try to automatically provide readable messages based on your locale, but that doesn't seem possible. I'm going to go ahead and close this.
Activity
YohDeadfall commentedon Apr 5, 2018
How many connections are opened by a superuser? It's not secure. Therefore, I think it would be rarely used. Maybe messages should be translated on the client side?
roji commentedon Apr 7, 2018
@YohDeadfall can you provide more information? Why would this not be secure, it's just a field in the startup packet which Npgsql sends to PostgreSQL when first connecting. PostgreSQL makes sure that it's a valid locale string, so I don't see any security implication. I also don't understand what superuser has to do with this.
YohDeadfall commentedon Apr 7, 2018
I've read documentation about
lc_messagesfrom a wrong section, from client connection defaults which says that the value affects server logs. Therefore, it can be changed by a super user only. So everything's okay now.roji commentedon Apr 7, 2018
OK no problem.
Brar commentedon Jul 2, 2018
@roji I've been investigating a little around this issue and finally think I agree with @YohDeadfall
select context from pg_settings where name = 'lc_messages';returnssuperusermeaning that while this setting can be "changed while a session is in progress, during a backend startup, using SIGHUP, at Postgres startup, or during code compilation" it can only be changed by superusers (for security reasons indeed).I've verified on the windows command line that
psql "user=SomeNonSuperUser dbname=myDataBase options=--lc_messages=de_DE.UTF-8"(which internally sets lc_messages in the startup message via libpq) fails withpsql: FATAL: permission denied to set parameter "lc_messages"So after all this would be a superuser-connection only feature in which case it doesn't seem very interesting to me.
If we really want to implement it, it actually isn't all that hard.
Just add the following (plus some guards for InvariantCulture) to
NpgsqlConnector.WriteStartupMessage()and it will work (for superusers and fail for ordinary users)One additional problem would the fact that it only works by trial and error as there is no reliable way to detect the locales supported by a server from the client side.
In fact you can set
lc_messagesto anything you want without getting an error on a windows backend.roji commentedon Jul 2, 2018
Thanks for looking into this @Brar, I didn't realize (and failed to understand from @YohDeadfall's comment) that this is a superuser-only feature. It's quite surprising - the reasoning given is that this setting modifies the language in the log files as well, which is odd (you would have expected it to be a user-facing change only).
in any case, I don't really see any value in implementing this for superuser only. The idea was to try to automatically provide readable messages based on your locale, but that doesn't seem possible. I'm going to go ahead and close this.
Thanks again for investigating!