Category Archives: Linux

yum install tree -y

You need to do this right now!

As root on your Oracle Linux server, type:

[root@sqlfundamentals ~]# yum install tree -y

Then you can do this:

[oracle@sqlfundamentals ~]$ cd labs/
[oracle@sqlfundamentals labs]$ tree
.
├── sql1
│   ├── code_ex
│   │   ├── cleanup_scripts
│   │   │   ├── cleanup_10.sql
│   │   │   └── cleanup_11.sql
│   │   ├── code_09_retired_emp_tab.sql
│   │   ├── code_10_cretest.sql
│   │   ├── code_ex_02.sql
│   │   ├── code_ex_03.sql
│   │   ├── code_ex_04.sql
│   │   ├── code_ex_05.sql
│   │   ├── code_ex_06.sql
│   │   ├── code_ex_07.sql
│   │   ├── code_ex_08.sql
│   │   ├── code_ex_09.sql
│   │   ├── code_ex_10.sql
│   │   └── code_ex_11.sql
│   ├── demo
│   │   ├── demo_02_alias.sql
│   │   ├── demo_02_null.sql
│   │   ├── demo_03_and.sql
│   │   ├── demo_03_betw.sql
│   │   ├── demo_03_expr.sql
│   │   ├── demo_03_in.sql
│   │   ├── demo_03_ordernull.sql
│   │   ├── demo_03_or.sql
│   │   ├── demo_03_sal1.sql
│   │   ├── demo_03_sal2.sql
│   │   ├── demo_03_varno.sql
│   │   ├── demo_03_varyes.sql
│   │   ├── demo_04_case.sql
│   │   ├── demo_04_nest.sql
│   │   ├── demo_05_day1.sql
│   │   ├── demo_05_day2.sql
│   │   ├── demo_05_hire.sql
│   │   ├── demo_05_mask.sql
│   │   ├── demo_06_count1.sql
│   │   ├── demo_06_count2.sql
│   │   ├── demo_06_error.sql
│   │   ├── demo_06_job1.sql
│   │   ├── demo_06_job2.sql
│   │   ├── demo_06_listagg.sql
│   │   ├── demo_06_order1.sql
│   │   ├── demo_06_order2.sql
│   │   ├── demo_07_cart.sql
│   │   ├── demo_07_loc.sql
│   │   ├── demo_09_inters.sql
│   │   ├── demo_09_minus.sql
│   │   ├── demo_09_orderby.sql
│   │   ├── demo_09_union1.sql
│   │   ├── demo_09_union3.sql
│   │   ├── demo_10_cretabs.sql
│   │   ├── demo_10_grant.sql
│   │   ├── demo_10_revoke.sql
│   │   ├── demo_10_select.sql
│   │   ├── demo_10_update.sql
│   │   ├── demo_11_identity_col.sql
│   │   ├── demo_11_invisible_col.sql
│   │   ├── demo_11_sol_col_default.sql
│   │   └── demo_d_loc.sql
│   ├── labs
│   │   ├── lab_10_01.sql
│   │   ├── Online_Book_Store_Create_Table.sql
│   │   ├── Online_Book_Store_Drop_Tables.sql
│   │   └── Online_Book_Store_Populate.sql
│   └── soln
│       ├── sol_02.sql
│       ├── sol_03.sql
│       ├── sol_04.sql
│       ├── sol_05.sql
│       ├── sol_06.sql
│       ├── sol_07.sql
│       ├── sol_08.sql
│       ├── sol_09.sql
│       ├── sol_10.sql
│       ├── sol_11.sql
│       └── sol_ap.sql
└── sql2
├── code_ex
│   ├── cleanup_scripts
│   │   ├── cleanup_03.sql
│   │   ├── cleanup_05.sql
│   │   ├── cleanup_07.sql
│   │   ├── cleanup_09.sql
│   │   └── cleanup_10.sql
│   ├── code_cre_emp_history.sql
│   ├── code_cre_emp_sales.sql
│   ├── code_cre_mgr_history.sql
│   ├── code_cre_sales_info.sql
│   ├── code_cre_sales_source_data.sql
│   ├── code_cre_sal_high.sql
│   ├── code_cre_sal_history.sql
│   ├── code_cre_sal_low.sql
│   ├── code_cre_sal_mid.sql
│   ├── code_ex_02.sql
│   ├── code_ex_03.sql
│   ├── code_ex_04.sql
│   ├── code_ex_05.sql
│   ├── code_ex_06.sql
│   ├── code_ex_07.sql
│   ├── code_ex_08.sql
│   ├── code_ex_09.sql
│   ├── code_ex_10.sql
│   └── code_ins_sales_source_data.sql
├── demo
│   ├── demo_04_easyvu.sql
│   ├── demo_04_emp.sql
│   ├── demo_06_ex_1a.sql
│   ├── demo_06_ex_1b.sql
│   ├── demo_06_ex_2.sql
│   ├── demo_06_pairwise_a.sql
│   ├── demo_06_pairwise_b.sql
│   ├── demo_06_pairwise.sql
│   ├── demo_06_With.sql
│   ├── demo_07_delete_rows.sql
│   ├── demo_07_update_rows.sql
│   ├── demo_07_update_subquery1.sql
│   ├── demo_07_update_subquery.sql
│   ├── demo_08_revoke.sql
│   ├── demo_09_default_tab.sql
│   ├── demo_10_tz.sql
│   ├── demo_d_loc.sql
│   ├── demo_I_regexp_replace_a.sql
│   └── demo_I_regexp_replace_b.sql
├── emp_dir
│   ├── emp.dat
│   ├── library_items.dat
│   ├── LIBRARY_ITEMS_EXT_23121.log
│   ├── LIBRARY_ITEMS_EXT_5040.log
│   ├── OLDEMP_14719.log
│   └── OLDEMP_26721.log
├── labs
│   ├── confidence.sql
│   ├── lab_02_06_tab.sql
│   ├── lab_04_07.sql
│   ├── lab_05_09.sql
│   ├── lab_05_10.sql
│   ├── lab_05_11_a.sql
│   ├── lab_05_11_b.sql
│   ├── lab_05_11_g.sql
│   ├── lab_06_insert_empdata.sql
│   ├── lab_08_05.sql
│   ├── lab_09_01.sql
│   ├── lab_09_03.sql
│   ├── lab_09_05.sql
│   ├── lab_09_08_a.sql
│   ├── lab_09_08_b.sql
│   ├── lab_09_08_e.sql
│   ├── lab_09_09.sql
│   ├── lab_09_10.sql
│   ├── lab_09_11.sql
│   ├── lab_10_06.sql
│   ├── lab_ap_cre_mgr_history.sql
│   ├── lab_ap_cre_sal_history.sql
│   ├── lab_ap_cre_special_sal.sql
│   ├── Online_Book_Store_Drop_Tables.sql
│   └── Online_Book_Store_Populate.sql
└── soln
├── sol_02.sql
├── sol_03.sql
├── sol_04.sql
├── sol_05.sql
├── sol_06.sql
├── sol_08.sql
├── sol_09.sql
├── sol_10.sql
└── sol_ap.sql

13 directories, 154 files
[oracle@sqlfundamentals labs]$

And this is awesome!

 

Advertisement

Command line editing with bash

I use Oracle Linux just about every day. I teach Oracle classes using Oracle Linux and work with a whole bunch of Oracle servers which, more often than not, use Oracle Linux (or sometimes Redhat Linux which is basically very similar to Oracle Linux). The vast majority of the time these systems are set up to use bash (From wikipedia: The name itself is an acronym, a pun, and a description. As an acronym, it stands for Bourne-again shell, referring to its objective as a free replacement for the Bourne shell. As a pun, it expressed that objective in a phrase that sounds similar to born again, a term for spiritual rebirth. The name is also descriptive of what it did, bashing together the features of sh, csh, and ksh.) as the default shell for users.

While teaching my classes, I frequently type commands while my students watch and it’s not unusual for me to make typing mistakes. I often bang the BACKSPACE key a bunch of times while removing a single word, or worse yet, I hold it down to erase and entire line and start all over again. Every time I did this I would think “I used to know how to do this better.”

Today I looked it up a book that I have sitting on my bookshelf, (I last read it in 1995), which I would highly recommend if you’re a Unix System Admin: Using csh & tcsh Type Less, Accomplish More. It’s a really great book if you are going to be using a Unix shell all day every day interactively. I read it way back when I was learning Unix and it made a huge difference in my productivity with interactive ‘shelling’. These days I’m mostly only working with Linux to get Oracle systems set up and configured correctly, so I’m usually sticking with the default shell… which is bash.

I tested out some of the things in the book and they work a bit differently in tcsh than they do in bash. Since I’ve become (largely by default) a bash user, here goes:

Remove the entire command line in bash with CTRL-u or CTLR-w

[oracle@multitenant ~]$ This is a command line that I want to erase

Type CTRL-u or CTRL-w (as an aside, CTRL-w in tcsh erases a single word) and voila:

[oracle@multitenant ~]$

Sometime I only mess up the last word…

Remove the last word typed in bash with ESC BACKSPACE

[oracle@multitenant ~]$ env | grep ORALCE

Oops! Messed up that ORACLE. Type ESC BACKSPACE and voila:

[oracle@multitenant ~]$ env | grep

Now I can correctly add ORACLE to the above without having to use backspace six times.

Reuse part of the previous commands arguments with !$, !^, !*

Often we’ll look at the contents of a file and then decide we want to edit it.

[oracle@multitenant ~]# cat /etc/oratab

Hmmm…. I see something I want to change, so rather than typing vi /etc/oratab I can just do the following:

[oracle@multitenant ~]# vi !$

!$ uses the last argument from the previous command, !^ uses the first argument from the previous command, and !* uses all arguments from the last command, so actually any of those would have worked in the example above. Remember that above I have two parts in the line I’m typing; The first is the actual command (cat) and then the second is the argument (/etc/oratab).

Hopefully this (along with the CTRL-r post from earlier) will help a few folks become just a bit more efficient in their day to day operations!


CTRL-r is your friend!

You already knew that the up and down arrows in a Linux terminal window allow you to navigate through previously typed commands, but did you know that you can also search through your command history?

CTRL-r is great for finding those commands that are a bit tedious to type.

When you type CTRL-R in a terminal window your whole prompt turns into this strange looking text:

(reverse-i-search)`':

As you type characters the first command in your history, starting from the most recent and working back towards the top will be displayed.

Let’s say you’ve typed the following list of commands:

sqlplus / as sysdba
rman target "'/ as sysbackup'"
ls
ls -als

At a command prompt you type CTRL-r and then type s. Your prompt will now look like this:

(reverse-i-search)`s': ls -als

And the s in the als will be highlighted. What you’ve done here is found the first s in your command history.

If you type Enter right now, you’ll rerun that command.

Things get more interesting when you start typing more letters. Instead of typing just s, type sq and you’ll get the following:

(reverse-i-search)`sq': sqlplus / as sysdba

Hitting Enter will rerun that sqlplus command.

What if you want to find something that you typed earlier than the last command that matched? Just type CTRL-r again. Each time you press CTRL-r you’ll find older and older strings that match. If you have a short search string (just s for example), then it’s not unusual to find that string in a single command multiple times. Once you’ve exhausted all the matches in one command, you’ll reach back into your history to find another that matches.

What if you want to find the last thing that you found with CTRL-r?

Start a new search (or just use backspace to remove any characters you’ve started typing) and press CTRL-r again. Let’s say that you used rm as your last successful search and retrieved the rman command from the above list of commands. You then ran a few more commands and decided to run rman again… Just type CTRL-r twice. The first CRTL-r says “I want to search through my history”, the second CTRL-r says “Remember the last successful search I used? I want that one again.”

What if you don’t want to run the command you found, but instead you just put the command at your prompt so you can edit it? Instead of hitting Enter after you find a command, just press Esc. This dumps the text of the command into your terminal at a command prompt.

Here’s where things get really cool… If you use rlwrap for various Oracle commands like sqlplus, rman, etc. (See this post to install rlwrap, and this post to configure the aliases to use with rlwrap) then CTRL-r will also work in those commands too!

Want to find the last alter user command that you ran? In sqlplus just type your good friend CTLR-r and start typing alter. You probably won’t have to actually type all the letters in alter and soon you’ll have the following:

(reverse-i-search)`al': alter user dbsnmp identified by oracle_4U account unlock;

Technically CTRL-r finds the spot in your history where the command you found lives, so once you’ve found a command, you can use the up and down arrows to cycle through the commands that are near that command. What was that command that I typed right after I did that alter user command? Just press the down arrow key and you’ve found it!

There are a few idiosyncrasies with CTRL-r. First it is case sensitive so you’ll have to remember if you used SELECT or select. Second it can be kind of easy to get it into a strange place with the characters you are searching for if you start typing characters that are not actually in your command history CTLR-r will beep at you a bunch and you may or may not be able to use the backspace key to get back to where you want to be… Just use Esc to get out of the CTRL-r search and try again.

Also you may want to give CTRL-r more history to work with. If you’d like to do this you’ll need export two different environment variables, HISTSIZE and HISTFILESIZE.

I added the following to my .bash_profile file in my home directory:

# Let's give the history command and CTRL-r more to work with!
export HISTSIZE=10000
export HISTFILESIZE=10000

CTRL-r has saved me much typing over the years, I hope it helps you too!


Thoughts on the Oracle users bashrc and bash_profile

For many, many years we’ve been clouding up the oracle user’s .bashrc and .bash_profile scripts with ‘lots of things’. Some of these things will be set automatically when we run the . oraenv command (that’s dot space oraenv). Our good old friend LD_LIBRARY_PATH gets set automatically, ORACLE_HOME gets set automatically, and the PATH is extended to search in your ORACLE_HOME/bin directory.

The below screenshot comes from a ‘new’ Oracle Linux 6 system where I’ve done a software only install of Oracle Database 12.1.0.2 and have yet to create any databases. Because I don’t have a database yet, I have to type in the path to the ORACLE_HOME when I give some random SID. Once I have a database created, that database will get added to the /etc/oratab file and the SID will be recognized and automatically set the ORACLE_HOME for me.

bashrc and bash_profile

Click the image above to get a full size picture of what’s happening.

Based on the above, I might change things a bit in this post from my 12c Install Series.


Oracle Database 12c on Oracle Linux 6 – Step 30: Install the VirtualBox guest additions in the VM

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

30-01

Select Devices -> Install Guest Additions… from the VirtualBox menu. You’ll have to use the right Ctrl key to release the mouse to do so.

30-02

Click Cancel.

30-03

Right-click the desktop and select Open in Terminal.

30-04

Type the following commands, pressing Enter after each.

su - 
root (at the Password: prompt)
export KERN_DIR=/usr/src/kernels/`uname –r`
cd /media/V [TAB]
./VBoxLinuxAdditions.run

Note:

Those are back ticks which are probably next to the 1 key on your keyboard, not forward ticks in the export command. The Tab key will autocomplete commands for you. When we type cd /media/V the shell will complete the name of the Virtualbox Guest Additions CD for you. It’s much easier than typing it. If you’d like to use the Tab key to autocomplete the second command, you’ll have to type up to the L in Linux before it will work because there are other commands in that directory that start with VBox. You can always hit the Tab key twice to see what the shell will be able to autocomplete based on your search path.

30-05

You should see output with all green OKs.

Note:

If you get a failed message it’s most probably because your kernel doesn’t match the kernel sources which usually means that your yum update kernel-uek-devel command from earlier didn’t work correctly. Recheck your commands from Step 9 to make sure you did everything correctly.

30-06

Select System -> Log out oracle… from the menu.

30-07

Click Log Out.

30-08

Press Enter and type oracle in the Password field.

30-09

Right click the Guest Additions CD and select Eject.

30-10

Your window should now resize to fill the whole screen!

Note:

We could actually do this step a lot earlier and get the nice widescreen if we want. It was just a bit harder to do screen captures for me so I stuck this at the end. This must be done AFTER the reboot in step 18 though…

Oracle Database 12c on Oracle Linux 6 – Step 29: Create a Link to SQL Developer and Database Connections < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 31: Enjoy a frosty beverage!


Oracle Database 12c on Oracle Linux 6 – Step 29: Create a Link to SQL Developer and Database Connections

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

29-01

Enter the following commands pressing Enter after each one.

cd $ORACLE_HOME
cd sqldeveloper/
./sqldeveloper.sh 

29-02

Click the small x in the top right hand corner of the Tip of the Day dialog.

29-03

Click the New Connection button.

29-04

Enter orcl – sys for Connection Name.

Enter sys for Username.

Enter oracle_4U for Password.

Check Save Password.

Select SYSDBA in the Role dropdown.

Change the SID to orcl.

Click Test.

Click Save.

29-05

Change Connection Name to pdborcl – system.

Change Username to system.

Change the Role dropdown to default.

Choose Service name and enter pdborcl.localdomain.

Click Test.

Click Save.

Click Cancel. (The connection dialog will go away.)

29-06

Select File -> Exit.

29-07

Right-click the banner at the top of the window and select Add to Panel…

29-08

Select Custom Application Launcher and click Add.

29-09

Enter SQL Developer for Name.

Enter The best tool for developing SQL for Comment.

Click Browse…

29-10

Click the left arrow next to the oracle folder.

29-11

Click the disk icon to get to the root directory.

29-12

Keep clicking folders until you have navigated to /u01/app/oracle/product/12.1.0/dbhome_1/sqldeveloper.

Select sqldeveloper.sh and click Open.

29-13

Click the Launch icon.

29-14

Navigate to /u01/app/oracle/product/12.1.0/dbhome_1/sqldeveloper again.

Select icon.png.

Click Open.

29-15

Click OK.

29-16

Click Close.

Oracle Database 12c on Oracle Linux 6 – Step 27: Configure the Pluggable Database to Autostart on Reboot < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 30: Install the VirtualBox guest additions in the VM


Oracle Database 12c on Oracle Linux 6 – Step 28: Log into Oracle Enterprise Manager Express

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

28-01

Click the Firefox icon in the menu bar.

28-02

Navigate to https://localhost:5500/em .

28-03

Click I Understand the Risks.

28-04

Click Add Exception….

28-05

Click Confirm Security Exception.

28-06

Select Edit -> Preferences, click Use Current page, and click Close.

28-07

Enter sys for User Name, oracle_4U for Password, check as sysdba and click Login.

28-08

Note:

For some reason the lower windows seem to error out…

28-09

Again… Errors.

Oracle Database 12c on Oracle Linux 6 – Step 27: Configure the Pluggable Database to Autostart on Reboot < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 29: Create a Link to SQL Developer and Database Connections

 


Oracle Database 12c on Oracle Linux 6 – Step 27: Configure the Pluggable Database to Autostart on Reboot

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

27-01

Right-click the desktop and select Open in Terminal.

27-02

Type the following command and press Enter.

sqlplus / as sysdba

27-03

Type the following lines, pressing Enter after each one. The last line is a backslash, /. As you press enter after each line the prompt will change to show you your current line number.

create or replace trigger autostart_pdb
after startup on database
begin
execute immediate ‘alter pluggable database all open’;
end autostart_pdb;
/
  

Note:

For some reason pluggable databases don’t automatically start on reboot. Our container database (orcl) does as it is registered with Oracle Restart dynamically as it is created. The above trigger will automatically start our pluggable database (pdborcl) when the orcl database starts.

27-04

Type the following command and press Enter.

exit

Oracle Database 12c on Oracle Linux 6 – Step 26: Modify glogin.sql < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 28: Log into Oracle Enterprise Manager Express


Oracle Database 12c on Oracle Linux 6 – Step 26: Modify glogin.sql

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

26-01

Type the following commands, pressing Enter after each command.

cd $ORACLE_HOME
cd sqlplus/admin/
gedit glogin.sql

26-02

The previous command will open the existing glogin.sql script.

26-03

Add the below lines to the glogin.sql file and then click Save.

set trimspool on
set long 5000
set linesize 100
set pagesize 9999
col table_name for a30
column global_name new_value gname
set termout off
define gname=idle
SELECT LOWER(user) || '@' ||
              SUBSTR ( global_name, 1, decode (dot, 0, length(global_name), dot-1)) 
             as global_name 
    from
             (select global_name, instr(global_name,'.') as dot from global_name );
set sqlprompt '&gname> '
set termout on

26-04

Select File -> Quit.

2016-02-15 Update: Laurent Schneider (laurentsch via twitter) suggested adding the col table_name for a30 which is always useful…

2015-04-10 Update:

While the above glogin.sql is really cool, it does have the side effect of not allowing Enterprise Manager Cloud Control 12c (12.1.0.4 at least) to start the database. It appears that the select statement (which of course errors out when the database is down, but since we turned off terminal output with the ‘set termout off’ and then back on with the ‘set termout on’ it really shouldn’t make a difference…) breaks EM. I’ve asked Oracle to log a bug on this.

2016-02-05 Update:

Very cool! I just tested this out with Enterprise Manager 13c and it’s fixed. I’ve got a login.sql (instead of glogin.sql) and a SQLPATH environment variable that points to it and was just able to start my database with EMCC 13c. Thanks Oracle!

Oracle Database 12c on Oracle Linux 6 – Step 25: Create the orcl and pdborcl databases < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 27: Configure the Pluggable Database to Autostart on Reboot

 


Oracle Database 12c on Oracle Linux 6 – Step 25: Create the orcl and pdborcl databases

Part of this series of posts: Oracle Database 12c on Oracle Linux 6

25-01

Open a new terminal window by right-clicking the desktop and select Open in Terminal.

25-02

Type the following command and press Enter.

dbca

25-03

The installer will start after a while (Java has to start up on the machine).

25-04

Click Next.

25-05

Choose Advanced Mode and click Next.

Note:

If you don’t want to install the sample schemas then you can just create a database with the default configuration, however do make sure to change the default character set to AL32UTF8.

25-06

Click Next.

25-07

Enter orcl.localdomain for Global Database Name. This will auto populate orcl for the SID.

Check Create As Container Database and enter pdborcl for PDB Name.

Click Next.

Note:

If you are in my Oracle Database 11g Admin I or II course at Austin Community College and you are using 12c for your own test server at home, you may want to skip the pluggable database part and just stick with a ‘regular’ orcl instance so your environment matches the Oracle training materials more closely. If so, don’t check the Create As Container Database check box.

25-08

Click Next.

25-09

Choose Use the Same Administrative Password for All Accounts and enter oracle_4U for Password and Confirm Password.

Click Next.

25-10

Click Next.

Note:

Our ASM listener (notice LISTENER is in the grid home) supports dynamic instance registration.

25-11

Change both Storage Type dropdowns to Automatic Storage Management.

Change Database File Locations from +FRA to +DATA.

Change Fast Recovery Area from +DATA to +FRA.

Click Next.

Note:

In any type of production situation you’d be enabling archiving. However since this is a learning environment we’re going to leave that unchecked for now.

25-12

Check Sample Schemas and click Next.

25-13

Confirm that Use Automatic Memory Management is checked. Enter 2048 for the Target database memory. Don’t click next, but instead click the Character sets tab.

Note:

Why so little memory? Two reasons: First, this is just a test or classroom system. Second, if the memory size is too large then you’ll get an error because /dev/shm will need to be resized to potentially fit the amount of memory allocated to Oracle. For very large amounts of memory you’ll want to look into enabling HugePages on Linux which means that you won’t be able to use Automatic Memory Management (AMM).

25-14

On the Character sets tab, choose Use Unicode (AL32UTF8) and click Next.

Note:

These days Unicode should be used for your Oracle databases. Oracle is requiring Unicode for some products and Java applications use Unicode natively so you won’t have to do character set conversions between the database and your application if you use Unicode.

25-15

Click Next.

25-16

Click Finish.

25-17

The installer will run for a while…

25-18

Click Exit.

25-19

Click Close.

Oracle Database 12c on Oracle Linux 6 – Step 24: Install the Oracle Database Software Only < Previous Post – Next Post > Oracle Database 12c on Oracle Linux 6 – Step 26: Modify glogin.sql