Skip to content
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

Trouble Creating Extension on M1 Mac #24

Open
Samuelodan opened this issue Jan 23, 2024 · 14 comments
Open

Trouble Creating Extension on M1 Mac #24

Samuelodan opened this issue Jan 23, 2024 · 14 comments

Comments

@Samuelodan
Copy link

Hi there,
I'm trying to install this extension on my Apple Silicon Mac, but I get this error on the CREATE EXTENSION step:

ERROR:  could not load library "/opt/homebrew/lib/postgresql@14/pg_uuidv7.so": dlopen(/opt/homebrew/lib/postgresql@14/pg_uuidv7.so, 0x000A): tried: '/opt/homebrew/lib/postgresql@14/pg_uuidv7.so' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/postgresql@14/pg_uuidv7.so' (no such file), '/opt/homebrew/lib/postgresql@14/pg_uuidv7.so' (not a mach-o file), '/opt/homebrew/Cellar/postgresql@14/14.10_1/lib/postgresql@14/pg_uuidv7.so' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/postgresql@14/14.10_1/lib/postgresql@14/pg_uuidv7.so' (no such file), '/opt/homebrew/Cellar/postgresql@14/14.10_1/lib/postgresql@14/pg_uuidv7.so' (not a mach-o file)

I'd appreciate it if I got some help on the install.
Thanks.

@fboulnois
Copy link
Owner

What process are you using to install?

@Samuelodan
Copy link
Author

Hi, I used a bash script based on the example script in the README. My machine doesn't have sha256sum installed, so I added the line below to the script:
function sha256sum() { openssl sha256 "$@" | awk '{print $2}'; }

Here's the full script just in case.

#! /bin/bash
cd "$(mktemp -d)"
curl -LO "https://github.com/fboulnois/pg_uuidv7/releases/download/v1.4.1/{pg_uuidv7.tar.gz,SHA256SUMS}"
tar xf pg_uuidv7.tar.gz

function sha256sum() { openssl sha256 "$@" | awk '{print $2}'; }
sha256sum -c SHA256SUMS
PG_MAJOR=$(pg_config --version | sed 's/^.* \([0-9]\{1,\}\).*$/\1/')
cp "$PG_MAJOR/pg_uuidv7.so" "$(pg_config --pkglibdir)"
cp pg_uuidv7--1.4.sql pg_uuidv7.control "$(pg_config --sharedir)/extension"
# the CREATE EXTENSION command will be run in a (Rails) migration with `enable_extension`

Thanks.

@matthiasbayer
Copy link

Similar error here on M3, but not sure if that's the root cause.

could not load library "/usr/lib/postgresql/16/lib/pg_uuidv7.so": /usr/lib/postgresql/16/lib/pg_uuidv7.so: cannot open shared object file: No such file or directory

even though the file exists:

root@3add0a82ddf9:/# ls -al /usr/lib/postgresql/16/lib/pg_uuidv7.so
-rwxr-xr-x 1 root root 21952 Jan 24 18:26 /usr/lib/postgresql/16/lib/pg_uuidv7.so

I'm using pg_uuidv7 at version 1.0.0.

@Samuelodan
Copy link
Author

@matthiasbayer I hope we find a neat solution, cos I think it's a nice implementation.
For now, I've fallen back to generating the UUIDv7 values in the application before creating resources. This should suffice until a database solution is found.

Oh, being relatively new to all this, I found out today that we can define a function in the database and use that as the default value for a column. Here's a cool one for UUIDv7 generation:

@matthiasbayer
Copy link

I was able to solve this by building the extension from source using the Makefile.

@Samuelodan
Copy link
Author

@matthiasbayer oh wow! That's great news. Is this something I can do in a script too? I'd like to make our application fairly straightforward.

@fboulnois
Copy link
Owner

fboulnois commented Jan 24, 2024

Yes, to clarify the issue, the releases are built for x86_64 and not for ARM (like the M1, M2, and M3 Macs), hence the error with loading the library if you download the release directly from GitHub.

The correct solution for other architectures is indeed to build the extension from source. You'll want to follow the local build process outlined in the README.md:

# assumes that libpq-dev and postgres are correctly set up
make
make install

I'll add a note in the docs about installing on other architectures.

@Samuelodan
Copy link
Author

Thank you so much @fboulnois
Yeah, I'll appreciate it if you add more details to the README. But it's mostly a skill issue. If I knew about using Makefiles, the solution would've been obvious to me.
Anyways, I'm happy to try it out and become somewhat comfortable with make. 😊

Thank you for the help. I'll let you know how it goes.

@fboulnois
Copy link
Owner

I added a note in #25 , hopefully that should help future developers.

@nataliachodelski
Copy link

nataliachodelski commented Mar 30, 2024

I'm new to docker & found the process to download and build the pg_uuidv7 extension confusing, so I wanted to share my resulting Dockerfile for the postgres container in which i want to use this extension.

FROM postgres:16.2

RUN apt-get update && apt-get -y install git build-essential postgresql-server-dev-16
RUN postgres --version
RUN git clone https://github.com/fboulnois/pg_uuidv7
RUN cd pg_uuidv7 && make && make install && ls -la

COPY ./init.sql /docker-entrypoint-initdb.d/init.sql

@Samuelodan
Copy link
Author

Thank you so much for sharing.
I considered the likelihood of switching to a managed postgres database for my app and realized that I wouldn't be able to use this extension with any of the services, so I stuck to generating and assigning the UUIDv7 values within the application itself using a callback.

It doesn't seem like the most elegant solution, but it works my situation right now.

@conradwt
Copy link

conradwt commented Mar 30, 2024

@Samuelodan It's always most important to get something working and iterate on that solution. It looks like UUIDv7 feature is targeted at PostgreSQL 17:

https://commitfest.postgresql.org/47/4388

@Samuelodan
Copy link
Author

Thanks @conradwt
I saw that it was coming to v17 so that's another thing that helped me to wait. I'll switch to the native extension as soon as I upgrade.

@dotZak
Copy link

dotZak commented Jun 1, 2024

Thread summary w/ a solution

I got this working today. I'll summarize the info in this thread.

⚠️ Don't use the release version on MacOS

Per the author in the README, the release version is for x86_64, not ARM (M1, M2, M3…).

👍 Install on MacOS for any M-series Macs

⚠️ Prerequisite/warning

Make sure your pg_config command is the one that you think it is. I was struggling because I would install and nothing would happen. It turns out I had two copies of Postgres installed: One from brew and one from the desktop app.

I had to update my $PATH variable so the "correct" version came first. ("Correct" is whichever version you intend to use).

$ whereis pg_config
pg_config: /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /Applications/Postgres.app/Contents/Versions/latest/share/man/man1/pg_config.1

Clone the repo

1️⃣ Use git to clone the repository to your machine. It doesn't matter where since you can delete it after install. e.g I used the Downloads directory.

cd ~/Downloads && \
git clone https://github.com/fboulnois/pg_uuidv7.git

Once that's done you can cd into the directory

cd pg_uuidv7

Make and install the extension

2️⃣ Run make, then make install.

make

You should get some output like this…

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro  -Os -mmacosx-version-min=10.13 -arch arm64 -arch x86_64  -fvisibility=hidden -I. -I./ -I/Applications/Postgres.app/Contents/Versions/16/include/postgresql/server -I/Applications/Postgres.app/Contents/Versions/16/include/postgresql/internal -I/Applications/Postgres.app/Contents/Versions/16/share/icu -I/Applications/Postgres.app/Contents/Versions/16/include/libxml2 -I/Applications/Postgres.app/Contents/Versions/16/include -I/Applications/Postgres.app/Contents/Versions/16/include  -I/Applications/Postgres.app/Contents/Versions/16/include  -c -o pg_uuidv7.o pg_uuidv7.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro  -Os -mmacosx-version-min=10.13 -arch arm64 -arch x86_64  -fvisibility=hidden pg_uuidv7.o -L/Applications/Postgres.app/Contents/Versions/16/lib  -L/Applications/Postgres.app/Contents/Versions/16/lib -L/Applications/Postgres.app/Contents/Versions/16/lib -L/Applications/Postgres.app/Contents/Versions/16/lib  -L/Applications/Postgres.app/Contents/Versions/16/lib -Wl,-dead_strip_dylibs   -fvisibility=hidden -bundle -bundle_loader /Applications/Postgres.app/Contents/Versions/16/bin/postgres -o pg_uuidv7.dylib

Notice the pg_uuidv7.dylib at the end there? That's the thing the release doesn't do for you.

3️⃣ If that's all good you can run the install.

make install

You should get a message similar to this:

/bin/sh /Applications/Postgres.app/Contents/Versions/16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/Applications/Postgres.app/Contents/Versions/16/share/postgresql/extension'
/bin/sh /Applications/Postgres.app/Contents/Versions/16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/Applications/Postgres.app/Contents/Versions/16/share/postgresql/extension'
/bin/sh /Applications/Postgres.app/Contents/Versions/16/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -d '/Applications/Postgres.app/Contents/Versions/16/lib/postgresql'

Verify and cleanup

To check that it installed correctly, attempt to use the CREATE function using the cli. If you don't get an error, then you're done and ready to use the extension.

4️⃣ You can use psql to see if there's an issue.

psql -c "CREATE EXTENSION pg_uuidv7;"

It should just echo the command back to you…

CREATE EXTENSION

5️⃣ Now you can remove the directory you cloned.

cd ~/Downloads && \
rm -rf ~/Downloads/pg_uuidv7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants