0

I am facing an issue while trying to create a C-based PostgreSQL extension. I have the extension code available in my GitHub repository, and I am trying to load it using the CREATE EXTENSION command in PostgreSQL. However, I am encountering the following error:

ERROR: could not load library "/Users/spartacus/Desktop/GSoC/CODE/pg_cext": dlopen(/Users/spartacus/Desktop/GSoC/CODE/pg_cext, 0x000A): tried: '/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (not a file), '/System/Volumes/Preboot/Cryptexes/OS/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (no such file), '/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (not a file)

I have verified that the extension files are present at the given location, and the necessary permissions are also set. Despite this, the extension is not loading, and the error persists.

Steps Taken to Resolve the Issue:

  1. I have checked the file permissions for the extension files, and they seem to be correct.
ls -l /Users/spartacus/Desktop/GSoC/CODE/pg_cext


total 80
-rw-r--r--@ 1 spartacus  staff    139 Jul 15 12:24 Makefile
-rw-r--r--@ 1 spartacus  staff    100 Jul 15 12:27 pg_cext--1.0.0.sql
-rw-r--r--@ 1 spartacus  staff    227 Jul 15 12:27 pg_cext.c
-rw-r--r--@ 1 spartacus  staff    157 Jul 15 11:56 pg_cext.control
-rw-r--r--  1 spartacus  staff    984 Jul 17 09:14 pg_cext.o
-rwxr-xr-x  1 spartacus  staff  16951 Jul 17 09:14 pg_cext.so
  1. I have tried reloading PostgreSQL, but the error still occurs.
  2. I have confirmed that the extension files exist at the specified location, but the error message suggests otherwise.

My Environment:

  • PostgreSQL version: postgres (PostgreSQL) 15.0
  • Operating System: MacOS [M1 chip]
  • Extension Code

Can anyone help me troubleshoot and fix this issue? Thank you in advance for your assistance!

Ishaan Adarsh
  • 197
  • 1
  • 11
  • I've used the C-API to write access routines, but not create an extension. The manual [CREATE EXTENSION](https://www.postgresql.org/docs/current/sql-createextension.html) seems to suggest what you load is the extension's *script file* -- while it looks like you are attempting to load a *shared-object library* directly (may be right -- just seems at odds with the documentation) – David C. Rankin Jul 26 '23 at 07:13
  • I have looked around a lot for the documentation to help me with this. `CREATE EXTENSION` should work in theory. I am referencing my code on this -> [PostgreSQL Extensions - A Deeper Dive (postgres conference content)](https://postgresconf.org/system/events/document/000/001/158/pg-extensions.pdf) – Ishaan Adarsh Jul 26 '23 at 07:20
  • The "Demo C Extension" looks like what you want. That is a good link. Thank you. – David C. Rankin Jul 26 '23 at 07:59

2 Answers2

0

Please do the following: 1.Check file permissions :

pg_cext.so: ls -l /Users/spartacus/Desktop/GSoC/CODE/pg_cext
  1. Verify file path is correct & then Set the DYLD_LIBRARY_PATH:
export DYLD_LIBRARY_PATH=/Users/spartacus/Desktop/GSoC/CODE
  1. Use an absolute path in CREATE EXTENSION command.
  2. Restart PostgreSQL by using the command
 sudo systemctl restart postgresql
  1. Check PostgreSQL logs for additional details & Ensure extension is compiled for PostgreSQL 15.0 and M1 architecture.

I hope it will work..

#Apache-Age #postgresql

saima ali
  • 133
  • 9
  • I tried this approach but not getting any results. Still getting the same result – Ishaan Adarsh Jul 26 '23 at 08:27
  • Also `sudo systemctl restart postgresql` command will not work on macOS. https://stackoverflow.com/questions/47934081/does-the-command-systemctl-and-service-exists-on-linux-only-and-not-mac – Ishaan Adarsh Jul 26 '23 at 08:42
0

I also faced some errors while developing a C extension (PostgreSQL).

There are 3 main files for any extension.

1 .c file

  1. .control file

  2. .sql file

Make sure, your system is running proper versions that are compatible with each other while developing an extension.

I hope this answers our question.


Reference => Manual.