Tuesday, August 18, 2015

How to flatten a zip file directory structure

This is short but super useful. 

If you have a zip file with a directory structure but want all the files to be extracted in the same folder, use the 'junk paths' parameter (-j). It will extract all the files in the zip file to the current folder, completely disregarding the directory structure.

Example:

 unzip -l myrubygems.zip

  Length      Date    Time    Name
---------  ---------- -----   ----
    27136  2015-08-14 16:05   dist/cache/actionmailer-4.2.3.gem
   185344  2015-08-14 16:05   dist/cache/actionpack-4.2.3.gem
   144896  2015-08-14 16:05   dist/cache/actionview-4.2.3.gem
    18944  2015-08-14 16:05   dist/cache/activejob-4.2.3.gem
    45568  2015-08-14 16:05   dist/cache/activemodel-4.2.3.gem
   327680  2015-08-14 16:05   dist/cache/activerecord-4.2.3.gem
   329728  2015-08-14 16:03   dist/cache/activesupport-4.2.3.gem

 unzip -j myrubygems.zip 

  inflating: actionmailer-4.2.3.gem  
  inflating: actionpack-4.2.3.gem    
  inflating: actionview-4.2.3.gem    
  inflating: activejob-4.2.3.gem     
  inflating: activemodel-4.2.3.gem   
  inflating: activerecord-4.2.3.gem  
  inflating: activesupport-4.2.3.gem  

ORA-01653: unable to extend table by in tablespace SYSTEM

If you get ORA-01653 when trying to insert data into the database, that means Oracle DB was unable to extend your tablespace, either because it reached its maximum allowed space or because autoextend is not enabled.

To solve that, first check the size of the datafiles attached to the tablespace and whether they can autoextend or not:

 select file_name, bytes, autoextensible, maxbytes from dba_data_files where
 tablespace_name='SYSTEM';

Then, add more space to that file:

 alter database datafile '/u01/app/oracle/oradata/XE/system.dbf' resize 1000m;  

And, turn the autoextend feature on:

 alter database datafile '/u01/app/oracle/oradata/XE/system.dbf' autoextend
 on next 100m maxsize 2000m;  

Alternatively, you can add a new datafile to the tablespace:

 alter tablespace SYSTEM add datafile '/u01/app/oracle/oradata/XE/system2.dbf' 
 size 100m autoextend on next 100m maxsize 2000m;

Sunday, August 9, 2015

Oracle expdp error: directory object parameter must be specified and non-null

When dumping a database as an non-privileged user (grants: CONNECT, RESOURCE) using Oracle Data Pump tool I got the following error:

 expdp tax_data/<passwd> schemas=tax_data dumpfile=tax_data.dmp logfile=expdp_tax_data.log  

 ORA-39002: invalid operation  
 ORA-39070: Unable to open the log file.  
 ORA-39145: directory object parameter must be specified and non-null  

This happens because non-privileged users don't have access to the DATA_PUMP_DIR directory object. To solve that all I had to do was grant the roles EXP_FULL_DATABASE and IMP_FULL_DATABASE to the user.

If the DATA_PUMP_DIR has not been created by a DBA beforehand, one would get a different message:

 ORA-39002: invalid operation   
 ORA-39070: Unable to open the log file.   
 ORA-39087: directory name DATA_PUMP_DIR is invalid   

To check what is the value of the DATA_PUMP_DIR:

 select * from dba_directories where DIRECTORY_NAME = 'DATA_PUMP_DIR';