Archive for the ‘DBA’ Category
Create Student User
It’s amazing how old some of my students’ computers are. The oldest with least memory are the foreign students. Fortunately, I kept copies of the old Oracle Database 10g XE. I give it to some students who need to run the smallest possible option. Then, again I have students who get emotional about having to use Unix or Linux as an operating system, which means I now also support Oracle Database 18c.
Anyway, I had to write a script that would support building a small 200 MB student
schema in any of the Express Edition databases from 10g to 18c. Here’s the script for those who would like to use it. It sets up a student
schema for Oracle Database 10g and 11g databases and a c##student
schema for Oracle’s Containized Database 12c and 18c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | DECLARE /* Control variable. */ container BOOLEAN := FALSE; /* Weakly structured system reference cursor. */ container_sql SYS_REFCURSOR; /* Constant required for pre-container databases to avoid a a compile time error. */ sql_statement CONSTANT VARCHAR2(50) := 'SELECT cdb FROM v$database WHERE cdb = ''YES'''; BEGIN /* Check if the current user is the superuser. */ FOR i IN (SELECT USER FROM dual) LOOP /* Perform tasks as superuser. */ IF i.USER = 'SYSTEM' THEN /* Check for a container-enabled column, which enables this to work in both pre-container Oracle databases, like 10g and 11g. */ FOR j IN (SELECT DISTINCT column_name FROM dba_tab_columns WHERE column_name = 'CDB') LOOP /* Check for a container database, set control variable and exit when found. */ OPEN container_sql FOR sql_statement; LOOP container := TRUE; EXIT WHEN container_sql%FOUND; END LOOP; END LOOP; /* Conditionally drop existing user and role. */ IF container THEN /* Conditionally drop a container user. */ FOR j IN (SELECT username FROM dba_users WHERE username = 'C##STUDENT') LOOP EXECUTE IMMEDIATE 'DROP USER c##student CASCADE'; END LOOP; /* Conditionally rop the container c##studentrole role. */ FOR j IN (SELECT ROLE FROM dba_roles WHERE ROLE = 'C##STUDENTROLE') LOOP EXECUTE IMMEDIATE 'DROP ROLE c##studentrole'; END LOOP; /* Create a container user with 200 MB of space. */ EXECUTE IMMEDIATE 'CREATE USER c##student'||CHR(10) || 'IDENTIFIED BY student'||CHR(10) || 'DEFAULT TABLESPACE users'||CHR(10) || 'QUOTA 200M ON users'||CHR(10) || 'TEMPORARY TABLESPACE temp'; /* Create a container role. */ EXECUTE IMMEDIATE 'CREATE ROLE c##studentrole CONTAINER = ALL'; /* Grant privileges to a container user. */ EXECUTE IMMEDIATE 'GRANT CREATE CLUSTER, CREATE INDEXTYPE,'||CHR(10) || 'CREATE PROCEDURE, CREATE SEQUENCE,'||CHR(10) || 'CREATE SESSION, CREATE TABLE,'||CHR(10) || 'CREATE TRIGGER, CREATE TYPE,'||CHR(10) || 'CREATE VIEW TO c##studentrole'; /* Grant role to user. */ EXECUTE IMMEDIATE 'GRANT c##studentrole TO c##student'; ELSE /* Conditonally drop the non-container database user. */ FOR j IN (SELECT username FROM dba_users WHERE username = 'STUDENT') LOOP EXECUTE IMMEDIATE 'DROP USER student CASCADE'; END LOOP; /* Create the student database. */ EXECUTE IMMEDIATE 'CREATE USER student'||CHR(10) || 'IDENTIFIED BY student'||CHR(10) || 'DEFAULT TABLESPACE users'||CHR(10) || 'QUOTA 200M ON users'||CHR(10) || 'TEMPORARY TABLESPACE temp'; /* Grant necessary privileges to the student database. */ EXECUTE IMMEDIATE 'GRANT CREATE CLUSTER, CREATE INDEXTYPE,'||CHR(10) || 'CREATE PROCEDURE, CREATE SEQUENCE,'||CHR(10) || 'CREATE SESSION, CREATE TABLE,'||CHR(10) || 'CREATE TRIGGER, CREATE TYPE,'||CHR(10) || 'CREATE VIEW TO student'; END IF; ELSE /* Print an message that the user lacks privilegs. */ dbms_output.put_line('You must be the SYSTEM user to drop and create a user.'); END IF; END LOOP; END; / |
As always, I hope this helps those looking for a solution beyond Quest’s Toad for Oracle, APEX, or SQL Developer. Let me know if you like it.
Java & MySQL 8.0.19
It’s the in-between term time and we’re all stuck at home. I decided to update the image for my Fedora 30 virtual machine. I had a work around to the update issue that I had encountered last October in Bug #96969 but it was not required with the current version. However, after updating from MySQL 8.0.17 to MySQL 8.0.19, I found that my Java connection example failed.
The $CLASSPATH
value was correct:
/usr/share/java/mysql-connector-java.jar:. |
The first error that I got was the my reference to MySQL JDBC driver was incorrect. The error message is quite clear:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Cannot connect to database server: The server time zone value 'MDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support. |
I changed the MySQL Driver reference as instructed by the error message:
29 30 31 | // Create instance of MySQLDriver. Class.forName ("com.mysql.cj.jdbc.Driver").newInstance(); conn = DriverManager.getConnection (url, username, password); |
After the change, I got the following error while retesting my little MySQL Java driver connection test program. Initially, I thought this required a change in the Java environment but that wasn’t it.
Cannot connect to database server: The server time zone value 'MDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support. |
It required me to add the following line to my /etc/my.cnf configuration file, which synchronizes the database’s timezone with the operating system.
# Synchronize the MySQL clock with the computer system clock. default-time-zone='+00:00' |
Then, running my MySQL Driver connection test program worked like a charm. It returns the following:
Database connection established MySQLDriver Version [8.0.19] Database connection terminated |
Here’s the MySQL Connector Java code if you’d like to use the MySQLDriver.java
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | // Import classes. import java.sql.*; /* You can't include the following on Linux without raising an exception. */ // import com.mysql.jdbc.Driver; public class MySQLDriver { public MySQLDriver() { /* Declare variables that require explicit assignments because they're addressed in the finally block. */ Connection conn = null; Statement stmt = null; ResultSet rset = null; /* Declare other variables. */ String url; String username = "student"; String password = "student"; String database = "studentdb"; String hostname = "localhost"; String port = "3306"; String sql; /* Attempt a connection. */ try { // Set URL. url = "jdbc:mysql://" + hostname + ":" + port + "/" + database; // Create instance of MySQLDriver. Class.forName ("com.mysql.cj.jdbc.Driver").newInstance(); conn = DriverManager.getConnection (url, username, password); // Query the version of the database. sql = "SELECT version()"; stmt = conn.createStatement(); rset = stmt.executeQuery(sql); System.out.println ("Database connection established"); // Read row returns for one column. while (rset.next()) { System.out.println("MySQLDriver Version [" + rset.getString(1) + "]"); } } catch (SQLException e) { System.err.println ("Cannot connect to database server:"); System.out.println(e.getMessage()); } catch (ClassNotFoundException e) { System.err.println ("Cannot find MySQL driver class:"); System.out.println(e.getMessage()); } catch (InstantiationException e) { System.err.println ("Cannot instantiate class:"); System.out.println(e.getMessage()); } catch (IllegalAccessException e) { System.err.println ("Illegal access exception:"); System.out.println(e.getMessage()); } finally { if (conn != null) { try { rset.close(); stmt.close(); conn.close(); System.out.println ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } } /* Unit test. */ public static void main(String args[]) { new MySQLDriver(); } } |
As always, I hope this helps those who encounter similar problems.
PostgreSQL Write JSON File
In the process of working through issues to support ETL transformations from JSON with Python. The first step was extracting a the data from a PostgreSQL table into a JSON file. The syntax wasn’t exactly clear and the PostgreSQL Tutorial was a bit misleading but I worked it out. My initial sample deals with writing the data from the item
table of my videodb
database to a item.json
file in the /tmp
directory.
The query retrieves the data but casts the creation_date
and last_update_date
timestamp
data types into date
data types, as follows:
SELECT row_to_json( (SELECT ROW FROM (SELECT item_id , item_barcode , item_type , item_title , item_subtitle , item_rating , item_release_date , created_by , creation_date::DATE , last_updated_by , last_update_date::DATE) ROW)) AS DATA FROM item; |
The internal SELECT
-list creates the name element of name:value pairs in the JSON structure. Naturally, it does exclude the type casting ::date
portion of the query from the name elements. The row_to_json()
maps the name
list to the list of value
results from in each row, and returns a result set.
The query returns the following 21 JSON objects:
{"item_id":1001,"item_barcode":"9736-05640-4","item_type":1016,"item_title":"The Hunt for Red October","item_subtitle":"Special Collector's Edition","item_rating":"PG","item_release_date":"1990-03-02","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1002,"item_barcode":"24543-02392","item_type":1016,"item_title":"Star Wars I","item_subtitle":"Phantom Menace","item_rating":"PG","item_release_date":"1999-05-04","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1003,"item_barcode":"24543-5615","item_type":1015,"item_title":"Star Wars II","item_subtitle":"Attack of the Clones","item_rating":"PG","item_release_date":"2002-05-16","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1004,"item_barcode":"24543-05539","item_type":1016,"item_title":"Star Wars II","item_subtitle":"Attack of the Clones","item_rating":"PG","item_release_date":"2002-05-16","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1005,"item_barcode":"24543-20309","item_type":1016,"item_title":"Star Wars III","item_subtitle":"Revenge of the Sith","item_rating":"PG13","item_release_date":"2005-05-19","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1006,"item_barcode":"86936-70380","item_type":1016,"item_title":"The Chronicles of Narnia","item_subtitle":"The Lion, the Witch and the Wardrobe","item_rating":"PG","item_release_date":"2002-05-16","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1007,"item_barcode":"91493-06475","item_type":1019,"item_title":"RoboCop","item_subtitle":"","item_rating":"Mature","item_release_date":"2003-07-24","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1008,"item_barcode":"93155-11810","item_type":1019,"item_title":"Pirates of the Caribbean","item_subtitle":"","item_rating":"Teen","item_release_date":"2003-06-30","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1009,"item_barcode":"12725-00173","item_type":1019,"item_title":"The Chronicles of Narnia","item_subtitle":"The Lion, the Witch and the Wardrobe","item_rating":"Everyone","item_release_date":"2003-06-30","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1010,"item_barcode":"45496-96128","item_type":1017,"item_title":"MarioKart","item_subtitle":"Double Dash","item_rating":"Everyone","item_release_date":"2003-11-17","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1011,"item_barcode":"08888-32214","item_type":1018,"item_title":"Splinter Cell","item_subtitle":"Chaos Theory","item_rating":"Teen","item_release_date":"2003-04-08","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1012,"item_barcode":"14633-14821","item_type":1018,"item_title":"Need for Speed","item_subtitle":"Most Wanted","item_rating":"Everyone","item_release_date":"2004-11-15","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1013,"item_barcode":"10425-29944","item_type":1019,"item_title":"The DaVinci Code","item_subtitle":"","item_rating":"Teen","item_release_date":"2006-05-19","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1014,"item_barcode":"52919-52057","item_type":1019,"item_title":"Cars","item_subtitle":"","item_rating":"Everyone","item_release_date":"2006-04-28","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1015,"item_barcode":"9689-80547-3","item_type":1020,"item_title":"Beau Geste","item_subtitle":"","item_rating":"PG","item_release_date":"1992-03-01","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1016,"item_barcode":"53939-64103","item_type":1020,"item_title":"I Remember Mama","item_subtitle":"","item_rating":"NR","item_release_date":"1998-01-05","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1017,"item_barcode":"24543-01292","item_type":1020,"item_title":"Tora! Tora! Tora!","item_subtitle":"The Attack on Pearl Harbor","item_rating":"G","item_release_date":"1999-11-02","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1018,"item_barcode":"43396-60047","item_type":1020,"item_title":"A Man for All Seasons","item_subtitle":"","item_rating":"G","item_release_date":"1994-06-28","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1019,"item_barcode":"43396-70603","item_type":1020,"item_title":"Hook","item_subtitle":"","item_rating":"PG","item_release_date":"1991-12-11","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1020,"item_barcode":"85391-13213","item_type":1020,"item_title":"Around the World in 80 Days","item_subtitle":"","item_rating":"G","item_release_date":"1992-12-04","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} {"item_id":1021,"item_barcode":"85391-10843","item_type":1020,"item_title":"Camelot","item_subtitle":"","item_rating":"G","item_release_date":"1998-05-15","created_by":1001,"creation_date":"2019-12-13","last_updated_by":1001,"last_update_date":"2019-12-13"} |
Moving on to the next step you enclose the query in the copy
command syntax, like:
COPY (SELECT row_to_json( (SELECT ROW FROM (SELECT item_id , item_barcode , item_type , item_title , item_subtitle , item_rating , item_release_date , created_by , creation_date::DATE , last_updated_by , last_update_date::DATE) ROW)) AS DATA FROM item) TO '/tmp/sample.json'; |
When you run it, it will fail with the following error message:
ERROR: must be superuser or a member of the pg_write_server_files role to COPY to a file HINT: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone. |
You can fix this problem by connecting as the postgres
user and granting the privilege to the student
user:
GRANT pg_write_server_files TO student; |
It then runs successfully as the student
user and creates the sample.json
file in the /tmp
directory. As always, I hope this helps those looking for a solution.
PostgreSQL Upsert Advanced
Nine years after writing how to use the MERGE
statement in Oracle, I am writing how you implement an UPSERT
statement in PostgreSQL. I wrote an initial post going over the basics of PostgreSQL’s upsert implementation of the INSERT
statement with an DO UPDATE
clause and a DO NOTHING
clause.
I thought it was interesting that the PostgreSQL Upsert Using INSERT ON CONFLICT
Statement web page didn’t cover using a subquery as the source for an INSERT
statement.
Demonstration
Here are the steps to accomplish an import/upload with the COPY
statement and the INSERT
statement with DO UPDATE
and DO NOTHING
clauses.
Step #1 : Position your CSV file in the physical directory
The example uses the following upload directory:
/u01/app/postgres/upload |
Put the following text in to the kingdom_import.csv
file.
Narnia,77600,Peter the Magnificent,1272-03-20,1292-06-19 Narnia,77600,Edmund the Just,1272-03-20,1292-06-19 Narnia,77600,Susan the Gentle,1272-03-20,1292-06-19 Narnia,77600,Lucy the Valiant,1272-03-20,1292-06-19 Narnia,42100,Peter the Magnificent,1531-04-12,1531-05-31 Narnia,42100,Edmund the Just,1531-04-12,1531-05-31 Narnia,42100,Susan the Gentle,1531-04-12,1531-05-31 Narnia,42100,Lucy the Valiant,1531-04-12,1531-05-31 Camelot,15200,King Arthur,0631-03-10,0686-12-12 Camelot,15200,Sir Lionel,0631-03-10,0686-12-12 Camelot,15200,Sir Bors,0631-03-10,0635-12-12 Camelot,15200,Sir Bors,0640-03-10,0686-12-12 Camelot,15200,Sir Galahad,0631-03-10,0686-12-12 Camelot,15200,Sir Gawain,0631-03-10,0686-12-12 Camelot,15200,Sir Tristram,0631-03-10,0686-12-12 Camelot,15200,Sir Percival,0631-03-10,0686-12-12 Camelot,15200,Sir Lancelot,0670-09-30,0682-12-12 Camelot,15200,Modred,0681-09-30,0682-12-12 |
Step #2 : Run the script that creates tables and sequences
Copy the following code into a create_kingdom_knight_tables.sql
file within a directory of your choice. Then, you run it as the student
user. Assuming you put the code in the create_kingdom_knight_tables.sql
script, you can call it like so
\i create_kingdom_knight_tables.sql |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | -- Conditionally drop three tables and sequences. DO $$ DECLARE /* Declare an indefinite length string and record variable. */ SQL VARCHAR; ROW RECORD; /* Declare a cursor. */ table_cursor CURSOR FOR SELECT TABLE_NAME FROM information_schema.tables WHERE table_catalog = 'videodb' AND table_schema = 'public' AND TABLE_NAME IN ('kingdom','knight','kingdom_knight_import'); BEGIN /* Open the cursor. */ OPEN table_cursor; LOOP /* Fetch table names. */ FETCH table_cursor INTO ROW; /* Exit when no more records are found. */ EXIT WHEN NOT FOUND; /* Concatenate together a DDL to drop the table with prejudice. */ SQL := 'DROP TABLE IF EXISTS '||ROW.table_name||' CASCADE'; /* Execute the DDL statement. */ EXECUTE SQL; END LOOP; /* Close the cursor. */ CLOSE table_cursor; END; $$; -- Create normalized kingdom table. CREATE TABLE kingdom ( kingdom_id SERIAL , kingdom_name VARCHAR(20) , population INTEGER , CONSTRAINT kingdom_uq_key UNIQUE ( kingdom_name , population )); -- Create normalized knight table. CREATE TABLE knight ( knight_id SERIAL , knight_name VARCHAR(24) , kingdom_allegiance_id INTEGER , allegiance_start_date DATE , allegiance_end_date DATE , CONSTRAINT knight_uq_key UNIQUE ( knight_name , kingdom_allegiance_id , allegiance_start_date , allegiance_end_date )); -- Create external import table. CREATE TABLE kingdom_knight_import ( kingdom_name VARCHAR(20) , population INTEGER , knight_name VARCHAR(24) , allegiance_start_date DATE , allegiance_end_date DATE); |
Step #3 : Run the COPY
command.
Run the COPY
command to move the data from the Comma Separated Values (CSV) file to the kingdom_knight_import
table. Then, run it as the student
account.
1 2 | COPY kingdom_knight_import FROM '/u01/app/postgres/upload/kingdom_import1.csv' DELIMITERS ',' CSV; |
Step #4 : Create the upload_kingdom
procedure
Copy the following code into a create_kingdom_knight_procedure.sql
file within a directory of your choice. Assuming you put the code in the create_kingdom_knight_procedure.sql
script, you can call it like so
\i create_kingdom_knight_procedure.sql |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | CREATE PROCEDURE upload_kingdom() AS $$ DECLARE /* Declare error handling variables. */ err_num TEXT; err_msg INTEGER; BEGIN /* Insert only unique rows. The DISTINCT operator compresses the result set to a unique set and avoids consuming sequence values for non-unique result sets. */ INSERT INTO kingdom ( kingdom_name , population ) ( SELECT DISTINCT kki.kingdom_name , kki.population FROM kingdom_knight_import kki LEFT JOIN kingdom k ON kki.kingdom_name = k.kingdom_name AND kki.population = k.population) ON CONFLICT ON CONSTRAINT kingdom_uq_key DO NOTHING; /* Insert only unique rows. */ INSERT INTO knight ( knight_name , kingdom_allegiance_id , allegiance_start_date , allegiance_end_date ) (SELECT kki.knight_name , k.kingdom_id , kki.allegiance_start_date AS start_date , kki.allegiance_end_date AS end_date FROM kingdom_knight_import kki INNER JOIN kingdom k ON kki.kingdom_name = k.kingdom_name AND kki.population = k.population LEFT JOIN knight kn ON k.kingdom_id = kn.kingdom_allegiance_id AND kki.knight_name = kn.knight_name AND kki.allegiance_start_date = kn.allegiance_start_date AND kki.allegiance_end_date = kn.allegiance_end_date) ON CONFLICT ON CONSTRAINT knight_uq_key DO NOTHING; EXCEPTION WHEN OTHERS THEN err_num := SQLSTATE; err_msg := SUBSTR(SQLERRM,1,100); RAISE NOTICE 'Trapped Error: %', err_msg; END $$ LANGUAGE plpgsql; |
Step #5 : Run the upload_kingdom
procedure and query the results
You run the upload_kingdom
procedure with the CALL
statement and then query the results. Assuming you put the code in the call_kingdom_knight_procedure.sql
script, you can call it like so
\i call_kingdom_knight_procedure.sql |
/* Call the upload_kingdom procedure. */ CALL upload_kingdom(); /* Query the kingdom_knight_import table. */ SELECT kingdom_name , population , knight_name , date_trunc('second',allegiance_start_date AT TIME ZONE 'MST') AS allegiance_start_date , date_trunc('second',allegiance_end_date AT TIME ZONE 'MST') AS allegiance_end_date FROM kingdom_knight_import; /* Query the kingdom table. */ SELECT * FROM kingdom; /* Query the knight table. */ SELECT kn.knight_id , kki.knight_name , k.kingdom_id , date_trunc('second',kki.allegiance_start_date AT TIME ZONE 'MST') AS start_date , date_trunc('second',kki.allegiance_end_date AT TIME ZONE 'MST') AS end_date FROM kingdom_knight_import kki INNER JOIN kingdom k ON kki.kingdom_name = k.kingdom_name AND kki.population = k.population LEFT JOIN knight kn ON k.kingdom_id = kn.kingdom_allegiance_id AND kki.knight_name = kn.knight_name AND kki.allegiance_start_date = kn.allegiance_start_date AND kki.allegiance_end_date = kn.allegiance_end_date; |
It prints the following results:
CALL kingdom_name | population | knight_name | allegiance_start_date | allegiance_end_date --------------+------------+-----------------------+-----------------------+--------------------- Narnia | 77600 | Peter the Magnificent | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 Narnia | 77600 | Edmund the Just | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 Narnia | 77600 | Susan the Gentle | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 Narnia | 77600 | Lucy the Valiant | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 Narnia | 42100 | Peter the Magnificent | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 Narnia | 42100 | Edmund the Just | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 Narnia | 42100 | Susan the Gentle | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 Narnia | 42100 | Lucy the Valiant | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 Camelot | 15200 | King Arthur | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Lionel | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Bors | 0631-03-09 23:59:56 | 0635-12-11 23:59:56 Camelot | 15200 | Sir Bors | 0640-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Galahad | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Gawain | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Tristram | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Percival | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 Camelot | 15200 | Sir Lancelot | 0670-09-29 23:59:56 | 0682-12-11 23:59:56 (18 rows) kingdom_id | kingdom_name | population ------------+--------------+------------ 1 | Narnia | 42100 2 | Narnia | 77600 3 | Camelot | 15200 (3 rows) knight_id | knight_name | kingdom_id | start_date | end_date -----------+-----------------------+------------+---------------------+--------------------- 1 | Peter the Magnificent | 2 | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 2 | Edmund the Just | 2 | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 3 | Susan the Gentle | 2 | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 4 | Lucy the Valiant | 2 | 1272-03-19 23:59:56 | 1292-06-18 23:59:56 5 | Peter the Magnificent | 1 | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 6 | Edmund the Just | 1 | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 7 | Susan the Gentle | 1 | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 8 | Lucy the Valiant | 1 | 1531-04-11 23:59:56 | 1531-05-30 23:59:56 9 | King Arthur | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 10 | Sir Lionel | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 11 | Sir Bors | 3 | 0631-03-09 23:59:56 | 0635-12-11 23:59:56 12 | Sir Bors | 3 | 0640-03-09 23:59:56 | 0686-12-11 23:59:56 13 | Sir Galahad | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 14 | Sir Gawain | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 15 | Sir Tristram | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 16 | Sir Percival | 3 | 0631-03-09 23:59:56 | 0686-12-11 23:59:56 17 | Sir Lancelot | 3 | 0670-09-29 23:59:56 | 0682-12-11 23:59:56 69 | Modred | 3 | 0681-09-29 23:59:56 | 0682-12-11 23:59:56 (18 rows) |
As always, I hope this works to help those trying to solve a similar problem.
Postgres Foreign Keys
Just sorting out how to query the information_schema
to discover the magic for a query of a table’s foreign key constraints. This query works to return the foreign key constraints:
SELECT conrelid::regclass::text AS table_from , conname AS foreign_key , pg_get_constraintdef(oid) FROM pg_constraint WHERE contype = 'f' AND connamespace = 'public'::regnamespace AND conrelid::regclass::text = 'rental_item' ORDER BY conrelid::regclass::text , conname; |
It returns the following for the rental_item
table:
table_from | foreign_key | pg_get_constraintdef -------------+------------------+--------------------------------------------------------------------------- rental_item | fk_rental_item_1 | FOREIGN KEY (rental_id) REFERENCES rental(rental_id) rental_item | fk_rental_item_2 | FOREIGN KEY (item_id) REFERENCES item(item_id) rental_item | fk_rental_item_3 | FOREIGN KEY (created_by) REFERENCES system_user(system_user_id) rental_item | fk_rental_item_4 | FOREIGN KEY (last_updated_by) REFERENCES system_user(system_user_id) rental_item | fk_rental_item_5 | FOREIGN KEY (rental_item_type) REFERENCES common_lookup(common_lookup_id) (5 rows) |
As always, I post these tidbit for others to discover and use with less pain.
Java and Postgres
I wanted to get Java working with PostgreSQL to test some GUI interfaces on Linux. Figuring out the necessary JAR file for the JDBC was my first hurdle. I found it was postgreSQL-42-2.5.jar
file.
You can download it with the following command line:
wget https://jdbc.postgresql.org/download/postgresql-42.2.5.jar |
I downloaded it to a Java directory off the home/student directory. Then, I added the following CLASSPATH
to local java.env
environment file.
#!/usr/bin/bash # Set the Java CLASSPATH environment variable to include the JDBC jar file. export set CLASSPATH=/home/student/Java/postgresql-42.2.5.jar:. |
I sourced the postgresql-42.2.5.jar
file and I wrote the following JavaTest.java
program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /* Import classes. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; public class JavaTest { public static void main(String[] args) { /* Set default strings for the connection. */ String url = "jdbc:postgresql://localhost:5432/videodb"; String user = "student"; String password = "student"; /* Try the connection and statement. */ try { Connection conn = DriverManager.getConnection(url, user, password); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT VERSION()"); if (rs.next()) { System.out.println(rs.getString(1)); } /* Close the result set and statement. */ rs.close(); st.close(); } catch (SQLException e) { Logger logger = Logger.getLogger(JavaTest.class.getName()); logger.log(Level.SEVERE, e.getMessage(), e); } } } |
I compiled the JavaTest.java
program and tested it. It failed with the following error:
FATAL: Ident authentication failed for user - Unable to connect to PostgreSQL |
The failure occurred because I hadn’t allowed the connection in PostgreSQL’s pg_hba.conf
file. I changed the following line in my pg_hba.conf
file:
host all all 127.0.0.1/32 ident |
to
host all all 127.0.0.1/32 trust |
Then, I restarted the postgresql-11
service, like this:
systemctl restart postgresql-11.service |
The JavaTest
program ran successfully and returned:
PostgreSQL 11.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1), 64-bit |
You can extend the logic to output a comma-separated value file by leveraging the JDBC help page, like this:
/* Import classes. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; /* Create class withonly a static method for runtime testing. */ public class JavaReturnSet { public static void main(String[] args) { /* Set default strings for the connection. */ String url = "jdbc:postgresql://localhost:5432/videodb"; String user = "student"; String password = "student"; /* Try the connection and statement. */ try { /* Set connection, statement, and result set. */ Connection conn = DriverManager.getConnection(url, user, password); Statement st = conn.createStatement(); /* Use the + to concatenate lines for query clarity. */ ResultSet rs = st.executeQuery("SELECT m.account_number\n" + ", CONCAT(c.last_name,', ',c.first_name)\n" + "FROM member m JOIN contact c\n" + "ON m.member_id = c.member_id"); /* Get query metadata for subsequent management of results. */ ResultSetMetaData rsmd = rs.getMetaData(); String line; while (rs.next()) { /* Initialize the line output for each row. */ line = ""; /* Process the columns. */ for (int i = 0; i < rsmd.getColumnCount(); i++) { if (rsmd.getColumnType(i + 1) == 12) { line = line + "\"" + rs.getString(i + 1) + "\""; } else { line = line + rs.getInt(i + 1); } /* Put a comma between output columns. */ if (i < rsmd.getColumnCount() - 1) { line = line + ","; } } System.out.println(line); } /* Close the result set and statement. */ rs.close(); st.close(); } catch (SQLException e) { Logger logger = Logger.getLogger(JavaReturnSet.class.getName()); logger.log(Level.SEVERE, e.getMessage(), e); } } } |
As always, I hope this helps those looking for a clean solution.
Misleading ORA- Message
Oracle error messages are more or less the best in the industry but time-to-time they saddle you with a bad or misleading message. For example, I was running one of the code modules from my Oracle Database 12c PL/SQL Programming book for a class exercise and got this error message:
BEGIN * ERROR AT line 1: ORA-22288: FILE OR LOB operation failed ORA-06512: AT "STUDENT.LOAD_CLOB_FROM_FILE", line 71 ORA-06512: AT line 11 |
Oddly enough, it was simple to identify generally. It failed on a call to the DBMS_LOB.LOADCLOBFROMFILE
procedure. However, the better question is why did it fail because the virtual directory resolved and the permissions worked.
The first test was to try another file, which worked perfectly with the same code. That meant it had to be something with the physical file. I took a look and sure enough I found a character set problem, like the following:
… he reveals that the Nazgûl, or Ringwraiths, have left Mordor to capture the Ring and kill whoever carries it.
and,
The group flees to the elvish realm of Lothlórien …
The “û” and “ó” characters were incompatible with the default NLS_LANG
setting of the database and a CLOB
limits the use of non-standard character sets. It’s ashamed that Oracle didn’t through a character set error, which would have expedited resolution of the problem.
As always, I hope this helps those looking for solutions.
Install Cassandra on Fedora
It was quite interesting to discover that DataStax no longer provides the DataStax Community version of Apache Cassandra or the DataStax Distribution of Apache Cassandra. Needless to say, I was quite disappointed because it means folks will get less opportunity to learn how to use Cassandra because it makes it more difficult for beginning developers.
I spent a good hour sorting through what was available and then figuring out the real requirements to install Apache Cassandra 3.11. These are the instructions.
Install Java and JRE as Prerequisites
jre-8u141-linux-x64.rpm
). You should use the rpm
utility to install the JRE package, like the following example:
rpm -ivh /home/student/Downloads/jre-8*.rpm |
It should generate the following installation report:
Preparing... ################################# [100%] package jre1.8.0_141-1.8.0_141-fcs.x86_64 is already installed sh-4.2# rpm -qa jre sh-4.2# rpm -qf jre error: file /jre: No such file or directory sh-4.2# rpm -qa | grep jre jre1.8.0_141-1.8.0_141-fcs.x86_64 sh-4.2# rpm -qa | grep jre | rpm -qi rpm: no arguments given for query sh-4.2# rpm -qi `rpm -qa | grep jre` Name : jre1.8.0_141 Version : 1.8.0_141 Release : fcs Architecture: x86_64 Install Date: Mon 24 Jul 2017 11:09:58 PM PDT Group : Development/Tools Size : 139460427 License : http://java.com/license Signature : (none) Source RPM : jre1.8.0_141-1.8.0_141-fcs.src.rpm Build Date : Wed 12 Jul 2017 04:47:52 AM PDT Build Host : jdk7-lin2-amd64 Relocations : /usr/java Packager : Java Software <jre-comments@java.sun.com> Vendor : Oracle Corporation URL : URL_REF Summary : Java Platform Standard Edition Runtime Environment Description : The Java Platform Standard Edition Runtime Environment (JRE) contains everything necessary to run applets and applications designed for the Java platform. This includes the Java virtual machine, plus the Java platform classes and supporting files. The JRE is freely redistributable, per the terms of the included license. |
Confirm Java and JRE Installation
alternatives
utility with the --config
option and the keyword of java
or jre
.
sh-4.2# alternatives --config java |
It should generate the following list when you check for the java
library:
There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79-2.5.5.0.fc20.x86_64/jre/bin/java + 2 /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java 3 /usr/java/jre1.8.0_141/bin/java Enter to keep the current selection[+], or type selection number: |
It should generate the following list when you check for the javac
library:
There are 2 programs which provide 'javac'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79-2.5.5.0.fc20.x86_64/bin/javac + 2 /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac Enter to keep the current selection[+], or type selection number: |
After installing and selecting them as the designated alternative, if you have more than one Java or JRE installed on your OS, you should create a configuration file for the root user. You should include the following to set your $PATH
, $JAVA_HOME
, and $JRE_HOME
environment variables:
# Add the Java and JRE paths to the $PATH environments. export set PATH=$PATH:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64/jre # Add the $JAVA_HOME and $JRE_HOME environment variables. export set JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64/ export set JRE_HOME=/usr |
Install Apache Cassandra
yum
utility is the best way to install Apache Cassandra. However, you will need to configure the /etc/yum.repos.d/cassandra.repo
before you attempt to install Cassandra 3.11 from the Apache organization, like this:
[cassandra] name=Apache Cassandra baseurl=https://www.apache.org/dist/cassandra/redhat/311x/ gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.apache.org/dist/cassandra/KEYS |
After you’ve added the necessary yum configuration file and ensured you’re using both Java 1.8 and JRE 1.8, you can install Apache Cassandra with the following yum
command as the root
user or as a sudoer member with the sudo
command:
yum install -y cassandra |
If successful, you should see the following output:
Loaded plugins: langpacks, refresh-packagekit cassandra/signature | 819 B 00:00 cassandra/signature | 2.9 kB 00:00 !!! mysql-connectors-community | 2.5 kB 00:00 mysql-tools-community | 2.5 kB 00:00 mysql56-community | 2.5 kB 00:00 http://yum.postgresql.org/9.3/fedora/fedora-20-x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found Trying other mirror. updates/20/x86_64/metalink | 2.6 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package cassandra.noarch 0:3.11.0-1 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: cassandra noarch 3.11.0-1 cassandra 28 M Transaction Summary ================================================================================ Install 1 Package Total download size: 28 M Installed size: 37 M Downloading packages: warning: /var/cache/yum/x86_64/20/cassandra/packages/cassandra-3.11.0-1.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID fe4b2bda: NOKEY Public key for cassandra-3.11.0-1.noarch.rpm is not installed cassandra-3.11.0-1.noarch.rpm | 28 MB 00:07 Retrieving key from https://www.apache.org/dist/cassandra/KEYS Importing GPG key 0xF2833C93: Userid : "Eric Evans <eevans@sym-link.com>" Fingerprint: cec8 6bb4 a0ba 9d0f 9039 7cae f835 8fa2 f283 3c93 From : https://www.apache.org/dist/cassandra/KEYS Importing GPG key 0x8D77295D: Userid : "Eric Evans <eevans@sym-link.com>" Fingerprint: c496 5ee9 e301 5d19 2ccc f2b6 f758 ce31 8d77 295d From : https://www.apache.org/dist/cassandra/KEYS Importing GPG key 0x2B5C1B00: Userid : "Sylvain Lebresne (pcmanus) <sylvain@datastax.com>" Fingerprint: 5aed 1bf3 78e9 a19d ade1 bcb3 4bd7 36a8 2b5c 1b00 From : https://www.apache.org/dist/cassandra/KEYS Importing GPG key 0x0353B12C: Userid : "T Jake Luciani <jake@apache.org>" Fingerprint: 514a 2ad6 31a5 7a16 dd00 47ec 749d 6eec 0353 b12c From : https://www.apache.org/dist/cassandra/KEYS Importing GPG key 0xFE4B2BDA: Userid : "Michael Shuler <michael@pbandjelly.org>" Fingerprint: a26e 528b 271f 19b9 e5d8 e19e a278 b781 fe4b 2bda From : https://www.apache.org/dist/cassandra/KEYS Running transaction check Running transaction test Transaction test succeeded Running transaction (shutdown inhibited) Warning: RPMDB altered outside of yum. Installing : cassandra-3.11.0-1.noarch 1/1 Verifying : cassandra-3.11.0-1.noarch 1/1 Installed: cassandra.noarch 0:3.11.0-1 Complete! |
Starting Cassandra
cassandra
user. Before starting Cassandra, you need to create a .bashrc
file for the cassandra
user because one isn’t created by default since you can’t log on to the Linux OS as the cassandra
user. The home directory for the cassandra
user is /var/lib/cassandra
and the owner of that directory is the root
user.
As the root
user, create the following .bashrc
file for the cassandra
user:
# Wrap sqlplus with rlwrap to edit prior lines with the # up, down, left and right keys. cqlsh() { if [ "$RLWRAP" = "0" ]; then cqlsh "$@" else rlwrap cqlsh "$@" fi } # Set vi as a command line editor. set -o vi # Add the Java and JRE paths to the $PATH environments. export set PATH=$PATH:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64/jre # Add the $JAVA_HOME and $JRE_HOME environment variables. export set JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45.x86_64/ export set JRE_HOME=/usr |
You should start Cassandra in background, like this:
cassandra |
Using Cassandra
cqlsh |
You will see the following:
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.0 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh> HELP Documented shell commands: =========================== CAPTURE CLS COPY DESCRIBE EXPAND LOGIN SERIAL SOURCE UNICODE CLEAR CONSISTENCY DESC EXIT HELP PAGING SHOW TRACING CQL help topics: ================ AGGREGATES CREATE_KEYSPACE DROP_TRIGGER TEXT ALTER_KEYSPACE CREATE_MATERIALIZED_VIEW DROP_TYPE TIME ALTER_MATERIALIZED_VIEW CREATE_ROLE DROP_USER TIMESTAMP ALTER_TABLE CREATE_TABLE FUNCTIONS TRUNCATE ALTER_TYPE CREATE_TRIGGER GRANT TYPES ALTER_USER CREATE_TYPE INSERT UPDATE APPLY CREATE_USER INSERT_JSON USE ASCII DATE INT UUID BATCH DELETE JSON BEGIN DROP_AGGREGATE KEYWORDS BLOB DROP_COLUMNFAMILY LIST_PERMISSIONS BOOLEAN DROP_FUNCTION LIST_ROLES COUNTER DROP_INDEX LIST_USERS CREATE_AGGREGATE DROP_KEYSPACE PERMISSIONS CREATE_COLUMNFAMILY DROP_MATERIALIZED_VIEW REVOKE CREATE_FUNCTION DROP_ROLE SELECT CREATE_INDEX DROP_TABLE SELECT_JSON |
Oracle Diagnostic Queries
It’s always a challenge when you want to build your own Oracle SQL Tools. I was asked how you could synchronize multiple cursors into a single source. The answer is quite simple, you write an Oracle object type to represent a record structure, an Oracle list of the record structure, and a stored function to return the list of the record structure.
For this example, you create the following table_struct
object type and a table_list
collection type:
/* Drop the types from most to least dependent. */ DROP TYPE table_list; DROP TYPE table_struct; /* Create the record type structure. */ CREATE OR REPLACE TYPE table_struct IS OBJECT ( table_name VARCHAR2(30) , column_cnt NUMBER , row_cnt NUMBER ); / /* Create the collection of a record type structure. */ CREATE OR REPLACE TYPE table_list IS TABLE OF table_struct; / |
The following listing
function now reads all table names from the user_tables
view. A subordinate cursor reads the user_tab_columns
view for the number of columns in a table. A Native Dynamic SQL (NDS) cursor counts the number of rows in each tables found in the .
/* Create the listing function. */ CREATE OR REPLACE FUNCTION listing RETURN table_list IS /* Variable list. */ lv_column_cnt NUMBER; lv_row_cnt NUMBER; /* Declare a statement variable. */ stmt VARCHAR2(200); /* Declare a system reference cursor variable. */ lv_refcursor SYS_REFCURSOR; lv_table_cnt NUMBER; /* Declare an output variable. */ lv_list TABLE_LIST := table_list(); /* Declare a table list cursor that excludes APEX tables. */ CURSOR c IS SELECT table_name FROM user_tables WHERE table_name NOT IN ('DEPT','EMP','APEX$_ACL','APEX$_WS_WEBPG_SECTIONS','APEX$_WS_ROWS' ,'APEX$_WS_HISTORY','APEX$_WS_NOTES','APEX$_WS_LINKS' ,'APEX$_WS_TAGS','APEX$_WS_FILES','APEX$_WS_WEBPG_SECTION_HISTORY' ,'DEMO_USERS','DEMO_CUSTOMERS','DEMO_ORDERS','DEMO_PRODUCT_INFO' ,'DEMO_ORDER_ITEMS','DEMO_STATES'); /* Declare a column count. */ CURSOR cnt ( cv_table_name VARCHAR2 ) IS SELECT table_name , COUNT(column_id) AS cnt_columns FROM user_tab_columns WHERE table_name = cv_table_name GROUP BY table_name; BEGIN /* Read through the data set of non-environment variables. */ FOR i IN c LOOP /* Count the columns of a table. */ FOR j IN cnt(i.table_name) LOOP lv_column_cnt := j.cnt_columns; END LOOP; /* Declare a statement. */ stmt := 'SELECT COUNT(*) AS column_cnt FROM '||i.table_name; /* Open the cursor and write set to collection. */ OPEN lv_refcursor FOR stmt; LOOP FETCH lv_refcursor INTO lv_table_cnt; EXIT WHEN lv_refcursor%NOTFOUND; lv_list.EXTEND; lv_list(lv_list.COUNT) := table_struct( table_name => i.table_name , column_cnt => lv_column_cnt , row_cnt => lv_table_cnt ); END LOOP; END LOOP; RETURN lv_list; END; / |
The following query pulls the processed data set as the function’s result:
COL table_name FORMAT A20 HEADING "Table Name" COL column_cnt FORMAT 9,999 HEADING "Column #" COL row_cnt FORMAT 9,999 HEADING "Row #" SELECT table_name , column_cnt , row_cnt FROM TABLE(listing); |
It returns the following result set:
Table Name Column # Row # -------------------- -------- ------ SYSTEM_USER 11 5 COMMON_LOOKUP 10 49 MEMBER 9 10 CONTACT 10 18 ADDRESS 10 18 STREET_ADDRESS 8 28 TELEPHONE 11 18 RENTAL 8 4,694 ITEM 14 93 RENTAL_ITEM 9 4,703 PRICE 11 558 TRANSACTION 12 4,694 CALENDAR 9 300 AIRPORT 9 6 ACCOUNT_LIST 8 200 15 rows selected. |
As always, I hope this helps those trying to work with the Oracle database.
Oracle 12c Pre-requisites
Installing any Oracle database is tedious, but the installing the prerequisites can be especially tedious. This post tries to simplify the process by creating a single prereq.sh
file for all the prerequisite libraries, except for the oracle-rdbms-server-12cR1-preinstall
, which you should run after the prerequisite file.
The prerequisite file should contain the following:
yum install -y binutils \ compat-libstdc++-33 \ compat-libstdc++-33.i686 \ gcc \ gcc-c++ \ glibc \ glibc.i686 \ glibc-devel \ glibc-devel.i686 \ ksh \ libgcc \ libgcc.i686 \ libstdc++ \ libstdc++.i686 \ libstdc++-devel \ libstdc++-devel.i686 \ libaio \ libaio.i686 \ libaio-devel \ libaio-devel.i686 \ libXext \ libXext.i686 \ libXtst \ libXtst.i686 \ libX11 \ libX11.i686 \ libXau \ libXau.i686 \ libxcb \ libxcb.i686 \ libXi \ libXi.i686 \ make \ sysstat \ unixODBC \ unixODBC-devel \ zlib-devel \ zlib-devel.i686 |
You can run the prereq.sh
script as the root
user like you would source an environment file:
. ./prereq.sh |
Dependent upon what you installed when creating the Oracle Linux 7.1 operating system, you should see something like this in the output console:
sh-4.2# . ./prereq.sh Loaded plugins: langpacks Package compat-libstdc++-33-3.2.3-72.el7.x86_64 already installed and latest version Package libXtst-1.2.2-2.1.el7.x86_64 already installed and latest version Package libXau-1.0.8-2.1.el7.x86_64 already installed and latest version Package 1:make-3.82-21.el7.x86_64 already installed and latest version Package sysstat-10.1.5-7.el7.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package binutils.x86_64 0:2.23.52.0.1-30.el7_1.2 will be updated ---> Package binutils.x86_64 0:2.23.52.0.1-55.el7 will be an update ---> Package compat-libstdc++-33.i686 0:3.2.3-72.el7 will be installed ---> Package gcc.x86_64 0:4.8.3-9.el7 will be updated --> Processing Dependency: gcc = 4.8.3-9.el7 for package: gcc-gfortran-4.8.3-9.el7.x86_64 --> Processing Dependency: gcc = 4.8.3-9.el7 for package: libquadmath-devel-4.8.3-9.el7.x86_64 ---> Package gcc.x86_64 0:4.8.5-4.el7 will be an update --> Processing Dependency: cpp = 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64 --> Processing Dependency: libgomp = 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64 ---> Package gcc-c++.x86_64 0:4.8.3-9.el7 will be updated ---> Package gcc-c++.x86_64 0:4.8.5-4.el7 will be an update ---> Package glibc.x86_64 0:2.17-78.0.1.el7 will be updated --> Processing Dependency: glibc = 2.17-78.0.1.el7 for package: glibc-headers-2.17-78.0.1.el7.x86_64 --> Processing Dependency: glibc = 2.17-78.0.1.el7 for package: glibc-common-2.17-78.0.1.el7.x86_64 ---> Package glibc.i686 0:2.17-106.0.1.el7_2.6 will be installed --> Processing Dependency: libfreebl3.so for package: glibc-2.17-106.0.1.el7_2.6.i686 --> Processing Dependency: libfreebl3.so(NSSRAWHASH_3.12.3) for package: glibc-2.17-106.0.1.el7_2.6.i686 ---> Package glibc.x86_64 0:2.17-106.0.1.el7_2.6 will be an update ---> Package glibc-devel.x86_64 0:2.17-78.0.1.el7 will be updated ---> Package glibc-devel.i686 0:2.17-106.0.1.el7_2.6 will be installed ---> Package glibc-devel.x86_64 0:2.17-106.0.1.el7_2.6 will be an update ---> Package ksh.x86_64 0:20120801-22.el7_1.3 will be installed ---> Package libX11.x86_64 0:1.6.0-2.1.el7 will be updated ---> Package libX11.i686 0:1.6.3-2.el7 will be installed --> Processing Dependency: libX11-common >= 1.6.3-2.el7 for package: libX11-1.6.3-2.el7.i686 ---> Package libX11.x86_64 0:1.6.3-2.el7 will be an update ---> Package libXau.i686 0:1.0.8-2.1.el7 will be installed ---> Package libXext.x86_64 0:1.3.2-2.1.el7 will be updated ---> Package libXext.i686 0:1.3.3-3.el7 will be installed ---> Package libXext.x86_64 0:1.3.3-3.el7 will be an update ---> Package libXi.x86_64 0:1.7.2-2.1.el7 will be updated ---> Package libXi.i686 0:1.7.4-2.el7 will be installed ---> Package libXi.x86_64 0:1.7.4-2.el7 will be an update ---> Package libXtst.i686 0:1.2.2-2.1.el7 will be installed ---> Package libaio.x86_64 0:0.3.109-12.el7 will be updated ---> Package libaio.i686 0:0.3.109-13.el7 will be installed ---> Package libaio.x86_64 0:0.3.109-13.el7 will be an update ---> Package libaio-devel.i686 0:0.3.109-13.el7 will be installed ---> Package libaio-devel.x86_64 0:0.3.109-13.el7 will be installed ---> Package libgcc.x86_64 0:4.8.3-9.el7 will be updated ---> Package libgcc.i686 0:4.8.5-4.el7 will be installed ---> Package libgcc.x86_64 0:4.8.5-4.el7 will be an update ---> Package libstdc++.x86_64 0:4.8.3-9.el7 will be updated ---> Package libstdc++.i686 0:4.8.5-4.el7 will be installed ---> Package libstdc++.x86_64 0:4.8.5-4.el7 will be an update ---> Package libstdc++-devel.x86_64 0:4.8.3-9.el7 will be updated ---> Package libstdc++-devel.i686 0:4.8.5-4.el7 will be installed ---> Package libstdc++-devel.x86_64 0:4.8.5-4.el7 will be an update ---> Package libxcb.x86_64 0:1.9-5.el7 will be updated ---> Package libxcb.i686 0:1.11-4.el7 will be installed ---> Package libxcb.x86_64 0:1.11-4.el7 will be an update ---> Package unixODBC.x86_64 0:2.3.1-11.el7 will be installed ---> Package unixODBC-devel.x86_64 0:2.3.1-11.el7 will be installed ---> Package zlib-devel.i686 0:1.2.7-15.el7 will be installed --> Processing Dependency: zlib = 1.2.7-15.el7 for package: zlib-devel-1.2.7-15.el7.i686 --> Processing Dependency: libz.so.1 for package: zlib-devel-1.2.7-15.el7.i686 ---> Package zlib-devel.x86_64 0:1.2.7-15.el7 will be installed --> Running transaction check ---> Package cpp.x86_64 0:4.8.3-9.el7 will be updated ---> Package cpp.x86_64 0:4.8.5-4.el7 will be an update ---> Package gcc-gfortran.x86_64 0:4.8.3-9.el7 will be updated ---> Package gcc-gfortran.x86_64 0:4.8.5-4.el7 will be an update --> Processing Dependency: libgfortran = 4.8.5-4.el7 for package: gcc-gfortran-4.8.5-4.el7.x86_64 --> Processing Dependency: libquadmath = 4.8.5-4.el7 for package: gcc-gfortran-4.8.5-4.el7.x86_64 ---> Package glibc-common.x86_64 0:2.17-78.0.1.el7 will be updated ---> Package glibc-common.x86_64 0:2.17-106.0.1.el7_2.6 will be an update ---> Package glibc-headers.x86_64 0:2.17-78.0.1.el7 will be updated ---> Package glibc-headers.x86_64 0:2.17-106.0.1.el7_2.6 will be an update ---> Package libX11-common.noarch 0:1.6.0-2.1.el7 will be updated ---> Package libX11-common.noarch 0:1.6.3-2.el7 will be an update ---> Package libgomp.x86_64 0:4.8.3-9.el7 will be updated ---> Package libgomp.x86_64 0:4.8.5-4.el7 will be an update ---> Package libquadmath-devel.x86_64 0:4.8.3-9.el7 will be updated ---> Package libquadmath-devel.x86_64 0:4.8.5-4.el7 will be an update ---> Package nss-softokn-freebl.x86_64 0:3.16.2.3-12.el7_1 will be updated ---> Package nss-softokn-freebl.i686 0:3.16.2.3-14.2.el7_2 will be installed ---> Package nss-softokn-freebl.x86_64 0:3.16.2.3-14.2.el7_2 will be an update ---> Package zlib.x86_64 0:1.2.7-13.el7 will be updated ---> Package zlib.i686 0:1.2.7-15.el7 will be installed ---> Package zlib.x86_64 0:1.2.7-15.el7 will be an update --> Running transaction check ---> Package libgfortran.x86_64 0:4.8.3-9.el7 will be updated ---> Package libgfortran.x86_64 0:4.8.5-4.el7 will be an update ---> Package libquadmath.x86_64 0:4.8.3-9.el7 will be updated ---> Package libquadmath.x86_64 0:4.8.5-4.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: compat-libstdc++-33 i686 3.2.3-72.el7 ol7_latest 196 k glibc i686 2.17-106.0.1.el7_2.6 ol7_latest 4.2 M glibc-devel i686 2.17-106.0.1.el7_2.6 ol7_latest 1.0 M ksh x86_64 20120801-22.el7_1.3 ol7_latest 880 k libX11 i686 1.6.3-2.el7 ol7_latest 609 k libXau i686 1.0.8-2.1.el7 ol7_latest 28 k libXext i686 1.3.3-3.el7 ol7_latest 38 k libXi i686 1.7.4-2.el7 ol7_latest 39 k libXtst i686 1.2.2-2.1.el7 ol7_latest 19 k libaio i686 0.3.109-13.el7 ol7_latest 24 k libaio-devel i686 0.3.109-13.el7 ol7_latest 12 k libaio-devel x86_64 0.3.109-13.el7 ol7_latest 12 k libgcc i686 4.8.5-4.el7 ol7_latest 102 k libstdc++ i686 4.8.5-4.el7 ol7_latest 310 k libstdc++-devel i686 4.8.5-4.el7 ol7_latest 1.5 M libxcb i686 1.11-4.el7 ol7_latest 201 k unixODBC x86_64 2.3.1-11.el7 ol7_latest 412 k unixODBC-devel x86_64 2.3.1-11.el7 ol7_latest 54 k zlib-devel i686 1.2.7-15.el7 ol7_latest 49 k zlib-devel x86_64 1.2.7-15.el7 ol7_latest 49 k Updating: binutils x86_64 2.23.52.0.1-55.el7 ol7_latest 5.0 M gcc x86_64 4.8.5-4.el7 ol7_latest 16 M gcc-c++ x86_64 4.8.5-4.el7 ol7_latest 7.2 M glibc x86_64 2.17-106.0.1.el7_2.6 ol7_latest 3.6 M glibc-devel x86_64 2.17-106.0.1.el7_2.6 ol7_latest 1.0 M libX11 x86_64 1.6.3-2.el7 ol7_latest 605 k libXext x86_64 1.3.3-3.el7 ol7_latest 38 k libXi x86_64 1.7.4-2.el7 ol7_latest 39 k libaio x86_64 0.3.109-13.el7 ol7_latest 24 k libgcc x86_64 4.8.5-4.el7 ol7_latest 94 k libstdc++ x86_64 4.8.5-4.el7 ol7_latest 297 k libstdc++-devel x86_64 4.8.5-4.el7 ol7_latest 1.5 M libxcb x86_64 1.11-4.el7 ol7_latest 189 k Installing for dependencies: nss-softokn-freebl i686 3.16.2.3-14.2.el7_2 ol7_latest 187 k zlib i686 1.2.7-15.el7 ol7_latest 90 k Updating for dependencies: cpp x86_64 4.8.5-4.el7 ol7_latest 5.9 M gcc-gfortran x86_64 4.8.5-4.el7 ol7_latest 6.6 M glibc-common x86_64 2.17-106.0.1.el7_2.6 ol7_latest 11 M glibc-headers x86_64 2.17-106.0.1.el7_2.6 ol7_latest 662 k libX11-common noarch 1.6.3-2.el7 ol7_latest 161 k libgfortran x86_64 4.8.5-4.el7 ol7_latest 292 k libgomp x86_64 4.8.5-4.el7 ol7_latest 130 k libquadmath x86_64 4.8.5-4.el7 ol7_latest 182 k libquadmath-devel x86_64 4.8.5-4.el7 ol7_latest 45 k nss-softokn-freebl x86_64 3.16.2.3-14.2.el7_2 ol7_latest 203 k zlib x86_64 1.2.7-15.el7 ol7_latest 89 k Transaction Summary ================================================================================ Install 20 Packages (+ 2 Dependent packages) Upgrade 13 Packages (+11 Dependent packages) Total download size: 71 M Downloading packages: No Presto metadata available for ol7_latest (1/46): compat-libstdc++-33-3.2.3-72.el7.i686.rpm | 196 kB 00:00 (2/46): binutils-2.23.52.0.1-55.el7.x86_64.rpm | 5.0 MB 00:01 (3/46): cpp-4.8.5-4.el7.x86_64.rpm | 5.9 MB 00:01 (4/46): gcc-c++-4.8.5-4.el7.x86_64.rpm | 7.2 MB 00:02 (5/46): gcc-4.8.5-4.el7.x86_64.rpm | 16 MB 00:03 (6/46): glibc-2.17-106.0.1.el7_2.6.i686.rpm | 4.2 MB 00:01 (7/46): gcc-gfortran-4.8.5-4.el7.x86_64.rpm | 6.6 MB 00:02 (8/46): glibc-2.17-106.0.1.el7_2.6.x86_64.rpm | 3.6 MB 00:01 (9/46): glibc-devel-2.17-106.0.1.el7_2.6.i686.rpm | 1.0 MB 00:00 (10/46): glibc-devel-2.17-106.0.1.el7_2.6.x86_64.rpm | 1.0 MB 00:00 (11/46): glibc-headers-2.17-106.0.1.el7_2.6.x86_64.rpm | 662 kB 00:00 (12/46): ksh-20120801-22.el7_1.3.x86_64.rpm | 880 kB 00:00 (13/46): libX11-1.6.3-2.el7.i686.rpm | 609 kB 00:00 (14/46): libX11-1.6.3-2.el7.x86_64.rpm | 605 kB 00:00 (15/46): libX11-common-1.6.3-2.el7.noarch.rpm | 161 kB 00:00 (16/46): libXau-1.0.8-2.1.el7.i686.rpm | 28 kB 00:00 (17/46): libXext-1.3.3-3.el7.i686.rpm | 38 kB 00:00 (18/46): libXext-1.3.3-3.el7.x86_64.rpm | 38 kB 00:00 (19/46): libXi-1.7.4-2.el7.i686.rpm | 39 kB 00:00 (20/46): libXi-1.7.4-2.el7.x86_64.rpm | 39 kB 00:00 (21/46): libXtst-1.2.2-2.1.el7.i686.rpm | 19 kB 00:00 (22/46): libaio-0.3.109-13.el7.i686.rpm | 24 kB 00:00 (23/46): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00 (24/46): libaio-devel-0.3.109-13.el7.i686.rpm | 12 kB 00:00 (25/46): glibc-common-2.17-106.0.1.el7_2.6.x86_64.rpm | 11 MB 00:04 (26/46): libaio-devel-0.3.109-13.el7.x86_64.rpm | 12 kB 00:00 (27/46): libgcc-4.8.5-4.el7.i686.rpm | 102 kB 00:00 (28/46): libgfortran-4.8.5-4.el7.x86_64.rpm | 292 kB 00:00 (29/46): libgomp-4.8.5-4.el7.x86_64.rpm | 130 kB 00:00 (30/46): libgcc-4.8.5-4.el7.x86_64.rpm | 94 kB 00:00 (31/46): libquadmath-4.8.5-4.el7.x86_64.rpm | 182 kB 00:00 (32/46): libquadmath-devel-4.8.5-4.el7.x86_64.rpm | 45 kB 00:00 (33/46): libstdc++-4.8.5-4.el7.i686.rpm | 310 kB 00:00 (34/46): libstdc++-4.8.5-4.el7.x86_64.rpm | 297 kB 00:00 (35/46): libstdc++-devel-4.8.5-4.el7.i686.rpm | 1.5 MB 00:00 (36/46): libstdc++-devel-4.8.5-4.el7.x86_64.rpm | 1.5 MB 00:00 (37/46): libxcb-1.11-4.el7.x86_64.rpm | 189 kB 00:00 (38/46): libxcb-1.11-4.el7.i686.rpm | 201 kB 00:00 (39/46): nss-softokn-freebl-3.16.2.3-14.2.el7_2.x86_64.rpm | 203 kB 00:00 (40/46): nss-softokn-freebl-3.16.2.3-14.2.el7_2.i686.rpm | 187 kB 00:00 (41/46): unixODBC-devel-2.3.1-11.el7.x86_64.rpm | 54 kB 00:00 (42/46): unixODBC-2.3.1-11.el7.x86_64.rpm | 412 kB 00:00 (43/46): zlib-1.2.7-15.el7.i686.rpm | 90 kB 00:00 (44/46): zlib-1.2.7-15.el7.x86_64.rpm | 89 kB 00:00 (45/46): zlib-devel-1.2.7-15.el7.x86_64.rpm | 49 kB 00:00 (46/46): zlib-devel-1.2.7-15.el7.i686.rpm | 49 kB 00:00 -------------------------------------------------------------------------------- Total 5.2 MB/s | 71 MB 00:13 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : libgcc-4.8.5-4.el7.x86_64 1/70 Updating : glibc-common-2.17-106.0.1.el7_2.6.x86_64 2/70 Updating : nss-softokn-freebl-3.16.2.3-14.2.el7_2.x86_64 3/70 Updating : glibc-2.17-106.0.1.el7_2.6.x86_64 4/70 Updating : zlib-1.2.7-15.el7.x86_64 5/70 Updating : libquadmath-4.8.5-4.el7.x86_64 6/70 Updating : libstdc++-4.8.5-4.el7.x86_64 7/70 Updating : glibc-headers-2.17-106.0.1.el7_2.6.x86_64 8/70 Updating : libX11-common-1.6.3-2.el7.noarch 9/70 Installing : nss-softokn-freebl-3.16.2.3-14.2.el7_2.i686 10/70 Installing : glibc-2.17-106.0.1.el7_2.6.i686 11/70 Installing : libgcc-4.8.5-4.el7.i686 12/70 Installing : glibc-devel-2.17-106.0.1.el7_2.6.i686 13/70 Updating : libgfortran-4.8.5-4.el7.x86_64 14/70 Updating : cpp-4.8.5-4.el7.x86_64 15/70 Updating : binutils-2.23.52.0.1-55.el7.x86_64 16/70 Updating : libaio-0.3.109-13.el7.x86_64 17/70 Installing : unixODBC-2.3.1-11.el7.x86_64 18/70 Updating : libgomp-4.8.5-4.el7.x86_64 19/70 Updating : gcc-4.8.5-4.el7.x86_64 20/70 Updating : libquadmath-devel-4.8.5-4.el7.x86_64 21/70 Updating : libxcb-1.11-4.el7.x86_64 22/70 Updating : libX11-1.6.3-2.el7.x86_64 23/70 Updating : libXext-1.3.3-3.el7.x86_64 24/70 Updating : libXi-1.7.4-2.el7.x86_64 25/70 Updating : gcc-gfortran-4.8.5-4.el7.x86_64 26/70 Installing : unixODBC-devel-2.3.1-11.el7.x86_64 27/70 Installing : libaio-devel-0.3.109-13.el7.x86_64 28/70 Updating : glibc-devel-2.17-106.0.1.el7_2.6.x86_64 29/70 Updating : libstdc++-devel-4.8.5-4.el7.x86_64 30/70 Installing : zlib-devel-1.2.7-15.el7.x86_64 31/70 Installing : ksh-20120801-22.el7_1.3.x86_64 32/70 Installing : libstdc++-4.8.5-4.el7.i686 33/70 Installing : libstdc++-devel-4.8.5-4.el7.i686 34/70 Installing : libXau-1.0.8-2.1.el7.i686 35/70 Installing : libxcb-1.11-4.el7.i686 36/70 Installing : libX11-1.6.3-2.el7.i686 37/70 Installing : libXext-1.3.3-3.el7.i686 38/70 Installing : libXi-1.7.4-2.el7.i686 39/70 Installing : libaio-0.3.109-13.el7.i686 40/70 Installing : zlib-1.2.7-15.el7.i686 41/70 Installing : zlib-devel-1.2.7-15.el7.i686 42/70 Installing : libaio-devel-0.3.109-13.el7.i686 43/70 Updating : gcc-c++-4.8.5-4.el7.x86_64 44/70 Installing : libXtst-1.2.2-2.1.el7.i686 45/70 Installing : compat-libstdc++-33-3.2.3-72.el7.i686 46/70 Cleanup : gcc-gfortran-4.8.3-9.el7.x86_64 47/70 Cleanup : gcc-c++-4.8.3-9.el7.x86_64 48/70 Cleanup : libgfortran-4.8.3-9.el7.x86_64 49/70 Cleanup : libXi-1.7.2-2.1.el7.x86_64 50/70 Cleanup : libquadmath-devel-4.8.3-9.el7.x86_64 51/70 Cleanup : libstdc++-devel-4.8.3-9.el7.x86_64 52/70 Cleanup : gcc-4.8.3-9.el7.x86_64 53/70 Cleanup : glibc-devel-2.17-78.0.1.el7.x86_64 54/70 Cleanup : binutils-2.23.52.0.1-30.el7_1.2.x86_64 55/70 Cleanup : cpp-4.8.3-9.el7.x86_64 56/70 Cleanup : libstdc++-4.8.3-9.el7.x86_64 57/70 Cleanup : libXext-1.3.2-2.1.el7.x86_64 58/70 Cleanup : glibc-headers-2.17-78.0.1.el7.x86_64 59/70 Cleanup : libX11-1.6.0-2.1.el7.x86_64 60/70 Cleanup : libxcb-1.9-5.el7.x86_64 61/70 Cleanup : zlib-1.2.7-13.el7.x86_64 62/70 Cleanup : libgomp-4.8.3-9.el7.x86_64 63/70 Cleanup : libquadmath-4.8.3-9.el7.x86_64 64/70 Cleanup : libaio-0.3.109-12.el7.x86_64 65/70 Cleanup : libX11-common-1.6.0-2.1.el7.noarch 66/70 Cleanup : glibc-common-2.17-78.0.1.el7.x86_64 67/70 Cleanup : nss-softokn-freebl-3.16.2.3-12.el7_1.x86_64 68/70 Cleanup : glibc-2.17-78.0.1.el7.x86_64 69/70 Cleanup : libgcc-4.8.3-9.el7.x86_64 70/70 Verifying : libXext-1.3.3-3.el7.x86_64 1/70 Verifying : libgcc-4.8.5-4.el7.i686 2/70 Verifying : gcc-4.8.5-4.el7.x86_64 3/70 Verifying : glibc-devel-2.17-106.0.1.el7_2.6.i686 4/70 Verifying : libXext-1.3.3-3.el7.i686 5/70 Verifying : libstdc++-4.8.5-4.el7.i686 6/70 Verifying : glibc-2.17-106.0.1.el7_2.6.x86_64 7/70 Verifying : libxcb-1.11-4.el7.i686 8/70 Verifying : gcc-c++-4.8.5-4.el7.x86_64 9/70 Verifying : zlib-devel-1.2.7-15.el7.x86_64 10/70 Verifying : libaio-devel-0.3.109-13.el7.i686 11/70 Verifying : libX11-1.6.3-2.el7.x86_64 12/70 Verifying : glibc-common-2.17-106.0.1.el7_2.6.x86_64 13/70 Verifying : unixODBC-devel-2.3.1-11.el7.x86_64 14/70 Verifying : libXau-1.0.8-2.1.el7.i686 15/70 Verifying : libaio-0.3.109-13.el7.i686 16/70 Verifying : zlib-1.2.7-15.el7.x86_64 17/70 Verifying : ksh-20120801-22.el7_1.3.x86_64 18/70 Verifying : libaio-0.3.109-13.el7.x86_64 19/70 Verifying : libXtst-1.2.2-2.1.el7.i686 20/70 Verifying : glibc-2.17-106.0.1.el7_2.6.i686 21/70 Verifying : libstdc++-4.8.5-4.el7.x86_64 22/70 Verifying : libX11-common-1.6.3-2.el7.noarch 23/70 Verifying : zlib-devel-1.2.7-15.el7.i686 24/70 Verifying : unixODBC-2.3.1-11.el7.x86_64 25/70 Verifying : libgfortran-4.8.5-4.el7.x86_64 26/70 Verifying : libstdc++-devel-4.8.5-4.el7.i686 27/70 Verifying : gcc-gfortran-4.8.5-4.el7.x86_64 28/70 Verifying : libaio-devel-0.3.109-13.el7.x86_64 29/70 Verifying : nss-softokn-freebl-3.16.2.3-14.2.el7_2.x86_64 30/70 Verifying : glibc-headers-2.17-106.0.1.el7_2.6.x86_64 31/70 Verifying : zlib-1.2.7-15.el7.i686 32/70 Verifying : libstdc++-devel-4.8.5-4.el7.x86_64 33/70 Verifying : libXi-1.7.4-2.el7.x86_64 34/70 Verifying : cpp-4.8.5-4.el7.x86_64 35/70 Verifying : compat-libstdc++-33-3.2.3-72.el7.i686 36/70 Verifying : libX11-1.6.3-2.el7.i686 37/70 Verifying : libgomp-4.8.5-4.el7.x86_64 38/70 Verifying : libgcc-4.8.5-4.el7.x86_64 39/70 Verifying : binutils-2.23.52.0.1-55.el7.x86_64 40/70 Verifying : libquadmath-devel-4.8.5-4.el7.x86_64 41/70 Verifying : libXi-1.7.4-2.el7.i686 42/70 Verifying : glibc-devel-2.17-106.0.1.el7_2.6.x86_64 43/70 Verifying : nss-softokn-freebl-3.16.2.3-14.2.el7_2.i686 44/70 Verifying : libquadmath-4.8.5-4.el7.x86_64 45/70 Verifying : libxcb-1.11-4.el7.x86_64 46/70 Verifying : glibc-common-2.17-78.0.1.el7.x86_64 47/70 Verifying : libX11-common-1.6.0-2.1.el7.noarch 48/70 Verifying : libxcb-1.9-5.el7.x86_64 49/70 Verifying : libgfortran-4.8.3-9.el7.x86_64 50/70 Verifying : glibc-2.17-78.0.1.el7.x86_64 51/70 Verifying : libaio-0.3.109-12.el7.x86_64 52/70 Verifying : cpp-4.8.3-9.el7.x86_64 53/70 Verifying : libstdc++-devel-4.8.3-9.el7.x86_64 54/70 Verifying : libX11-1.6.0-2.1.el7.x86_64 55/70 Verifying : gcc-gfortran-4.8.3-9.el7.x86_64 56/70 Verifying : libquadmath-devel-4.8.3-9.el7.x86_64 57/70 Verifying : libXi-1.7.2-2.1.el7.x86_64 58/70 Verifying : glibc-devel-2.17-78.0.1.el7.x86_64 59/70 Verifying : gcc-c++-4.8.3-9.el7.x86_64 60/70 Verifying : nss-softokn-freebl-3.16.2.3-12.el7_1.x86_64 61/70 Verifying : libgcc-4.8.3-9.el7.x86_64 62/70 Verifying : binutils-2.23.52.0.1-30.el7_1.2.x86_64 63/70 Verifying : glibc-headers-2.17-78.0.1.el7.x86_64 64/70 Verifying : gcc-4.8.3-9.el7.x86_64 65/70 Verifying : zlib-1.2.7-13.el7.x86_64 66/70 Verifying : libXext-1.3.2-2.1.el7.x86_64 67/70 Verifying : libstdc++-4.8.3-9.el7.x86_64 68/70 Verifying : libgomp-4.8.3-9.el7.x86_64 69/70 Verifying : libquadmath-4.8.3-9.el7.x86_64 70/70 Installed: compat-libstdc++-33.i686 0:3.2.3-72.el7 glibc.i686 0:2.17-106.0.1.el7_2.6 glibc-devel.i686 0:2.17-106.0.1.el7_2.6 ksh.x86_64 0:20120801-22.el7_1.3 libX11.i686 0:1.6.3-2.el7 libXau.i686 0:1.0.8-2.1.el7 libXext.i686 0:1.3.3-3.el7 libXi.i686 0:1.7.4-2.el7 libXtst.i686 0:1.2.2-2.1.el7 libaio.i686 0:0.3.109-13.el7 libaio-devel.i686 0:0.3.109-13.el7 libaio-devel.x86_64 0:0.3.109-13.el7 libgcc.i686 0:4.8.5-4.el7 libstdc++.i686 0:4.8.5-4.el7 libstdc++-devel.i686 0:4.8.5-4.el7 libxcb.i686 0:1.11-4.el7 unixODBC.x86_64 0:2.3.1-11.el7 unixODBC-devel.x86_64 0:2.3.1-11.el7 zlib-devel.i686 0:1.2.7-15.el7 zlib-devel.x86_64 0:1.2.7-15.el7 Dependency Installed: nss-softokn-freebl.i686 0:3.16.2.3-14.2.el7_2 zlib.i686 0:1.2.7-15.el7 Updated: binutils.x86_64 0:2.23.52.0.1-55.el7 gcc.x86_64 0:4.8.5-4.el7 gcc-c++.x86_64 0:4.8.5-4.el7 glibc.x86_64 0:2.17-106.0.1.el7_2.6 glibc-devel.x86_64 0:2.17-106.0.1.el7_2.6 libX11.x86_64 0:1.6.3-2.el7 libXext.x86_64 0:1.3.3-3.el7 libXi.x86_64 0:1.7.4-2.el7 libaio.x86_64 0:0.3.109-13.el7 libgcc.x86_64 0:4.8.5-4.el7 libstdc++.x86_64 0:4.8.5-4.el7 libstdc++-devel.x86_64 0:4.8.5-4.el7 libxcb.x86_64 0:1.11-4.el7 Dependency Updated: cpp.x86_64 0:4.8.5-4.el7 gcc-gfortran.x86_64 0:4.8.5-4.el7 glibc-common.x86_64 0:2.17-106.0.1.el7_2.6 glibc-headers.x86_64 0:2.17-106.0.1.el7_2.6 libX11-common.noarch 0:1.6.3-2.el7 libgfortran.x86_64 0:4.8.5-4.el7 libgomp.x86_64 0:4.8.5-4.el7 libquadmath.x86_64 0:4.8.5-4.el7 libquadmath-devel.x86_64 0:4.8.5-4.el7 nss-softokn-freebl.x86_64 0:3.16.2.3-14.2.el7_2 zlib.x86_64 0:1.2.7-15.el7 Complete! |
After you have installed the prerequisites, you install the oracle-dbms-server-12cR1-preinstall
library as the root
user. You run the command as the root user like this:
yum install -y oracle-dbms-server-12cR1-preinstall |
You should see the following when it’s successful:
Loaded plugins: langpacks adobe-linux-x86_64 | 951 B 00:00 ol7_UEKR3 | 1.2 kB 00:00 ol7_latest | 1.4 kB 00:00 (1/2): ol7_latest/x86_64/updateinfo | 829 kB 00:00 (2/2): ol7_latest/x86_64/primary | 16 MB 00:02 ol7_latest 14500/14500 Resolving Dependencies --> Running transaction check ---> Package oracle-rdbms-server-12cR1-preinstall.x86_64 0:1.0-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: oracle-rdbms-server-12cR1-preinstall x86_64 1.0-4.el7 ol7_latest 18 k Transaction Summary ================================================================================ Install 1 Package Total download size: 18 k Installed size: 43 k Downloading packages: oracle-rdbms-server-12cR1-preinstall-1.0-4.el7.x86_64.rpm | 18 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : oracle-rdbms-server-12cR1-preinstall-1.0-4.el7.x86_64 1/1 Verifying : oracle-rdbms-server-12cR1-preinstall-1.0-4.el7.x86_64 1/1 Installed: oracle-rdbms-server-12cR1-preinstall.x86_64 0:1.0-4.el7 Complete! |
After running the oracle-dbms-server-12cR1-preinstall library, you can navigate through the Applications, Sundry, and Users and Groups to see the following dialog:
It’s hard to tell from the GUI the oracle
user’s group. You can find oracle
primary user’s group by checking the /etc/passwd
file. You will find that oinstall
is the primary user’s group.
As always, I hope this helps those trying to install an Oracle Database 12c instance. Please post a comment if you have a better way to load the pre-requisite packages.