Monday, November 7, 2022

script to find out unload and copy counts on Redshift database?

script to find out unload and copy counts on Redshift database:

The below script will provide the count of copy/unload process on the same session.


 select pg_last_copy_count();


select pg_last_unload_count();

script to find out if the user granted assumrole privilege on database for unload/copy?

 script to find out if the user granted assumrole privilege on database for unload/copy:


select has_assumerole_privilege('user@abc.com', 'arn:aws:iam::123456789:role/redshift-s3-unload-service-role', 'copy');


has_assumerole_privilege

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

false      


select has_assumerole_privilege('user@abc.com', 'arn:aws:iam::123456789:role/redshift-s3-unload-service-role', 'unload');


has_assumerole_privilege

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

false      

Thursday, November 3, 2022

SQL Error [XX000]: ERROR: User user@abc.com does not have ASSUMEROLE permission on IAM role "arn:aws:iam::123456789:role/Redshift-s3-unload-role" for UNLOAD

 Issue:

when I tried to unload some data from Redshift to S3 bucket using the  Redshift SSO  user got the below error.


SQL Error [XX000]: ERROR: User user@abc.com does not have ASSUMEROLE permission on IAM role "arn:aws:iam::123456789:role/Redshift-s3-unload-role" for UNLOAD


Solution:

after some investigation  found that ,we should grant the assumrole privilege's to the user ,after granting the privilege issue resolved.

Syntax: ==>Unload

grant assumerole on 'arn:aws:iam::123456789:role/Redshift-s3-unload-role'  to "user@abc.com" for unload;

Syntax: ==>copy

grant assumerole on 'arn:aws:iam::123456789:role/Redshift-s3-unload-role'  to "user@abc.com" for copy;

Thursday, October 13, 2022

can we create database user name start with undercore(_) in aws Redshift?

 can we create database user name  start with underscore(_)  in aws Redshift?

No,its not allowed in IAM database user with Single sign on,you should create the database  name starting with character.


DbUser parameter must begin with a letter, contain only alphanumeric characters, underscore ('_'), plus sign ('+'), dot ('.'), at ('@'), or hyphen ('-'), and be less than 128 characters. (Service: AmazonRedshift; Status Code: 400; Error Code: InvalidParameterValue

Thursday, September 8, 2022

How to change the time zone of time in oracle database

 we have requirement to change the time zone format of the data (UTC to CST)  from the column and oracle provided solution to convert the time zones.


Here is the function that you should use to convert the timezone:

to_char(NEW_TIME(SCHEDULED_TIME,'GMT','CDT'), 'dd-mm-yy hh:mi:ss')


old time zone data:

WORK_NAME JOB_NAME  NEWTIME_TEST

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

servername124        FINAL            06-09-22 03:29:00 PM


new  time zone data:


WORK_NAME JOB_NAME  NEWTIME_TEST

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

servername124         FINAL            07-09-22 10:29:00 AM



Monday, July 4, 2022

ORA-39181: Only partial table data may be exported due to fine grain access control on

 

Issue:

I got the below error while doing the export of few tables.


. exported "admin"."REG_CONFIG"                          6.507 KB       1 rows

. . exported "admin"."TEST_TO_UPLOAD"                    5.156 KB       3 rows

ORA-39181: Only partial table data may be exported due to fine grain access control on "admin"."fiel_TAB"


Root cause:
Looks like fine grained access policy has been enabled on those tables and need to granted the access .

Solution:
select * from dba_policies where OBJECT_OWNER='ADMIN' AND OBEJCT_NAME='FIEL_TAB';

grant EXEMPT ACCESS POLICY to  ADMIN;


Monday, February 28, 2022

SAML error: invalid_grant: BBSTS50056: The user account {EmailHidden} does not exist in

 Issue:

we are using SSO on aws  Redshift database login and we got the below error and I tried to connect to Redshift using SSO and got the below error,but local accounts able to make connections to database.Then found the issue Related to SAML assertion.

Something unusual has occurred to cause the driver to fail. Please report this exception.


  SAML error: invalid_grant: BBSTS50056: The user account {EmailHidden} does not exist in the 45f81a76-3477-44dd-b547-fgb3b6a146543 directory. 

To sign into this application, the account must be added to the directory. Trace ID: 45dd7dae-8355-45bc-b4f9-43df120f888 Correlation ID: 1fed5c1a-7c4f-4ffc-b234-672d069c15c1 Timestamp: 2022-02-28 05:28:14Z 

 Impact:

unable to login to Redshift database using SSO

Root cause:

Then found the issue Related to SAML assertion. Users unable to connect to Redshift DB because  the respective  AD account has been deleted on Azure Active directory.

looks like the AD accounts marked as deleted on AZURE Active directory.

Solution

we asked the cloud admin to enable the AD accounts on Azure active directory and issue resolved.


script to find out which database actively used in AWS redshift

 To identify which databases are actively used, you can run this SQL command as a superuser.

SELECT database,

  COUNT(*) as num_queries,

  AVG(DATEDIFF(sec,starttime,endtime)) avg_duration,

  MIN(starttime) as oldest_ts,

  MAX(endtime) as latest_ts

FROM stl_query

WHERE userid > 1

GROUP BY database; 

script to find out owner of the schema in aws Redshift

 script to find out owner of the schema in aws Redshift:

select nspname as schema, usename as owner

from pg_catalog.pg_namespace, pg_catalog.pg_user

where pg_catalog.pg_namespace.nspowner = pg_catalog.pg_user.usesysid

and pg_catalog.pg_user.usename ='us_sales';


   schema |  owner

----------+----------

 us_sales | dwuser

(1 row)


script to list all schema in AWS redshift database

 script to list all schema in AWS redshift database:

select s.nspname as table_schema,

       s.oid as schema_id,  

       u.usename as owner

from pg_catalog.pg_namespace s

join pg_catalog.pg_user u on u.usesysid = s.nspowner

order by table_schema;