Skip to content

Transmit user's preferred locale to PostgreSQL #685

Closed

Description

@roji

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...

Activity

  1. YohDeadfall commented on Apr 5, 2018

    @YohDeadfall
    Contributor

    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?

  2. roji commented on Apr 7, 2018

    @roji
    MemberAuthor

    @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.

  3. YohDeadfall commented on Apr 7, 2018

    @YohDeadfall
    Contributor

    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.

  4. roji commented on Apr 7, 2018

    @roji
    MemberAuthor

    OK no problem.

  5. added this to the Backlog milestone on Jun 8, 2018
  6. Brar commented on Jul 2, 2018

    @Brar
    Member

    @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 superuser meaning 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)

    startupMessage["lc_messages"] = CultureInfo.CurrentUICulture.Name.Replace("-", "_") + ".UTF-8";

    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.

    psql -c "SHOW lc_messages;" "options=--lc_messages=MyCompleteNonsenseLocale"
           lc_messages
    --------------------------
     MyCompleteNonsenseLocale
    (1 Zeile)
    
  7. roji commented on Jul 2, 2018

    @roji
    MemberAuthor

    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!

  8. removed this from the Backlog milestone on Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions