Tuesday, September 12, 2023

As sysdba how can I analyze my table spaces?

 As a `SYSDBA` user in Oracle, you can analyze your tablespaces to gather statistics and improve performance using the `DBMS_STATS` package. Here are the steps to analyze tablespaces:


1. **Connect to the Database**: First, connect to your Oracle database as the `SYSDBA` user using SQL*Plus or another SQL client:


   ```sql

   sqlplus / as sysdba

   ```


2. **Select the Tablespace**: Choose the specific tablespace you want to analyze. Replace `your_tablespace_name` with the name of your tablespace.


   ```sql

   ALTER TABLESPACE your_tablespace_name;

   ```


3. **Analyze the Tablespace**:


   a. **Analyze All Tables in the Tablespace**: You can analyze all tables within the selected tablespace by running:


      ```sql

      EXEC DBMS_STATS.GATHER_TABLE_STATS(ownname => NULL, tabname => NULL, partname => NULL, objname => NULL, estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, cascade => TRUE, degree => DBMS_STATS.AUTO_DEGREE, method_opt => 'FOR ALL COLUMNS SIZE AUTO', granularity => 'ALL', options => 'GATHER', stale_percent => NULL, stattab => NULL, statid => NULL, statown => NULL, no_invalidate => FALSE);

      ```


   b. **Analyze Specific Tables**: If you want to analyze specific tables within the tablespace, replace the `tabname` and other relevant parameters in the above procedure.


4. **View the Results**: You can view the results of the tablespace analysis in the `DBA_TABLES` or `DBA_TAB_STATISTICS` view. For example, to view statistics for a specific table:


   ```sql

   SELECT table_name, num_rows, last_analyzed

   FROM dba_tables

   WHERE table_name = 'your_table_name';

   ```


   Replace `your_table_name` with the name of the table you're interested in.


5. **Repeat as Needed**: You can repeat these steps for other tablespaces or tables as necessary.


Analyzing tablespaces helps Oracle's query optimizer make better decisions about execution plans, which can lead to improved query performance. However, keep in mind that analyzing large tables can be resource-intensive, so it's essential to schedule these operations during low-traffic periods or maintenance windows.


Additionally, you can customize the analysis settings and parameters based on your specific requirements. The provided example uses default settings, but you can adjust them as needed using the `DBMS_STATS` procedures.

How do I list all my tablespaces?

 To list all the tablespaces in your Oracle database, you can use SQL queries to access the relevant data dictionary views. Here are the steps to list all your tablespaces:


1. **Connect to the Database**: Start by connecting to your Oracle database using SQL*Plus or another SQL client as the `SYSDBA` user or any user with appropriate privileges.


   ```sql

   sqlplus / as sysdba

   ```


2. **Run the SQL Query**: You can use the following SQL query to list all tablespaces in the database:


   ```sql

   SELECT tablespace_name

   FROM dba_tablespaces;

   ```


   This query selects the `tablespace_name` column from the `dba_tablespaces` view, which contains the names of all tablespaces in the database.


3. **View the Results**: After executing the query, you will see a list of all tablespaces in your Oracle database.


   Example Output:

   ```

   TABLESPACE_NAME

   ------------------------------

   SYSTEM

   SYSAUX

   UNDOTBS1

   USERS

   TEMP

   EXAMPLE

   ...

   ```


This query provides a straightforward way to retrieve the names of all tablespaces in your Oracle database. Keep in mind that you need appropriate privileges to access the `dba_tablespaces` view. If you don't have these privileges, you can use the `user_tablespaces` view instead to list tablespaces owned by the current user:


```sql

SELECT tablespace_name

FROM user_tablespaces;

```


This query will display the tablespaces owned by the user who is currently connected to the database.

Tuesday, December 13, 2016

Oracle Passwords - how to unlock and change

Oracle passwords - changing, expiring and locking users

Oracle Tips by Steve Karam, OCM

See these important notes on how to un-lock a database and make_a password_not_expire.

Change Oracle passwords, expire, and lock unnecessary usersThere are many users on a full installation of Oracle, most of which you probably won't need. To lock an Oracle user account, you can use the following command:
alter user username account lock;
To unlock the user, simply replace 'lock' with 'unlock.'
Oracle comes with a few default accounts that should never be locked or dropped. These include: SYS, SYSTEM, SYSMAN (Oracle 10g), OUTLN. However, you do want always to change the password for these users. The default password for SYS is change_on_install. It is important that you follow these directions. To change the password for a user:
alter user username identified by new_password;
For non-critical users, you can always lock and expire the account. We can change the password for, lock, and expire the account CTXSYS all at once:
alter user ctxsys identified by 0bscur3 account lock password expire;
This will ensure that CTXSYS password has been changed from the self evident default of CTXSYS; on a successful login the password will have to be changed (because it is expired); and because it is locked, he account can't be logged into under any circumstances.
To aid you in this task, here is a list of users that come with a full database installation that are safe to expire and lock if you are not using their functionality:
  1. AURORA$ORB$UNAUTHENTICATED - Jserver user
  2. BI - demo user
  3. CTXSYS - Oracle Text/interMedia administrator
  4. DBSNMP - Oracle Intelligent Agent
  5. DSSYS - Dynamic Services and Syndication Server
  6. HR - demo user
  7. MDSYS - Spatial administrator
  8. ORDSYS/ORDPLUGIN - Object Relational Data user
  9. OE - demo user
  10. PERFSTAT - Statspack administrative user
  11. SCOTT - demo user
  12. SH - demo user
  13. TRACESVR - Oracle trace server
  14. WKSYS - Ultrasearch administrator
The best rule of thumb is to install only the features you need when you install Oracle. If you are not going to use Spatial, interMedia, or UltraSearch, don't install them. Then you will not have to worry about those three users.
Once an account has been expired, it can only be revived by assigning it a new password.  You can save the old password.

ALTER USER scott IDENTIFIED BY tiger;

You can then re-add the original password, provided that password_reuse_max is greater than zero.

Also see our notes on:

Friday, December 9, 2016

SQLDeveloper - How to change SAVE AS default path for files and Export

2
Is there a way to configure the directory SQL Developer uses to save SQL scripts?
When I do ... File, New, SQL File ... the directory is always set to the \AppData\Roaming\ for my user.
I'd like to set the default to a directory in my dev source code tree.
shareimprove this question
  
If it is hardcoded, you should think about just dropping a symlink to your desired directory in Appdata\roaming. – surfasb Mar 6 '12 at 14:57
  
Checked the registry and can't find any setting – SteveC Mar 8 '12 at 16:15

3 Answers


When you go to save your sql file you can change where the save defaults to. Change it in Tools>Preferences>Database>Worksheet Parameters. You can browse to a new location under "Select default path to look for scripts"
Can also change the Export Data so that it defaults to somewhere else. Go to Tools>Preferences>Database>Export and Browse to the location you want to export to for "Directory"
This used to annoy me bad before I changed it. Now all my saves and exports default to a folder I actually use.
shareimprove this answer


Found it ...
In the Choose Directory dialog, the left hand side has a number of commonly used short cuts, e.g. Desktop, Documents, but you can also have your own directories in there
shareimprove this answer

There is a post about this in OTN, and AlexAnd's solution opens the specified folder when I do File => Open.
The post is @
AlexAnd is saying that locate "\sqldeveloper\sqldeveloper\bin\sqldeveloper.conf" and simply add "AddVMOption -Dide.user.dir=" (where " is the full folder path that you like to use) to that file.
The disadvantage of this solution is that it will also move your settings folders to the specified folder (for me it was about 34MB), I use drop box to keep my queries so that is a wasted space.

Wednesday, December 7, 2016

How to find a session in Oracle DB and kill it.

select inst_id,sid,serial# from gv$session where username='HYP_CCC'; alter system kill session '70,5,@1' ; ---------- Other code that works: SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session where username = 'HYP_CCC'; SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session where type = 'USER'; SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session WHERE username IS NOT NULL OR username <> 'SYS'; alter system kill session'5,13,@1'; alter system kill session'6,107,@1'; alter system kill session'8,11,@1'; alter system kill session'9,5521,@1'; alter system kill session'14,2221,@1'; alter system kill session'15,2233,@1'; alter system kill session'16,692,@1'; alter system kill session'68,3,@1'; alter system kill session'70,5,@1'; alter system kill session'73,2270,@1'; alter system kill session'74,3350,@1'; alter system kill session'75,3255,@1'; alter system kill session'130,7,@1'; alter system kill session'133,2867,@1'; alter system kill session'134,1234,@1'; alter system kill session'145,1937,@1'; alter system kill session'146,902,@1'; alter system kill session'191,23,@1'; alter system kill session'192,11,@1'; alter system kill session'199,6839,@1'; alter system kill session'200,1959,@1'; alter system kill session'201,1694,@1';

Wednesday, November 16, 2016

Oracle Loader with SQL Developer

http://www.thatjeffsmith.com/archive/2012/08/using-oracle-sql-developer-to-setup-sqlloader-runs/
URL - Click Me That is all.

Friday, March 25, 2016

Rebuild targets.xml for Oracle Enterprise Manager Grid Control Agent

 1. Agents installations before 10.2.0.3 have a bug in the 'agentca' command
that prevents the targets.xml file from getting populated with the initial
parameters (AGENT_TOKEN, ORACLE_EMD, and/or HOST) when the file does not
already exist. To work around this we will need to manually create a targets.xml
file if it does not exist.

Windows create the new file in the Agent %ORACLE_HOME%\sysman\emd\ directory.
(Where %ORACLE_HOME% is the agent's home)

Unix$
$ cd $ORACLE_HOME/sysman/emd (where $ORACLE_HOME is the Agent's home)
$ touch targets.xml.
 2. Once you have created the targets.xml file, view the Agent's
$ORACLE_HOME/sysman/config/emd.properties file. 
Copy the values for:
agentSeed=12345 EMD_URL=http://hostname.oracle.com:9876/emd/main
3. Manually update the new targets.xml and add the following entries to the file following
the syntax exactly:
<targets agent_seed="agentseed from emd.properties">
  <target name="hostname and port from emd.properrties EMD_URL" type="oracle_emd">
  <target name="hostname as it appears in the emd_url" type="host">
</targets>
  <targets agent_seed="agentseed from emd.properties">
  <target type="oracle_emd" name="hostname and port from emd.properties EMD_URL">
  <target type="host" name="hostname as it appears in the emd_url">
</targets>
For example:

<targets agent_seed="12345">
  <target type="oracle_emd" name="hostname.domain.com:port">
  <target type="host" name="hostname.domain.com">
</targets>
<targets agent_seed="12345">
  <target name="hostname.domain.com:port" type="oracle_emd">
  <target name="hostname.domain.com" type="host">
</targets>

4. Force target re-discovery:

a. Verify that the environment variables are setup for the Management Agent:
$ORACLE_HOME set$ORACLE_HOME/bin in $PATH
b. The agentca utility is expecting the oraInst.loc to be located in the root of the Agent's $ORACLE_HOME

NOTE: Solaris puts the oraInst.loc in /var/opt/oracle.
Agentca will not fine the oraInst.loc on a Solaris platform.
For Solaris platforms you need to create a soft link:
$ORACLE_HOME/oraInst.loc to /var/opt/oracle/oraInst.loc

c. Run agentca -d to force a new discovery of the targets on the host
agentca -d