Snowflake Configuration
Connect to Snowflake for analytics, large-scale queries, and business intelligence workloads.
Connection Parameters
Required Fields
- Account: Account identifier (e.g., xy12345.us-east-1)
- Warehouse: Compute warehouse name
- Database: Database name
- Username: Snowflake username
- Password: User password
Connection String Format
snowflake://user:***@account/database/warehouse
Configuration Example
When creating a Snowflake data source, provide the following information:
| Field | Example Value | Notes |
|---|---|---|
| Name | prod-snowflake | Unique identifier |
| Label | Production Snowflake | Display name |
| Account | xy12345.us-east-1 | Account identifier |
| Warehouse | COMPUTE_WH | Warehouse name |
| Database | ANALYTICS_DB | Database name |
| Username | app_user | Snowflake user |
| Password | •••••••• | Encrypted at rest |
Finding Your Account Identifier
Your Snowflake account identifier can be found in several places:
- From URL: Look at your Snowflake URL:
https://<account_identifier>.snowflakecomputing.com - From Snowflake UI: Account → Account Name (shown in bottom left)
- Format Examples:
- Legacy:
xy12345 - Preferred:
xy12345.us-east-1 - With organization:
orgname-xy12345
- Legacy:
Account Identifier Format
Use the full account identifier including region for best compatibility: xy12345.us-east-1
Usage in Applications
Python Example
import os, json
import snowflake.connector
# Parse STRONGLY_SERVICES environment variable
services = json.loads(os.getenv('STRONGLY_SERVICES', '{}'))
datasources = services.get('datasources', {})
# Get Snowflake data source
sf_config = datasources['prod-snowflake']
creds = sf_config['credentials']
# Connect using credentials
conn = snowflake.connector.connect(
account=creds['account'],
user=creds['username'],
password=creds['password'],
warehouse=creds['warehouse'],
database=creds['database']
)
# Execute queries
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE active = true")
users = cursor.fetchall()
Python with Pandas
import os, json
import snowflake.connector
import pandas as pd
# Parse STRONGLY_SERVICES environment variable
services = json.loads(os.getenv('STRONGLY_SERVICES', '{}'))
datasources = services.get('datasources', {})
# Get Snowflake data source
sf_config = datasources['prod-snowflake']
creds = sf_config['credentials']
# Connect
conn = snowflake.connector.connect(
account=creds['account'],
user=creds['username'],
password=creds['password'],
warehouse=creds['warehouse'],
database=creds['database']
)
# Query into DataFrame
df = pd.read_sql("SELECT * FROM users WHERE active = true", conn)
print(df.head())
Node.js Example
const snowflake = require('snowflake-sdk');
// Parse STRONGLY_SERVICES environment variable
const services = JSON.parse(process.env.STRONGLY_SERVICES || '{}');
const datasources = services.datasources || {};
// Get Snowflake data source
const sfConfig = datasources['prod-snowflake'];
const creds = sfConfig.credentials;
// Create connection
const connection = snowflake.createConnection({
account: creds.account,
username: creds.username,
password: creds.password,
warehouse: creds.warehouse,
database: creds.database
});
// Connect
connection.connect((err, conn) => {
if (err) {
console.error('Unable to connect: ' + err.message);
} else {
console.log('Successfully connected to Snowflake.');
// Execute query
connection.execute({
sqlText: 'SELECT * FROM users WHERE active = true',
complete: (err, stmt, rows) => {
if (err) {
console.error('Failed to execute statement: ' + err.message);
} else {
console.log('Number of rows produced: ' + rows.length);
}
}
});
}
});
Java Example
import java.sql.*;
import java.util.*;
import org.json.*;
public class SnowflakeExample {
public static void main(String[] args) throws Exception {
// Parse STRONGLY_SERVICES environment variable
String servicesJson = System.getenv("STRONGLY_SERVICES");
JSONObject services = new JSONObject(servicesJson);
JSONObject datasources = services.getJSONObject("datasources");
JSONObject sfConfig = datasources.getJSONObject("prod-snowflake");
JSONObject creds = sfConfig.getJSONObject("credentials");
// Build connection URL
String url = String.format(
"jdbc:snowflake://%s.snowflakecomputing.com",
creds.getString("account")
);
// Connection properties
Properties props = new Properties();
props.put("user", creds.getString("username"));
props.put("password", creds.getString("password"));
props.put("warehouse", creds.getString("warehouse"));
props.put("db", creds.getString("database"));
// Connect and query
Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE active = true");
while (rs.next()) {
System.out.println(rs.getString(1));
}
conn.close();
}
}
Warehouse Configuration
Snowflake warehouses control compute resources:
Warehouse Sizes
| Size | Servers | Credits/Hour | Use Case |
|---|---|---|---|
| X-Small | 1 | 1 | Development, testing |
| Small | 2 | 2 | Light production workloads |
| Medium | 4 | 4 | Standard production |
| Large | 8 | 8 | Heavy analytics |
| X-Large | 16 | 16 | Very large queries |
Auto-suspend and Auto-resume
Configure warehouses to automatically suspend when idle:
ALTER WAREHOUSE COMPUTE_WH SET
AUTO_SUSPEND = 300 -- Suspend after 5 minutes
AUTO_RESUME = TRUE; -- Resume automatically when needed
Cost Optimization
Use auto-suspend to minimize costs. Warehouses incur charges only when running.
Common Issues
Invalid Account Identifier
- Verify the account identifier format
- Include the region:
xy12345.us-east-1 - Check for typos or extra spaces
- Try the legacy format if the preferred format doesn't work
Authentication Failed
- Verify username and password are correct
- Check if user account is locked or expired
- Ensure user has necessary privileges
- Verify IP whitelist if configured
Warehouse Not Found
- Ensure warehouse name is spelled correctly
- Check if warehouse exists:
SHOW WAREHOUSES; - Verify user has USAGE privilege on the warehouse:
GRANT USAGE ON WAREHOUSE COMPUTE_WH TO USER app_user;
Database Not Found
- Verify the database name is correct (case-sensitive)
- Check if database exists:
SHOW DATABASES; - Grant access if needed:
GRANT USAGE ON DATABASE ANALYTICS_DB TO USER app_user;
Insufficient Privileges
Grant necessary privileges to your application user:
-- Grant warehouse usage
GRANT USAGE ON WAREHOUSE COMPUTE_WH TO USER app_user;
-- Grant database access
GRANT USAGE ON DATABASE ANALYTICS_DB TO USER app_user;
-- Grant schema access
GRANT USAGE ON SCHEMA ANALYTICS_DB.PUBLIC TO USER app_user;
-- Grant table access (read-only)
GRANT SELECT ON ALL TABLES IN SCHEMA ANALYTICS_DB.PUBLIC TO USER app_user;
-- Grant future tables access
GRANT SELECT ON FUTURE TABLES IN SCHEMA ANALYTICS_DB.PUBLIC TO USER app_user;
Best Practices
- Use Appropriate Warehouse Size: Match warehouse size to workload requirements
- Enable Auto-suspend: Configure warehouses to auto-suspend when idle
- Least Privilege: Grant minimal required permissions to application users
- Query Optimization: Use clustering keys and optimize queries for better performance
- Result Caching: Leverage Snowflake's result cache for repeated queries
- Multi-cluster Warehouses: Use for high concurrency workloads
- Monitor Costs: Track warehouse usage and optimize query patterns
Query Performance Tips
Use Query Tags
Track queries from your application:
cursor.execute("ALTER SESSION SET QUERY_TAG = 'my-app-users-query'")
cursor.execute("SELECT * FROM users WHERE active = true")
Optimize with Clustering
For large tables, use clustering keys:
ALTER TABLE users CLUSTER BY (created_date, region);
Use Materialized Views
Cache complex query results:
CREATE MATERIALIZED VIEW active_users AS
SELECT * FROM users WHERE active = true;