I am trying to create a new schema in SQL Developer:
CREATE USER admindba
IDENTIFIED BY pwd4dba
DEFAULT TABLESPACE tbs_perm_01
TEMPORARY TABLESPACE tbs_temp_01
QUOTA 20M on tbs_perm_01;
I am getting error
SQL Error: ORA-00959: tablespace 'TBS_PERM_01' does not exist
00959. 00000 - "tablespace '%s' does not exist"
What is wrong? Can anyone clear the error?
I think, following steps will help you.
Login as sysdba in oracle developer.
Execute the create user statement. For example, create a new user named smith with a password of password as follows:
CREATE USER smith IDENTIFIED BY password;
Grant specific access to the new schema user. For example:
GRANT CREATE TABLE TO smith;
(Or this one to give all privileges to this user )
GRANT ALL PRIVILEGES TO smith;
Verify schema creation. For example, use the following query for new user smith:
SELECT username, account_status FROM dba_users
WHERE username = 'SMITH';
Then login as smith
I refer from this link
You have to create the tablespace first. Example:
create tablespace tbs_perm_01 datafile '/path/to/data/mydatafile01.dbf' size 1G autoextend on;
You will likely have create the temporary tablespace too. Then you can create the user that will use those tablespaces.
connect as sys to your server and check tablespaces
it looks that the tablespace TBS_PERM_01 is missing
select * from dba_tablespaces
select * from dba_tablespaces where tablespace_name = 'TBS_PERM_01'
Related
I have download the oracle sql developer version 21.2.1 and I want to create a new connection. But I do not have any schema created. Can somebody help me or any links would be helpful.
Note: I have searched on youtube and google. All the tutorials that I have seen seems to have already a schema.
Well, SQL Developer you downloaded is just a tool you'd use to access an Oracle database. What you need next is the database itself. Once you download & install it, create user (schema). This is 11g database version example:
Connect as a privileged user (SYS if you don't have any other; and you probably don't) using SQL*Plus (command-line tool):
SQL> connect sys/password_goes_here#xe as sysdba
Connected.
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USER_DATA
Create user:
SQL> create user will identified by ashoti
2 default tablespace user_data
3 temporary tablespace temp
4 quota unlimited on user_data;
User created.
Grant privileges which will allow that user to actually do something:
SQL> grant create session to will;
Grant succeeded.
SQL> grant create table to will;
Grant succeeded.
That's it; connect as newly created user:
SQL> connect will/ashoti#xe
Connected.
SQL> create table test as select sysdate as datum from dual;
Table created.
SQL> select * from test;
DATUM
----------
06.10.2021
SQL>
It works; moreover, it means that you should now be able to establish connection via SQL Developer as well.
I was trying to delete PostgreSQL user:
DROP USER ryan;
I received this error:
Error in query:
ERROR: role "ryan" cannot be dropped because some objects depend on it
DETAIL: privileges for database mydatabase
I looked for a solution from these threads:
PostgreSQL - how to quickly drop a user with existing privileges
How to drop user in postgres if it has depending objects
Still have the same error.
This happens after I grant all permission to user "ryan" with:
GRANT ALL PRIVILEGES ON DATABASE mydatabase ON SCHEMA public TO ryan;
DROP USER (or DROP ROLE, same thing) cannot proceed while the role still owns anything or has any granted privileges on other objects.
Get rid of all privileges with DROP OWNED (which isn't too obvious from the wording). The manual:
[...] Any privileges granted to the given roles on objects in the current
database and on shared objects (databases, tablespaces) will also be revoked.
So the reliable sequence of commands to drop a role is:
REASSIGN OWNED BY ryan TO postgres; -- or some other trusted role
DROP OWNED BY ryan;
Run both commands in every database of the same cluster where the role owns anything or has any privileges!
And finally:
DROP USER ryan;
REASSIGN OWNED changes ownership for all objects currently owned by the role.
DROP OWNED then only revokes privileges (ownerships out of the way).
Alternatively, you can skip REASSIGN OWNED. Then DROP OWNED will (also) drop all objects owned by the user. (Are you sure?!)
Related:
Drop a role with privileges (with a function to generate commands for all relevant DBs)
Find objects linked to a PostgreSQL role
What worked for me was to follow these steps:
Connecting to the database
\c mydatabase
Reassigning ownership
REASSIGN OWNED BY ryan TO <newuser>;
Or/and just deleting the object
DROP OWNED BY ryan;
Executing REVOKE PRIVILEGES
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM ryan;
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM ryan;
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM ryan;
Dropping the user
DROP USER ryan;
PS: You might not need to execute both Step 2 and 3, just one of the two steps might be usually enough.
What worked for me on RDS Postgres 13:
REVOKE ALL PRIVILEGES ON DATABASE <my_db> FROM <my_user>;
I also had a similar error where the role was owner for tables so it couldn't be dropped, had to re-assign table owner with:
ALTER TABLE <my_table> OWNER TO <trusted_role>;
Doing a REASSIGN like this didn't work for me on RDS because AWS doesn't give you full superuser to your master user:
REASSIGN OWNED BY <olduser> TO <newuser>;
REVOKE ALL ON SCHEMA "public" FROM "<user>";
Worked for me.
What worked for me was to recreate template1 database and then drop some role:
$ psql -U postgres postgres
postgres=# update pg_database set datistemplate = false where datname='template1';
UPDATE 1
postgres=# drop database template1;
DROP DATABASE
postgres=# create database template1 template=template0;
CREATE DATABASE
postgres=# update pg_database set datistemplate = true where datname='template1';
UPDATE 1
postgres=# DROP ROLE test;
DROP ROLE
For people who use AWS Postgresql RDS, you may try following
login to postgres user, then grant owner
postgres=> GRANT target_user to old_user;
GRANT ROLE
Login to target db using user that would like to remove(old_user), then reassign
target_db=> REASSIGN OWNED BY old_user TO target_user;
REASSIGN OWNED
Login back to postgres user, revoke all privileges then drop user
postgres=> REVOKE ALL PRIVILEGES ON DATABASE target_db FROM old_user;
REVOKE
postgres=> DROP USER old_user;
DROP ROLE
Ref. https://aws.amazon.com/premiumsupport/knowledge-center/rds-postgresql-drop-user-role/
I'm using Oracle 12c on my localhost. I wanted to create trigger for the tables.
It gives me an error:
"ORA-04089: cannot create triggers on objects owned by SYS"
I tried it by creating another user and granted it to create a trigger as it mentioned in this this post.
But it gives me a same error.
Here is my USER's scritp that created
CREATE USER DEVELOPER
IDENTIFIED BY <password>
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
-- 2 Roles for DEVELOPER
GRANT CONNECT TO DEVELOPER CONTAINER=ALL;
GRANT RESOURCE TO DEVELOPER CONTAINER=ALL;
ALTER USER DEVELOPER DEFAULT ROLE NONE;
-- 3 System Privileges for DEVELOPER
GRANT CREATE SESSION TO DEVELOPER;
GRANT CREATE TABLE TO DEVELOPER;
GRANT CREATE TRIGGER TO DEVELOPER;
-- 2 Tablespace Quotas for DEVELOPER
ALTER USER DEVELOPER QUOTA UNLIMITED ON SYSAUX;
ALTER USER DEVELOPER QUOTA UNLIMITED ON USERS;
I am running PostgreSQL 9.3.1. I have test database and backup user which is used to backup the database. I have no problems with granting privileges to all current tables, but I have to grant privileges each time the new table is added to schema.
createdb test
psql test
test=# create table foo();
CREATE TABLE
test=# grant all on all tables in schema public to backup;
GRANT
test=# create table bar();
CREATE TABLE
psql -U backup test
test=> select * from foo;
test=> select * from bar;
ERROR: permission denied for relation bar
Is it possible to grant access to tables which will be created in future without making user owner of the table?
It looks like the solution is to alter default privileges for backup user:
alter default privileges in schema public grant all on tables to backup;
alter default privileges in schema public grant all on sequences to backup;
From the comment by Matt Schaffer:
As caveat, the default only applies to the user that executed the
alter statement. This confused me since I was driving most of my
permissions statements from the postgres user but creating tables from
an app user. In short, you might need something like this depending on
your setup:
ALTER DEFAULT PRIVILEGES FOR USER webapp IN SCHEMA public GRANT SELECT ON SEQUENCES TO backup;
ALTER DEFAULT PRIVILEGES FOR USER webapp IN SCHEMA public GRANT SELECT ON TABLES TO backup;
Where webapp is the user that will be creating new tables in the futrue and backup is the user that will be able to read from new tables created by webapp.
If you want the backup user to have access to the future tables of userN,
you must run the code below under each userN who creates new tables,
because ALTER DEFAULT PRIVILEGES...
works only for objects by that user under whom you run ALTER DEFAULT PRIVILEGES...
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO backup;
I am trying to create a role, grant connect access to the role and then alter default privileges to keep access for future objects. However, it seems that the below command doesn't work at role level.
alter default privileges in schema public grant all on tables to backup;
I followed the below documentation but seems that there are two command do not work for roles.
DOC: https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/
First command:
GRANT CONNECT ON DATABASE mydatabase TO readonly;
Second command:
GRANT USAGE ON SCHEMA myschema TO readonly;
(For ROLES usually it needs TO ROLE, I also tried TO ROLE but still doesn't work.
I have granted the user in my connection to create tables, triggers, procedures, and sequence using sql+ (grant create table to <my_user>); however, that still does not allow me to create a table in that schema showing the error message:
java.sql.sqlsyntaxerrorexception ora-01031 insufficient privileges
select * from session_privs; shows:
PRIVILEGE
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
Does anybody know what I am doing wrong here? I am just setting up pl/sql developer at home, so everything is brand new. Does this have anything to do with TABLESPACE?
Run the following command from a privileged user and re-connect with your user:
GRANT RESOURCE to my_user;