Snowflake SQL Tutorial 173 - I Said These Would Be Refused. All Eight Ran. Replication Explained

Snowflake SQL · Episode 173

In this post we are going to cover replication in Snowflake. This is also the last post in this series.

Replication copies a database from one Snowflake account to another one. The database you copy from is the primary, the copy is the secondary, and the whole feature is built around the idea of this database, over there.

The account these posts were captured on does not have another account, and that turns out to be the best way to see what the feature is actually made of. Everything that reads about replication runs here and answers nothing. Everything that does replication is refused, and the refusals are not all about the same thing.

We will start with how an account is addressed and build it up step by step. At the end we will look at what a single account can still recover on its own, which is the part you can use today.

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

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

Let's create a table to work with

At the end of this post we are going to delete some rows by accident and get them back without a replica. So let's make something worth getting back: a small ledger with an opening balance, two invoices and a deposit.

Sample data
-- Sample data for this post.
-- A small ledger: an opening balance, two invoices and a deposit. We are
-- going to have an accident with it later on.
USE DATABASE DEMO_DB;

CREATE OR REPLACE SCHEMA DEMO_DB.REPL_T173
    COMMENT = 'episode 173 - one account recovery, dropped at the end';

USE SCHEMA DEMO_DB.REPL_T173;

CREATE OR REPLACE TABLE DEMO_DB.REPL_T173.LEDGER_T173 (
    ENTRY_ID  NUMBER,
    NOTE      VARCHAR(50),
    AMOUNT    NUMBER(10,2)
);

INSERT INTO DEMO_DB.REPL_T173.LEDGER_T173 (ENTRY_ID, NOTE, AMOUNT)
VALUES (1, 'opening balance', 1000.00),
       (2, 'invoice 4471',    -240.00),
       (3, 'invoice 4472',    -118.50),
       (4, 'deposit',          600.00);

Here it is.

Query
SELECT * FROM DEMO_DB.REPL_T173.LEDGER_T173 ORDER BY ENTRY_ID;
Result4 rows · 3 columns
ENTRY_IDNOTEAMOUNT
1opening balance1000.00
2invoice 4471-240.00
3invoice 4472-118.50
4deposit600.00

Four rows. Remember the number four, because it is going to come back twice and be right only once.

Let's start with how an account is addressed

Replication is a question about places, so the first thing to know is how one account names another one.

It is not the account locator, which is the short code in the connection string. There are two other functions, and the pair of them joined with a dot is the identifier replication uses.

Query
-- How replication addresses an account. It is NOT the locator.
SELECT CURRENT_ORGANIZATION_NAME() AS THE_ORGANISATION,
       CURRENT_ACCOUNT_NAME()      AS THE_ACCOUNT_NAME;

-- And the two of them joined with a dot is the identifier you would hand to
-- the other account:
SELECT CURRENT_ORGANIZATION_NAME() || '.' || CURRENT_ACCOUNT_NAME()
       AS HOW_THIS_ACCOUNT_IS_ADDRESSED;

Those two statements are the teaching, and the values they return are not on this page. An organisation name and an account name identify a real account, and this post is public. Run them on your own account and you will see your own pair.

Now the places themselves. I marked this next statement as one I expected to be refused, on the grounds that a trial account has no business asking about other regions.

Query
SHOW REGIONS;
Query
SELECT COUNT(*) AS REGIONS_LISTED
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
REGIONS_LISTED
48

Forty eight regions, and it is not refused at all. That is the first of eight wrong predictions in this post, and they are all going to be wrong in the same direction.

Here are twelve of them, ordered by cloud and then by region.

Query
SELECT "snowflake_region", "cloud", "region", "display_name"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 ORDER BY "cloud", "region"
 LIMIT 12;
Result12 rows · 4 columns
Twelve of the forty eight.
snowflake_regioncloudregiondisplay_name
AWS_AF_SOUTH_1awsaf-south-1Africa (Cape Town)
AWS_AP_NORTHEAST_1awsap-northeast-1Asia Pacific (Tokyo)
AWS_AP_NORTHEAST_2awsap-northeast-2Asia Pacific (Seoul)
AWS_AP_NORTHEAST_3awsap-northeast-3Asia Pacific (Osaka)
AWS_AP_SOUTH_1awsap-south-1Asia Pacific (Mumbai)
AWS_AP_SOUTHEAST_1awsap-southeast-1Asia Pacific (Singapore)
AWS_AP_SOUTHEAST_2awsap-southeast-2Asia Pacific (Sydney)
AWS_AP_SOUTHEAST_3awsap-southeast-3Asia Pacific (Jakarta)
AWS_AP_SOUTHEAST_5awsap-southeast-5Asia Pacific (Malaysia)
AWS_AP_SOUTHEAST_6awsap-southeast-6Asia Pacific (New Zealand)
AWS_AP_SOUTHEAST_7awsap-southeast-7Asia Pacific (Thailand)
AWS_CA_CENTRAL_1awsca-central-1Canada (Central)

Three clouds in that list altogether, and each of them has its own name for the same city. A replica would live in one of those regions, and every account can read this list whether or not it can put anything in it.

Now let's ask what this account replicates

There are four SHOW statements for replication, and I marked all four as ones I expected to be refused. Here is the first.

Query
SHOW REPLICATION DATABASES;
Result0 rows · 11 columns · scroll →
snowflake_regioncreated_onaccount_namenamecommentis_primaryprimaryreplication_allowed_to_accountsfailover_allowed_to_accountsorganization_nameaccount_locator
Query
SELECT COUNT(*) AS REPLICATION_DATABASES
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
REPLICATION_DATABASES
0

Nought rows, and eleven columns sitting there waiting for them. The statement exists. The thing it describes does not exist here. Those are not the same fact.

Second, every account in the organisation that replication can see.

Query
SHOW REPLICATION ACCOUNTS;
Result0 rows · 7 columns · scroll →
snowflake_regioncreated_onaccount_nameaccount_locatorcommentorganization_nameis_org_admin
Query
SELECT COUNT(*) AS REPLICATION_ACCOUNTS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
REPLICATION_ACCOUNTS
0

Nought again. Seven columns, no rows, and no error at all.

Third, failover groups. A failover group is the unit you actually replicate: you put object types and databases into one and replicate the group rather than the database.

Query
SHOW FAILOVER GROUPS;
Result0 rows · 20 columns · scroll →
snowflake_regioncreated_onaccount_namenametypecommentis_primaryprimaryobject_typesallowed_integration_typesallowed_accountsorganization_nameaccount_locatorreplication_schedulesecondary_statenext_scheduled_refreshowneris_listing_auto_fulfillment_grouperror_integrationis_optimized_refresh_enabled
Query
SELECT COUNT(*) AS FAILOVER_GROUPS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
FAILOVER_GROUPS
0

Nought rows and twenty columns. Read the headings on that empty grid, because they are the best description of the feature on this page: object types, allowed accounts, a replication schedule, a secondary state, a next scheduled refresh.

Fourth, replication groups, which are the newer name for almost the same thing.

Query
SHOW REPLICATION GROUPS;
Result0 rows · 20 columns · scroll →
snowflake_regioncreated_onaccount_namenametypecommentis_primaryprimaryobject_typesallowed_integration_typesallowed_accountsorganization_nameaccount_locatorreplication_schedulesecondary_statenext_scheduled_refreshowneris_listing_auto_fulfillment_grouperror_integrationis_optimized_refresh_enabled
Query
SELECT COUNT(*) AS REPLICATION_GROUPS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
REPLICATION_GROUPS
0

Nought, and the same twenty columns. So four SHOW statements and four noughts.

Nought rows is an answer

This is what I got wrong, four times in a row. I expected an account with no replication to refuse to discuss replication. It does not. It answers, and the answer is nothing.
An empty grid with twenty column headings tells you the feature exists and you are not using it. An error tells you that you cannot use it. Those are two completely different facts and I had them confused.

Now let's see where replication is written down

Whether you use it is one question. Whether Snowflake has somewhere to record it is another. Let's look in the account's metadata schema from Episode 171.

Query
SELECT TABLE_NAME
  FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND (TABLE_NAME LIKE '%REPLICATION%' OR TABLE_NAME LIKE '%FAILOVER%')
 ORDER BY TABLE_NAME;
Result5 rows · 1 column
TABLE_NAME
DATABASE_REPLICATION_USAGE_HISTORY
REPLICATION_GROUPS
REPLICATION_GROUP_REFRESH_HISTORY
REPLICATION_GROUP_USAGE_HISTORY
REPLICATION_USAGE_HISTORY
Query
SELECT COUNT(*) AS REPLICATION_RELATED_VIEWS
  FROM SNOWFLAKE.INFORMATION_SCHEMA.VIEWS
 WHERE TABLE_SCHEMA = 'ACCOUNT_USAGE'
   AND (TABLE_NAME LIKE '%REPLICATION%' OR TABLE_NAME LIKE '%FAILOVER%');
Result1 row · 1 column
REPLICATION_RELATED_VIEWS
5

Five views with replication or failover in the name. A usage history for database replication, the groups themselves, a refresh history and two more usage histories.

And the per-database catalogue from Episode 170 has two of its own.

Query
SELECT TABLE_NAME, TABLE_TYPE
  FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_SCHEMA = 'INFORMATION_SCHEMA'
   AND TABLE_NAME LIKE '%REPLICATION%'
 ORDER BY TABLE_NAME;
Result2 rows · 2 columns
TABLE_NAMETABLE_TYPE
REPLICATION_DATABASESVIEW
REPLICATION_GROUPSVIEW

Both of them views, both of them present, in every database on every account. Let's ask one of them how many rows it has here. This is another statement I marked as a refusal.

Query
SELECT COUNT(*) AS ROWS_IN_REPLICATION_DATABASES
  FROM DEMO_DB.INFORMATION_SCHEMA.REPLICATION_DATABASES;
Result1 row · 1 column
ROWS_IN_REPLICATION_DATABASES
0

Nought. It runs, it is empty, and my prediction was wrong again. Same for the history view in the other schema.

Query
SELECT COUNT(*) AS ROWS_IN_REPLICATION_USAGE_HISTORY
  FROM SNOWFLAKE.ACCOUNT_USAGE.REPLICATION_USAGE_HISTORY;
Result1 row · 1 column
ROWS_IN_REPLICATION_USAGE_HISTORY
0

Nought rows there too. That is seven of the eight, and every one of the seven was wrong the same way.

And where you would look for a replica

If a replica existed on this account, it would be a database. So let's look at the databases.

Query
SHOW DATABASES;
Query
SELECT "name", "origin", "owner", "kind", "is_current", "retention_time"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 ORDER BY "name";
Result5 rows · 6 columns · showing first 4 · scroll →
Five databases. The fifth row is a personal database named after the user, so it is left off this page.
nameoriginownerkindis_currentretention_time
DEMO_DBACCOUNTADMINSTANDARDY1
SNOWFLAKESNOWFLAKE.ACCOUNT_USAGEAPPLICATIONN0
SNOWFLAKE_LEARNING_DBACCOUNTADMINSTANDARDN1
SNOWFLAKE_SAMPLE_DATASFSALESSHARED.SFC_SAMPLES_AWSUSEAST2.SAMPLE_DATAACCOUNTADMINIMPORTED DATABASEN0

SHOW DATABASES carries fourteen columns and not one of them is about replication. The nearest thing is origin, and it is filled in on one of these rows.

But that is an imported database from a share, which is what Episode 169 was about. A share and a replica are not the same thing: a share gives another account read access to your data where it already is, and a replica is a copy of it somewhere else.

And for completeness, here is the same question asked of the view that remembers everything.

Query
SELECT DATABASE_NAME, DATABASE_OWNER, IS_TRANSIENT, DELETED
  FROM SNOWFLAKE.ACCOUNT_USAGE.DATABASES
 ORDER BY DATABASE_NAME;
Result12 rows · 4 columns · showing first 8
Twelve rows for five databases. The first eight of them; the twelfth is the personal database again.
DATABASE_NAMEDATABASE_OWNERIS_TRANSIENTDELETED
CLONEDB_T134ACCOUNTADMINNO2026-10-02 08:46:25.058000-07:00
CLONEDB_T134ACCOUNTADMINNO2026-10-02 06:43:20.425000-07:00
CLONEDB_T134ACCOUNTADMINNO2026-10-02 08:26:32.949000-07:00
DDL_DEMO_T98NULLNO2026-09-28 13:00:56.909000-07:00
DDL_DEMO_T98NULLNO2026-09-28 13:00:52.482000-07:00
DEMO_DBACCOUNTADMINNONULL
NO_PUBLIC_T99NULLNO2026-09-28 13:01:24.810000-07:00
PUBLIC_PROBE_T99NULLNO2026-09-28 13:01:24.459000-07:00

Twelve rows for five databases, with a DELETED timestamp on the ones that are gone and a real NULL on the ones that are still here. That is Episode 171's point, one last time: a history, not a picture.

Now the other direction: let's try to do it

Reading about replication works. Let's try to turn it on, on a database we own.

Query
ALTER DATABASE DEMO_DB ENABLE REPLICATION;
Query failed — Snowflake returned an error
003914 (42601): SQL Compilation Error:
At least one target account needs to be specified to run this command.

003914. At least one target account needs to be specified. Read that carefully: it is a complaint about our statement. It says nothing at all about our account.

All right, a failover group instead, with the object types and the database named.

Query
CREATE FAILOVER GROUP FG_T173
    OBJECT_TYPES      = DATABASES
    ALLOWED_DATABASES = DEMO_DB;
Query failed — Snowflake returned an error
500079 (42601): Missing required parameter(s): ALLOWED_ACCOUNTS.

500079. Missing required parameter, and the parameter it names is the allowed accounts. Again about the statement.

Did anything get made before it refused? This is the last of my eight predicted refusals.

Query
SHOW FAILOVER GROUPS LIKE 'FG\\_T173';
Result0 rows · 20 columns · scroll →
snowflake_regioncreated_onaccount_namenametypecommentis_primaryprimaryobject_typesallowed_integration_typesallowed_accountsorganization_nameaccount_locatorreplication_schedulesecondary_statenext_scheduled_refreshowneris_listing_auto_fulfillment_grouperror_integrationis_optimized_refresh_enabled
Query
SELECT COUNT(*) AS FAILOVER_GROUPS_OF_MINE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
FAILOVER_GROUPS_OF_MINE
0

It runs, and it returns nothing. Nought failover groups of ours, so nothing half-existed. That is eight of eight, and all eight ran.

Let's try the newer statement for the same idea.

Query
CREATE REPLICATION GROUP RG_T173
    OBJECT_TYPES      = DATABASES
    ALLOWED_DATABASES = DEMO_DB;
Query failed — Snowflake returned an error
500079 (42601): Missing required parameter(s): ALLOWED_ACCOUNTS.

The identical message. Two different statements, one missing parameter, word for word the same refusal.

Now a statement with nothing missing from it

Those two refusals were both about the shape of what we wrote. So let's write something complete and see what Snowflake says then.

Query
CREATE DATABASE REPLICA_T173 AS REPLICA OF DEMO_DB;
Query failed — Snowflake returned an error
003078 (55000): Replication is not enabled for your account. You can find instructions to enable replication for your account at https://docs.snowflake.com/alias/replication/enable-account-repl

003078. Replication is not enabled for your account, with a link to the instructions for enabling it. There it is. The real reason, and it took a complete statement to hear it.

Query
SHOW DATABASES LIKE 'REPLICA\\_T173';
Result0 rows · 14 columns · scroll →
created_onnameis_defaultis_currentoriginownercommentoptionsretention_timekindowner_role_typeobject_visibilitydata_quality_monitoring_settingsresharing_settings
Query
SELECT COUNT(*) AS REPLICA_DATABASES_OF_MINE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
REPLICA_DATABASES_OF_MINE
0

No replica appeared. Let's try the other two things you do to a replicated database.

Query
ALTER DATABASE DEMO_DB REFRESH;
Query failed — Snowflake returned an error
003078 (55000): Replication is not enabled for your account. You can find instructions to enable replication for your account at https://docs.snowflake.com/alias/replication/enable-account-repl

The same 003078. And promoting a database to primary.

Query
ALTER DATABASE DEMO_DB PRIMARY;
Query failed — Snowflake returned an error
003900 (55000): Failover capability not enabled for your account. Please contact Snowflake support for more information.

003900, failover capability not enabled, which is a third code for the same missing thing.

So six refusals and three codes. And the first two complained about our statement rather than about our account, which means you can be refused twice, truthfully and beside the point, before anybody tells you the actual reason.

And after all six, the database we were aiming all this at is untouched.

Query
SELECT "name", "origin", "owner", "retention_time", "kind", "options"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 6 columns · scroll →
nameoriginownerretention_timekindoptions
DEMO_DBACCOUNTADMIN1STANDARD
Why the first two errors were beside the point

Snowflake checks the shape of your statement before it checks what your account is allowed to do. That order is sensible and it is also why error messages mislead people: a complete statement gets you the honest answer, and an incomplete one gets you a true answer to a different question.

So what can one account do on its own?

No replica, no second account. What is left is time travel, and it is more useful than people expect. It starts with the retention time on the database.

Query
SHOW DATABASES LIKE 'DEMO\_DB';
Query
SELECT "name", "retention_time", "kind"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameretention_timekind
DEMO_DB1STANDARD

One day. And a table inherits that from its database unless somebody sets it separately.

Query
SHOW TABLES LIKE 'LEDGER\_T173' IN SCHEMA DEMO_DB.REPL_T173;
Query
SELECT "name", "retention_time", "kind", "rows", "bytes"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 5 columns
nameretention_timekindrowsbytes
LEDGER_T1731TABLE41024

One day of retention, four rows, 1024 bytes. Now let's have an accident: delete everything except the opening balance.

Query
DELETE FROM DEMO_DB.REPL_T173.LEDGER_T173 WHERE ENTRY_ID > 1;
Result1 row · 1 column
number of rows deleted
3

Three rows deleted. Before we do anything else, let's save the id of the statement that did it.

Query
SET QID_DELETE_T173 = LAST_QUERY_ID();
Result1 row · 1 column
status
Statement executed successfully.

And here is the damage.

Query
SELECT * FROM DEMO_DB.REPL_T173.LEDGER_T173 ORDER BY ENTRY_ID;
Result1 row · 3 columns
ENTRY_IDNOTEAMOUNT
1opening balance1000.00
Query
SELECT COUNT(*) AS ROWS_LEFT FROM DEMO_DB.REPL_T173.LEDGER_T173;
Result1 row · 1 column
ROWS_LEFT
1

One row left out of four. This is the moment you would start looking for a replica.

Let's get them back without a replica

There is no replica. There is BEFORE (STATEMENT => ...) and the query id we just saved.

Query
SELECT * FROM DEMO_DB.REPL_T173.LEDGER_T173
  BEFORE (STATEMENT => $QID_DELETE_T173)
 ORDER BY ENTRY_ID;
Result4 rows · 3 columns
ENTRY_IDNOTEAMOUNT
1opening balance1000.00
2invoice 4471-240.00
3invoice 4472-118.50
4deposit600.00
Query
SELECT COUNT(*) AS ROWS_TIME_TRAVEL_CAN_STILL_SEE
  FROM DEMO_DB.REPL_T173.LEDGER_T173
 BEFORE (STATEMENT => $QID_DELETE_T173);
Result1 row · 1 column
ROWS_TIME_TRAVEL_CAN_STILL_SEE
4

All four rows back. No second account, no replica, one day of retention and one statement id.

Notice what we asked for: the table as it was before that particular statement. We named the moment we wanted.

Now something worse: let's drop the table

Deleting rows is one kind of accident. Dropping the whole table is another.

Query
DROP TABLE DEMO_DB.REPL_T173.LEDGER_T173;
Result1 row · 1 column
status
LEDGER_T173 successfully dropped.
Query
SELECT COUNT(*) AS MENTIONS_AFTER_THE_DROP
  FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_NAME = 'LEDGER_T173';
Result1 row · 1 column
MENTIONS_AFTER_THE_DROP
0

Gone from the catalogue, in the statement straight afterwards. Now let's undrop it.

Query
UNDROP TABLE DEMO_DB.REPL_T173.LEDGER_T173;
Result1 row · 1 column
status
Table LEDGER_T173 successfully restored.

Successfully restored. And here is what came back.

Query
SELECT * FROM DEMO_DB.REPL_T173.LEDGER_T173 ORDER BY ENTRY_ID;
Result1 row · 3 columns
ENTRY_IDNOTEAMOUNT
1opening balance1000.00
Query
SELECT COUNT(*) AS ROWS_AFTER_UNDROP FROM DEMO_DB.REPL_T173.LEDGER_T173;
Result1 row · 1 column
ROWS_AFTER_UNDROP
1

One row. Not four.

UNDROP restored the table as it was at the moment of the drop, and at that moment it had already lost three rows to our accident. It did not go back any further, because we never asked it to. UNDROP has nowhere to put a moment.

The thing to take away from this section

Retention is a window, not an undo button. The same table, with the same one day of retention, gave two different answers a few statements apart, and the difference was entirely whether we named the moment we wanted. If you are recovering from an accident, work out when the accident was first and ask for that.

And the clean-up

Everything this post made comes back out, including the objects that were refused, in case any of them had half-existed.

Clean-up
-- Everything this post made, taken back out again, including the
-- objects that were refused in case any of them half-existed.
DROP TABLE IF EXISTS DEMO_DB.REPL_T173.LEDGER_T173;
DROP FAILOVER GROUP IF EXISTS FG_T173;
DROP REPLICATION GROUP IF EXISTS RG_T173;
DROP DATABASE IF EXISTS REPLICA_T173;
USE SCHEMA DEMO_DB.PUBLIC;
DROP SCHEMA IF EXISTS DEMO_DB.REPL_T173;
Query
SELECT COUNT(*) AS MY_SCHEMAS_LEFT
  FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
 WHERE SCHEMA_NAME = 'REPL_T173';
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 '%\\_T173' ESCAPE '\\';
Result1 row · 1 column
MY_TABLES_LEFT
0

And the databases, which is where we came in.

Query
SELECT "name", "origin", "owner", "kind"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 ORDER BY "name";
Result5 rows · 4 columns · showing first 4
The same five as the start. The fifth row is the personal database, left off as before.
nameoriginownerkind
DEMO_DBACCOUNTADMINSTANDARD
SNOWFLAKESNOWFLAKE.ACCOUNT_USAGEAPPLICATION
SNOWFLAKE_LEARNING_DBACCOUNTADMINSTANDARD
SNOWFLAKE_SAMPLE_DATASFSALESSHARED.SFC_SAMPLES_AWSUSEAST2.SAMPLE_DATAACCOUNTADMINIMPORTED DATABASE
Query
SELECT COUNT(*) AS DATABASES_AT_THE_END
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
DATABASES_AT_THE_END
5

Five databases, the same five we opened with. No replica, no failover group, no replication group, and nothing of ours left behind.

One last thing: what this account remembers about the course

This is the last post, so let's ask the account what the whole series looked like from its side. The views we used in Episode 171 keep all of it.

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
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

One thousand four hundred and twelve tables made and dropped, against two hundred and twenty still standing. Forty seven schemas gone, seventy three left.

Query
SELECT COUNT(*) AS QUERIES_ON_THE_RECORD
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY;
Result1 row · 1 column
QUERIES_ON_THE_RECORD
62750
Query
SELECT COUNT(*) AS STATEMENTS_THAT_FAILED
  FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
 WHERE ERROR_CODE IS NOT NULL;
Result1 row · 1 column
STATEMENTS_THAT_FAILED
1297
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

Sixty two thousand seven hundred and fifty queries, of which one thousand two hundred and ninety seven failed, across two hundred and fifteen distinct error codes. Most of those failures were refusals we went looking for on purpose, because a refusal usually teaches you more about a feature than a success does.

And that is Episode 173. One hundred and seventy three posts, thirteen levels, from a first SELECT to an account that will not let you replicate it.

There is plenty of Snowflake these posts never reached, and there always would be. What they do have is this: every grid in every one of them is output a real account actually gave back, including the ones where it refused, and including the ones where it proved me wrong.

Thank you for reading it. If you worked through all thirteen levels, you can now read a Snowflake worksheet, write most of what you need in it, and know where to look when it tells you no.

Key points

  • Replication copies a database to another account, so it needs a second account to be about anything at all.
  • An account is addressed for replication as organisation.account, from CURRENT_ORGANIZATION_NAME() and CURRENT_ACCOUNT_NAME(), not by its locator.
  • SHOW REGIONS returned 48 regions across three clouds, on an account that cannot replicate anything.
  • SHOW REPLICATION DATABASES, SHOW REPLICATION ACCOUNTS, SHOW FAILOVER GROUPS and SHOW REPLICATION GROUPS all ran and all returned nought rows.
  • Nought rows is an answer. An empty grid with its column headings tells you the feature exists and you are not using it. An error tells you that you cannot use it.
  • Eight statements I expected to be refused all ran. That is eight wrong predictions in one post, all in the same direction, and they are all on the page.
  • Five ACCOUNT_USAGE views and two INFORMATION_SCHEMA views carry replication, on every account, whether or not it replicates anything.
  • Six statements were refused, and they were the six that tried to do something: 003914, 500079 twice, 003078 twice and 003900.
  • Snowflake validates the shape of your statement before it validates your account, so the first two refusals never mention the real problem.
  • One account can still recover. BEFORE (STATEMENT => ...) brought all four rows back after a bad DELETE.
  • UNDROP restores the table as it was at the drop, not before the accident. It came back with one row, not four.
  • Retention is a window, not an undo button. You have to say where in the window you want to land.
Next in this series

That is the end of Snowflake SQL: Zero to Hero. If you are starting out, Episode 1 is the SELECT statement and the sample table every post in Level 1 runs against. If you came here for the administration level, Episode 155 is where it begins, with warehouses.

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. Six of the statements on this page are refusals, and they are shown as Snowflake returned them. The organisation name, account name, account locator, region and user name are deliberately kept off the page: the two functions that return the first two are named and their statements shown, which is the teaching, while printing this account's own values is not. The SHOW DATABASES grids show four of their five rows for the same reason. Everything created here is dropped here. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake replication documentation.

No comments:

Post a Comment

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