Finding tablespace size on oracle without dba_* metatables - oracle

I need to find the current tablespace size for a db in Oracle 10g. Looking around, I've found many scripts that determine size using tables like dba_extents, but the database I'm using has none of these dba_* tables.
(I'm using this as a proxy for finding table size, which is complicated because most of the table size is in blobs.)

The DBA_* views are part of the "Static Data Dictionary Views" Generally there are three versions of every view, DBA_ that shows everything, ALL_ that shows what you have access to, and USER_ that will show what you own, and will not have the OWNER column.
For example DBA_TABLES has all tables, ALL_TABLES are the table you can select from, and USER_TABLES are the tables you own.
The views are documented in "Static Data Dictionary Views". A good resource if you need to translate from DBA_ to ALL_ or USER_.
Unfortunately _EXTENTS only comes in a DBA and USER version. So if want information on objects you can access but do not own, you will need to ask your resident DBA for help.

The dba_* views are part of the data dictionary, which exists in every Oracle database. They're in the sys schema, and if you can't query them, it probably just means you don't have SELECT access to them.
If the table you want to check is in your schema, you can replace e.g. dba_extents with user_extents and the query should work.
Here's my suggestion for a script to tell the size of a table in your schema (indexes included):
select segment_name, segment_type, bytes/1024/1024 as size_in_mb
from user_segments
where segment_name = :YOUR_TABLE
or segment_name in (select segment_name from user_lobs where table_name = :YOUR_TABLE)
or segment_name in (select index_name from user_indexes where table_name = :YOUR_TABLE);

Related

Oracle Apex application

We are doing a project on Oracle Apex for university. We have 12 tables and try to build an app for our project. When we try to add a new page for some of our tables (not all of them) we encounter this error error description.
Can someone know how to solve this issue which is really blocking us right now.
We tried everything to solve it. All of our constraints in our tables work. What we don't understand is why we can create sometimes new pages from some tables but for other it does not work.
To me, that (unfortunately) looks like bug as you don't have any impact on Apex' data dictionary tables.
If you connect as a privileged user and check what's exactly being violated, you'll see something like this.
Which table is that constraint related to? Apparently, none:
SQL> select table_name from dba_constraints where owner = 'APEX_200200' and constraint_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
no rows selected
Any luck with (unique) indexes, then? Yes!
SQL> select table_name from dba_indexes where owner = 'APEX_200200' and index_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
TABLE_NAME
------------------------------
WWV_DICTIONARY_CACHE_OBJ
Which columns are used to enforce uniqueness?
SQL> select column_name from dba_ind_columns where index_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
COLUMN_NAME
--------------------------------------------------------------------------------
SECURITY_GROUP_ID
OBJECT_ID
OBJECT_TYPE
SQL>
That's to get you started; you know which table you used for that page so write some more queries and you'll - hopefully - find some move info.
How to "fix" that error? I hope you won't delete or update anything on Apex' dictionary tables! Maybe you'd rather rename that table (to avoid uniqueness violation) and try to use it, with its new name, while creating the page in your application.
If a workspace contains other object types with the same name as a table, APEX data dictionary cache job, ORACLE_APEX_DICTIONARY_CACHE, fails with ORA-00001: UNIQUE CONSTRAINT (APEX_190200.WWV_DICTIONARY_CACHE_OBJ_IDX1)
Workaround: Remove the duplicate object that is not a table. You can list database objects by selecting from sys.dba_objects.
Oracle APEX 19.2 Known Issues

Identify system table in Oracle 11

ALL,
Is there a way to identify the system tables in Oracle 11g?
If I call SQLTables() API, I will get a list of all tables available. What I'd like is to identify what table is internal Oracle and which one is user-made.
I'm connecting with the system account. (a dba one).
TIA!
Query e.g. DBA_TABLES (which means that you have access to all tables in that database), using the OWNER column name as filter. For example:
select owner, table_name
from dba_tables
where owner in ('SYS', 'SYSTEM');
For more owners, query DBA_USERS:
select * from dba_users;
and include any you want into the first query.

Oracle - Move all tables and reclaim free space

I have this query:
select file_id, block_id first_block, block_id+blocks-1 last_block,
segment_name
from dba_extents
where tablespace_name = 'USERS'
union all
select file_id, block_id, block_id+blocks-1, 'free'
from dba_free_space
where tablespace_name = 'USERS'
order by file_id, first_block DESC;
It shows lot of "free" segments in between. There are lot of tables which are coming in between.
I move the tables using:
Alter table table_name move;
I have 2000 such tables. Is there a way on how I can move it altogether so I can reclaim all the free space from the tablespace?
To achieve your goal you have to move all objects in the tablespace, not just tables.
At least you have to move tables and then rebuild all their indexes because when you move a table all indexes built on this table are invalidated.
You can not move all tables all together but you can obtain all commands in the following way:
select 'alter table ' ||table_name ||' move;'
from dba_tables where tablespace_name = 'YOURTABLESPACENAME';
To rebuild indexes:
select 'alter index ' ||index_name ||' rebuild;'
from dba_indexes where tablespace_name = 'YOURTABLESPACENAME' and status <>'VALID';
Be careful: this procedure is not complete, you can have indexes of different kind.
Note: to obtain best results you should move objects in a different tablespace.
A simpler approach can be the one explained here: this article describe how to use the shrink command against Oracle database tables to reclaim wated space.
If you want a detailed procedure give me the result of the following query:
select distinct segment_type from dba_segments where tablespace_name='YOURTABLESPACENAME';

In Oracle, how to list all the tables in *my* schema that *I* created (without having DBA privileges)

I'm an Oracle11XE user with privileges to create and drop tables and procedures. I create a few tables, then while visiting the restroom, MIB zap me with a memory wipe (I foolishly looked into the light). Returning to sit at my workstation, I realize I need to query the database with my regular user privs, and figure out what that table or tables I created and the DBA has mysteriously gone missing.
You can use USER_TABLES view to get all the tables currently in your schema:
select table_name
from user_tables
If, additionally, you are interested in knowing when the tables were created, then you can use the USER_OBJECTS view where OBJECT_TYPE = 'TABLE'. That view includes the CREATED column.
select object_name, created
from user_objects
where object_type = 'TABLE'

oracle 11g dispaly user created tables

Hi I m new to oracle using 11g exprs edition and familiar with mysql. We can use the below code to display all databases in mysql
show databases;
What is the corresponding command in Oracle. Or how can i display all databases. Also We have
use mydatabase;
to chanage database in mysql. How can i change database in oracle. I tried to display all owners and their tables using the following command
select table_name, owner from all_tables;
It working fine. But when I tried to display tables I have created, by adding a where cluase
select table_name, owner from all_tables where owner='root';
it shows no rows were selected. Why this happens? Also I am facing the same problem with most of the queries when using the where clause. Without where clause it works fine. but when using it, the result is no rows selected for example
select * from all_tab_comments where owner='root';
select constraint_name, constraint_type from user_constraints where table_name='location';
Is there anything special in oracle for where clause or the problem with my query.
Your username is very unlikely to be root; it could however be ROOT, in which case you could do:
select table_name, owner from all_tables where owner='ROOT';
The owner name is case-sensitive, and all objects including users and table names are upper-case by default (unless they're created with double-quotes, which is a bad idea). If you're connected as that user, to see only your own tables you can also do:
select table_name from user_tables;
And there is the dba_tables view which also shows you tables you don't have permissions on, but you can only see that with elevated privileges.
Oracle doesn't have 'databases' in the same sense as other products. You probably means schemas, as the logical grouping of objects. And schemas and users are essentially synonymous.
To get a list of all schemas you can query dba_users (if you have the right privileges), or to get a list of schemas that have objects - as you may have users who only use objects in other schemas - you can do:
select distinct owner from dba_objects;
... or all_objects to again only see things you have permissions for. To see what kind of objects:
select owner, object_type, count(*) from dba_objects group by owner, object_type;
The documentation explains the static data dictionary views which hold all of this information. You won't be able to see all of them though, unless you're connected as a privileged user.
There will be a lot of differences between the two products; you might be better off trying to find a tutorial that works through them rather than using trial and error and trying to understand what's gone wrong at each step. Or at least familiarise yourself with the Oracle documentation so you can research issues.
First, there is going to be a terminology difference when you change platforms. What MySQL calls a "database" is most similar to what Oracle calls a "schema". If you are using Oracle XE, you can only have one database (using Oracle terminology) on the machine. You can have many schemas within that database.
The owner in all_tables is the name of the schema that owns the table. Assuming that you created an Oracle user root (which seems like an odd choice for a database user) and assuming that you did not create a case-sensitive user name in all lower case (which would create a ton of issues down the line), the owner will always be upper-case.
SELECT owner, table_name
FROM all_tables
WHERE owner = 'ROOT'
In Oracle, you do not generally change from one schema to another. You either fully qualify the table name
SELECT *
FROM schema_name.table_name
or you create synonyms (public or private) for objects that you want to reference
CREATE SYNONYM synonym_name
FOR schema_name.table_name;
SELECT *
FROM synonym_name
If you really want to, however, you can change your current schema for name resolution purposes
ALTER SESSION SET current_schema = <<schema name>>
use the view : tabs
select * from tabs;

Resources