Friday, April 30, 2010

Oracle UNDO DBF issues

Oracle 10.2 is installed on Windows XP SP3.

Useful references:

1. Switch Undo Tablespace
2. Fun with UNDO tablespaces
3. ORA-01548: active rollback segment '_SYSSMU1$' found, terminate dropping tablespace
4. Oracle Init.Ora & SPFile
5. Automatic UNDO Management in Oracle9i

Problem description:
UNDO dbf file was f**ed up, it have to be removed and replaced.

Create temp tablespace and switch UNDO to it:
sqlplus> create undo tablespace UNDO_RBS1 datafile 'path_to_new_undo_dbf' size 500M AUTOEXTEND ON MAXSIZE 3900M;
sqlplus> alter system set undo_tablespace=UNDO_RBS1;

sqlplus> select status from v$rollstat;
STATUS
---------------
ONLINE
PENDING OFFLINE
PENDING OFFLINE
ONLINE
ONLINE
ONLINE
ONLINE
ONLINE
ONLINE
ONLINE
ONLINE
You can't drop or offline if status show offline pending.
Restart DB:
sqlplus> shutdown immediate;
sqlplus> startup;
And now try to drop undo tablespace:
sqlplus>alter tablespace UNDOTBS1 offline;
sqlplus>drop tablespace UNDOTBS1 including contents and datafiles;
*
ERROR at line 1:
ORA-01548: active rollback segment '_SYSSMU1$' found, terminate dropping
tablespace
Cause of The Problem
An attempt was made to drop a tablespace that contains active rollback segments.

Solution of The Problem
In order to get rid of this error you have to follow following steps.

1)Create pfile if you started with database with spfile.
sqlplus> create PFILE from SPFILE;
You can use the next command to get path to spfile (in my case pfile was located at "D:\oracle\product\10.2.0\admin\A7\pfile\init.ora.1252010112825" ):
sqlplus> show parameter spfile

2)Edit pfile and set undo management to manual.
undo_management = manual

3)Put the entries of the undo segments in the pfile by using the following statement in the pfile:
_CORRUPTED_ROLLBACK_SEGMENTS=(_SYSSMU1$,_SYSSMU2$,_SYSSMU3$,.....)
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=MANUAL
undo_tablespace=UNDOTBS1
_CORRUPTED_ROLLBACK_SEGMENTS=(_SYSSMU1$)

4)Mount the database using new pfile:
sqlplus> shutdown immediate;
sqlplus> startup mount pfile='fullpath to pfile'

5)Drop the undo segments,
sqlplus> drop rollback segment "_SYSSMU1$";

6) Drop Old undo tablespace.
sqlplus> drop tablespace UNDOTBS1 including contents and datafiles;

7) Add the new undo tablespace:
sqlplus> create undo tablespace UNDOTBS1 datafile 'path to new undo table space' size 500M AUTOEXTEND ON MAXSIZE 32000M;
sqlplus> alter system set undo_tablespace=UNDOTBS1;

8) Remove temp undo table space:
sqlplus> alter tablespace UNDO_RBS1 offline;
sqlplus> drop tablespace UNDO_RBS1 including contents and datafiles;
sqlplus> shutdown immediate;

9) Change the pfile parameters back to Undo_management = AUTO and modify the parameter Undo_tablespace=new_undo_tablespace_name and remove the _corrupted_rollback_segments parameter:
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
#_CORRUPTED_ROLLBACK_SEGMENTS=(_SYSSMU1$)

10) Startup the Database:
sqlplus> startup

NOTE: In step #3 I've tried to use _OFFLINE_ROLLBACK_SEGMENT = (_syssmu1$). But it didn't work.

Monday, April 26, 2010

How to change the default editor in Ubuntu?

The default editor in Ubuntu is nano. But I like Vim.

$ sudo update-alternatives --config editor

And You will get the next:

There are 6 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                    Priority   Status
------------------------------------------------------------
* 0            /bin/nano                40        auto mode
  1            /bin/ed                 -100       manual mode
  2            /bin/nano                40        manual mode
  3            /usr/bin/mcedit-debian   25        manual mode
  4            /usr/bin/vim.basic       30        manual mode
  5            /usr/bin/vim.nox         40        manual mode
  6            /usr/bin/vim.tiny        10        manual mode

Press enter to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode. 
Select 4, in this case and that's it.

How to use SUDO without password in Ubuntu?

I don't need to type password all the time when I use sudo in Ubuntu.
$ sudo visudo
Type the next thing at the end of the opened file:
username ALL=(ALL) NOPASSWD: ALL
Save and close this file.

Thursday, April 22, 2010

How to setup Ruby/Rails development environment, Part 2 - E-TextEditor

There are tons of text editors which are good enough for Ruby/Rails/web development. And it's not so easier to choose the "best" editor.
I'd like to talk about my top three editors which like the most:

Notepad++
It's the base text editor on my workstation. It has active community, plug-in repository developing fast enough. But, this editor doesn't have Rails syntax highlight, here I mean ERB files. So, for Rails editing I have to skip it (for now)
Vim
Cross-platform text editor. It has BIG, super active community with tons of plugins.

E-TextEditor
It's Textmate clone for Windows.

There are two choices for using these text editors:
  1. Use Notepad++/E-TextEditor (or other editors) on host machine and connect to Ubuntu VM via tool such as ExpanDrive.
  2. Use Vim via SSH (Putty) terminal. You'll have got plain linux terminal with all restrictions, but in this case you shouldn't install such tool as ExpanDrive which cost some money.
So, I will describe first solutions in this post and second - in the next post.

E-TextEditor and ExpanDrive
I assume that you install both e-texteditor and ExpanDrive.
Now, we can create some Rails project:
$ rails bar
And check IP address our Ubuntu VM:
$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:2b:58:78
          inet addr:192.168.72.132  Bcast:192.168.72.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2b:5878/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:185 errors:0 dropped:0 overruns:0 frame:0
          TX packets:191 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:20339 (20.3 KB)  TX bytes:33193 (33.1 KB)
          Interrupt:18 Base address:0x2000
Now open ExpanDrive and setup connection to VM:

As you can see my Ubuntu VM disk is mapped to host machine and I can use it for my Rails development.
Now, we can use any Windows based text editor and made modification directly on Ubuntu VM disk:
For Rails scaffolding we use SSH/Putty terminal.


References:
How to setup Ruby/Rails development environment, Part 1 - Ubuntu VM

Friday, April 16, 2010

How to setup Ruby/Rails development environment, Part 1 - Ubuntu VM

The most popular Ruby/Rails development platform isn't Windows. There are a lot of plug-ins, tutorials and blogs about Ruby/Rails on *nix like system. But, I'm Windows user (yes I know, Linux - rules!), so how can I use all community knowledge and easily apply it?
I've decided setup VMWare VM with Ubuntu Server v.9.10. And perform all Ruby/Rails development there via Putty (SSH).
I assume that You have installed Ubuntu VM.

This post is base on the next articles:

Step 1: Install Ubuntu VM - done 
Step 2: Install Putty on Windows 
Step 3: Configure Putty - Ubuntu VM connection
Check Ubuntu VM IP: ifconfig. Apply this VM IP in Putty setting. All next steps will be performed via Putty console 
Step 4: Update Ubuntu installation
sudo apt-get update
sudo apt-get dist-upgrade

Step 5: Install all necessary libs
sudo apt-get install build-essential
sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.1 mysql-common mysql-server-5.1 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libhtml-template-perl mysql-server-core-5.1 libmysqlclient16 libreadline5 psmisc
Step 6: During installation MySQL will ask to setup credentials:
user = "root"
password = "root"
Check Ruby version
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
Step 7: Install RubyGems
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz
tar xvzf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ruby setup.rb

sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Step 8: Install Rails
sudo gem install rails 
Step 9: Install SQLlite
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby    
Step 10: Install MySQL client
sudo apt-get install libmysqlclient-dev
sudo gem install mysql
Step 11: Test your Rails instalation
$ rails myrailsapp