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
- Let's start with how much of this there is
- Now let's look at the biggest view in there
- How far back does it go?
- Now the question that matters: how far behind is it?
- And one of them says minus one
- What else it records about the account
- Two answers that look like a contradiction
- Now the same trap, larger
- What it keeps, and it keeps all of it
- The view you would reach for in an incident
- And one prediction I got wrong
- One last thing: these views are read only
- And the clean-up
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 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.
SELECT TABLE_NAME, TABLE_TYPE, ROW_COUNT
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'AUSAGE_T171';| TABLE_NAME | TABLE_TYPE | ROW_COUNT |
|---|---|---|
| GHOST_T171 | BASE TABLE | 2 |
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.
SELECT CURRENT_TIMESTAMP() AS SNOWFLAKES_CLOCK,
CURRENT_DATE() AS SNOWFLAKES_DATE;| SNOWFLAKES_CLOCK | SNOWFLAKES_DATE |
|---|---|
| 2026-10-08 04:58:45.483000-07:00 | 2026-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.
SHOW VIEWS IN SCHEMA SNOWFLAKE.ACCOUNT_USAGE;SELECT COUNT(*) AS VIEWS_IN_ACCOUNT_USAGE
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| 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.
SELECT (SELECT COUNT(*)
FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE') AS THE_CATALOG_SAYS;| THE_CATALOG_SAYS |
|---|
| 211 |
The catalogue says the same number. And ACCOUNT_USAGE is only one of the schemas in that database.
SHOW SCHEMAS IN DATABASE SNOWFLAKE;SELECT "name", "comment"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY "name";| name | comment |
|---|---|
| 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.
SELECT "name", "is_secure"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%HISTORY%'
ORDER BY "name"
LIMIT 15;| name | is_secure |
|---|---|
| ACCESS_HISTORY | true |
| AGGREGATE_ACCESS_HISTORY | true |
| AGGREGATE_QUERY_HISTORY | true |
| AI_GATEWAY_USAGE_HISTORY | true |
| ALERT_HISTORY | true |
| APPLICATION_CALLBACK_HISTORY | true |
| APPLICATION_CONFIGURATION_VALUE_HISTORY | true |
| APPLICATION_DAILY_USAGE_HISTORY | true |
| APPLICATION_REMOTE_OPERATION_HISTORY | true |
| APPLICATION_SPECIFICATION_STATUS_HISTORY | true |
| ARCHIVE_STORAGE_DATA_RETRIEVAL_USAGE_HISTORY | true |
| AUTOMATIC_CLUSTERING_HISTORY | true |
| BACKUP_OPERATION_HISTORY | true |
| BLOCK_STORAGE_HISTORY | true |
| CATALOG_LINKED_DATABASE_USAGE_HISTORY | true |
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.
SELECT COUNT(*) AS COLUMNS_IN_QUERY_HISTORY
FROM SNOWFLAKE.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
AND TABLE_NAME = 'QUERY_HISTORY';| COLUMNS_IN_QUERY_HISTORY |
|---|
| 85 |
Eighty five columns. Here are ten of them, picked by name.
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;| COLUMN_NAME | DATA_TYPE |
|---|---|
| BYTES_SCANNED | NUMBER |
| CREDITS_USED_CLOUD_SERVICES | FLOAT |
| DATABASE_NAME | TEXT |
| ERROR_CODE | TEXT |
| ERROR_MESSAGE | TEXT |
| QUERY_ID | TEXT |
| QUERY_TEXT | TEXT |
| ROWS_PRODUCED | NUMBER |
| TOTAL_ELAPSED_TIME | NUMBER |
| WAREHOUSE_SIZE | TEXT |
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?
SELECT COUNT(*) AS QUERIES_IT_KNOWS_ABOUT
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;| 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.
SELECT QUERY_TYPE, COUNT(*) AS HOW_MANY
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
GROUP BY QUERY_TYPE
ORDER BY HOW_MANY DESC
LIMIT 12;| QUERY_TYPE | HOW_MANY |
|---|---|
| SELECT | 32451 |
| GRANT | 7650 |
| CALL | 7610 |
| CREATE | 4465 |
| INSERT | 1952 |
| CREATE_TABLE | 1264 |
| REVOKE | 1216 |
| DROP | 934 |
| ALTER | 818 |
| SHOW | 726 |
| USE | 608 |
| MERGE | 324 |
Selects, grants, calls, creates, inserts. The shape of a course rather than the shape of a workload. And how many of them failed?
SELECT EXECUTION_STATUS, COUNT(*) AS HOW_MANY
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
GROUP BY EXECUTION_STATUS
ORDER BY HOW_MANY DESC;| EXECUTION_STATUS | HOW_MANY |
|---|---|
| SUCCESS | 61409 |
| FAIL | 1297 |
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;| ERROR_CODE | HOW_MANY |
|---|---|
| 002003 | 187 |
| 001003 | 149 |
| 002139 | 104 |
| 000904 | 101 |
| 090105 | 21 |
| 091083 | 20 |
| 100103 | 17 |
| 002002 | 17 |
| 100357 | 16 |
| 000002 | 15 |
| 100100 | 15 |
| 002031 | 13 |
SELECT COUNT(DISTINCT ERROR_CODE) AS DISTINCT_ERROR_CODES
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE ERROR_CODE IS NOT NULL;| 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.
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;| THE_VIEW | OLDEST_ROW | DAYS_OF_HISTORY |
|---|---|---|
| QUERY_HISTORY | 2026-09-21 18:33:47.252000-07:00 | 17 |
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;| THE_VIEW | OLDEST_ROW | DAYS_OF_HISTORY |
|---|---|---|
| WAREHOUSE_METERING_HISTORY | 2026-09-21 18:00:00-07:00 | 17 |
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;| THE_VIEW | OLDEST_ROW | DAYS_OF_HISTORY |
|---|---|---|
| LOGIN_HISTORY | 2026-09-21 18:36:55.576000-07:00 | 17 |
Seventeen days in all three. Now let's find out how old the account itself is.
SELECT MIN(CREATED) AS OLDEST_OBJECT_ON_THE_ACCOUNT,
DATEDIFF('day', MIN(CREATED), CURRENT_TIMESTAMP()) AS DAYS_OLD
FROM SNOWFLAKE.ACCOUNT_USAGE.DATABASES;| OLDEST_OBJECT_ON_THE_ACCOUNT | DAYS_OLD |
|---|---|
| 2026-09-21 18:33:42.814000-07:00 | 17 |
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.
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;| OLDEST_IT_REMEMBERS | NEWEST_IT_HAS | MINUTES_BEHIND |
|---|---|---|
| 2026-09-21 18:33:47.252000-07:00 | 2026-10-08 04:43:03.523000-07:00 | 16 |
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.
SELECT QUERY_TYPE, EXECUTION_STATUS, ROLE_NAME, WAREHOUSE_NAME, START_TIME
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
ORDER BY START_TIME DESC
LIMIT 8;| QUERY_TYPE | EXECUTION_STATUS | ROLE_NAME | WAREHOUSE_NAME | START_TIME |
|---|---|---|---|---|
| SELECT | SUCCESS | SNOWFLAKE | COMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_0 | 2026-10-08 04:43:03.523000-07:00 |
| ALTER | SUCCESS | SNOWFLAKE | COMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_0 | 2026-10-08 04:43:03.228000-07:00 |
| SELECT | SUCCESS | SNOWFLAKE | COMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_0 | 2026-10-08 04:43:02.650000-07:00 |
| SELECT | SUCCESS | SNOWFLAKE | COMPUTE_SERVICE_WH_USER_TASKS_POOL_STANDARD_GEN2_XSMALL_0 | 2026-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.
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;| NEWEST_LOGIN_IT_HAS | MINUTES_BEHIND |
|---|---|
| 2026-10-07 14:11:21.016000-07:00 | 888 |
Eight hundred and eighty eight minutes. And a third view.
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;| NEWEST_GRANT_IT_HAS | MINUTES_BEHIND |
|---|---|
| 2026-10-07 14:11:38.044000-07:00 | 889 |
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.
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.
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;| OLDEST_IT_REMEMBERS | NEWEST_IT_HAS | MINUTES_BEHIND |
|---|---|---|
| 2026-09-21 18:00:00-07:00 | 2026-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.
SELECT COUNT(*) AS ROWS_IN_WAREHOUSE_METERING
FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY;| ROWS_IN_WAREHOUSE_METERING |
|---|
| 95 |
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;| WAREHOUSE_NAME | START_TIME | CREDITS_USED | CREDITS_USED_COMPUTE | CREDITS_USED_CLOUD_SERVICES |
|---|---|---|---|---|
| COMPUTE_WH | 2026-10-08 04:00:00-07:00 | 0.002026392 | 0.000000000 | 0.002026392 |
| WH_T172 | 2026-10-07 14:00:00-07:00 | 0.000012500 | 0.000000000 | 0.000012500 |
| COMPUTE_WH | 2026-10-07 14:00:00-07:00 | 0.227030561 | 0.202500000 | 0.024530561 |
| COMPUTE_WH | 2026-10-07 12:00:00-07:00 | 0.332384454 | 0.288000000 | 0.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.
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;| WAREHOUSE_NAME | HOURS_RECORDED | CREDITS_ALTOGETHER |
|---|---|---|
| CLOUD_SERVICES_ONLY | 14 | 0.003112774 |
| COMPUTE_WH | 57 | 11.249667076 |
| WH2_T157 | 1 | 0.024463887 |
| WHBIG_T155 | 1 | 0.022724445 |
| WHDEFAULTS_T155 | 1 | 0.000100000 |
| WHGONE_T159C | 4 | 0.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.
SELECT COUNT(*) AS ROWS_IN_STORAGE_USAGE
FROM SNOWFLAKE.ACCOUNT_USAGE.STORAGE_USAGE;| ROWS_IN_STORAGE_USAGE |
|---|
| 21 |
SELECT USAGE_DATE,
STORAGE_BYTES,
STAGE_BYTES,
FAILSAFE_BYTES
FROM SNOWFLAKE.ACCOUNT_USAGE.STORAGE_USAGE
ORDER BY USAGE_DATE DESC
LIMIT 5;| USAGE_DATE | STORAGE_BYTES | STAGE_BYTES | FAILSAFE_BYTES |
|---|---|---|---|
| 2026-10-08 | 722854 | 31296 | 777607794 |
| 2026-10-07 | 672184533 | 31296 | 106456109 |
| 2026-10-06 | 112743424 | 31296 | 2848131 |
| 2026-10-05 | 272222 | 31296 | 2971459 |
| 2026-10-04 | 267011 | 31343 | 2970179 |
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.
SELECT COUNT(*) AS ROWS_IN_METERING_DAILY_HISTORY
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY;| ROWS_IN_METERING_DAILY_HISTORY |
|---|
| 21 |
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;| SERVICE_TYPE | DAYS_RECORDED | CREDITS_ALTOGETHER |
|---|---|---|
| AUTO_CLUSTERING | 2 | 0.000000000 |
| COPY_FILES | 1 | 0.000693333 |
| PIPE | 1 | 0.000000000 |
| SEARCH_OPTIMIZATION | 1 | 0.000300411 |
| SERVERLESS_TASK | 1 | 0.000296189 |
| WAREHOUSE_METERING | 15 | 11.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.
SELECT 'episode-171-marker' AS THE_MARKER,
CURRENT_TIMESTAMP() AS WHEN_I_RAN_IT,
1 + 1 AS SOMETHING_TO_COMPUTE;| THE_MARKER | WHEN_I_RAN_IT | SOMETHING_TO_COMPUTE |
|---|---|---|
| episode-171-marker | 2026-10-08 04:58:54.643000-07:00 | 2 |
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.
SELECT COUNT(*) AS ROWS_THE_FUNCTION_RETURNED
FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 100));| 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.
SELECT COUNT(*) AS QUERIES_IN_THE_LAST_FIVE_MINUTES
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE START_TIME > DATEADD('minute', -5, CURRENT_TIMESTAMP());| 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.
SELECT COUNT(*) AS TIMES_IT_FOUND_MY_MARKER
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE QUERY_TEXT LIKE '%episode-171-marker%';| 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.
DROP TABLE DEMO_DB.AUSAGE_T171.GHOST_T171;| status |
|---|
| GHOST_T171 successfully dropped. |
Now let's ask the fast catalogue about it.
SELECT COUNT(*) AS MENTIONS_IN_INFORMATION_SCHEMA
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'GHOST_T171';| 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.
SELECT TABLE_NAME, TABLE_SCHEMA, DELETED, ROW_COUNT
FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
WHERE TABLE_NAME = 'GHOST_T171';| TABLE_NAME | TABLE_SCHEMA | DELETED | ROW_COUNT |
|---|---|---|---|
| GHOST_T171 | AUSAGE_T171 | 2026-10-07 14:12:48.495000-07:00 | 2 |
SELECT COUNT(*) AS ROWS_FOR_THE_GHOST_TABLE
FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
WHERE TABLE_NAME = 'GHOST_T171';| 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.
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.
SELECT COUNT(*) AS DROPPED_TABLES_IT_REMEMBERS
FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
WHERE DELETED IS NOT NULL;| DROPPED_TABLES_IT_REMEMBERS |
|---|
| 1412 |
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;| STATE | HOW_MANY |
|---|---|
| dropped | 1412 |
| still there | 220 |
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.
SELECT TABLE_NAME, TABLE_SCHEMA, DELETED
FROM SNOWFLAKE.ACCOUNT_USAGE.TABLES
WHERE DELETED IS NOT NULL
ORDER BY DELETED DESC
LIMIT 8;| TABLE_NAME | TABLE_SCHEMA | DELETED |
|---|---|---|
| WHEN_T172 | SESS_T172 | 2026-10-07 14:15:23.693000-07:00 |
| LEDGER_T173 | REPL_T173 | 2026-10-07 14:14:49.372000-07:00 |
| GHOST_T171 | AUSAGE_T171 | 2026-10-07 14:12:48.495000-07:00 |
| TYPED_SHAPES | PUBLIC | 2026-10-07 14:11:38.136000-07:00 |
Schemas are the same story.
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;| STATE | HOW_MANY |
|---|---|
| dropped | 47 |
| still there | 73 |
And grants, which is the one that surprises people, because a revoked grant is not deleted from here either.
SELECT COUNT(*) AS GRANT_ROWS_IT_REMEMBERS
FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES;| GRANT_ROWS_IT_REMEMBERS |
|---|
| 1474 |
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;| STATE | HOW_MANY |
|---|---|
| gone | 115 |
| still granted | 1359 |
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.
SELECT COUNT(*) AS ROWS_IN_LOGIN_HISTORY
FROM SNOWFLAKE.ACCOUNT_USAGE.LOGIN_HISTORY;| ROWS_IN_LOGIN_HISTORY |
|---|
| 114 |
A hundred and fourteen rows. Here is the statement that reads them one at a time.
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.
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;| REPORTED_CLIENT_TYPE | IS_SUCCESS | HOW_MANY |
|---|---|---|
| PYTHON_DRIVER | YES | 113 |
| SNOWFLAKE_UI | YES | 1 |
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.
SELECT COUNT(*) AS ROWS_IN_ACCESS_HISTORY
FROM SNOWFLAKE.ACCOUNT_USAGE.ACCESS_HISTORY;| 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.
SELECT TABLE_NAME
FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
AND TABLE_NAME LIKE '%ACCESS%'
ORDER BY TABLE_NAME;| 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 |
SELECT COUNT(*) AS VIEWS_WITH_ACCESS_IN_THE_NAME
FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
AND TABLE_NAME LIKE '%ACCESS%';| 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.
INSERT INTO SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY (QUERY_ID) VALUES ('nope');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.
DROP VIEW SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;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:
SELECT COUNT(*) AS VIEWS_STILL_IN_ACCOUNT_USAGE
FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE';| 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.
-- Everything this post made, taken back out again.
USE SCHEMA DEMO_DB.PUBLIC;
DROP SCHEMA IF EXISTS DEMO_DB.AUSAGE_T171;SELECT COUNT(*) AS MY_SCHEMAS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = 'AUSAGE_T171';| MY_SCHEMAS_LEFT |
|---|
| 0 |
SELECT COUNT(*) AS MY_TABLES_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%\\_T171' ESCAPE '\\';| 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_USAGEis 211 views in one schema of the sharedSNOWFLAKEdatabase, and it keeps everything, including what you dropped.- Measure the lag yourself: take
MAXof the view's time column and compare it withCURRENT_TIMESTAMP(). - There is no single
ACCOUNT_USAGElag. 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
DELETEDtimestamp 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_SCHEMAforgets instantly whileACCOUNT_USAGEis still showing you last time. Neither is wrong, and the two are not interchangeable.QUERY_HISTORYhas 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_HISTORYran on a trial account against my prediction, and returned 13504 rows.- These views are read only.
INSERTandDROP VIEWboth give003001, and the message names the provider share rather than your privileges.
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.