Thursday, April 7, 2016

ERROR: could not load library "/usr/pgsql-9.5/lib/oracle_fdw.so": libclntsh.so.12.1: cannot open shared object file: No such file or directory - resolve

While trying to connect from PostgreSQL to Oracle via oracle_fdw foreign data wrapper, you execute the command, CREATE EXTENSION oracle_fdw; after you have installed the Oracle Instant Client and the Foreign Data Wrapper for Oracle, you receive this message: ERROR:  could not load library "/usr/pgsql-9.5/lib/oracle_fdw.so": libclntsh.so.12.1: cannot open shared object file: No such file or directory.

To fix this problem:

1. Copy the oracle_few.so from the foreign data wrapper directory to the /usr/pgsql-9.5/lib directory.

2. Create symbolic links in the /usr/pgsql-9.5/lib directory for all the .so files in the oracle instant client directory.

ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libclntshcore.so.12.1 /usr/pgsql-9.5/lib/libclntshcore.so.12.1
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libipc1.so /usr/pgsql-9.5/lib/libipc1.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libmql1.so /usr/pgsql-9.5/lib/libmql1.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libnnz12.so /usr/pgsql-9.5/lib/libnnz12.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libocci.so /usr/pgsql-9.5/lib/libocci.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libociei.so /usr/pgsql-9.5/lib/libociei.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libocijdbc12.so /usr/pgsql-9.5/lib/libocijdbc12.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libons.so /usr/pgsql-9.5/lib/libons.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/liboramysql12.so /usr/pgsql-9.5/lib/liboramysql12.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libsqlplus.so /usr/pgsql-9.5/lib/libsqlplus.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libsqlplusic.so /usr/pgsql-9.5/lib/libsqlplusic.so
ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libclntsh.so /usr/pgsql-9.5/lib/libclntsh.so

3. Ensure the libclntsh.so file is on your PATH

4. If the problem remains, run command: ldconfig as root to config the dynamic linker run time binding.

--------------------------------------------------------------------------------------
                        

If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

2 comments:

  1. it is probably because you use ROOT to start the postgres server, and the oracle client path ( in particular the library path) is not included in the root shell profile.

    ReplyDelete
    Replies
    1. Yunwei, That is a nice shot.

      I started the postgresql server as postgres and the Oracle home was set to the Oracle instant client folder which is on the path. Please see these two posts about how I did it.

      http://flyingjxswithjava.blogspot.com/2016/04/migration-from-oracle-to-postgresql.html

      http://flyingjxswithjava.blogspot.com/2016/03/install-oracle-instant-client-on-windows.html

      Anyway, thank you for your interest!

      Delete