If your user is granted with the create session
privilege, most of the alter session
statements are possible, except the ones which require specifically the alter session
privilege.
Demo
SQL> create user test6 identified by Oracle_1234 ;
User created.
SQL> grant create session to test6 ;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
We now connect with the new user
$ sqlplus test6/Oracle_1234
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Oct 7 14:03:57 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> alter session enable parallel dml ;
Session altered.
SQL> alter session enable parallel query ;
Session altered.
SQL> alter session set optimizer_mode=first_rows ;
Session altered.
SQL> alter session set sql_trace= true ;
ERROR:
ORA-01031: insufficient privileges
As the documentation states, in the following cases you would need to grant the privilege directly
To enable and disable the SQL trace facility, you must have ALTER SESSION
system privilege.
To enable or disable resumable
space allocation, you must have the
RESUMABLE system privilege.
You do not need any privileges to perform the other operations of
this statement unless otherwise indicated.
If we grant the privilege, the enable of trace will work
SQL> grant alter session to test6 ;
Grant succeeded.
Then we connect again with the user
sqlplus test6/Oracle_1234
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Oct 7 14:11:22 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Thu Oct 07 2021 14:11:03 +02:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> alter session set sql_trace=true ;
Session altered.
UPDATE
If you are using MULTITENANT, you need to create the user in the right pluggable database.
CONN / AS SYSDBA -- you connect to the container root
-- Switch container while connected to a common user.
ALTER SESSION SET CONTAINER = yourpdb;
-- Create the local user using the CONTAINER clause.
CREATE USER xxxx IDENTIFIED BY xxxxx CONTAINER=CURRENT;
GRANT CREATE SESSION TO xxxx CONTAINER=CURRENT;
You can connect directly to the pdb ( pluggable database )
CONN system/password@pdb1
-- Create the local user using the default CONTAINER setting.
CREATE USER xxxxxxxx IDENTIFIED BY xxxxxxxxxx;
GRANT CREATE SESSION TO xxxxxx;
Then, connect with the user to the pluggable database
conn xxxx/password@pdb1
alter session set optimizer_dynamic_sampling=0 ;