-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Perl Locale update with LANG env setting #93
Conversation
PGDATA=$(dirname "$(sudo -u postgres psql --tuples-only --pset format=unaligned --command "SHOW config_file;")") | ||
source ~/`[[ $SHELL == *"zsh" ]] && echo '.zshenv' || echo '.bashrc'` | ||
perl -i -pe 's/^[#\s]*(lc_messages|lc_time)\s*=.+$/\1 = '\''en_US.UTF-8'\''/' "$PGDATA/postgresql.conf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting lc_messages
and lc_time
in the postgresql.conf
file is not needed when the LANG
is set as the Postgres server will use the value of this whenever it's set and only default back to the values in the postgresql.conf
file when LANG
is not set
Source
Postgres docs
Postgres docs
source ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` | ||
perl -i -pe 's/^[#\s]*(lc_messages|lc_time)\s*=.+$/\1 = '\''en_US.UTF-8'\''/' "$PGDATA/postgresql.conf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting lc_messages
and lc_time
in the postgresql.conf
file is not needed when the LANG
is set as the Postgres server will use the value of this whenever it's set and only default back to the values in the postgresql.conf
file when LANG
is not set
Source
Postgres docs
Postgres docs
source "$USERPROFILE/.bash_profile" | ||
perl -i -pe 's/^[#\s]*(lc_messages|lc_time)\s*=.+$/\1 = '\''en_US.UTF-8'\''/' "$PGDATA/postgresql.conf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting lc_messages
and lc_time
in the postgresql.conf
file is not needed when the LANG
is set as the Postgres server will use the value of this whenever it's set and only default back to the values in the postgresql.conf
file when LANG
is not set
Source
Postgres docs
Postgres docs
macos.md
Outdated
echo "\nexport PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` | ||
echo -e "export PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add a setting for the environment variable for the
LANG
locale, as Postgres server will use the encoding set to it and ignore the settings in thepostgresql.conf
file - Use the similar
echo
command that is used on other systems because the previous command doesn't work onLinux
andWindows
windows.md
Outdated
echo "export PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> "$USERPROFILE/.bash_profile" | ||
echo -e "export PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> "$USERPROFILE/.bash_profile" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add a setting for the environment variable for the
LANG
locale, as Postgres server will use the encoding set to it and ignore the settings in thepostgresql.conf
file
linux.md
Outdated
echo "export PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshenv' || echo '.bashrc'` | ||
echo -e "export PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshenv' || echo '.bashrc'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add a setting for the environment variable for the
LANG
locale, as Postgres server will use the encoding set to it and ignore the settings in thepostgresql.conf
file
macos.md
Outdated
@@ -191,9 +191,8 @@ Make sure that you're running the 2nd-newest macOS version or the newest version | |||
|
|||
```bash | |||
[[ -d /opt/homebrew/var/postgresql@16 ]] && PGDATA_TMP=/opt/homebrew/var/postgresql@16 || PGDATA_TMP=/usr/local/var/postgresql@16 | |||
echo "\nexport PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` | |||
echo -e "export PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we should keep the \n
at the beginning, in case the config file doesn't have a newline at the end of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the \n
without the -e
flag works in macOS but not on Windows
and Linux
because new line is handled differently on those systems
echo "\n" vs echo -e "\n"
These commands produce different results on macOS than on others
macOS
echo "\nexport PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'`
Result
export PGDATA=/opt/homebrew/var/postgresql@16
export PSQL_PAGER="less --chop-long-lines --header 1"
export LANG=en_US.UTF-8
Linux
echo "\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshenv' || echo '.bashrc'`
Result
\nexport PSQL_PAGER="less --chop-long-lines --header 1"\nexport LANG=en_US.UTF-8
Windows
echo "\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> "$USERPROFILE/.bash_profile"
Result
\nexport PSQL_PAGER="less --chop-long-lines --header 1"\nexport LANG=en_US.UTF-8
We can add the \n
only for the macOS script
db38259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I want to use the first \n
on other systems, I can do something like this, but I don't see the need apart from making everything look the same. We can have the new line for macOS and have the -e
for other systems
macOS
echo -e "\nexport PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'`
Linux
echo -e "\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshenv' || echo '.bashrc'`
Windows
echo -e "\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> "$USERPROFILE/.bash_profile"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macos.md
Outdated
@@ -191,9 +191,8 @@ Make sure that you're running the 2nd-newest macOS version or the newest version | |||
|
|||
```bash | |||
[[ -d /opt/homebrew/var/postgresql@16 ]] && PGDATA_TMP=/opt/homebrew/var/postgresql@16 || PGDATA_TMP=/usr/local/var/postgresql@16 | |||
echo "\nexport PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` | |||
echo -e "export PGDATA=$PGDATA_TMP\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> ~/`[[ $SHELL == *"zsh" ]] && echo '.zshrc' || echo '.bash_profile'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need the -e flag now, and why didn't we need it before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows.md
Outdated
echo "export PATH=\$PATH:\"/c/Program Files/PostgreSQL/16/bin\"" >> "$USERPROFILE/.bash_profile" | ||
echo "export PGDATA=\"/c/Program Files/PostgreSQL/16/data\"" >> "$USERPROFILE/.bash_profile" | ||
echo "export PSQL_PAGER=\"less --chop-long-lines --header 1\"" >> "$USERPROFILE/.bash_profile" | ||
echo -e "\nexport PSQL_PAGER=\"less --chop-long-lines --header 1\"\nexport LANG=en_US.UTF-8" >> "$USERPROFILE/.bash_profile" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like these previous export
commands should be also moved to this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to have all the echo
commands for all systems separated into multiple commands as this would make it clear for the students to understand what they are running and what it is doing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Closes #47
The solution provided in #80 caused a new error
postmaster became multithreaded during startup
as postgres server could not be started in macOS terminal if theLANG
locale is not set. This was not noticed during the PR because the iTerm2 used for the testing sets theLANG
locale automatically but the macOS terminal does not.The
FATAL: postmaster became multithreaded during startup
error could be caused by anything, but these are the things we know now so farLANG
environment variable is unset toLANG=
orLANG=""
, the above error will occur. When running Postgres from iTerm2, this error doesn't occur because iTerm2 sets thisLANG
environment variable by default using the system language settingen_GB.UTF-8
, which is my system's primary language setting for all localeLANG
is unset by default.LANG
in the macOS terminal fixed the issue, and Postgres could run without any problemLANG
in the iTerm2 terminal causes the error to also occur thereLANG
is set, otherLC_
variables use the value assigned to itLANG
is unset, otherLC_
variables will have a default value ofC
Values when
LANG
is unsetlocale output when running
locale
macOS terminal
iterm2 Terminal
env variables output when running
env
macOS terminal
iterm2 terminal
TERM_SESSION_ID=w0t0p0:289876C1-77BD-4A97-92B7-FB315FED884B SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.a9uJAPLv9o/Listeners LC_TERMINAL_VERSION=3.5.3 COLORFGBG=15;0 ITERM_PROFILE=Default XPC_FLAGS=0x0 PWD=/Users/upleveled SHELL=/bin/zsh __CFBundleIdentifier=com.googlecode.iterm2 TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF TERM_PROGRAM_VERSION=3.5.3 TERM_PROGRAM=iTerm.app PATH=/Users/upleveled/.console-ninja/.bin:/Users/upleveled/.console-ninja/.bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/upleveled/development/flutter/bin:/Users/upleveled/Library/Android/sdk/platform-tools:/Applications/iTerm.app/Contents/Resources/utilities LC_TERMINAL=iTerm2 COLORTERM=truecolor COMMAND_MODE=unix2003 TERM=xterm-256color TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo HOME=/Users/upleveled TMPDIR=/var/folders/0w/8ddfv3y91kqf7_qpsxwv9y2r0000gn/T/ USER=upleveled XPC_SERVICE_NAME=0 LOGNAME=upleveled ITERM_SESSION_ID=w0t0p0:289876C1-77BD-4A97-92B7-FB315FED884B __CF_USER_TEXT_ENCODING=0x0:0:0 SHLVL=1 OLDPWD=/Users/upleveled ANDROID_SDK=/Users/upleveled/Android/Sdk HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_REPOSITORY=/opt/homebrew INFOPATH=/opt/homebrew/share/info: PGDATA=/opt/homebrew/var/postgresql@16 PSQL_PAGER=less --chop-long-lines --header 1 _=/usr/bin/env
Postgres not running when
LANG
is unsetiTerm2 terminal
macOS terminal
Values when
LANG
is setlocale output when running
locale
macOS terminal
iTerm2 Terminal
env variables output when running
env
macOS terminal
iTerm2 terminal
TERM_SESSION_ID=w0t0p0:289876C1-77BD-4A97-92B7-FB315FED884B SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.a9uJAPLv9o/Listeners LC_TERMINAL_VERSION=3.5.3 COLORFGBG=15;0 ITERM_PROFILE=Default XPC_FLAGS=0x0 PWD=/Users/upleveled SHELL=/bin/zsh __CFBundleIdentifier=com.googlecode.iterm2 TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF TERM_PROGRAM_VERSION=3.5.3 TERM_PROGRAM=iTerm.app PATH=/Users/upleveled/.console-ninja/.bin:/Users/upleveled/.console-ninja/.bin:/Users/upleveled/.console-ninja/.bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/upleveled/development/flutter/bin:/Users/upleveled/Library/Android/sdk/platform-tools:/Applications/iTerm.app/Contents/Resources/utilities LC_TERMINAL=iTerm2 COLORTERM=truecolor COMMAND_MODE=unix2003 TERM=xterm-256color TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo HOME=/Users/upleveled TMPDIR=/var/folders/0w/8ddfv3y91kqf7_qpsxwv9y2r0000gn/T/ USER=upleveled XPC_SERVICE_NAME=0 LOGNAME=upleveled ITERM_SESSION_ID=w0t0p0:289876C1-77BD-4A97-92B7-FB315FED884B __CF_USER_TEXT_ENCODING=0x0:0:0 SHLVL=1 OLDPWD=/Users/upleveled ANDROID_SDK=/Users/upleveled/Android/Sdk HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_REPOSITORY=/opt/homebrew INFOPATH=/opt/homebrew/share/info: PGDATA=/opt/homebrew/var/postgresql@16 PSQL_PAGER=less --chop-long-lines --header 1 LANG=en_US.UTF-8 _=/usr/bin/env
Postgres running with no error when
LANG
is setiTerm2
macOS terminal
https://iterm2.com/documentation-preferences-profiles-terminal.html#:~:text=a%20bell%20graphic.-,Environment,-You%20have%20the
Solutions: setting the
LANG
After checking all the systems, I realized that setting the
LANG
to English and recommended encoding (export LANG=en_US.UTF-8) will make Postgres use these values and encoding which will solve the postmaster multithreaded error and also make postgres ignore the values of thelc_messages
and the lc_timeset in the
postgresql.conf` file which makes this PR #80 obsolete.Postgres will only default to the values in postgresql.conf file if none of these are set (LC_ALL, LC_COLLATE, LANG)
Before running the environment variable setup
After running the environment variable setup