スキップしてコンテンツを表示

How to get last modified datetime of tables in Redshift Serverless

0

Hello all,

Just wondering if it is possible to get the last modified datetime of tables in Redshift Serverless?

Ben.

質問済み 3ヶ月前165ビュー
2回答
2

Just to add a "bit more technical detail" for anyone implementing this:

It is important to distinguish between the two timestamps provided by SHOW TABLES and SVV_ALL_TABLES:

  • table_last_altered_time: This reflects DDL changes. It updates when the table structure is modified (e.g., ALTER TABLE, TRUNCATE, or when the table is dropped and recreated).
  • table_last_modified_time: This reflects DML operations. It updates when data is actually added or changed (e.g., INSERT, UPDATE, DELETE, or COPY).

In my experience, as mentioned, keep in mind the asynchronous update of these metadata fields; it can take up to 20 minutes for a data load to be reflected in the last_modified timestamp. This matches to the AWS documentation "The modification and alteration timestamps can lag behind the table updates by approximately 20 minutes." source: https://docs.aws.amazon.com/redshift/latest/dg/r_SHOW_TABLES.html

If you need to query this programmatically for a specific schema, you can use:

SELECT 
    table_name, 
    table_last_modified_time 
FROM svv_all_tables 
WHERE table_schema = 'your_schema_name'
AND table_type = 'BASE TABLE';

source: https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_ALL_TABLES.html#r_SVV_ALL_TABLES-sample-queries

エキスパート
回答済み 3ヶ月前
0
承認された回答

Yes, you can get the last modified datetime of tables in Redshift Serverless using the SHOW TABLES command. This command displays a list of tables in a schema along with various table attributes, including the last modified time and last altered time.

When you run SHOW TABLES, each output row includes information such as database name, schema name, table name, table type, and importantly, both the last altered time and last modified time for each table. You can also query the SVV_ALL_TABLES system view for more detailed information about these attributes.

It's worth noting that the modification and alteration timestamps may lag behind actual table updates by approximately 20 minutes, so there could be a slight delay in reflecting the most recent changes.
Sources
SHOW TABLES - Amazon Redshift

回答済み 3ヶ月前
エキスパート
レビュー済み 3ヶ月前
  • Hi @Shajam

    Thank you for the solution, I was able to get last_altered_time and last_modified_time from SHOW TABLES function.

    However, I would like to create a redshift view using SHOW TABLES

    create view schema02.view1 as (
    show tables from schema schema01);
    

    However i would get the following error.

    Enter image description here

    is there anyway to create a redshift view with SHOW TABLES function?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

関連するコンテンツ