Showing posts with label dbc tables in teradata. Show all posts
Showing posts with label dbc tables in teradata. Show all posts

Wednesday, 2 September 2015

Teradata DBA Queries - Using Roles and manage Privileges in Teradata - Examples and Scripts

/* FOR MAINTENANCE OF ROLES AND PRIVILEGES */

SELECT * FROM DBC.AllRights WHERE TABLENAME = 'ORDERS';

We need to create Roles and assign privileges to the roles, rather than individual roles.

The below query will give us the list of access rights for a particular user (DBC in this case) on a particular database (retail in the example below).

 select DB.databasename
 , tvm1.tvmname as tvmname
 , user1.databasename as usrname
 ,AR.* 
 from dbc.accessrights as AR
 inner join dbc.dbase as DB
 on AR.databaseid = DB.databaseid
 inner join DBC.TVM as tvm1
 on AR.tvmid = tvm1.tvmid
  inner join dbc.dbase as user1
 on AR.userid = user1.databaseid
 where user1.databasename = 'dbc'
 and DB.databasename = 'retail';

If we keep assigning privileges to individual users, then this table will keep growing. In addition, maintenance will be a overhead.

Individual privileges are assigned as seen in the example below:

GRANT SELECT ON RETAIL.ORDERS TO TRAINING_1;

As per Teradata:

Using Roles simplifies the management of user privileges with roles. 
Roles help improve performance by reducing the number of rows added to and deleted from DBC.AccessRights. 
To use roles, assign privileges to a specific role and then grant the role to users. The users can then access all the objects on which their assigned role and nested roles have privileges.

The above can be achieved using the below list of commands:

CREATE ROLE REPORT_USER;
GRANT SELECT ON RETAIL.ORDERS TO REPORT_USER;


SELECT * FROM DBC.USERS;

CREATE USER TRAINING_1
FROM RETAIL
AS PASSWORD = "TRAINING_1"
, PERMANENT = 40000
, DEFAULT ROLE = REPORT_USER;

DROP USER TRAINING_2;
CREATE USER TRAINING_2
FROM TRAINING_1
AS PASSWORD = "TRAINING_2"
, PERMANENT = 40000
, DEFAULT ROLE = REPORT_USER
, PROFILE = HIGH_SPOOL_USER;

CREATE PROFILE HIGH_SPOOL_USER
AS SPOOL = 10000;


SELECT * FROM DBC.ROLES;

SELECT * FROM DBC.RoleInfo;

Roles and Privileges in Teradata



To manage privileges using roles:
  • Create different roles for the different job functions and responsibilities. Roles work best when based on job functions or responsibilities. Some users may belong to more than one role.
  • Decide which privileges to which objects a role should have.
  • Grant specific privileges on database objects to the roles.
  • Grant the role to users or other roles. However, note that roles can only be nested one level.
  • Assign default roles to users. Assigning a default role to a user allows the user to automatically access all the objects to which the role has been granted privileges. It also gives the user additional privileges to all the objects its nested roles also owns
Join us in our classroom for more discussion on Teradata.

Friday, 15 March 2013

Important DBC tables in Teradata - The data-dictionary of Teradata

The following tables provide a great deal of information about your Teradata system. They store the demographics of table, views, macros, column-definition, error-codes and numerous other information.

All we have to understand is how to use these tables to help ourselves and enable our Organization to "Work Smarter"

Examples:

1. SELECT * FROM DBC.TABLES WHERE TABLENAME LIKE '%Customer%'
----this is typically used in impact analysis phase, to see how many tables belong to a particular subject area. (Customer in the above example)


2. SELECT * FROM DBC.INDICES
----this table stores information about the indices, which table they are stored, etc.


3. SELECT * FROM DBC.COLUMNS
---this table stores the column information, not null/nullable, datatype, unique/non-unique. Greatly helps in Physical Data Modelling activities


4. SELECT * FROM DBC.DBQLOGTBL
---- The DBC.DBQLogTbl stands for database query log. As the name explains, it contains all the core performance data for the queries that run on the system. Before you start querying this table ensure that Query logging is enabled for the User.

This can be accomplished for training_1 user as follows:

---- enable query logging so that all the queries run by a particular user is logged

begin query logging with sql on training_1 ;

select * from dbc.users;
select * from dbc.dbase;
select db1.databasename,dblog1.*from dbc.dbqlogtbl as dblog1
inner join 
dbc.dbase as db1 
on dblog1.userid = db1.databaseid

where db1.databasename = 'training_1';


5. SELECT * FROM DBC.ERRORMSGS WHERE ERRORCODE =3523
---this table gives an understandable description of the Teradata errors. Great for any Developer.

6. select  * from dbc.dbqlogtbl where querytext like '%corp_ksn%' order by CollectTimeStamp desc
---- this query will return the logon information about the user along with the IP address and username. Any modification to the table can be easily tracked using this query.


7. Select count(distinct nodeid) from dbc.resusagescpu;

--- this query will let you find the total no. of Teradata nodes in the system

8. Select nodeid,count(distinct Vproc) from dbc.ResCpuUsageByAmpView group by 1;


---- this query will allow to find the no. of Vproc in the system


Please Donate using the Donate button. Your support is much appreciated !!

Like us on Facebook or Google+