Outils pour utilisateurs

Outils du site


issue89:python

Oracle, which provides the world’s leading Relational Database Management System (RDBMS), offers a free developer license for their product, but *buntu users seem to be left in the cold. All is not lost, however, because in this article I’ll show you how to install and run the Oracle 11gR2 Express Edition on 64-bit versions of Ubuntu 12.04 and 14.04 – this may work for other Debian-based systems, but I haven’t confirmed that. If you are serious about becoming a database guru, this is an easy way to obtain a professional environment in which to do so.

The following will explain how to obtain the rpm (Red Hat Package Manager) package, convert it to a deb package, perform the initial set up of Oracle XE, and how to begin using Oracle’s SQL-Plus command-line interface.

There are a few limitations. Oracle is suitable only for 64-bit *buntu installations. The database will be limited to a mere 11 GB of user data, and is limited to using only one processor and no more than 1 GB of memory. The installation requires at least 512 MB. Details about Oracle XE can be seen at: http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html

To download the package, you will need to create a free online account with Oracle – a very small price to pay, and, based on my experience, one that doesn’t result in any unsolicited material in your in-box. The e-mail and the password you select also give you access to other developer utilities.

Throughout these instructions, the use of a text editor is required. The example commands assume the use of gedit, since that is Ubuntu’s default editor, but you can use any text editor you want.

Step A: You will need to know the amount of installed RAM as a number of bytes. The easiest way to do this is to see the value displayed in “System Settings …” from the desktop, but you may also use:

sudo lshw -short -C memory

The number must be at least 512 MB; to convert that to an exact byte count, use the formula: 512 * 1,048,576 = 536,870,912 bytes (multiply GB by 1073741824 to obtain bytes)

Write this number down for reference for the later steps. If you wish to allocate more RAM to Oracle, you may do so, but the minimum is usually sufficient for a single user running multiple applications.

The remaining commands are all issued from a terminal, opened with Ctrl+T in Ubuntu.

Step B: Oracle 11gR2 XE requires at least 2GB of available swap space. Determine if your available swap space (in gigabytes) is sufficient by issuing the following command:

free -g

Look for a line similar to the following:

Swap: 13 0 13

In this example, the machine has 13 GB available (the third number). If you have insufficient swap space, you will need to either create a swap partition or a swap file. Instructions for doing this in Ubuntu are readily available on the web, and so will not be repeated here.

Pre-Installation Steps

Step C: Download the zip file containing the 64-bit Linux package named oracle-xe-11.2.0-1.0.x86_64.rpm by selecting downloads from the previous page, or by directly choosing: http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html

Step D: Unzip the file using the following command: unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip

Step E: If you do not have the packages alien, liaio1, and unixodbc, you will need to install them. Since no harm will be done if they are already installed, enter the following command:

sudo apt-get install alien libaio1 unixodbc

Step F: Convert the red-hat rpm package to an Ubuntu .deb package using the following command:

sudo alien –scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm

Alien takes quite a while to do all the required conversions and reconfiguring of the rpm package, but you can use this time to perform all of the steps up to “Step M Perform the Installation,” but don’t proceed beyond that until the oracle-xe-11.2.0-1.0.x86_64.deb package has been created.

Step G: Create a chkconfig script using a text editor:

The Red Hat installer assumes the existence of a file /sbin/chkconfig that doesn’t exist in Ubuntu. Do not load the chkconfig package that is available for Ubuntu, though, since it can cause errors. Instead, create the file directly using the following commands:

sudo gedit /sbin/chkconfig

When the blank file is opened, copy and paste the text shown above right into the editor.

Save the file and close the editor.

Step H: Now apply execute privileges to the /sbin/chkconfig file you just created using the following command:

sudo chmod 755 /sbin/chkconfig

You can confirm the settings have been applied properly using the following command:

ls -l /sbin

You should see:

-rwxr-xr-x 1 root root 660 Nov 23 20:29 /sbin/chkconfig

Step I: Define the Linux Kernel parameters

Oracle 11gR2 XE requires the setting of some additional kernel parameters. First we’ll create a suitable Oracle configuration file using the editor, and then we’ll make the settings permanent by applying them to the kernel so they’ll be set on each reboot. First create the file using the editor.

sudo gedit /etc/sysctl.d/60-oracle.conf

When the blank file is opened, copy and paste the text shown below into the editor.

The value used for kernel.shmmax in the last line above (536870912) is the minimum recommended amount of RAM from Step A above. For use of Oracle while learning, this is probably sufficient, but the value may be increased up to the amount of RAM in your system if desired (i.e. the number does not need to match the amount of RAM in your system, but it cannot exceed it.) Save the file and close the editor.

Confirm the settings have been applied using the following command:

sudo cat /etc/sysctl.d/60-oracle.conf

Step J: Load the Linux Kernel parameters

sudo service procps start

This command should return:

me@myMachine:~$ procps stop/waiting

Verify the that parameters have been loaded by issuing the command:

sudo sysctl -q fs.file-max

This command should return something like the following:

me@myMachine:~$ fs.file-max = 773266

Step K: On an Ubuntu system, /dev/shm is defined as a link to /run/shm, but a link won’t satisfy Oracle, so the link needs to be removed and replaced with an actual directory which is then mounted. To do so, execute the following commands:

sudo rm -rf /dev/shm

sudo mkdir /dev/shm

sudo mount -t tmpfs shmfs -o size=2048m /dev/shm

(The size value can be any value up to the size of your RAM in MB, but I’ve found 2048 is quite sufficient).

To make these changes permanent, we need to create another file called S01shm_load in the directory /etc/rc2.d, so another editing session is required:

sudo gedit /etc/rc2.d/S01shm_load

Copy and paste the text shown above right into the editor.

Save the file and close the editor.

Confirm the settings have been applied using the following command:

ls -l /etc/rc2.d

There should be an appropriate line for the new file similar to the following: -rw-r–r– 1 root root 273 Nov 23 20:41 S01shm_load

Now set execute permissions for the file with the command:

sudo chmod 755 /etc/rc2.d/S01shm_load

Confirm that this was successful by repeating the last command:

ls -l /etc/rc2.d

If successful, the appropriate result line should look like this:

-rwxr-xr-x 1 root root 273 Nov 23 20:41 S01shm_load

Using the mount command, confirm that the shmfs temporary file system has been loaded by looking for a line like the following toward the end of the listing: shmfs on /dev/shm type tmpfs (rw,size=2048m)

Step L: The Red Hat installation process uses the /bin/awk utility but, since Ubuntu places this at /usr/bin/awk, we need to create a symbolic link to the location Red Hat expects by issuing the following command:

sudo ln -s /usr/bin/awk /bin/awk

Create an empty listener directory and listener file for Oracle’s use by issuing the following commands:

mkdir /var/lock/subsys

touch /var/lock/subsys/listener

DO NOT PROCEED BEYOND THIS POINT UNTIL THE oracle-xe-11.2.0-1.0.x86_64.deb package has been created (see step F).

Step M: Perform the Installation

Ensure that you are in the directory where the oracle-xe-11.2.0-1.0.x86_64.deb file was created in Step F. Begin the installation with the following command:

sudo dpkg –install oracle-xe_11.2.0-2_amd64.deb

Step N: Remove extraneous installation artifact

By default, the Red Hat installation procedure creates a desktop start icon, but this won’t work under Ubuntu, so either reconfigure it, or delete it with the following command:

rm $HOME/Desktop/oraclexe-gettingstarted.desktop

Step O: Configure the Oracle Installation

Once installed, Oracle needs to be configured prior to using it. The utility to do this is run with the following command:

sudo /etc/init.d/oracle-xe configure

You will need to enter the following information:

A valid HTTP port for the Oracle Application Express (unless you have a good reason for not doing so, accept the default value of 8080 by pressing Enter at the prompt)

A valid port for the Oracle database listener (unless you have a good reason for not doing so, accept the default value of 1521 by pressing Enter)

A single password for both the SYS and SYSTEM administrative user accounts; you will be asked to re-enter the password for confirmation. SAVE THIS PASSWORD!! It is for the system user “Oracle.”

You will then be asked whether you want the database service to start automatically each time the computer starts. It is most convenient to have the service run at log-in, so answer “Yes.” You’ll see:

Starting Oracle Net Listener. Step P: Several environment variables need to be set up for Oracle to run; this is done by editing the existing (hidden) .bashrc file using the following command:

sudo gedit $HOME/.bashrc

Add the lines shown below to the end of the .bashrc file:

Save the file and close the editor. Reload your profile by issuing the following commands:

cd $HOME

. ./.profile

The command above is “period, space, period, slash, period” followed by the word “profile.” The command will only take a second to execute and won’t display anything if it executed successfully.

Step Q: Start Oracle:

Depending on whether or not you chose the option to have Oracle start at boot, the oracle-xe service may or may not have already been started. Execute the following command anyway:

sudo service oracle-xe start

If the service has already been started, you will receive the message:

Oracle Database 11g Express Edition instance is already started

Otherwise, the following message will appear:

Starting Oracle Database 11g Express Edition instance.

Step R: Create a Database User

For normal activities, you should create one or more individual database user accounts. To do so, execute the following command:

sqlplus sys as sysdba

The following message will be displayed, confirming that your installation has been successful:

SQL*Plus: Release 11.2.0.2.0 Production on Wed May 9 12:12:16 2012 Copyright © 1982, 2011, Oracle. All rights reserved. Enter password:

Enter the password you chose in Step O:. Assuming you entered the correct password, the following message will be displayed, confirming that your installation has been successful:

Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL>

It is a good practice to set up one or more separate user accounts for development and experimentation – perhaps even one for each project you are working on. This will permit you to use Oracle without logging out of your current user session. As an example, you would create a user named JohnQ and set his password to “Jello” by entering the following command:

create user JohnQ identified by Jello;

The system will respond with:

User created.

In order to give JohnQ the ability to connect to and use the system to create or access a database, enter the following command:

grant connect, resource to JohnQ;

You may or may not wish to add other permissions to that list, such as dba, depending on your needs. The system will respond with:

Grant succeeded.

Repeat this process to create any other users that may be needed at this time.

Step S: Log in as a User and Confirm Operations

The following command will disconnect you from the SYS account, and connect you to JohnQ’s account to confirm that your user setup was successful:

sqlplus JohnQ/Jello

If you simply type “sqlplus” alone, SQL*Plus will prompt for a user id and password. A minimal method of confirming that the database is operational is to execute the following command:

select sysdate from dual;

The system will return something that looks like the following:

SYSDATE


5-JUN-14

Uninstalling Oracle

To completely uninstall the Oracle RDBMS, execute the following commands from a terminal:

sudo -s

/etc/init.d/oracle-xe stop

sudo ps -ef | grep oracle | grep -v grep | awk '{print $2}' | xargs kill

sudo dpkg –purge oracle-xe

sudo rm -r /u01

sudo rm /etc/default/oracle-xe

sudo update-rc.d -f oracle-xe remove

Remove the following files that are no longer needed:

sudo rm /sbin/chkconfig

sudo rm /etc/sysctl.d/60-oracle.conf (may not exist)

sudo rm /etc/rc2.d/S01shm_load

Remove the lines previously added to the end of $HOME/.bashrc in Step P. This will prevent any warning messages about non-existent files from appearing when starting a shell.

Remove the symbolic link to awk:

sudo ln -s /usr/bin/awk /bin/awk

Empty and then remove the /var/lock/subsys directory:

sudo rm -Ir /var/lock/subsys

sudo rmdir /var/lock/subsys

issue89/python.txt · Dernière modification : 2014/10/31 18:19 de andre_domenech