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();
Sharing DBA experience to all -- Oracle,MS SQL, DB2 , Netezza DBA,postgreSQL,AWS Redshift,MySQL,oracle SAP,Snowflake,MongoDB
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:
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
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;
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
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
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"
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.
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:
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:
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;