Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Monday, January 13, 2014

How to create a user with read only priviliges for the schema

This ain´t an easy task as I thought you will need to run some commands before you have it going.

In this case let's assume that you already have the database created and the required accounts and that you are familiar with sqlplus

1) Login as system
sqlplus system/pwd@SID




2) You will need to create the user

CREATE USER your_user IDENTIFIED BY yourPassword;


This user will be created on the default tablespace




3)  Allow the user to create a session and view the table names

GRANT CREATE SESSION TO your_user;
GRANT SELECT ON SYS.EXTERNAL_TAB$ to your_user;



4) Create the queries to grant permissions on every table:
SELECT 'GRANT SELECT ON your_schema.' ||TABLE_NAME || ' TO your_user;' FROM DBA_TABLES WHERE OWNER='schema_owner';



5) Execute the result of the previous query
GRANT SELECT ON your_schema.Table1 TO DEVELS;
GRANT SELECT ON  your_schema.Table2 TO DEVELS;
...
GRANT SELECT ON  your_schema.TableN TO DEVELS;

Now your will have a user that can only see the data there

Friday, November 8, 2013

Oracle: Move undo tablespace to a different path

1) Login as sysadmin to the database (Remember that you need to be logged into the server, you cannot do this remotly)


   1: #sqlplus '/ as sysdba'

sql1

2) Check your currents undo tablespaces

select to_char(begin_time, 'DD-MON-RR HH24:MI') begin_time, 

to_char(end_time, 'DD-MON-RR HH24:MI') end_time, 

tuned_undoretention from v$undostat order by end_time;


3) Create the new undo tablespace



CREATE UNDO TABLESPACE undotbs_01 DATAFILE 

'/[your_path]/undo01.dbf' SIZE 2M REUSE AUTOEXTEND ON;

sql3

4) Set your system to use the new tablespace



ALTER SYSTEM SET UNDO_TABLESPACE = 

undotbs_01; 
sql4

5) Restart your database (There are some other ways but I prefer this one)

SHUTDOWN IMMEDIATE

sql5
STARTUP
sql6

6)  Drop your old undo tablespace to free some space

DROP TABLESPACE undotbs_02 INCLUDING CONTENTS AND DATAFILES;
sql7
Notes:
I had to do this movement in order to create some space in the file system, the partition was completely full and the database crashing. One of those things that you find in your development servers sometimes :)