Snowflake SQL Tutorial 171 - ACCOUNT_USAGE Found The Table I Just Dropped. It Was The Wrong One

Snowflake SQL · Episode 171

In this post we are going to cover ACCOUNT_USAGE in Snowflake.

ACCOUNT_USAGE is a schema inside the shared SNOWFLAKE database, and it holds views that record what has happened on your account: every query, every login, every grant, every object that has ever existed. It is the opposite of the INFORMATION_SCHEMA we looked at in the last post. That one is a picture of now and it forgets instantly. This one forgets nothing and it is always behind.

The useful question is how far behind, so we are going to measure it rather than quote a figure. We will start with how much of this there is and build it up step by step.

Every query below was run on a real Snowflake account, and every result you see is the output it gave back.

Episode 171 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.

Let's set up a table to work with

Later in this post we are going to drop a table and then ask two different metadata sources what happened to it. So let's make it now.

Sample data
-- Sample data for this post.
-- A schema and a table with two rows in it. Later on we are going to drop
-- this table and then ask both metadata sources what became of it.
USE DATABASE DEMO_DB;

CREATE OR REPLACE SCHEMA DEMO_DB.AUSAGE_T171
    COMMENT = 'episode 171 - account usage, dropped at the end';

USE SCHEMA DEMO_DB.AUSAGE_T171;

CREATE OR REPLACE TABLE DEMO_DB.AUSAGE_T171.GHOST_T171 (
    ID     NUMBER,
    LABEL  VARCHAR(40)
);

INSERT INTO DEMO_DB.AUSAGE_T171.GHOST_T171 (ID, LABEL)
VALUES (1, 'this table is about to be dropped'),
       (2, 'and account usage should remember it');

Let's check it is there, using the fast catalogue from the last post.

Query
SELECT TABLE_NAME, TABLE_TYPE, ROW_COUNT
  FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_SCHEMA = 'AUSAGE_T171';
Result1 row · 3 columns
TABLE_NAMETABLE_TYPEROW_COUNT
GHOST_T171BASE TABLE2

One table, two rows, visible in the statement straight after the insert.

One more thing before we start, and it matters for everything that follows. Every “how far behind” number in this post is a comparison against the session clock, so here is what the clock said during this run.

Query
SELECT CURRENT_TIMESTAMP() AS SNOWFLAKES_CLOCK,
       CURRENT_DATE()      AS SNOWFLAKES_DATE;
Result1 row · 2 columns
SNOWFLAKES_CLOCKSNOWFLAKES_DATE
2026-10-08 04:58:45.483000-07:002026-10-08

Note the date as well as the time. We will need it when we get to the dropped table.

Let's start with how much of this there is

ACCOUNT_USAGE is one schema. Let's see how many views are in it.

Query
SHOW VIEWS IN SCHEMA SNOWFLAKE.ACCOUNT_USAGE;
Query
SELECT COUNT(*) AS VIEWS_IN_ACCOUNT_USAGE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
VIEWS_IN_ACCOUNT_USAGE
211

Two hundred and eleven views, in one schema, inside a database nobody on this account created. Let's confirm that a completely different statement agrees.

Query
SELECT (SELECT COUNT(*)
          FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
         WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE') AS THE_CATALOG_SAYS;
Result1 row · 1 column
THE_CATALOG_SAYS
211

The catalogue says the same number. And ACCOUNT_USAGE is only one of the schemas in that database.

Query
SHOW SCHEMAS IN DATABASE SNOWFLAKE;
Query
SELECT "name", "comment"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 ORDER BY "name";
Result35 rows · 2 columns · showing first 6
The first six of the thirty five, alphabetically.
namecomment
ACCESS_INTELLIGENCE
ACCESS_INTELLIGENCE_INTERNAL
ACCOUNT_USAGE
ALERT
BCR_ROLLOUT
BILLING

Now let's look at the ones that grow, which are the history views.

Query
SELECT "name", "is_secure"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "name" LIKE '%HISTORY%'
 ORDER BY "name"
 LIMIT 15;
Result15 rows · 2 columns
nameis_secure
ACCESS_HISTORYtrue
AGGREGATE_ACCESS_HISTORYtrue
AGGREGATE_QUERY_HISTORYtrue
AI_GATEWAY_USAGE_HISTORYtrue
ALERT_HISTORYtrue
APPLICATION_CALLBACK_HISTORYtrue
APPLICATION_CONFIGURATION_VALUE_HISTORYtrue
APPLICATION_DAILY_USAGE_HISTORYtrue
APPLICATION_REMOTE_OPERATION_HISTORYtrue
APPLICATION_SPECIFICATION_STATUS_HISTORYtrue
ARCHIVE_STORAGE_DATA_RETRIEVAL_USAGE_HISTORYtrue
AUTOMATIC_CLUSTERING_HISTORYtrue
BACKUP_OPERATION_HISTORYtrue
BLOCK_STORAGE_HISTORYtrue
CATALOG_LINKED_DATABASE_USAGE_HISTORYtrue

That is fifteen rows because the query asked for fifteen. Look at the names: they run from A to C and stop. So this is the first fifteen alphabetically, not all of them, and a count taken from that result would be a count of the LIMIT rather than of the schema.

Now let's look at the biggest view in there

QUERY_HISTORY is one row per query. Let's see how much it records about each one.

Query
SELECT COUNT(*) AS COLUMNS_IN_QUERY_HISTORY
  FROM SNOWFLAKE.INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND TABLE_NAME   = 'QUERY_HISTORY';
Result1 row · 1 column
COLUMNS_IN_QUERY_HISTORY
85

Eighty five columns. Here are ten of them, picked by name.

Query
SELECT COLUMN_NAME, DATA_TYPE
  FROM SNOWFLAKE.INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND TABLE_NAME   = 'QUERY_HISTORY'
   AND COLUMN_NAME IN ('QUERY_ID','QUERY_TEXT','DATABASE_NAME','WAREHOUSE_SIZE',
                       'TOTAL_ELAPSED_TIME','BYTES_SCANNED','ROWS_PRODUCED',
                       'ERROR_CODE','ERROR_MESSAGE','CREDITS_USED_CLOUD_SERVICES')
 ORDER BY COLUMN_NAME;
Result10 rows · 2 columns
COLUMN_NAMEDATA_TYPE
BYTES_SCANNEDNUMBER
CREDITS_USED_CLOUD_SERVICESFLOAT
DATABASE_NAMETEXT
ERROR_CODETEXT
ERROR_MESSAGETEXT
QUERY_IDTEXT
QUERY_TEXTTEXT
ROWS_PRODUCEDNUMBER
TOTAL_ELAPSED_TIMENUMBER
WAREHOUSE_SIZETEXT

The text of the query, the database it ran against, the warehouse size, the bytes scanned, the rows produced, the error code and message if it failed, and the credits it used. Now, how many queries does it know about on this account?

Query
SELECT COUNT(*) AS QUERIES_IT_KNOWS_ABOUT
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;
Result1 row · 1 column
QUERIES_IT_KNOWS_ABOUT
62706

Sixty two thousand seven hundred and six. This course has been busy. Let's see what kinds of statement they were.

Query
SELECT QUERY_TYPE, COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 GROUP BY QUERY_TYPE
 ORDER BY HOW_MANY DESC
 LIMIT 12;
Result12 rows · 2 columns
QUERY_TYPEHOW_MANY
SELECT32451
GRANT7650
CALL7610
CREATE4465
INSERT1952
CREATE_TABLE1264
REVOKE1216
DROP934
ALTER818
SHOW726
USE608
MERGE324

Selects, grants, calls, creates, inserts. The shape of a course rather than the shape of a workload. And how many of them failed?

Query
SELECT EXECUTION_STATUS, COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 GROUP BY EXECUTION_STATUS
 ORDER BY HOW_MANY DESC;
Result2 rows · 2 columns
EXECUTION_STATUSHOW_MANY
SUCCESS61409
FAIL1297
Query
SELECT ERROR_CODE, COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 WHERE ERROR_CODE IS NOT NULL
 GROUP BY ERROR_CODE
 ORDER BY HOW_MANY DESC
 LIMIT 12;
Result12 rows · 2 columns
ERROR_CODEHOW_MANY
002003187
001003149
002139104
000904101
09010521
09108320
10010317
00200217
10035716
00000215
10010015
00203113
Query
SELECT COUNT(DISTINCT ERROR_CODE) AS DISTINCT_ERROR_CODES
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 WHERE ERROR_CODE IS NOT NULL;
Result1 row · 1 column
DISTINCT_ERROR_CODES
215

Two hundred and fifteen distinct error codes, which is a lot of this course on purpose. Most of the failures on this account are refusals we went looking for.

How far back does it go?

Before we ask how far behind it is, let's ask how far back it reaches. The oldest row in the query history first.

Query
SELECT 'QUERY_HISTORY' AS THE_VIEW,
       MIN(START_TIME) AS OLDEST_ROW,
       DATEDIFF('day', MIN(START_TIME), CURRENT_TIMESTAMP()) AS DAYS_OF_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;
Result1 row · 3 columns
THE_VIEWOLDEST_ROWDAYS_OF_HISTORY
QUERY_HISTORY2026-09-21 18:33:47.252000-07:0017
Query
SELECT 'WAREHOUSE_METERING_HISTORY' AS THE_VIEW,
       MIN(START_TIME) AS OLDEST_ROW,
       DATEDIFF('day', MIN(START_TIME), CURRENT_TIMESTAMP()) AS DAYS_OF_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY;
Result1 row · 3 columns
THE_VIEWOLDEST_ROWDAYS_OF_HISTORY
WAREHOUSE_METERING_HISTORY2026-09-21 18:00:00-07:0017
Query
SELECT 'LOGIN_HISTORY' AS THE_VIEW,
       MIN(EVENT_TIMESTAMP) AS OLDEST_ROW,
       DATEDIFF('day', MIN(EVENT_TIMESTAMP), CURRENT_TIMESTAMP()) AS DAYS_OF_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY;
Result1 row · 3 columns
THE_VIEWOLDEST_ROWDAYS_OF_HISTORY
LOGIN_HISTORY2026-09-21 18:36:55.576000-07:0017

Seventeen days in all three. Now let's find out how old the account itself is.

Query
SELECT MIN(CREATED) AS OLDEST_OBJECT_ON_THE_ACCOUNT,
       DATEDIFF('day', MIN(CREATED), CURRENT_TIMESTAMP()) AS DAYS_OLD
  FROM SNOWFLAKE.ACCOUNT_USAGE.DATABASES;
Result1 row · 2 columns
OLDEST_OBJECT_ON_THE_ACCOUNTDAYS_OLD
2026-09-21 18:33:42.814000-07:0017

The same seventeen. So it goes back to the day the account was made, because that is all the history there is. On an older account these views have their own retention periods instead, and they are not all the same.

Now the question that matters: how far behind is it?

Take the newest row in a view, compare it with the clock, and you have measured the lag yourself rather than taken somebody's word for it.

Query
SELECT MIN(START_TIME) AS OLDEST_IT_REMEMBERS,
       MAX(START_TIME) AS NEWEST_IT_HAS,
       DATEDIFF('minute', MAX(START_TIME), CURRENT_TIMESTAMP()) AS MINUTES_BEHIND
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;
Result1 row · 3 columns
OLDEST_IT_REMEMBERSNEWEST_IT_HASMINUTES_BEHIND
2026-09-21 18:33:47.252000-07:002026-10-08 04:43:03.523000-07:0016

Sixteen minutes. That is the answer for that view, at that moment. Let's look at the rows it does have at the newest end.

Query
SELECT QUERY_TYPE, EXECUTION_STATUS, ROLE_NAME, WAREHOUSE_NAME, START_TIME
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 ORDER BY START_TIME DESC
 LIMIT 8;
Result8 rows · 5 columns · showing first 4
The four newest rows it holds.
QUERY_TYPEEXECUTION_STATUSROLE_NAMEWAREHOUSE_NAMESTART_TIME
SELECTSUCCESSSNOWFLAKECOMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_02026-10-08 04:43:03.523000-07:00
ALTERSUCCESSSNOWFLAKECOMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_02026-10-08 04:43:03.228000-07:00
SELECTSUCCESSSNOWFLAKECOMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_02026-10-08 04:43:02.650000-07:00
SELECTSUCCESSSNOWFLAKECOMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_02026-10-08 04:43:02.291000-07:00

Those are not even our queries. They are Snowflake's own background work, running as the SNOWFLAKE role on an internal warehouse.

Now the same measurement on a different view, on the same account, at the same moment.

Query
SELECT MAX(EVENT_TIMESTAMP) AS NEWEST_LOGIN_IT_HAS,
       DATEDIFF('minute', MAX(EVENT_TIMESTAMP), CURRENT_TIMESTAMP())
         AS MINUTES_BEHIND
  FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY;
Result1 row · 2 columns
NEWEST_LOGIN_IT_HASMINUTES_BEHIND
2026-10-07 14:11:21.016000-07:00888

Eight hundred and eighty eight minutes. And a third view.

Query
SELECT MAX(CREATED_ON) AS NEWEST_GRANT_IT_HAS,
       DATEDIFF('minute', MAX(CREATED_ON), CURRENT_TIMESTAMP()) AS MINUTES_BEHIND
  FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES;
Result1 row · 2 columns
NEWEST_GRANT_IT_HASMINUTES_BEHIND
2026-10-07 14:11:38.044000-07:00889

Eight hundred and eighty nine. So three views, on one account, measured within seconds of each other, are the better part of a day apart from one another.

The thing to take away from this section

There is no single number called “the ACCOUNT_USAGE lag”, and anybody quoting you one is guessing. The documented figures are per view and they are maximums, not promises. If a decision of yours depends on the lag, measure the view you are actually using, the way we just did.

And one of them says minus one

Let's run the same measurement on the metering view.

Query
SELECT MIN(START_TIME) AS OLDEST_IT_REMEMBERS,
       MAX(START_TIME) AS NEWEST_IT_HAS,
       DATEDIFF('minute', MAX(END_TIME), CURRENT_TIMESTAMP()) AS MINUTES_BEHIND
  FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY;
Result1 row · 3 columns
OLDEST_IT_REMEMBERSNEWEST_IT_HASMINUTES_BEHIND
2026-09-21 18:00:00-07:002026-10-08 04:00:00-07:00-1

Minus one. That is not a lag and it is not a bug. Let's look at the rows to see why.

Query
SELECT COUNT(*) AS ROWS_IN_WAREHOUSE_METERING
  FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY;
Result1 row · 1 column
ROWS_IN_WAREHOUSE_METERING
95
Query
SELECT WAREHOUSE_NAME,
       START_TIME,
       CREDITS_USED,
       CREDITS_USED_COMPUTE,
       CREDITS_USED_CLOUD_SERVICES
  FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
 ORDER BY START_TIME DESC
 LIMIT 8;
Result8 rows · 5 columns · showing first 4
The four newest rows.
WAREHOUSE_NAMESTART_TIMECREDITS_USEDCREDITS_USED_COMPUTECREDITS_USED_CLOUD_SERVICES
COMPUTE_WH2026-10-08 04:00:00-07:000.0020263920.0000000000.002026392
WH_T1722026-10-07 14:00:00-07:000.0000125000.0000000000.000012500
COMPUTE_WH2026-10-07 14:00:00-07:000.2270305610.2025000000.024530561
COMPUTE_WH2026-10-07 12:00:00-07:000.3323844540.2880000000.044384454

Every START_TIME is on the hour. This view is bucketed by the hour, and its newest row is the hour we are currently inside, so its end time is in the future and the subtraction comes out negative.

A “minutes behind” calculation only means something on a view whose rows are events. On a bucketed view it measures the bucket, not the lag. That is worth knowing before you build an alert on one.

Here is the same view grouped by warehouse, which is what it is actually for.

Query
SELECT WAREHOUSE_NAME,
       COUNT(*)          AS HOURS_RECORDED,
       SUM(CREDITS_USED) AS CREDITS_ALTOGETHER
  FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
 GROUP BY WAREHOUSE_NAME
 ORDER BY WAREHOUSE_NAME;
Result21 rows · 3 columns · showing first 6
The first six warehouses, alphabetically.
WAREHOUSE_NAMEHOURS_RECORDEDCREDITS_ALTOGETHER
CLOUD_SERVICES_ONLY140.003112774
COMPUTE_WH5711.249667076
WH2_T15710.024463887
WHBIG_T15510.022724445
WHDEFAULTS_T15510.000100000
WHGONE_T159C40.000165834

Those names are warehouses this course created and dropped in earlier episodes. The warehouse is gone and its row in here is not.

What else it records about the account

Two more views worth knowing, both of them daily rather than per-event. Storage first.

Query
SELECT COUNT(*) AS ROWS_IN_STORAGE_USAGE
  FROM SNOWFLAKE.ACCOUNT_USAGE.STORAGE_USAGE;
Result1 row · 1 column
ROWS_IN_STORAGE_USAGE
21
Query
SELECT USAGE_DATE,
       STORAGE_BYTES,
       STAGE_BYTES,
       FAILSAFE_BYTES
  FROM SNOWFLAKE.ACCOUNT_USAGE.STORAGE_USAGE
 ORDER BY USAGE_DATE DESC
 LIMIT 5;
Result5 rows · 4 columns
USAGE_DATESTORAGE_BYTESSTAGE_BYTESFAILSAFE_BYTES
2026-10-0872285431296777607794
2026-10-0767218453331296106456109
2026-10-06112743424312962848131
2026-10-05272222312962971459
2026-10-04267011313432970179

One row per day, with the bytes in tables, the bytes in stages and the bytes in fail-safe kept separately. And the spend, broken down by what it was spent on.

Query
SELECT COUNT(*) AS ROWS_IN_METERING_DAILY_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY;
Result1 row · 1 column
ROWS_IN_METERING_DAILY_HISTORY
21
Query
SELECT SERVICE_TYPE,
       COUNT(*)              AS DAYS_RECORDED,
       SUM(CREDITS_USED)     AS CREDITS_ALTOGETHER
  FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY
 GROUP BY SERVICE_TYPE
 ORDER BY SERVICE_TYPE;
Result6 rows · 3 columns
SERVICE_TYPEDAYS_RECORDEDCREDITS_ALTOGETHER
AUTO_CLUSTERING20.000000000
COPY_FILES10.000693333
PIPE10.000000000
SEARCH_OPTIMIZATION10.000300411
SERVERLESS_TASK10.000296189
WAREHOUSE_METERING1511.559891240

Automatic clustering, file copying, pipes, search optimization. Each service type is its own row, which is why a bill and a warehouse total are different questions.

Two answers that look like a contradiction

Let's run a query with a marker string in it, something we can go looking for afterwards.

Query
SELECT 'episode-171-marker' AS THE_MARKER,
       CURRENT_TIMESTAMP()  AS WHEN_I_RAN_IT,
       1 + 1                AS SOMETHING_TO_COMPUTE;
Result1 row · 3 columns
THE_MARKERWHEN_I_RAN_ITSOMETHING_TO_COMPUTE
episode-171-marker2026-10-08 04:58:54.643000-07:002

That ran, and we also saved its query id with LAST_QUERY_ID(). The id itself is not on this page, because a query id identifies this account's session.

The INFORMATION_SCHEMA table function from the last post can see our queries immediately. Let's ask it for a hundred rows.

Query
SELECT COUNT(*) AS ROWS_THE_FUNCTION_RETURNED
  FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 100));
Result1 row · 1 column
ROWS_THE_FUNCTION_RETURNED
100

A hundred back, because we asked for a hundred. That source is instant. Now let's ask ACCOUNT_USAGE how many queries it has seen in the last five minutes.

Query
SELECT COUNT(*) AS QUERIES_IN_THE_LAST_FIVE_MINUTES
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 WHERE START_TIME > DATEADD('minute', -5, CURRENT_TIMESTAMP());
Result1 row · 1 column
QUERIES_IN_THE_LAST_FIVE_MINUTES
0

Nought. Which fits what we measured: its newest row is sixteen minutes old, so it has nothing from the last five minutes to give us.

Now let's ask it how many rows contain our marker text.

Query
SELECT COUNT(*) AS TIMES_IT_FOUND_MY_MARKER
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 WHERE QUERY_TEXT LIKE '%episode-171-marker%';
Result1 row · 1 column
TIMES_IT_FOUND_MY_MARKER
2

Two. And we ran that marker seconds ago. Those two numbers look like a contradiction.

They are not, and reading them together is the whole lesson. The newest row this view holds is sixteen minutes old, so it cannot be holding anything we ran today. Which means those two rows are from an earlier run of this same script, on an earlier day.

A marker string does not identify your run. It identifies the string. If you had used that count to confirm your query landed, you would have been wrong, and not because the view lied to you. Because you asked it a question it cannot answer yet.

Now the same trap, larger

Here is the table we made at the top of the post. Let's drop it.

Query
DROP TABLE DEMO_DB.AUSAGE_T171.GHOST_T171;
Result1 row · 1 column
status
GHOST_T171 successfully dropped.

Now let's ask the fast catalogue about it.

Query
SELECT COUNT(*) AS MENTIONS_IN_INFORMATION_SCHEMA
  FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_NAME = 'GHOST_T171';
Result1 row · 1 column
MENTIONS_IN_INFORMATION_SCHEMA
0

Nought mentions. Gone instantly, exactly as the last post showed. Now let's ask ACCOUNT_USAGE about the same table name.

Query
SELECT TABLE_NAME, TABLE_SCHEMA, DELETED, ROW_COUNT
  FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
 WHERE TABLE_NAME = 'GHOST_T171';
Result1 row · 4 columns
TABLE_NAMETABLE_SCHEMADELETEDROW_COUNT
GHOST_T171AUSAGE_T1712026-10-07 14:12:48.495000-07:002
Query
SELECT COUNT(*) AS ROWS_FOR_THE_GHOST_TABLE
  FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
 WHERE TABLE_NAME = 'GHOST_T171';
Result1 row · 1 column
ROWS_FOR_THE_GHOST_TABLE
1

One row came back, with the right table name, the right schema and a row count of two. At this point it looks like the slow view is not slow after all.

Read the DELETED column, and compare it with the clock we printed at the top of this post. That timestamp is from the previous day. Our drop happened seconds ago.

So this is not the table we just dropped. It is a different table with the same name, created and dropped by an earlier run of this same script, and the view has been carrying its row ever since. Today's table is not in there, and it could not be: the newest row this view holds is sixteen minutes old.

So one catalogue had already forgotten the real table, and the other one was showing us the old one. Between them, neither answered the question we actually asked.

The one habit this episode is worth

A row coming back does not mean it is your row. On a view that keeps everything and lags behind, a name match is not an identity match. Read the timestamp, every time.

What it keeps, and it keeps all of it

That ghost row is not an accident. Keeping dropped objects is the job. Let's see how much of that there is.

Query
SELECT COUNT(*) AS DROPPED_TABLES_IT_REMEMBERS
  FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
 WHERE DELETED IS NOT NULL;
Result1 row · 1 column
DROPPED_TABLES_IT_REMEMBERS
1412
Query
SELECT CASE WHEN DELETED IS NULL THEN 'still there' ELSE 'dropped' END AS STATE,
       COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
 GROUP BY STATE
 ORDER BY STATE;
Result2 rows · 2 columns
STATEHOW_MANY
dropped1412
still there220

One thousand four hundred and twelve dropped tables against two hundred and twenty still alive. It has every one of the dead ones. Here are the most recently dropped.

Query
SELECT TABLE_NAME, TABLE_SCHEMA, DELETED
  FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
 WHERE DELETED IS NOT NULL
 ORDER BY DELETED DESC
 LIMIT 8;
Result8 rows · 3 columns · showing first 4
The four most recently dropped.
TABLE_NAMETABLE_SCHEMADELETED
WHEN_T172SESS_T1722026-10-07 14:15:23.693000-07:00
LEDGER_T173REPL_T1732026-10-07 14:14:49.372000-07:00
GHOST_T171AUSAGE_T1712026-10-07 14:12:48.495000-07:00
TYPED_SHAPESPUBLIC2026-10-07 14:11:38.136000-07:00

Schemas are the same story.

Query
SELECT CASE WHEN DELETED IS NULL THEN 'still there' ELSE 'dropped' END AS STATE,
       COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.SCHEMATA
 GROUP BY STATE
 ORDER BY STATE;
Result2 rows · 2 columns
STATEHOW_MANY
dropped47
still there73

And grants, which is the one that surprises people, because a revoked grant is not deleted from here either.

Query
SELECT COUNT(*) AS GRANT_ROWS_IT_REMEMBERS
  FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES;
Result1 row · 1 column
GRANT_ROWS_IT_REMEMBERS
1474
Query
SELECT CASE WHEN DELETED_ON IS NULL THEN 'still granted' ELSE 'gone' END AS STATE,
       COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES
 GROUP BY STATE
 ORDER BY STATE;
Result2 rows · 2 columns
STATEHOW_MANY
gone115
still granted1359

One hundred and fifteen of those grants are gone and their rows are still here, with a DELETED_ON date on them. That is the trade this view makes. It is slow because it is complete, and it is complete because it is slow.

The view you would reach for in an incident

LOGIN_HISTORY records who connected, from what, and whether it worked.

Query
SELECT COUNT(*) AS ROWS_IN_LOGIN_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY;
Result1 row · 1 column
ROWS_IN_LOGIN_HISTORY
114

A hundred and fourteen rows. Here is the statement that reads them one at a time.

Query
SELECT EVENT_TIMESTAMP, USER_NAME, REPORTED_CLIENT_TYPE,
       FIRST_AUTHENTICATION_FACTOR, IS_SUCCESS, ERROR_MESSAGE
FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY
ORDER BY EVENT_TIMESTAMP DESC
LIMIT 6;

That grid is not on this page. Its USER_NAME column is the account's user on every row, and the builder here cannot drop one column out of a grid. The grouped version of the same question carries no user name, so that is the one we will show.

Query
SELECT REPORTED_CLIENT_TYPE, IS_SUCCESS, COUNT(*) AS HOW_MANY
  FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY
 GROUP BY REPORTED_CLIENT_TYPE, IS_SUCCESS
 ORDER BY HOW_MANY DESC;
Result2 rows · 3 columns
REPORTED_CLIENT_TYPEIS_SUCCESSHOW_MANY
PYTHON_DRIVERYES113
SNOWFLAKE_UIYES1

Two rows. Almost every connection to this account was made by the Python driver that captured this course, and one was made through the Snowflake web interface. IS_SUCCESS reads yes on both, so nothing has ever failed to log in here.

And one prediction I got wrong

I marked this next statement as one I expected to be refused, because access history is an Enterprise feature and this is a trial account.

Query
SELECT COUNT(*) AS ROWS_IN_ACCESS_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.ACCESS_HISTORY;
Result1 row · 1 column
ROWS_IN_ACCESS_HISTORY
13504

Thirteen thousand five hundred and four rows. It is not gated here at all, and my prediction was wrong. Let's see how many views in the schema are about access.

Query
SELECT TABLE_NAME
  FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND TABLE_NAME LIKE '%ACCESS%'
 ORDER BY TABLE_NAME;
Result9 rows · 1 column
TABLE_NAME
ACCESS_HISTORY
AGGREGATE_ACCESS_HISTORY
EXTERNAL_ACCESS_HISTORY
INGRESS_NETWORK_ACCESS_HISTORY
INTERNAL_STAGE_NETWORK_ACCESS_HISTORY
OBJECT_ACCESS_REQUEST_HISTORY
QUOTA_ACCESS_BLOCK_HISTORY
ROW_ACCESS_POLICIES
SPCS_EGRESS_ACCESS_HISTORY
Query
SELECT COUNT(*) AS VIEWS_WITH_ACCESS_IN_THE_NAME
  FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND TABLE_NAME LIKE '%ACCESS%';
Result1 row · 1 column
VIEWS_WITH_ACCESS_IN_THE_NAME
9

Nine of them. Access history, aggregate access history, external access, network access, and more.

One last thing: these views are read only

They live in a shared database, and Episode 169 showed what that means. Let's confirm it on a view rather than on the database.

Query
INSERT INTO SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY (QUERY_ID) VALUES ('nope');
Query failed — Snowflake returned an error
003001 (42501): SQL access control error:
Insufficient privileges to operate on view 'QUERY_HISTORY'. Provider share does not have sufficient privileges.

003001, and read the second sentence: the provider share does not have sufficient privileges. It is not that we lack a grant. The share itself cannot be written to.

Query
DROP VIEW SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;
Query failed — Snowflake returned an error
003001 (42501): SQL access control error:
Insufficient privileges to operate on view 'QUERY_HISTORY'. Provider share does not have sufficient privileges.

The same code and the same sentence. And afterwards:

Query
SELECT COUNT(*) AS VIEWS_STILL_IN_ACCOUNT_USAGE
  FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE';
Result1 row · 1 column
VIEWS_STILL_IN_ACCOUNT_USAGE
211

All two hundred and eleven still there.

And the clean-up

The table is already gone. The schema goes with it.

Clean-up
-- Everything this post made, taken back out again.
USE SCHEMA DEMO_DB.PUBLIC;
DROP SCHEMA IF EXISTS DEMO_DB.AUSAGE_T171;
Query
SELECT COUNT(*) AS MY_SCHEMAS_LEFT
  FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
 WHERE SCHEMA_NAME = 'AUSAGE_T171';
Result1 row · 1 column
MY_SCHEMAS_LEFT
0
Query
SELECT COUNT(*) AS MY_TABLES_LEFT
  FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_NAME LIKE '%\\_T171' ESCAPE '\\';
Result1 row · 1 column
MY_TABLES_LEFT
0

Nothing of ours left in the fast catalogue. In the slow one, of course, both of them are now rows with a DELETED date on them, and they will be there for as long as the account is.

Key points

  • ACCOUNT_USAGE is 211 views in one schema of the shared SNOWFLAKE database, and it keeps everything, including what you dropped.
  • Measure the lag yourself: take MAX of the view's time column and compare it with CURRENT_TIMESTAMP().
  • There is no single ACCOUNT_USAGE lag. On one account at one moment, three views were 16, 888 and 889 minutes behind.
  • A negative “minutes behind” means the view is bucketed rather than per-event. The calculation only means something on a view whose rows are events.
  • A marker string finds the string, not your run. It said nought queries in the last five minutes and found the marker twice, and both were true.
  • When it returned a row for the table we had just dropped, the DELETED timestamp on that row was from the previous day. It was a different table of the same name, from an earlier run. Read the timestamp, every time.
  • INFORMATION_SCHEMA forgets instantly while ACCOUNT_USAGE is still showing you last time. Neither is wrong, and the two are not interchangeable.
  • QUERY_HISTORY has 85 columns, and on this account 62706 queries, 1297 of them failed, across 215 distinct error codes.
  • It remembers 1412 dropped tables, 47 dropped schemas and 115 revoked grants. Slow because complete, complete because slow.
  • ACCESS_HISTORY ran on a trial account against my prediction, and returned 13504 rows.
  • These views are read only. INSERT and DROP VIEW both give 003001, and the message names the provider share rather than your privileges.
Next in this series

In the next post we look at ALTER SESSION and parameters: the level column, what it means when the level is somebody other than you, and one parameter name that gave three different answers at the same moment.

Every query and every result grid on this page was captured from a live Snowflake account (version 10.36.101) running the demo script for this episode, all of it as ACCOUNTADMIN reading. Nothing was created except the one table, which is dropped in the section that uses it. The lag figures are a measurement taken at one moment on one account and they are not a benchmark: your own account will give different numbers, which is the point of measuring them. Grids that identify the account, the user or a query id are deliberately left off the page, and the post says so each time one is missing. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake ACCOUNT_USAGE documentation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.