oracle View the number of user tables, table size, number of views, etc.
View the default tablespace of the current user
SQL>select username, default_tablespace from user_users;
View the role of the current user
SQL>select * from user_role_privs;
View the system permissions and table level of the current user Permissions
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
view all tables under the user
SQL>select * from user_tables;
1. User
View the default tablespace of the current user
SQL>select username, default_tablespace from user_users;
view the current User's role
SQL>select * from user_role_privs;
View the system privileges and table-level privileges of the current user
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
Display the privileges of the current session
SQL>select * from session_privs;
Display the system privileges of the specified user
SQL>select * from dba_sys_privs where grantee='GAME';
2. Tables
View all the tables under the user
SQL>select * from user_tables;
View the tables whose names contain log characters
SQL>select object_name,object_id from user_objects
where instr(object_name,'LOG')>0;
View the creation time of a table
SQL>select object_name,created from user_objects where object_name=upper('&table_name');
View the size of a table
SQL>select sum(bytes) /(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&table_name');
View the table placed in the memory area of ORACLE
SQL>select table_name,cache from user_tables where instr(cache,'Y ')>0;
3. Index
View number and category of indexes
SQL>select index_name,index_type,table_name from user_indexes order by table_name;
View the indexed fields
SQL>select * from user_ind_columns where index_name=upper('&index_name');
View the size of the index
SQL>select sum(bytes)/(1024 *1024) as "size(M)" from user_segments
where segment_name=upper('&index_name');
4. Sequence number
View the sequence number, last_number is the current value
SQL>select * from user_sequences;
5.
View View the name of the view
SQL> select view_name from user_views;
View the select statement for creating a view
SQL>set view_name,text_length from user_views;
SQL>set long 2000; Note: You can set the size of set long according to the text_length value of the view
SQL>select text from user_views where view_name=upper (' &view_name');
6. Synonyms
View synonyms
SQL>select * from user_synonyms;
7. Constraints
View the constraints of a table
SQL>select constraint_name, constraint_type,search_condition, r_constraint_name
from user_constraints where table_name = upper('&table_name');
SQL>select c .constraint_name,c.constraint_type,cc.column_name
from user_constraints c,user_cons_columns cc
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')
and c.owner = cc.owner and c.constraint_name = cc.constraint_name
order by cc.position;
8. Stored functions and procedures
View the status of functions and procedures
SQL>select object_name,status from user_objects where object_type='FUNCTION';
SQL>select object_name,status from user_objects where object_type='PROCEDURE';
View the source code of functions and procedures
SQL>select text from all_source where owner=user and name=upper('&plsql_name');
-------- -------------------------------------------------- -------------------------------------------------- -------------------------
ORACLE:
----Common data dictionary
USER_
records the information of user objects, such as user_tables contains all the tables created by users; user_views, user_constraints, etc.; ALL_records
user
object information and authorized access object information;
DBA_records
all object information of database instance, such as DBA_USERS contains
all , DBA information contains user and all information;
V$ The dynamic view of the current instance, including the view of system management and optimized use;
GV_ The dynamic view of all instances in the distribution environment, including the view of system management and optimized use, where GV means Global v$;
such as the current distribution environment Start multiple instances under:
set line 160 (160 characters per line)
select inst_id,sid,lmode from gv$lock where inst_id = 1 or inst_id=2;
Oracle commonly used data dictionaries, oracle10 added a lot of data dictionaries 10g r1 has 1713, r2 has 1870:
1 Basic data dictionary:
DBA_TABLES all user table information;
DBA_TAB_COLUMNS all user table column (field) information;
DBA_VIEWS all user view information;
DBA_SYNONYMS all user synonym information;
DBA_SEQUENCES all user sequence information;
DBA_CONSTRAINTS table constraint information of all users;
DBA_INDEXES brief information of all user indexes;
DBA_IND_COLUMNS all user index column information;
DBA_TRIGGERS all user trigger information;
DBA_SOURCE all user stored procedure source code information;
DBA_PROCEDUS all user stored procedures;
DBA_SEGMENTS all user segments (table, index, Cluster) use space information;
DBA_EXTENTS extended segment information of all user segments;
DBA_OBJECTS basic information of all user objects (including prime index, table, view, sequence, etc.);
CAT all base tables that the current user can access ;
TAB All base tables, views, synonyms, etc. created by the current user;
DICT Information of all tables that constitute the data dictionary;
2 Data dictionary related to database components:
database:
V$DATABASE synonym V_$DATABASE, recording the operation of the system;
table Space:
DBA_TABLESPACES records the basic information of the system table space; DBA_DATA_FILES records the basic information of the
system data file and table space;
DBA_FREE_SPACE records the information of the remaining space of the system table space;
Control file:
V$CONTROLFILE records the path information of the system control file;
V$ PARAMETER records the basic information of each parameter of the system;
v$CONTROLFILE_RECORD_SECTION records the basic information of the system control operation;
data files:
DBA_DATA_FILES records the basic information of the system data files and table space;
v$DATAFILE records the data file information from the control file;
v$FILESTAT Record the basic information of reading and writing data files; --View
VGA information:
show sga;
select * from v$sgastat; --You
can view the information through the following dynamic performance views:
V$sysstat System statistics
V$sesstat User session statistics information
V$pgastat Displays memory usage statistics
V$sql_workarea Information about the work area used by SQL cursors
V$ sql_workarea_active Information about the current system work area
--In the V$process dynamic performance view, you can query the memory and memory allocated by the PGA of each Oracle process. The memory used,
-- where PGA_used_mem means used, pag_alloc_mem means allocated, pga_max_men means the maximum value of PGA.
SQL> select pid,pga_used_mem,pga_alloc_mem,pga_max_mem from v$process; --View
background processes:
SELECT * FROM v$bgprocess WHERE paddr <> '00'; --View
all tablespaces;
SQL> select tablespace_name from dba_data_files order by tablespace_name; --View
the name and size of the tablespace:
SQL> select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name
group by t.tablespace_name; --The
syntax for creating a tablespace is:
CREATE TABLESPACE tablespacename
DATAFILE 'filename' [SIZE integer [K|M]]
[AUTOEXTEND [OFF|ON]]; --Create
a tablespace with multiple datafiles:
SQL> create tablespace SALES
datafile 'd:/sales/SALES_DATA01 .dbf' size 10m autoextend on next 10m maxsize 100m,
'd:/sales/SALES_DATA02.dbf' size 10m autoextend on next 10m maxsize
unlimited,'d:/sales/SALES_DATA03.dbf' size 10m; --View
tablespace Size;
SQL> SELECT TABLESPACE_NAME,SUM(BYTES)/1024/1024 MB FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME; --View
the path where data files are stored in the tablespace:
SQL> SELECT TABLESPACE_NAME, BYTES/1024/1024 FILE_SIZE_MB, FILE_NAME FROM DBA_DATA_FILES; Drop tablespace
:
SQL> drop tablespace worktbs including contents;
tablespace has been dropped.
Querying the tablespace again will find that there is no worktbs tablespace.
What happens if we drop the tablespace again?
Drop a tablespace that does not exist:
SQL> drop tablespace worktbs including contents;
drop tablespace worktbs including contents
*
ERROR at line 1:
ORA-00959: tablespace 'WORKTBS' does not exist
o add data files
for tablespace SQL> alter tablespace sales add datafile 'd:/oracle/oradata/test/testtablespace/
sales_data04.dbf' size 10m autoextend on next 10m maxsize 100m,
'c:/oracle/oradata/test/testtablespace/sales_data05.dbf' size 10m autoextend on next 10m maxsize unlimited, 'c:/oracle/oradata/test/testtablespace/sales_data06.dbf' size 10m;
tablespace changed.
o Modify the size
of the data file. o When the free space in the data file is not used up, it is allowed to compress the data file. When the size of the compressed space exceeds the size of the unused space, an error will be generated.
SQL> alter database datafile 'c:/oracle/oradata/test/testtablespace/SALES_DATA04.dbf' resize 30m;
database changed.
o Turn off autoextend attribute of tablespace data file
o alter database
o datafile 'c:/SALES_DATA04.dbf' ,
o 'c:/SALES_DATA05.dbf',
o 'c:/SALES_DATA06.dbf'
o autoextend off;
o Open table Autoextend attributes of spatial data files
o alter database
o datafile 'c:/SALES_DATA04.dbf' ,
o 'c:/SALES_DATA05.dbf',
o 'c:/SALES_DATA06.dbf'
o autoextend on;
o Modify tablespace attributes ( offline)
o alter tablespace sales offline;
o alter tablespace attributes (online)
o alter tablespace sales online;
o alter tablespace attributes (read only)
o alter tablespace sales read only;
o alter tablespace sales read write;
o The following system tablespaces must not be set to offline or read only
o system, temp, undo, undotbs
o Move the data files
of the tablespace o 1. Make the tablespace offline (the system tablespace must not be offline,
o 2. Modify the name of the data file o
3. Execute the alter tablespace rename datafile command
o 4. Bring the tablespace online
o Step 1: alter tablespace sales offline;
o Step 2: Physically move the data file to the destination (It can be the
o part of the data file of the tablespace, and the name of the data file can be modified)
o Step 3: Logical move, modify the content of the control file
o alter tablespace sales rename
o datafile 'c:/sales01.dbf' to 'd: /sales02.dbf'
o -- There can be multiple data files, but the source file
o should be on the left side of to, the destination file should be on the right side of to, and the file names should be separated by commas.
o Step 4: Connect the tablespace online
o alter tablespace sales online;
o Step 5: Query dba_data_files to confirm
o Create user, specify default tablespace, disk quota
o create user rose identified by rose default
o tablespace sales quota 10m on sales;
o authorize user
o grant connect,resource,dba to rose;
o user login
o connect rose/rose
o create table
o create table emp(eid number)
o The table is placed in the tablespace sales by default
o query the user's storage quota dba_ts_quotas
o delete the tablespace (if the tablespace is empty)
o drop tablespace sales ;
o delete the tablespace and delete the data files (not empty)
o drop tablespace sales including contents and datafiles;
o create a table and specify the storage location of the table
o create table mytab(tid int ) tablespace sales;
o drop the tablespace (if the tablespace is empty)
o drop tablespace sales ;
o drop the tablespace Also delete data files (not empty)
o drop tablespace sales including contents and datafiles;
o When creating a table, specify the storage location of the table
o create table mytab(tid int ) tablespace sales;
o View the size of the space occupied by each table of the current user:
o select segment_name,sum(bytes)/1024/1024 from user_extents group by segment_name
o View the size of the space occupied by each tablespace:
o select tablespace_name,sum(bytes)/1024/1024 from dba_segments group by tablespace_name
Only valid user accounts can access the Oracle database
Oracle has several default database users
Scott/tiger
Create a user named martin with a password of martinpwd
CREATE USER MARTIN IDENTIFIED BY martinpwd
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP; The
GRANT command can be used to assign privileges or roles to the user; the
CONNECT role allows the user to connect to the database and create database objects.
The GRANT CONNECT TO MARTIN;
RESOURCE role allows users to use storage space in the database.
GRANT RESOURCE TO MARTIN;
This system privilege allows the user to create sequences in the current schema, and this privilege is included in the CONNECT role.
GRANT CREATE SEQUENCE TO MARTIN; GRANT
CREATE SESSION TO MARTIN; GRANT CREATE
TABLE TO MARTIN; GRANT
CREATE VIEW TO MARTIN; EMP TO MARTIN; Allows users to update records in TEST table GRANT UPDATE ON EMP TO MARTIN; Allows users to insert, delete, update and query records in TEST table GRANT ALL ON EMP TO MARTIN; ALTER USER command can be used to change password: modify MARTIN User's password: ALTER USER MARTIN IDENTIFIED BY martinpass; DROP USER command to drop user: drop MARTIN user mode: DROP USER MARTIN CASCADE; alter session set nls_date_format='yyyy-mm-dd';
1 Start to create the database:
---------------- Use tools to create (steps omitted)
2 Log in to the new database
run/sqlplus sys/sys@ACCP
(if you log in to the old database at this time, use sqlplus sys /sys@orac9i)
2 Create tablespace: sales (used to save data in accp database)
create tablespace TestTBS datafile 'd:/sales/sales001.dbf' size 10m autoextend on next 10m maxsize 30m,'d:/sales/sales002 .dbf' size 10m autoextend on next 10m maxsize 30m
3 Create user accp and grant permission
grant connect to accp;
grant resource to accp;
4 Log in to accp database as accp user
create table person(pid number(5),pname varchar2(20 )) tablespace testtbs;
insert into person values(1001,'TOM');
commit;
select table_name,tablespace_name from user_tables;
select * from person;
Oracle View the number of user tables, table size, number of views, etc.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327049269&siteId=291194637
Ranking