View Database information |
---|
1. View the version of Oracle that is installed.SELECT * FROM PRODUCT_COMPONENT_VERSION; - or - SELECT * FROM V$VERSION; |
2. View database name.SELECT NAME FROM V$DATABASE; - or - SELECT * FROM GLOBAL_NAME; |
3. View NLS (National Language Support) ParametersSELECT * FROM NLS_DATABASE_PARAMETERS; - or - SELECT * FROM V$NLS_PARAMETERS; |
4. View SessionsSELECT SCHEMANAME, OSUSER, MACHINE, PROGRAM, STATE FROM V$SESSION; |
5. View ServicesSELECT SERVICE_ID, NAME, NETWORK_NAME FROM DBA_SERVICES; |
6. View current database instance detailsSELECT INSTANCE_NAME, HOST_NAME, VERSION, STARTUP_TIME, STATUS FROM V$INSTANCE; |
Managing Tablespaces and Data files |
1. List tablespaces, status and typeSELECT TABLESPACE_NAME, STATUS, CONTENTS FROM DBA_TABLESPACES; |
2. Create tablespaceCREATE TABLESPACE myspace DATAFILE 'datafile_directory_path\data_file_name.dbf' SIZE 20M AUTOEXTEND ON NEXT 512K MAXSIZE UNLIMITED; |
3. List Datafiles, tablespaces and statusSELECT FILE_NAME, TABLESPACE_NAME, STATUS FROM DBA_DATA_FILES; |
4. To check the current size of a tablespaceSELECT SUM(bytes/1024/1024/1024) "Size in GB" from DBA_DATA_FILES WHERE TABLESPACE_NAME='MYSPACE'; |
3. List Datafiles, tablespaces and statusSELECT FILE_NAME, TABLESPACE_NAME, STATUS FROM DBA_DATA_FILES; |
5. Check the size of a databaseSize of an Oracle database is the sum of the size of its Data files, Temporary files, Redo logs and Control files. SELECT ROUND( SUM(Q1."Data Files" + Q2."Temp Files" + Q3."Redo Logs" + Q4."Control Files" )/1024/1024/1024, 2) AS "Total Size (GB)" FROM (SELECT SUM(bytes) "Data Files" from DBA_DATA_FILES) Q1, (SELECT SUM(bytes) "Temp Files" from DBA_TEMP_FILES) Q2, (SELECT SUM(bytes) "Redo Logs" from V_$LOG) Q3, (SELECT SUM(BLOCK_SIZE * FILE_SIZE_BLKS)"Control Files" FROM V$CONTROLFILE) Q4; |
Managing Users and Security |
1. List all users, account status and profileSELECT USERNAME, ACCOUNT_STATUS, PROFILE FROM DBA_USERS; |
2. List all rolesSELECT * FROM DBA_ROLES; |
3. Create UserCREATE USER charlie IDENTIFIED BY password123; |
Note: Two administrative user accounts SYS and SYSTEM are created by default. Default password for SYS user is CHANGE_ON_INSTALL and SYSTEM user is MANAGER |
4. Change user passwordALTER USER charlie IDENTIFIED BY newpassword; - or - PASSWORD |
5. Create user profile (with all default limits)CREATE PROFILE MY_PROFILE LIMIT; |
6. View all user profiles and limitsSELECT * FROM DBA_PROFILES; SELECT * FROM DBA_PROFILES WHERE PROFILE='MY_PROFILE'; |
7. Change password lifetime, reuse time, failed login attemptsSELECT * FROM DBA_PROFILES WHERE PROFILE='MY_PROFILE' AND RESOURCE_NAME = 'PASSWORD_LIFE_TIME'; |
8. Set password expiryTo set password to 60 days for example: ALTER PROFILE MY_NEW_PROFILE LIMIT PASSWORD_LIFE_TIME 60; To set password to never expire: ALTER PROFILE MY_PROFILE LIMIT PASSWORD_LIFE_TIME UNLIMITED; |
9. View privileges granted to a user on other users tablesSELECT * FROM DBA_TAB_PRIVS WHERE GRANTEE='USERNAME'; |
10. View all user privileges including the privileges that are indirectly granted through rolesSELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE='USERNAME' or GRANTEE in (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE='USERNAME'); |