Postgres & Django - DataError: time zone not recognized - django

We are getting the following error from some of our users:
DataError: time zone "Asia/Qostanay" not recognized
We've found out that the problem was coming from the following SQL query:
SELECT *
FROM "app_foobar"
WHERE (
EXTRACT('hour' FROM "app_foobar"."date" AT TIME ZONE 'Asia/Qostanay') = 0
);

There are two problems:
Timezone definitions change over time. Update Ubuntu timezone data:
sudo apt-get update
sudo apt-get install tzdata
Postgres 11.1 doesn't support this timezone (and some others). Update Postgres to 11.4:
sudo apt-get update
sudo apt-get install postgresql-11
sudo apt-get install postgresql-client-11
Some notes on updating Postgres:
No data migration needed for minor versions (e.g. 11.0 -> 11.4). Only executables are updated.
PostgreSQL will restart (database will be unavailable for a second or two)
The relevant postgresql changelog (https://www.postgresql.org/docs/release/11.2/):
Update time zone data files to tzdata release 2018i for DST law changes in Kazakhstan, Metlakatla, and Sao Tome and Principe. Kazakhstan's Qyzylorda zone is split in two, creating a new zone Asia/Qostanay, as some areas did not change UTC offset. Historical corrections for Hong Kong and numerous Pacific islands.

Related

Which is more preferable? Try to downgrade Ubuntu version of an EC2 server or create a new instance altogether?

I have a dilemma, I am trying to set up the Microsoft slqsrv drivers for PHP and a laravel project so that it can connect to an RDS service and do my migrations, however, the Microsoft page dictates that the supported versions for the Ubuntu Server are 18, 20 and 21. The following snippet is the exact commands for an Ubuntu server from the official Microsoft page.
if ! [[ "18.04 20.04 21.04" == *"$(lsb_release -rs)"* ]];
then
echo "Ubuntu $(lsb_release -rs) is not currently supported.";
exit;
fi
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list >
/etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev
Trying to run the commands without the if statement installs "something" but it ends up with errors, moreover, the pdo_sqlsrv and sqlsrv extensions do show up in the extensions list of PHP, running the command "php -m" shows that they are indeed loaded, but if I try to run the migration it shows the alert that the OBDC driver is missing.
What makes me think this is not working is that my EC2 instance has the Ubuntu 22 version, which would make sense since the drivers are not supported at the moment and are not installed properly. The options I concluded are that either somehow downgrade my Ubuntu version from my EC2 server or create a new instance with a version that supports the sqlsrv drivers. I don't know if there's a third option for the installation to work properly in this version, but I assume the previous two are the more sensible.
My question is, is it possible or recommended to downgrade the Ubuntu version of the EC2 server? or should I create a new instance with a compatible version?
One of the main benefits of the cloud is resource provisioning speed.
It takes seconds to create a new EC2 instance, it's much easier & quicker to just create a new instance with the Ubuntu 20.04 LTS or Ubuntu 18.04 LTS AMIs available.

How to: Connecting a Instance (Virtual Machine from Google Cloud Service) with local runtime from Google Colab

I just struggled for 3 days to get this to work but many of the sources that explain it are somehow misleading. Therefore I share that now.
I was using windows and used the Windows 10 Subsystem for Linux to operate from there:
(instruction on how to activate you can find here https://learn.microsoft.com/en-us/windows/wsl/install-win10)
I first created a virtual machine on google cloud called colav-vm in the geographic zone us-east4-c
Start the VM in google cloud
Opened Ubuntu Linux Terminal:
Type:
gcloud compute ssh colav-vm --zone=us-east4-c -- -L 8888:locahost:8888
Enter Password to connect to it
Install pip:
(found it here: https://askubuntu.com/questions/672808/sudo-apt-get-install-python-pip-is-failing)
(In the connected terminal from the VM)
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install python-pip
- Install jupyter_http_over_ws
sudo -i pip install jupyter_http_over_ws
- Run the jupyter-server still on the connected VM:
jupyter serverextension enable --py jupyter_http_over_ws
jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0
(this should be also a code cell - but the formatting doesn't let me)
Then go to the browser on your local computer and type in " http://localhost:8888/ " to open a Jupyter environment if you have it installed - or go to google Colab and connect to runtime on the top right and type it in there and connect (there you need to add the full line including the token like that:
http://localhost:8888/?token=bd391421b3ec5c08f35ef28e2eb9d01fab6501e341c82e35)
I hope this saves some people some time.
The original sources are from here:
https://research.google.com/colaboratory/local-runtimes.html
https://medium.com/#yufengg/how-to-upgrade-colab-with-more-compute-64d53a9b05dc
(but somehow it confused me and it didn't work for me at least)

What's this error about while adding postgis in docker [duplicate]

This question already has answers here:
How to fill user input for interactive command for "RUN" command?
(2 answers)
Closed 6 months ago.
Part of my Dockerfile is as:
RUN apt-get install -yqq software-properties-common
RUN add-apt-repository ppa:ubuntugis/ppa && apt-get update -yqq
RUN apt-get install -yqq gdal-bin
RUN apt-get install -yqq postgis
I installed postgis repo, then installing postgis, but when it got to the installation step of postgis, I get this prompt on the screen & it's stuck there.
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
1. Africa 4. Australia 7. Atlantic 10. Pacific 13. Etc
2. America 5. Arctic 8. Europe 11. SystemV
3. Antarctica 6. Asia 9. Indian 12. US
Geographic area:
Does anyone has any idea??
Use RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq postgis when install postgis to suppress the dialog, or use ARG DEBIAN_FRONTEND=noninteractive which will also not persist to container but still have same effect.
Maybe also refers to https://github.com/docker/docker/issues/4032

How do I answer install prompts (other than with "yes") automatically?

Synopsis
I'm trying to build a Docker image, but it fails because one of the packages I'm trying to get with apt install prompts the user during the install process. I would like to reply to this prompt, but I can't figure out how to do it non-interactively.
Description
I'm building a Docker image, and my Dockerfile has the following line:
RUN apt install -y texlive-latex-extra
(This package has some LaTeX libraries that I need.)
During installation, this halts with:
Setting up tzdata (2018d-1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
1. Africa 6. Asia 11. System V timezones
2. America 7. Atlantic Ocean 12. US
3. Antarctica 8. Europe 13. None of the above
4. Australia 9. Indian Ocean
5. Arctic Ocean 10. Pacific Ocean
Geographic area:
At this point, it is waiting for some input. (There's another prompt after this for selecting timezone—I assume this is important to know for the \today directive in LaTeX files. ¯\_(ツ)_/¯)
How can I answer this non-interactively?
What I've tried so far
I've tried doing this:
apt install -y texlive-latex-extra <(echo 12 && echo 2)
and this:
echo 12 && echo 2 | apt install -y texlive-latex-extra
The first one died with this error:
apt install -y texlive-latex-extra <(echo 12 && echo 9)
and the second one seemed to have no effect.
For reference, here is my Dockerfile up until this point:
FROM ubuntu:latest
RUN apt update && apt upgrade -y && apt install -y curl bzip2 tar make gcc wget gnupg unzip
RUN apt install -y texlive
RUN apt install -y nodejs npm git
RUN npm install -g bower
RUN apt install -y texlive-latex-extra
UPDATE
I found something close here which suggested running apt install with DEBIAN_FRONTEND=noninteractive. This solved my problem sufficiently. :) However, I still would like to know how to respond to prompts, as the solution offered there only offered how to suppress them.
If you want to script a terminal interaction, you could use expect on Linux (that might not be very easy; you need to predict the interactions).
Remember that terminal emulators are complex and arcane things (because terminals like VT100 have been complex). See termios(3), pty(7) and read The Tty demystified.
The specific install prompt mentioned in the question is caused by the package tzdata. I managed to get it configured non-interactively in my docker build by setting these environment variables:
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y texlive-luatex texlive-latex-extra texlive-font
I found this solution over here: https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image

Disable `pip` retry installing packages - Speedup installation

I have a custom pip repository which is used inside my company but not outside. Now every time I'm at home and want to install something eg. pip install pandas it is trying also the "company" repo. Even decreasing the timeout pip still tries multiple times which takes a long time.
What can I do to speed up?
[global]
timeout = 1
extra-index-url = http://foo.bar/packages
trusted-host = pypi-dev.foo.bar
pip will ignore settings in the pip.conf if you run it with the '--isolated' option.
pip install --isolated <package>