Wednesday, August 31, 2016

Create a new table using schema (columns) and / or data from an existing table in Oracle and PostgreSQL

A. Oracle

1. Create a new table using the complete schema and data from an existing table.

      create table <new table name> as select * from <existing table name>;

2. Create a new table using partial of the schema and data of an existing table.

      create table <new table name> as select <column 1>, <column 2>, .... from <existing table name>;

     The new table would have only the columns and their data selected from the existing table.

3. Create a new table using the schema but not data from an existing table.

      create table <new table name> as select * from <existing table name> where 1=0;
      create table <new table name> as select <column 1><column 2>, .... from <existing table name> where 1=0;

B. PostgreSQL

1. Create a new table using the complete schema and data from an existing table.

      select * into <new table name> from <existing table name>;

2. Create a new table using partial of the schema and data of an existing table.

      select <column 1><column 2>, .... into <new table name> from <existing table name>;

3. Create a new table using the schema but not data from an existing table.

      select * into <new table name> from <existing table name> where 1=0;
      select <column 1><column 2>, .... into <new table name> from <existing table name> where 1=0;

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

                        

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.

Monday, August 8, 2016

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

This error happened when I was making the protocol for converting from Oracle to PostgreSQL on linux. It happened to me two times on two different machines and for different reasons.

The first time:

I installed PosgreSQL, Oracle JDBC, Oracle Instant Client, and oracle_fdw, everything worked fine. Before I was going to make the protocol final, I reinstalled everything to ensure there is no problems. At each step of the installation, the test worked OK. However, when I tried to run the command: "CREATE EXTENSION oracle_fdw", it returned this error:

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

This, at first glance, appears to be a path problem. So, I checked to ensure that a symbolic link for libmql1.so is in the /usr/pgsql-9.5/lib/ directory and the PATH environmental variable was set correctly, but it did not solve the problem. Even though the libmql1.so is right next to the oracle_fdw.so in the /usr/pgsql-9.5/lib/ directory, it was just not able to see it.

The problem was cleared up by restarting the PostgreSQL server. It turned out that after you have installed the Oracle JDBC, it is critical to restart the PostgreSQL server for the oracle_fdw to work.

The second time:

After installed PosgreSQL, Oracle JDBC, Oracle Instant Client, and oracle_fdw on a different linux CentOS 6.6, I got the same error when running "CREATE EXTENSION oracle_fdw". Like before, I ensured the PATH was correctly set and restarted the PostgreSQL server, this time restarting the server did not remove the problem. The problem was solved by executing the command "ldconfig" as root, which configures the dynamic linker run time bindings.

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

                        

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.

Friday, August 5, 2016

ERROR: could not access file "$libdir/oracle_fdw": No such file or directory - Solved

After you have installed Oracle Instant Client and Oracle Data Wrapper, you execute the command: CREATE EXTENSION oracle_fdw, and you are returned with the following error:

      ERROR:  could not access file "$libdir/oracle_fdw": No such file or directory

This is obviously a PATH problem.

When you are running psql, it will look for files in the /usr/pgsql-9.5 directory. The above error occurs because it could not find the oracle_fdw.so in the /usr/pgsql-9.5/lib directory.

To fix it,  copy the oracle_fdw.so from oracle_fdw-ORACLE_FDW_1_3_0 directory to the /usr/pgsql-9.5/lib directory or create a symbolic link.

Also make sure that all the .so files in your Oracle Instant Client directory also have symbolic links in the /usr/pgsql-9.5/lib directory.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




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 for free here.

/usr/bin/ld: cannot find -lclntsh during make of oracle_fdw

After you have unzipped the oracle_fdw-ORACLE_FDW_1_3_0.zip file and then run the make command in the oracle_fdw-ORACLE_FDW_1_3_0 directory, it gives the message: 

       /usr/bin/ld: cannot find -lclntsh
       collect2: ld returned 1 exit status
       make: *** [oracle_fdw.so] Error 1

You run the command: /usr/bin/ld -lclntsh --verbose 
It prints at the end of the messages:

      attempt to open /usr/x86_64-redhat-linux/lib64/libclntsh.so failed
      attempt to open /usr/x86_64-redhat-linux/lib64/libclntsh.a failed
      attempt to open /usr/local/lib64/libclntsh.so failed
      attempt to open /usr/local/lib64/libclntsh.a failed
      attempt to open /lib64/libclntsh.so failed
      attempt to open /lib64/libclntsh.a failed
      attempt to open /usr/lib64/libclntsh.so failed
      attempt to open /usr/lib64/libclntsh.a failed
      attempt to open /usr/x86_64-redhat-linux/lib/libclntsh.so failed
      attempt to open /usr/x86_64-redhat-linux/lib/libclntsh.a failed
      attempt to open /usr/lib64/libclntsh.so failed
      attempt to open /usr/lib64/libclntsh.a failed
      attempt to open /usr/local/lib/libclntsh.so failed
      attempt to open /usr/local/lib/libclntsh.a failed
      attempt to open /lib/libclntsh.so failed
      attempt to open /lib/libclntsh.a failed
      attempt to open /usr/lib/libclntsh.so failed
      attempt to open /usr/lib/libclntsh.a failed
      /usr/bin/ld: cannot find -lclntsh

To fix this, do the following.
   
      ln -s /usr/pgsql-9.5/oracle/instantclient_12_1/lib/libclntsh.so.12.1 /usr/lib/libclntsh.so

which makes a symbolic link libclntsh.so in the /usr/lib directory that points to the libclntsh.so.12.1 of the oracle instant client.

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

                        
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.