asdf-postgres icon indicating copy to clipboard operation
asdf-postgres copied to clipboard

Can't install latest postgres on WSL

Open thiagomajesk opened this issue 1 year ago • 15 comments

Describe the bug

Trying to install the latest (16.0) Postgres on a brand-new WSL machine yields the following error (this is the end of the stack trace):

make -C uuid-ossp install
make[1]: Entering directory '/home/thiago/.asdf/downloads/postgres/16.0/contrib/uuid-ossp'
/home/linuxbrew/.linuxbrew/bin/gmkdir -p '/home/thiago/.asdf/installs/postgres/16.0/lib'
/home/linuxbrew/.linuxbrew/bin/gmkdir -p '/home/thiago/.asdf/installs/postgres/16.0/share/extension'
/home/linuxbrew/.linuxbrew/bin/gmkdir -p '/home/thiago/.asdf/installs/postgres/16.0/share/extension'
/home/linuxbrew/.linuxbrew/bin/ginstall -c -m 755  uuid-ossp.so '/home/thiago/.asdf/installs/postgres/16.0/lib/uuid-ossp.so'
/home/linuxbrew/.linuxbrew/bin/ginstall -c -m 644 ./uuid-ossp.control '/home/thiago/.asdf/installs/postgres/16.0/share/extension/'
/home/linuxbrew/.linuxbrew/bin/ginstall -c -m 644 ./uuid-ossp--1.1.sql ./uuid-ossp--1.0--1.1.sql  '/home/thiago/.asdf/installs/postgres/16.0/share/extension/'
make[1]: Leaving directory '/home/thiago/.asdf/downloads/postgres/16.0/contrib/uuid-ossp'
/home/thiago/.asdf/installs/postgres/16.0/bin/initdb: error while loading shared libraries: libicuuc.so.73: cannot open shared object file: No such file or directory

Steps to reproduce

Running asdf install postgres latest doesn't seem do to anything. This doesn't happen for the previous version though, asdf install postgres 15.4 installed Postgres correctly.

thiagomajesk avatar Oct 21 '23 22:10 thiagomajesk

Are you on Ubuntu in your wsl environment?

smashedtoatoms avatar Oct 21 '23 23:10 smashedtoatoms

And just to be sure, did you install the prerequisites for Ubuntu on WSL from the readme?

smashedtoatoms avatar Oct 21 '23 23:10 smashedtoatoms

If you're on Ubuntu on wsl, can you run sudo apt-get install libicu-dev and then install it again. I will try 16 when I get home, but it sounds like they may include it in the default build now, which means I'll have to update the docs.

smashedtoatoms avatar Oct 21 '23 23:10 smashedtoatoms

Oh, sorry for not adding more information to the issue, I ended up forgetting...

I'm using Ubuntu 22.04.3 in WSL and I have installed all the required dependencies listed on the R EADME (BTW icu-devtools is missing from the WSL part).

Installing libicu-dev doesn't seem to have fixed it for me. I get the exact same error.

thiagomajesk avatar Oct 22 '23 00:10 thiagomajesk

I installed libicu-dev and re-installed the plugin from scratch. After doing that, I could install 15.4 and 16.0 successfully on Ubuntu 22.04.3 LTS. Can you make sure libicu-dev is installed and make sure it is version 70.1-2? Maybe restart your shell after installing it? I admit, I am grasping at straws since it worked for me.

smashedtoatoms avatar Oct 22 '23 02:10 smashedtoatoms

Hi, @smashedtoatoms! Tried uninstalling and installing the plugin again to no avail.

libicu-dev is installed and when I run dpkg -l | grep libicu-dev the version returned is indeed 70.1-2.

Ok, so I tried to redirect the output of the asdf install postgres latest command and it made the log a little bit better to read. This is something that I haven't seen before (the log output is quite large tbh):

configure: WARNING: *** Include directory '/opt/local/lib does not exist.
configure: WARNING: *** Include directory /sw/lib does not exist.
configure: WARNING: *** Include directory /usr/local/opt/openssl/include does not exist.
configure: WARNING: *** Include directory /opt/homebrew/include does not exist.
configure: WARNING: *** Include directory /home/linuxbrew/.linuxbrew/openssl/include does not exist.
configure: WARNING: *** Include directory /home/linuxbrew/.linuxbrew/libressl/include does not exist.
configure: WARNING: *** Include directory /usr/lib' does not exist.
configure: WARNING: *** Library directory '/opt/local/lib does not exist.
configure: WARNING: *** Library directory /sw/lib does not exist.
configure: WARNING: *** Library directory /usr/local/opt/
openssl/lib does not exist.
configure: WARNING: *** Library directory /home/linuxbrew/.linuxbrew/openssl/lib does not exist.
configure: WARNING: *** Library directory /home/linuxbrew/.linuxbrew/libressl/lib does not exist.
configure: WARNING: *** Library directory /usr/lib' does not exist.
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from Git nor
*** change any of the parser definition files.  You can obtain Bison from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this, because the Bison
*** output is pre-generated.)
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from Git nor
*** change any of the scanner definition files.  You can obtain Flex from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this because the Flex
*** output is pre-generated.)
/home/thiago/.asdf/installs/postgres/16.0/bin/initdb: error while loading shared libraries: libicuuc.so.73: cannot open shared object file: No such file or directory

And this is the full output: asdf-postgres-log.txt

thiagomajesk avatar Oct 23 '23 14:10 thiagomajesk

I have no idea. Are you using homebrew in Ubuntu to manage dependencies? I have never done that in Ubuntu, but OpenSSL via homebrew is the fifth circle of hell on my mac. Maybe you can try to set your LD_LIBRARY_PATH to point to where Ubuntu puts has installed the libicu library, or use homebrew to install the libicu dependency. I have no idea what could be going on.

smashedtoatoms avatar Oct 24 '23 01:10 smashedtoatoms

Yes, I'm using homebrew in Ubuntu for some applications that I use (like asdf), but system dependencies are installed via apt. Interestingly enough, it works for installing any other version besides 16.0, so I'm not sure what's happening.

I see that I had icu4c installed via brew because some package uses it and tried reinstalling 16.0 by setting LD_LIBRARY_PATH to the Homebrew path (just for testing) and I still get the same error.

Ok, so I may have a hint here... You said we need icu 70, but now that I've spent more time looking at this stack trace, it says:

~/.asdf/installs/postgres/16.0/bin/initdb: error while loading shared libraries: libicuuc.so.73: cannot open shared object file: No such file or directory

So, does it actually require libicu 73? Because that would make more sense, because I already have 70.1-2. What's the version that you have on the machine you can install 16.0?

thiagomajesk avatar Oct 24 '23 02:10 thiagomajesk

I get this when I run dpkg. 16 and 15.4 both install fine on mine. That said, I have had this wsl instance configured since April, so who knows what magical incantations I have that might be allowing it to work.

(me) ➜  me git:(dev) ✗ dpkg -l | grep libicu-dev
ii  libicu-dev:amd64                     70.1-2                                  amd64        Development files for International Components for Unicode

smashedtoatoms avatar Oct 24 '23 03:10 smashedtoatoms

I'll take a stab at nuking my WSL and doing it from scratch, but I use it for work, so it will have to wait until this weekend.

smashedtoatoms avatar Oct 24 '23 13:10 smashedtoatoms

I had the same issue with postgres@16 on WSL2 with brew. I'm actually using rtx, but it is mostly just a wrapper on asdf in the installation stage, especially when we are talking about community plugins.

I've found that find / -name 'libicuuc.so.*' 2>/dev/null gives the following:

/usr/lib/x86_64-linux-gnu/libicuuc.so.70.1
/usr/lib/x86_64-linux-gnu/libicuuc.so.70
/home/linuxbrew/.linuxbrew/lib/libicuuc.so.73.2
/home/linuxbrew/.linuxbrew/lib/libicuuc.so.73
/home/linuxbrew/.linuxbrew/Cellar/icu4c/73.2/lib/libicuuc.so.73.2
/home/linuxbrew/.linuxbrew/Cellar/icu4c/73.2/lib/libicuuc.so.73

So, I unlinked icu4c with: brew unlink icu4c.

Then rtx install postgres@{16.0, 15.4, 14.9}. And it worked for me.

After this I linked icu4c back with brew link icu4c.

ruslanSorokin avatar Nov 07 '23 05:11 ruslanSorokin

Oh wild. So something with the way brew's icu package is linked causes icu to not be found by this plug-in. That does narrow it down. I'm not sure when I'll have a chance to chase this down, but I'll see if I can figure it out.

smashedtoatoms avatar Nov 07 '23 12:11 smashedtoatoms

By the way, I just checked it on the MacOS and there is quite the opposite problem. I can't install postgres without force linking of icu4c with brew link icu4c --force

ruslanSorokin avatar Nov 07 '23 19:11 ruslanSorokin

I'm using plain asdf and just unlinking with brew doesn't work unfortunately...

@smashedtoatoms I was reading the postgres docs for the --with-icu flag and wondering if we could dynamically pass ICU_LIBS to the installation based on the result of find / -name 'libicuuc.so.*' 2>/dev/null or something 🤔.

Also, I noticed this from the docs:

By default, pkg-config will be used to find the required compilation options. This is supported for ICU4C version 4.6 and later. For older versions, or if pkg-config is not available, the variables ICU_CFLAGS and ICU_LIBS can be specified to configure

It seems that installing pkg-config changes the error, but it's not sufficient for the installation to properly complete:

make[1]: Leaving directory '/home/thiago/.asdf/downloads/postgres/16.1/contrib/uuid-ossp'
/home/thiago/.asdf/installs/postgres/16.1/bin/initdb: error while loading shared libraries: libicuuc.so.73: cannot open shared object file: No such file or directory

thiagomajesk avatar Nov 23 '23 15:11 thiagomajesk

By the way, I just checked it on the MacOS and there is quite the opposite problem. I can't install postgres without force linking of icu4c with brew link icu4c --force

Although it believe this part is a separate issue, I bet on macOS we do not necessarily need to force link but export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig" which brew info icu4c suggestively returns.

I do not own wsl environment and i do not have any idea about the original issue, but since it seems it partly has to do with the combination of homebrew and linking or unlinking of icu4c, I comment this for your information.

sato11 avatar Dec 25 '23 11:12 sato11

https://github.com/smashedtoatoms/asdf-postgres/issues/80#issuecomment-1954665952 suggests that using 16.2 may work. Also, if you're using pkgconfig, you will have to figure out how to get your linking to work. There is nothing strictly wrong with asdf-postgres, but since it compiles from source and uses linking to system resources, infinite permutations of things cause it to fail. By using brew, apt, pkgconfig, etc. all together, you're in a situation that is going to be really hard for me to figure out.

See if you can work through it using suggestions from other tickets on this repo. I am sorry I can't be more helpful, but between macOS and every Linux distro, basically yolo-ing everything involving openssl and every program linking to a different version, this is impossible for me to keep up with, given the limited time I have. I'm really sorry.

smashedtoatoms avatar Feb 27 '24 16:02 smashedtoatoms