Syntax to Create User On Another Server via DB Link - oracle

I'd like to create a user on another server using a db link. Is this possible? (Lets assume I have permission)
Here's the syntax for creating a user on the local server
create user TEST_USER
identified by TEST_USER_PW
default tablespace USERS
temporary tablespace TEMP;
How could it be done with a db link?
Thank you (Feel free to migrate this to DBA if it's off topic)
Edit: Haki brought up that DDL operations are not allowed on a remote database. I'll post an alternative once I find one.

You can execute DDL on over a database link using DBMS_UTILITY.EXEC_DDL_STATEMENT:
begin
dbms_utility.exec_ddl_statement#myself(
'create user TEST_USER
identified by TEST_USER_PW
default tablespace USERS
temporary tablespace TEMP');
end;
/

Related

Oracle - unable to create DB link

I am unable to create the DB link as it's throwing ORA - 01031 insufficient privileges error.
Let's say I have database DB1 and schema name as s1 and second database as DB2 with schema t1.
I am trying to create the DB link by sysdba user by running below -
alter session set current_schema=s1;
Create database_link dblinkname connect to t1 identified by password using DB2;
But this is giving me error. I tried giving privileges also to s1 but no luck. Any leads. I don't have the schema password for s1 and I can't reset it as it's production environment.
I had the same issue a several years ago.
Assuming, you don't want to create a public database link...
You can do this:
Grant privilege create database link to target schema.
Create a stored procedure in your target schema, which creates database link per execute immediate
Call this procedure
Finally drop this procedure.

How to create schema in Oracle and table spaces?

I create user(schema) in oracle. like this
create user EMP_DB identified by netsolpk account unlock;
But when i tried login through schema name and password, login failed. Below is the error message.
user EMP_DB lacks create session privilage; login denied.
I've not created any tablespaces.
For this, do I need to create any tablespace? If needed, how to create a tablespace?
And what more things are required for creating a schema in oracle 11g.
Please help me and give me step by step procedure.
The error user EMP_DB lacks create session privilage; login denied indicates that you need privilege to create a session. So you need to grant the appropriate privilege like,
GRANT CREATE SESSION TO emp_db;
Or You can go with granting the roles(group of privileges), CONNECT and RESOURCE.
CONNECT role has only CREATE SESSION privilege.
RESOURCE has the following privilges,
CREATE TRIGGER
CREATE SEQUENCE
CREATE TYPE
CREATE PROCEDURE
CREATE CLUSTER
CREATE OPERATOR
CREATE INDEXTYPE
CREATE TABLE
To find these PRIVILEGES of a ROLE, You can query the DBA_SYS_PRIVS table with a query like this:
SELECT grantee, privilege, admin_option
FROM DBA_SYS_PRIVS
WHERE grantee='RESOURCE';
Also to use the existing tablespace USERS, You can create a user with QUOTA UNLIMITED statement like,
CREATE USER emp_db IDENTIFIED BY netsolpk QUOTA UNLIMITED on USERS;
the fastest, quickest way to create a new user with privileges is
grant connect, resource to NewUser_name identified by NewUser_password;
by this command you will be sure that errors like above will not displayed.

Create user in oracle database

I have below requirement in oracle database
Create User and grant to all objects in schema "abc"
If i add any tables to schema "abc", then the user should have access by default without executing individual Grant
Current we are executing Grant statements for every objects created in schema, is there any onetime configuration available? Please help
Note: Here user is not a schema owner, for ex. some one who having access to read-only access.
In current versions of Oracle, you could create a DDL Trigger and have this automatically execute a grant on the newly created object to your other user.
See the excellent PSOUG site for an overview: http://psoug.org/reference/ddl_trigger.html

not able to drop a user in oracle

I am trying to drop a tablespace in oracle 10g , using my application .
A bit about my application -- In my application I can create tablespaces.
Now what happens in oracle is that when you create a tablespace , then a new user automatically gets created and is attached to the database.
When you have to drop a tablespace what one has to do is to , first drop the user connected to the database and then the database.
When I try to drop a user associated with a tablespace.
An exception is thrown by the database which is the System.Data.OracleClient.OracleException
The details of the exception are as follows - ORA - 01904 (Can Not drop a user that is currently connected)
The thing is I have closed all the connections.Pretty sure about this.
Still oracle is throwing this exception.
Any suggestions???
Still it is not able to drop the user and throws the exception.
It can happen that you closed applications but did not ended Oracle sessions for that user. Log in as sysdba and query active sessions:
SQL> select sid, serial#, username from v$session;
SID SERIAL# USERNAME
---------- ---------- ------------------------------
122 2557 SYS
126 7878 SOME_USER
If you find your user in this list then kill all his sessions:
SQL> alter system kill session 'sid,serial#';
Seems to be your error code is ORA-01940 and not ORA-01904 which says -
ORA-01940: cannot DROP a user that is currently logged in
Cause: An attempt was made to drop a user that was currently logged in.
Action: Make sure the user is logged out, then re-execute the command.
Hope the below link might help you -
http://www.dba-oracle.com/t_ora_01940_cannot_drop_user.htm
We do following and works..
ALTER TABLESPACE "OUR_INDEX" OFFLINE NORMAL;
DROP TABLESPACE "OUR_INDEX" INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
Please be sure that the user you're trying to drop is not currently connected. I did encounter this problem last year. My workaround was to restart the database. Once the database is up i drop the user.
Another workaround i haven't tried was to restart the listener. This too (logically) can ensure that the 'to be dropped' user is not connected when the listener is down.
This workaround (of course) cannot be used in production database.
A user does NOT automatically get created when you create a tablespace.
A user does get assigned a default tablespace. They may (or may not) create objects in that tablespace. They may (or may not) create objects in other tablespaces too.
Generally, rather than dropping the user, I would drop the user's objects. Then lock the account so they can't log in again. Then revoke any privileges they have.
If desired, you can then drop the 'unused' users after month or so.

Access to a oracle Database

I have created a database in Oracle. Say "TEMP" is the name of the database created. I have created a user DWH. Now I would like to grant access to TEMP for the user DWH.
How shall i do?
. When you say you have created a user DWH do you mean at operating system level or database level ?If you have created a database user
Anyway the command for creating a user in database is
create user DWH identified by password;
Now if you want to be able to connect to database and create a table you need the following
grant create session to DWH;
alter user DWH default tablespace users quota 100m on users;
grant create table to DWH;
You can grant other permissions also.You can also group permissions into a role and grant the role.

Resources