Ubuntu10.10 自宅サーバ構築手順:DB実行環境(Oracle)インストール

導入するバージョンは無償版である『Oracle Database 10g Express Edition』。


アプリケーションのインストール

  • サーバにログイン後、以下のファイルに定義を追加。
absj31@absj31-MyHomeServer:~$ sudo vi /etc/apt/sources.list
--------------------
※ファイル末尾に以下の行を追加
deb http://oss.oracle.com/debian unstable main non-free
  • 以下のコマンドを実行し、インストールの準備を行う。
absj31@absj31-MyHomeServer:~$ sudo wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle  -O- | sudo apt-key add -
absj31@absj31-MyHomeServer:~$ sudo apt-get update
  • apt-getコマンドでインストール。
absj31@absj31-MyHomeServer:~$ sudo apt-get install -y oracle-xe-universal
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  linux-headers-2.6.35-22 linux-headers-2.6.35-22-generic
これらを削除するには 'apt-get autoremove' を利用してください。
以下の特別パッケージがインストールされます:
  libaio
以下のパッケージが新たにインストールされます:
  libaio oracle-xe-universal
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
262MB のアーカイブを取得する必要があります。
この操作後に追加で 451MB のディスク容量が消費されます。
取得:1 http://oss.oracle.com/debian/ unstable/main libaio i386 0.3.104-1 [6,018B]
取得:2 http://oss.oracle.com/debian/ unstable/non-free oracle-xe-universal i386 10.2.0.1-1.1 [262MB]
262MB を 6分 49秒 で取得しました (641kB/s)                              
未選択パッケージ libaio を選択しています。
(データベースを読み込んでいます ... 現在 151313 個のファイルとディレクトリがインストールされています。)
(.../libaio_0.3.104-1_i386.deb から) libaio を展開しています...
未選択パッケージ oracle-xe-universal を選択しています。
(.../oracle-xe-universal_10.2.0.1-1.1_i386.deb から) oracle-xe-universal を展開しています...
desktop-file-utils のトリガを処理しています ...
python-gmenu のトリガを処理しています ...
Rebuilding /usr/share/applications/desktop.ja_JP.utf8.cache...
man-db のトリガを処理しています ...
ureadahead のトリガを処理しています ...
python-support のトリガを処理しています ...
libaio (0.3.104-1) を設定しています ...
oracle-xe-universal (10.2.0.1-1.1) を設定しています ...
update-rc.d: warning: /etc/init.d/oracle-xe missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Executing Post-install steps...
-e You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

libc-bin のトリガを処理しています ...
ldconfig deferred processing now taking place
absj31@absj31-MyHomeServer:~$ 
  • ログに従い、『sudo /etc/init.d/oracle-xe configure』で設定を行う。
absj31@absj31-MyHomeServer:~$ sudo /etc/init.d/oracle-xe configure

Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express 
Edition.  The following questions will determine whether the database should 
be starting upon system boot, the ports it will use, and the passwords that 
will be used for database accounts.  Press <Enter> to accept the defaults. 
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:【任意のポート番号を入力-デフォルト8080】

Specify a port that will be used for the database listener [1521]:【任意の数値を入力-デフォルト1521】

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of 
different passwords for each database account.  This can be done after 
initial configuration:【任意のパスワードを入力】
Confirm the password:【上記設定パスワードを再入力】

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:y 【再起動する場合はy】

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to "http://127.0.0.1:(設定したポート番号)/apex"
absj31@absj31-MyHomeServer:~$
(.../oracle-xe-universal_10.2.0.1-1.1_i386.deb から) oracle-xe-universal を展開しています...
This system does not meet the minimum requirements for swap space.  Based on 
the amount of physical memory available on the system, Oracle Database 10g 
Express Edition requires 992 MB of swap space. This system has 755 MB 
of swap space.  Configure more swap space on the system and retry the installation.
dpkg: /var/cache/apt/archives/oracle-xe-universal_10.2.0.1-1.1_i386.deb の処理中にエラーが発生しました (--unpack):
 サブプロセス 新 pre-installation スクリプト はエラー終了ステータス 1 を返しました
以下のパッケージの処理中にエラーが発生しました:
 /var/cache/apt/archives/oracle-xe-universal_10.2.0.1-1.1_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
  • Oracleの起動・停止・再起動は以下の形式で。
absj31@absj31-MyHomeServer:~$ sudo /etc/init.d/oracle-xe restart
Shutting down Oracle Database 10g Express Edition Instance.
Stopping Oracle Net Listener.

Starting Oracle Net Listener.
Starting Oracle Database 10g Express Edition Instance

動作確認

  • インストール端末のブラウザを起動、指定URLにアクセス。設定したユーザ名/パスワードでログイン実行。

  • ログイン完了。


ユーザ作成

  • SYS/SYSTEMユーザにてログイン、[管理]→[データベース・ユーザー]→[ユーザーの作成]でDB接続用のユーザを作成。
  • 作成したユーザでログインし直す。

テーブル作成

  • [オブジェクトブラウザ]→[作成]→[表]でテーブルを作成。
  • 作成するテーブルは例によって『都道府県』テーブル。以下の構成とした。


クライアント接続確認(GUI Tool)

insert_mst_pref.sql 直

  • 登録データの内容確認。


クライアント接続確認(Java)

package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class OracleConnectTest {
    public static void main(String[] args) {
        String prefCode = "";
        String prefName = "";
        int population = 0;
        System.out.println("START");
        Statement stmt = null;
        ResultSet rs = null;
        Connection con = null;
        try {
            // JDBCドライバの登録
            String driver = "oracle.jdbc.driver.OracleDriver";

            // データベースの指定
            String url = "jdbc:oracle:thin:@(対象サーバIP):1521:XE"; //
            // サーバ名またはIPアドレス+データベース名
            String user = "(接続DBユーザ名)"; // データベース作成ユーザ名
            String password = "(接続DBパスワード)"; // データベース作成ユーザパスワード
            Class.forName(driver);

            // データベースとの接続
            con = DriverManager.getConnection(url, user, password);

            // テーブル照会実行
            stmt = con.createStatement();
            String sql = "SELECT * FROM MST_PREF";
            rs = stmt.executeQuery(sql);

            // テーブル照会結果を出力
            while (rs.next()) {
                prefCode = rs.getString("pref_code");
                prefName = rs.getString("pref_name");
                population = rs.getInt("population");
                System.out.println("都道府県コード:[" + prefCode + "] 都道府県名:[" + prefName + "] 人口:[" + population + "]");
            }
            // データベースのクローズ
            rs.close();
            stmt.close();
            con.close();
        } catch (SQLException e) {
            System.err.println("SQL failed.");
            e.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } finally {
         }
    }
}
  • 動作確認実施。



これであと主要なDBはPostgreSQLか。時期見つけてこなしたい所ですね。