PostgreSQL to Snowflake Postgres Migration
Windows users: see references/windows.md — install prereqs, credential file paths (%APPDATA%\postgresql\ instead of ~/), and command-flow notes differ on native Windows. WSL behaves as Linux.
When to Use
When migrating any PostgreSQL database to Snowflake Postgres:
- On-premises PostgreSQL → Snowflake Postgres
- Cloud PostgreSQL (RDS, Aurora, Cloud SQL, Azure, Crunchy Bridge, Neon, Supabase) → Snowflake Postgres
- Self-managed PostgreSQL → Snowflake Postgres
Credentials — always use service names, never passwords in chat.
Passwords should end up in ~/.pgpass, referenced by a profile in ~/.pg_service.conf, so standard PostgreSQL tools (psql, pg_dump, pg_restore, pg_dumpall) keep working. In chat-safe setup flows, gather only non-secret fields in chat, direct the user to /secrets for the password, then register the profile so the password is written into ~/.pgpass without appearing in chat or process argv. Pass --source-service <NAME> / --target-service <NAME> to every migration script invocation — never --password <pw> or -W <pw> in chat.
- Register a Snowflake Postgres target profile once:
uv run --project <SKILL_DIR> python <SKILL_DIR>/scripts/pg_connect.py --create --instance-name <NAME> --compute-pool <COMPUTE_FAMILY> --storage <GB> (also fetches the CA cert and saves the profile under the lowercased instance name). --role is for --reset only — --create provisions all roles automatically. To run the SQL with an elevated Snowflake role, pass --use-role ACCOUNTADMIN (session-scoped, not persisted). For valid compute families, storage bounds, and HA restrictions, see ../references/instance-options.md.
- Register a non-Snowflake source profile once: collect
host / port / dbname / user / sslmode in chat, have the user add the password via /secrets, then run uv run --project <SKILL_DIR> python <SKILL_DIR>/scripts/shared/pg_common.py --add-source-service <NAME> --host ... --port ... --dbname ... --user ... [--sslmode ...]. pg_common.py accepts the password from agent-injected env vars as well as --password, so the chat-safe path still lands the secret in ~/.pgpass. Trusted-shell fallback: rerun the same command once outside chat with --password .... pg_common.py is invoked as a script because it isn't packaged as an importable module at the project root; the file's __main__ block dispatches the CLI directly.
After profiles exist, every migration script invocation looks like … --source-service prod_source --target-service sf_target … with no password material in sight.
Helper: setup_connection shell function
Several legacy reference docs (under replicate/, dump-restore/, rollback/, validate/references/) include psql examples that begin with setup_connection "SOURCE" or setup_connection "TARGET". That is a small shell helper that exports PG* env vars from the prefixed SOURCE_PG* / TARGET_PG* ones. The function definition lives in migrate/references/pg_migration_env.template alongside the env-var template — copy the template to ~/.pg_migration_env, fill it in, and source it once per shell session to make every legacy example runnable.
In chat-safe workflows you don't need this helper at all — prefer the Python scripts under migrate/scripts/ with --source-service / --target-service flags, which never touch PGPASSWORD and never echo credentials.
First Question: Interactive Scope Gathering
MANDATORY: Use ask_user_question for each fixed-choice step. Do NOT present all questions as a wall of text. For exact identifiers (database names, file paths), ask in normal chat after the relevant choice, or use the tool's automatic "Something else" path if available.
Step 1: Ask About Assessment
question: "Would you like to run a migration assessment first?"
header: "Assessment"
options:
- label: "Yes"
description: "Analyze the source database for blockers, complexity, and recommended method before migrating"
- label: "No"
description: "I already know my migration approach — skip straight to setup"
If Yes → Gather connection details (Step 1a), then load assess/SKILL.md. The assessment will recommend a method and present it at its approval checkpoint. After the user approves a method, proceed to Step 2 (scope).
If No → Skip assessment entirely. Proceed to Step 2 (scope), then ask for method directly at Step 5.
Step 1a: Get Source Connection (if Assessment)
Load references/connection-setup.md to gather source connection details.
For assessment-first workflows, the first connection question should make the existing-connection path obvious:
Saved connection means "I already have a saved source connection"
Enter source details now means "register a new source profile now"
Legacy environment file is the fallback for older shell-based workflows
If the user already has a saved source connection, list saved connections first and let them pick. Do not send them to inspect ~/.pg_service.conf manually unless the picker path fails. If the user provides raw host / port / dbname / user values instead of an existing saved connection, direct them to /secrets for the password, register a source profile so the password lands in ~/.pgpass, then run assessment via assess/SKILL.md.
Do not ask about target instance existence, target profiles, or billable target creation during assessment intake. Assessment presents findings and recommends a method at its approval checkpoint (assess/SKILL.md Step 4). The user selects the method there, and only then do target-creation / billable questions become relevant.
Step 2: Ask What to Migrate
IMPORTANT: Even if the user has a database specified in their environment file or connection string, always confirm which database(s) to migrate. Do not assume the env variable is the correct or only target.
question: "What would you like to migrate to Snowflake Postgres?"
header: "Scope"
options:
- label: "Single database"
description: "Migrate one specific database"
- label: "Multiple databases"
description: "Migrate a specific list of databases"
- label: "All databases"
description: "Migrate the entire cluster"
Based on response:
- Single database → Ask for database name (Step 2a), even if one is already set in the environment
- Multiple databases → Ask for list of database names (Step 2b)
- All databases → Note will use
pg_dumpall
Step 2a: Get Database Name (if Single)
Ask for the exact database name in normal chat after the user chooses Single database. Do not use unsupported free-text question fields here.
Step 2b: Get Database List (if Multiple)
Ask the user to send the exact database names in normal chat after they choose Multiple databases (comma-separated or one per line). Do not use unsupported free-text question fields here.
Step 3: Ask About Schema Scope
question: "Which schemas should be migrated?"
header: "Schemas"
options:
- label: "All schemas"
description: "Migrate all user schemas (default)"
- label: "Specific schemas"
description: "Only migrate selected schemas"
- label: "Exclude schemas"
description: "Migrate all except certain schemas"
Step 4: Ask About Users/Roles
question: "Should users, roles, and grants be migrated?"
header: "Roles"
options:
- label: "Yes (recommended)"
description: "Migrate using pg_dumpall --globals-only"
- label: "No"
description: "Roles already exist or managed separately"
- label: "Partial"
description: "Only specific roles"
Based on response:
- Yes / Partial → Load
security/SKILL.md and run that workflow FIRST,
before any data migration. Roles must exist on the target before
ownership/grants in the data dump can resolve. Return here after
security/SKILL.md completes.
- No → Continue to Step 5.
Notes: Cloud-managed roles (rds_*, azure_*, cloudsql*) cannot be
migrated and are filtered out by filter_vendor_dump.py.
Step 5: Ask About Method (if assessment was skipped)
Only ask this if the user chose No at Step 1 (no assessment).
question: "Which migration method do you want to use?"
header: "Method"
options:
- label: "Logical replication"
description: "Near-zero downtime. Requires PG 10+, tables with primary keys, network connectivity (target→source)"
- label: "pg_dump/pg_restore"
description: "Offline migration. Requires a downtime window. Simplest approach."
- label: "Hybrid"
description: "Logical replication for qualifying tables + pg_dump for non-replicable objects (unlogged, no PK, inheritance)"
- label: "postgres_fdw"
description: "Foreign data wrapper. Target queries source directly via SQL. Good for selective/filtered migration or as alternative to pg_dump in hybrid."
- label: "Replica-assisted (large DB)"
description: "For databases >= 2 TB or RDS/Aurora with S3 Parquet export + pg_lake. Replica handles initial load; logical replication catches up."
Based on response:
- Logical replication → Load
replicate/SKILL.md
- pg_dump/pg_restore → Load
dump-restore/SKILL.md
- Hybrid → Investigate/classify actual objects first (and review inheritance semantics if present), then ask dump timing and execute the phased plan (see
assess/SKILL.md Step 5 for details)
- postgres_fdw → See
references/complex-migration-strategies.md (postgres_fdw section). Can also be used within Hybrid instead of pg_dump.
- Replica-assisted (large DB) → Load
large-db/SKILL.md
Auto-route to LARGE-DB when ANY of these are detected without asking:
- User mentions "TB", "terabyte", "large database", "very large", "S3 export"
- Source is RDS/Aurora and database size > 2 TB
- Assessment reports
total_size_bytes >= 2_000_000_000_000
If assessment was performed, the method was already chosen at the assessment approval checkpoint — skip this step.
Step 6: Proceed to Connection Setup
After gathering scope and method, load references/connection-setup.md for connection setup, then proceed to the chosen migration method sub-skill.
Setup
Need continuous managed replication from Snowflake Postgres into Snowflake tables via SNOWFLAKE.POSTGRES.CREATE_MIRROR, $live, or $changes? That is owned by ../mirror/SKILL.md, not this migration skill. Use migrate/ for one-time or cutover-oriented moves into Snowflake Postgres.
- Load
references/migration-overview.md for architecture context
- Load
references/blockers-checklist.md for common migration blockers
Intent Detection
| Intent |
Trigger Phrases |
Route |
| ASSESS |
"migration readiness", "check blockers", "assessment" |
Load assess/SKILL.md |
| REPLICATE |
"logical replication", "live sync", "near-zero downtime" |
Load replicate/SKILL.md |
| LARGE-DB |
"large database", "terabyte migration", "TB", "S3 export", "RDS Parquet export", "very large", "2TB", "5TB", "fast initial load", "replica-assisted" |
Load large-db/SKILL.md |
| DUMP |
"pg_dump", "dump and restore", "offline migration" |
Load dump-restore/SKILL.md |
| VALIDATE |
"validate migration", "data validation", "pgcompare" |
Load validate/SKILL.md |
| SECURITY |
"migrate users", "migrate roles", "grants", "RBAC" |
Load security/SKILL.md |
| CUTOVER |
"cutover plan", "go-live", "switch over" |
Load cutover/SKILL.md |
| ROLLBACK |
"rollback plan", "failback", "reverse migration" |
Load rollback/SKILL.md |
| MONITOR |
"monitor replication", "check lag", "replication status" |
Load monitor/SKILL.md |
| RESUME |
"resume migration", "continue migration", "where did I leave off" |
Load resume/SKILL.md |
| PAUSE |
"pause migration", "stop after this phase", "save progress" |
Load resume/SKILL.md (pause workflow) |
| REPEAT |
"repeat phase", "re-run validation", "redo pg_dump", "run phase again" |
Load resume/SKILL.md (repeat workflow) |
| PLATFORM |
"migrate from RDS", "migrate from Aurora", "migrate from Azure", "migrate from Cloud SQL", "migrate from Heroku", "migrate from Crunchy Bridge", "migrate from Supabase", "migrate from Neon", "migrate from Aiven", "on-prem postgres" |
Load references/source-platform-guide.md (router that auto-detects platform and points to the exact per-platform file to read; do not derive filenames from the platform display name) |
| FULL |
"full migration", "end-to-end migration" |
Start with assess/SKILL.md |
| FALLBACK |
(no match above) |
Ask user to clarify intent, then route |
Migration Methods
1. Logical Replication (Near-Zero Downtime)
- Best for: Production databases requiring minimal downtime
- Requirements: PostgreSQL 10+ source, tables with primary keys, network connectivity (Target→Source)
- Process: Network verify → Live sync → Cutover → Validation
2. pg_dump/pg_restore (Offline)
- Best for: Development/staging, smaller databases, simple migrations
- Requirements: Downtime window available
- Process: Dump → Transfer → Restore → Validation
3. Direct COPY (Bulk Transfer)
- Best for: Individual tables, data refresh scenarios
- Requirements: Network connectivity between source and target
4. RDS S3 Parquet Export + pg_lake (AWS Only)
- Best for: Very large RDS/Aurora databases (200GB+)
- Requirements: pg_lake extension, S3 bucket, IAM roles
5. Hybrid Migration (Mixed Workloads)
- Best for: Databases with mix of replicable and non-replicable objects
- Use when: Unlogged tables, table inheritance, tables without PKs that cannot be modified
- Process: Logical replication for qualifying tables + pg_dump for blockers
- Tool:
<SKILL_DIR>/migrate/scripts/generate_hybrid_plan.py generates phased plan
For time estimates, see references/time-estimation.md
Workflow Overview
┌─────────────┐ ┌─────────────────────┐ ┌──────────────┐ ┌──────────────┐
│ SCOPE CHECK │────▶│ ASSESS │────▶│ APPROVAL │────▶│ SECURITY │
│ │ │ │ │ │ │ (if opted) │
│ • Database? │ │ • Blockers │ │ Review │ │ │
│ • Schemas? │ │ • Size │ │ findings │ │ • Roles │
│ • Roles? │ │ • Features │ │ Choose method│ │ • Grants │
└─────────────┘ └─────────────────────┘ └──────┬───────┘ └──────┬───────┘
│ │
┌──────────────────────────────────┘ ┌───────────────┘
│ │
▼ ▼
┌──────────────────────────────┐ ┌──────────────────────┐
│ Method: Replication │ │ Method: Dump/Restore│
│ ───────────────── │ │ ──────────────── │
│ Replicate → Monitor → ... │ │ pg_dump → restore │
└──────────────┬───────────────┘ └──────────┬───────────┘
│ │
│ ┌──────────────────────────────┐ │
│ │ Method: Hybrid │ │
│ │ ───────────────── │ │
│ │ Replicate (PK tables) │ │
│ │ + pg_dump (non-replicable) │ │
│ └──────────────┬───────────────┘ │
│ │ │
└──────────┬───────┘────────────────────┘
│
▼
┌──────────────┐ ┌──────────────┐
│ VALIDATE │────▶│ CUTOVER │
│ │ │ │
│ • Row counts │ │ • Stop writes│
│ • Checksums │ │ • Switch DNS │
│ • pgCompare │ │ • Sync seqs │
└──────────────┘ └──────────────┘
Long-Running Phases
Use background agents only for read-mostly observation during long-running migration work: initial sync, long pg_dump / pg_restore, replica catch-up, or a short post-cutover soak check.
- Background agents are safe for monitoring, summarizing status, and surfacing alerts.
resume/SKILL.md remains the durable path for anything that may span hours, days, or a new session.
- Do not hand off state-changing or downtime-sensitive steps to background agents: credential setup, target create/reset, schema DDL, subscription create/drop, cutover, or rollback.
User Prompts Summary
| Step |
Prompt |
Options/Type |
| 1 |
Assessment |
Yes / No |
| 2 |
Migration Scope |
Single DB / Multiple DBs / All DBs |
| 2a |
Database Name (if single) |
Follow-up chat with exact name |
| 2b |
Database List (if multiple) |
Follow-up chat with exact names |
| 3 |
Schema Scope |
All schemas / Specific / Exclude |
| 4 |
Users/Roles |
Yes / No / Partial |
| 5 |
Method (if no assessment) |
Logical replication / pg_dump / Hybrid |
| 5 |
Method (if assessment done) |
Chosen at assess/SKILL.md approval checkpoint |
| 6 |
Connection Setup |
See references/connection-setup.md |
| If Hybrid |
Dump Timing |
Now (during migration) / At cutover (with sequences) |
| Any phase |
Pause |
Update state file, exit. Resume with "resume migration" |
| Any phase |
Repeat Phase |
Re-run a completed phase (e.g., validation before cutover) |
| Before Long Ops |
Monitor Progress |
Live dashboard / Manual / Background |
| After Migration |
Validation Method |
Row counts / Checksums / pgCompare (multi-select) |
CRITICAL: Each fixed-choice prompt uses ask_user_question - NEVER dump all questions as text.
Critical Migration Facts
Supported in Snowflake Postgres: 70+ extensions (pgvector, PostGIS, pg_cron, pglogical), logical replication as subscriber, standard PostgreSQL features.
Not supported / requires manual handling: See references/blockers-checklist.md for the full list of 21 blockers (unlogged tables, table inheritance, large objects, sequences, MVs, missing PKs, pgvector indexes, etc.) with detection queries and remediation steps. The assessment phase auto-detects all of these — assess/SKILL.md Step 4 produces the report.
Operational ordering for things logical replication does not carry:
- Users/Roles/Grants — migrate FIRST via
security/SKILL.md (uses pg_dumpall --globals-only). Required so dump ownership/grants resolve on the target.
- Sequences — sync as the FINAL cutover step via
cutover_tools.py sequences --execute.
- pgvector indexes — rebuild AFTER replication catches up (data replicates, IVFFlat/HNSW indexes do not).
Safety Rules
- MANDATORY PREFLIGHT CHECK before any migration: run
prepare_target.py preflight-check --schemas <list> to verify that target schemas (except public) do not already exist with objects. If they do, abort and ask the user to clean or choose a different target.
- MANDATORY CHECKPOINT after assessment - user must approve before migration
- MANDATORY CHECKPOINT before creating Snowflake Postgres instance (billable)
- MANDATORY CHECKPOINT before cutover (point of no return)
- MANDATORY CHECKPOINT before any destructive operation (DROP, TRUNCATE)
- Always verify network connectivity before starting replication
- Never expose connection credentials in chat
- Always have a rollback plan before cutover
Tool Usage Rules
- Prefer the Python migration helpers where available. Assessment, connectivity, validation, and replication setup are Python-based (
<SKILL_DIR>/migrate/scripts/ and <SKILL_DIR>/scripts/shared/), but dump/restore and some legacy operator workflows still require PostgreSQL client tools such as pg_dump, pg_restore, and psql.
- Always pass
--no-psqlrc (short form: -X) to every psql invocation in migration workflows. A user's ~/.psqlrc can silently flip AUTOCOMMIT, ON_ERROR_STOP, output format (\x, \pset, \timing), and aliases — any of which can corrupt heredocs, break output parsing in validation scripts, or leave DDL half-applied. Since PG 9.6, psql -c "..." no longer implies -X, so even one-liners need it explicitly. This applies to every form: psql -c, psql -f, psql <<EOF, and ... | psql. The flag is not needed for pg_dump / pg_restore / pg_dumpall (they don't read psqlrc).
- After assessment, ALWAYS generate the HTML report. Open it automatically when an interactive desktop/browser is available; otherwise provide the report path and summary.
run_assessment.py opens the report by default (pass --no-open to suppress for non-interactive runs; pass --open <file> to reopen an existing report without re-running).
- Python dependencies are managed by
uv via <SKILL_DIR>/pyproject.toml. The uv run --project <SKILL_DIR> python … invocations in this skill resolve psycopg2-binary and pg8000 automatically — no manual pip install or virtualenv setup required. Scripts call pg_common.check_driver() at entry and surface install guidance if the driver is missing.
Tools
Python Scripts
Full CLI reference with all flags, subcommands, and examples: see references/script-usage.md
Migration scripts (in migrate/scripts/)
| Script |
Purpose |
run_assessment.py |
Full assessment + HTML report (supports --schemas for scoped assessment) |
validate_migration.py |
Compare row counts, checksums, aggregates (handles materialized views separately) |
prepare_target.py |
Pre-restore target prep: preflight-check, extensions, check-data, clean-schemas |
cutover_tools.py |
Generate/execute sequence sync + trigger management |
setup_replication.py |
Safe-DSN CREATE/DROP SUBSCRIPTION wrapper — resolves source password from ~/.pgpass via --source-service, constructs DSN in-process, never leaks credentials to chat transcripts or shell history. Use instead of the legacy psql <<EOF ... password=$SOURCE_PGPASSWORD ... EOF heredoc pattern. |
migration_monitor.py |
Monitor replication lag, sync progress, dashboard |
migration_helpers.py |
PostGIS assessment, pgvector index rebuild, replication blocker detection, readiness check |
validate_schema_compatibility.py |
Pre-flight schema validation (extensions, types, indexes) |
generate_hybrid_plan.py |
Generate hybrid migration plan for mixed workloads |
post_migration_cleanup.py |
Tear down replication artifacts (subscriptions, publications, slots, test objects) — wired in by cutover/SKILL.md after final validation |
filter_vendor_dump.py |
Filter vendor-specific commands from pg_dump (Crunchy, RDS, Azure, GCP, Neon platform roles). Invoke via python or uv run python. Reads stdin or a positional input file; supports --stats and --verbose. |
Shared scripts (in scripts/shared/)
| Script |
Purpose |
pg_common.py |
Shared DB connection, query, arg-parsing, identifier-quoting utilities (used by every script above; includes venv detection) |
test_connectivity.py |
Test source/target connections + network path (DNS, TCP, auth, replication readiness, target→source via postgres_fdw) |
Sub-Skills
| Sub-Skill |
Purpose |
assess/ |
Pre-migration assessment and blocker detection |
replicate/ |
Logical replication setup (near-zero downtime) |
large-db/ |
Replica-assisted migration for very large databases |
dump-restore/ |
pg_dump/pg_restore workflow (offline) |
validate/ |
Post-migration validation (incl. pgCompare) |
security/ |
Users, roles, and permissions migration |
cutover/ |
Step-by-step cutover runbook |
rollback/ |
Rollback and failback strategies |
monitor/ |
Replication monitoring and alerting |
resume/ |
Track state and resume after interruption |
Reference Documents
| Reference |
Purpose |
references/connection-setup.md |
Connection configuration (Steps 5-9) |
references/connection-troubleshooting.md |
Auth methods, common errors |
references/command-logging.md |
Audit trail setup |
references/time-estimation.md |
Migration duration estimates |
references/instance-sizing.md |
Snowflake Postgres instance sizing recommendations based on source DB |
references/source-platform-guide.md |
Platform router — auto-detects source (RDS, Aurora, Azure, GCP, Heroku, Crunchy, Supabase, Neon, Aiven, on-prem) and points to the exact per-platform reference path in references/source-platforms/ |
references/blockers-checklist.md |
Migration blockers with detection queries |
references/complex-migrations.md |
Index: PostGIS, partitions, custom types, LOBs (split into 3 focused docs) |
references/complex-spatial-vector.md |
PostGIS spatial data and pgvector index migration |
references/complex-schema-objects.md |
Partitions, inheritance, functions, triggers, custom types, FTS, JSON, LOBs |
references/complex-migration-strategies.md |
Unlogged tables, hybrid migration, audit script, PgBouncer, app compat |
references/migration-overview.md |
Architecture and concepts |
references/lessons-learned.md |
Real-world issues and solutions from migrations |
dump-restore/references/dump-commands.md |
Detailed pg_dump commands and monitoring |
dump-restore/references/restore-commands.md |
Detailed pg_restore, post-tasks, sequences |
replicate/references/subscription-management.md |
Publication and subscription setup |
replicate/references/initial-sync.md |
Initial sync monitoring and management |
replicate/references/cutover-sequence.md |
Cutover, validation, and sequence sync |
validate/references/validate-row-counts.md |
Row count validation procedures |
validate/references/validate-checksum.md |
Checksum-based validation |
validate/references/validate-snowconvert.md |
SnowConvert SQL validation |
validate/references/validate-pgcompare.md |
pgCompare data comparison |
validate/references/validate-sample-data.md |
Sample data row comparison |
validate/references/validate-aggregation.md |
Aggregate value comparison |
large-db/references/platform-specific.md |
Large DB platform-specific instructions |
large-db/references/rds-parquet-export.md |
RDS S3 Parquet export with pg_lake |
Common Pitfalls to Avoid
| Pitfall |
Prevention |
| No rollback plan |
Setup reverse replication BEFORE cutover |
| Forgot scheduled jobs |
Audit ALL database consumers |
| ORM cache issues |
Restart apps after DNS switch |
| Replication slot WAL bloat |
Monitor slots, drop orphaned ones |
| Sequence values not synced |
Run sequence sync as FINAL step |
| Forgot users/roles |
Ask if roles should be migrated; if yes, migrate FIRST |
| Network rules not configured |
Configure EGRESS rules BEFORE creating subscription |
| Schema not copied before subscription |
Run pg_dump --schema-only BEFORE creating subscription |
| Vendor-specific pg_dump errors |
Filter Crunchy/RDS/Azure commands from pg_dump output |
| CREATE SUBSCRIPTION in transaction |
Use heredoc or -f file, not psql -c flag |
Troubleshooting
For connection issues, see references/connection-troubleshooting.md.
Network Connectivity Issues (Logical Replication)
Error: "could not connect to publisher"
→ Snowflake Postgres cannot reach the source. Check:
- Network rules on Snowflake Postgres allow egress to source host:port
- Source firewall/security groups allow ingress from Snowflake Postgres
- Source
pg_hba.conf allows replication connections
To configure network rules for Snowflake Postgres egress:
⚠️ MANDATORY: Always confirm with the user before creating or modifying any network rules or network policies. Show the exact SQL that will be executed and wait for explicit approval.
⚠️ CRITICAL: Snowflake Postgres egress rules MUST use:
TYPE = IPV4 (NOT HOST_PORT)
MODE = POSTGRES_EGRESS (NOT EGRESS)
-- Step 1: Resolve source hostname to IP address
-- Run: dig +short source-host.example.com
-- Example result: 3.150.49.165
-- Step 2: Create network rule with POSTGRES_EGRESS mode and IPV4 type
CREATE OR REPLACE NETWORK RULE <database>.<schema>.migration_egress_rule
TYPE = IPV4
VALUE_LIST = ('3.150.49.165/32')
MODE = POSTGRES_EGRESS
COMMENT = 'Egress to source PostgreSQL for migration';
-- Step 3: Add rule to existing network policy attached to Postgres instance
ALTER NETWORK POLICY <your_network_policy> SET
ALLOWED_NETWORK_RULE_LIST = (
<existing_ingress_rules>,
<database>.<schema>.migration_egress_rule
);
Common mistakes:
- Using
TYPE = HOST_PORT → Will fail, must use TYPE = IPV4
- Using
MODE = EGRESS → Will fail, must use MODE = POSTGRES_EGRESS
- Using hostname instead of IP → Resolve with
dig +short first
Other Common Errors
| Error |
Solution |
| "table does not have a REPLICA IDENTITY" |
Add primary key or set REPLICA IDENTITY FULL |
| "permission denied for replication" |
ALTER ROLE user REPLICATION; |
| "wal_level must be logical" |
Set wal_level = logical and restart |
| Replication lag increasing |
Check network bandwidth, target instance size |
| WAL directory filling up |
Check for inactive replication slots |
Output
Routes to the appropriate sub-skill and guides through complete migration workflow.
1---2name: migrate3description: "Migrate PostgreSQL databases to Snowflake Postgres. **[REQUIRED]** Use for ALL pg migration tasks including: pg migration, migrate postgres, replicate to snowflake postgres, pg_dump migration, logical replication setup, migration assessment, data validation, cutover planning, rollback strategy, postgres sync, database move, pg transfer, copy postgres data. Triggers: migrate postgres, pg migration, postgres to snowflake, replication setup, migration readiness, cutover plan, rollback plan, move my postgres, sync databases, transfer postgres, copy from postgres, postgres dump, pg_restore, migrate from RDS, migrate from Aurora, migrate from Azure postgres, migrate from Cloud SQL."4parent_skill: snowflake-postgres5metadata:6 source: https://skillmd.com/skills/s-14-h/migrate7---89# PostgreSQL to Snowflake Postgres Migration1011> **Windows users:** see [references/windows.md](../references/windows.md) — install prereqs, credential file paths (`%APPDATA%\postgresql\` instead of `~/`), and command-flow notes differ on native Windows. WSL behaves as Linux.1213## When to Use1415When migrating any PostgreSQL database to Snowflake Postgres:16- On-premises PostgreSQL → Snowflake Postgres17- Cloud PostgreSQL (RDS, Aurora, Cloud SQL, Azure, Crunchy Bridge, Neon, Supabase) → Snowflake Postgres18- Self-managed PostgreSQL → Snowflake Postgres1920> **Credentials — always use service names, never passwords in chat.**21> Passwords should end up in `~/.pgpass`, referenced by a profile in `~/.pg_service.conf`, so standard PostgreSQL tools (`psql`, `pg_dump`, `pg_restore`, `pg_dumpall`) keep working. In chat-safe setup flows, gather only non-secret fields in chat, direct the user to `/secrets` for the password, then register the profile so the password is written into `~/.pgpass` without appearing in chat or process argv. Pass `--source-service <NAME>` / `--target-service <NAME>` to every migration script invocation — never `--password <pw>` or `-W <pw>` in chat.22>23> - Register a Snowflake Postgres **target** profile once: `uv run --project <SKILL_DIR> python <SKILL_DIR>/scripts/pg_connect.py --create --instance-name <NAME> --compute-pool <COMPUTE_FAMILY> --storage <GB>` (also fetches the CA cert and saves the profile under the lowercased instance name). `--role` is for `--reset` only — `--create` provisions all roles automatically. To run the SQL with an elevated Snowflake role, pass `--use-role ACCOUNTADMIN` (session-scoped, not persisted). For valid compute families, storage bounds, and HA restrictions, see `../references/instance-options.md`.24> - Register a non-Snowflake **source** profile once: collect `host` / `port` / `dbname` / `user` / `sslmode` in chat, have the user add the password via `/secrets`, then run `uv run --project <SKILL_DIR> python <SKILL_DIR>/scripts/shared/pg_common.py --add-source-service <NAME> --host ... --port ... --dbname ... --user ... [--sslmode ...]`. `pg_common.py` accepts the password from agent-injected env vars as well as `--password`, so the chat-safe path still lands the secret in `~/.pgpass`. Trusted-shell fallback: rerun the same command once outside chat with `--password ...`. `pg_common.py` is invoked as a script because it isn't packaged as an importable module at the project root; the file's `__main__` block dispatches the CLI directly.25>26> After profiles exist, every migration script invocation looks like `… --source-service prod_source --target-service sf_target …` with no password material in sight.2728## Helper: `setup_connection` shell function2930Several legacy reference docs (under `replicate/`, `dump-restore/`, `rollback/`, `validate/references/`) include `psql` examples that begin with `setup_connection "SOURCE"` or `setup_connection "TARGET"`. That is a small shell helper that exports `PG*` env vars from the prefixed `SOURCE_PG*` / `TARGET_PG*` ones. The function definition lives in `migrate/references/pg_migration_env.template` alongside the env-var template — copy the template to `~/.pg_migration_env`, fill it in, and `source` it once per shell session to make every legacy example runnable.3132In **chat-safe workflows you don't need this helper at all** — prefer the Python scripts under `migrate/scripts/` with `--source-service` / `--target-service` flags, which never touch `PGPASSWORD` and never echo credentials.3334## First Question: Interactive Scope Gathering3536**MANDATORY: Use `ask_user_question` for each fixed-choice step. Do NOT present all questions as a wall of text. For exact identifiers (database names, file paths), ask in normal chat after the relevant choice, or use the tool's automatic "Something else" path if available.**3738### Step 1: Ask About Assessment3940```41question: "Would you like to run a migration assessment first?"42header: "Assessment"43options:44 - label: "Yes"45 description: "Analyze the source database for blockers, complexity, and recommended method before migrating"46 - label: "No"47 description: "I already know my migration approach — skip straight to setup"48```4950**If Yes** → Gather connection details (Step 1a), then load `assess/SKILL.md`. The assessment will recommend a method and present it at its approval checkpoint. After the user approves a method, proceed to Step 2 (scope).51**If No** → Skip assessment entirely. Proceed to Step 2 (scope), then ask for method directly at Step 5.5253### Step 1a: Get Source Connection (if Assessment)5455Load `references/connection-setup.md` to gather source connection details.5657For assessment-first workflows, the first connection question should make the existing-connection path obvious:58- `Saved connection` means "I already have a saved source connection"59- `Enter source details now` means "register a new source profile now"60- `Legacy environment file` is the fallback for older shell-based workflows6162If the user already has a saved source connection, **list saved connections first and let them pick**. Do not send them to inspect `~/.pg_service.conf` manually unless the picker path fails. If the user provides raw host / port / dbname / user values instead of an existing saved connection, direct them to `/secrets` for the password, register a source profile so the password lands in `~/.pgpass`, then run assessment via `assess/SKILL.md`.6364**Do not ask about target instance existence, target profiles, or billable target creation during assessment intake.** Assessment presents findings and recommends a method at its approval checkpoint (assess/SKILL.md Step 4). The user selects the method there, and only then do target-creation / billable questions become relevant.6566### Step 2: Ask What to Migrate6768**IMPORTANT:** Even if the user has a database specified in their environment file or connection string, always confirm which database(s) to migrate. Do not assume the env variable is the correct or only target.6970```71question: "What would you like to migrate to Snowflake Postgres?"72header: "Scope"73options:74 - label: "Single database"75 description: "Migrate one specific database"76 - label: "Multiple databases"77 description: "Migrate a specific list of databases"78 - label: "All databases"79 description: "Migrate the entire cluster"80```8182**Based on response:**83- **Single database** → Ask for database name (Step 2a), even if one is already set in the environment84- **Multiple databases** → Ask for list of database names (Step 2b)85- **All databases** → Note will use `pg_dumpall`8687### Step 2a: Get Database Name (if Single)8889Ask for the exact database name in normal chat after the user chooses **Single database**. Do not use unsupported free-text question fields here.9091### Step 2b: Get Database List (if Multiple)9293Ask the user to send the exact database names in normal chat after they choose **Multiple databases** (comma-separated or one per line). Do not use unsupported free-text question fields here.9495### Step 3: Ask About Schema Scope9697```98question: "Which schemas should be migrated?"99header: "Schemas"100options:101 - label: "All schemas"102 description: "Migrate all user schemas (default)"103 - label: "Specific schemas"104 description: "Only migrate selected schemas"105 - label: "Exclude schemas"106 description: "Migrate all except certain schemas"107```108109### Step 4: Ask About Users/Roles110111```112question: "Should users, roles, and grants be migrated?"113header: "Roles"114options:115 - label: "Yes (recommended)"116 description: "Migrate using pg_dumpall --globals-only"117 - label: "No"118 description: "Roles already exist or managed separately"119 - label: "Partial"120 description: "Only specific roles"121```122123**Based on response:**124- **Yes / Partial** → Load `security/SKILL.md` and run that workflow FIRST,125 before any data migration. Roles must exist on the target before126 ownership/grants in the data dump can resolve. Return here after127 `security/SKILL.md` completes.128- **No** → Continue to Step 5.129130**Notes:** Cloud-managed roles (`rds_*`, `azure_*`, `cloudsql*`) cannot be131migrated and are filtered out by `filter_vendor_dump.py`.132133### Step 5: Ask About Method (if assessment was skipped)134135Only ask this if the user chose **No** at Step 1 (no assessment).136137```138question: "Which migration method do you want to use?"139header: "Method"140options:141 - label: "Logical replication"142 description: "Near-zero downtime. Requires PG 10+, tables with primary keys, network connectivity (target→source)"143 - label: "pg_dump/pg_restore"144 description: "Offline migration. Requires a downtime window. Simplest approach."145 - label: "Hybrid"146 description: "Logical replication for qualifying tables + pg_dump for non-replicable objects (unlogged, no PK, inheritance)"147 - label: "postgres_fdw"148 description: "Foreign data wrapper. Target queries source directly via SQL. Good for selective/filtered migration or as alternative to pg_dump in hybrid."149 - label: "Replica-assisted (large DB)"150 description: "For databases >= 2 TB or RDS/Aurora with S3 Parquet export + pg_lake. Replica handles initial load; logical replication catches up."151```152153**Based on response:**154- **Logical replication** → Load `replicate/SKILL.md`155- **pg_dump/pg_restore** → Load `dump-restore/SKILL.md`156- **Hybrid** → Investigate/classify actual objects first (and review inheritance semantics if present), then ask dump timing and execute the phased plan (see `assess/SKILL.md` Step 5 for details)157- **postgres_fdw** → See `references/complex-migration-strategies.md` (postgres_fdw section). Can also be used within Hybrid instead of pg_dump.158- **Replica-assisted (large DB)** → Load `large-db/SKILL.md`159160**Auto-route to LARGE-DB** when ANY of these are detected without asking:161- User mentions "TB", "terabyte", "large database", "very large", "S3 export"162- Source is RDS/Aurora and database size > 2 TB163- Assessment reports `total_size_bytes >= 2_000_000_000_000`164165If assessment **was** performed, the method was already chosen at the assessment approval checkpoint — skip this step.166167### Step 6: Proceed to Connection Setup168169After gathering scope and method, load `references/connection-setup.md` for connection setup, then proceed to the chosen migration method sub-skill.170171## Setup172173> Need **continuous managed replication from Snowflake Postgres into Snowflake tables** via `SNOWFLAKE.POSTGRES.CREATE_MIRROR`, `$live`, or `$changes`? That is owned by `../mirror/SKILL.md`, not this migration skill. Use `migrate/` for one-time or cutover-oriented moves into Snowflake Postgres.1741751. **Load** `references/migration-overview.md` for architecture context1762. **Load** `references/blockers-checklist.md` for common migration blockers177178## Intent Detection179180| Intent | Trigger Phrases | Route |181|--------|-----------------|-------|182| **ASSESS** | "migration readiness", "check blockers", "assessment" | Load `assess/SKILL.md` |183| **REPLICATE** | "logical replication", "live sync", "near-zero downtime" | Load `replicate/SKILL.md` |184| **LARGE-DB** | "large database", "terabyte migration", "TB", "S3 export", "RDS Parquet export", "very large", "2TB", "5TB", "fast initial load", "replica-assisted" | Load `large-db/SKILL.md` |185| **DUMP** | "pg_dump", "dump and restore", "offline migration" | Load `dump-restore/SKILL.md` |186| **VALIDATE** | "validate migration", "data validation", "pgcompare" | Load `validate/SKILL.md` |187| **SECURITY** | "migrate users", "migrate roles", "grants", "RBAC" | Load `security/SKILL.md` |188| **CUTOVER** | "cutover plan", "go-live", "switch over" | Load `cutover/SKILL.md` |189| **ROLLBACK** | "rollback plan", "failback", "reverse migration" | Load `rollback/SKILL.md` |190| **MONITOR** | "monitor replication", "check lag", "replication status" | Load `monitor/SKILL.md` |191| **RESUME** | "resume migration", "continue migration", "where did I leave off" | Load `resume/SKILL.md` |192| **PAUSE** | "pause migration", "stop after this phase", "save progress" | Load `resume/SKILL.md` (pause workflow) |193| **REPEAT** | "repeat phase", "re-run validation", "redo pg_dump", "run phase again" | Load `resume/SKILL.md` (repeat workflow) |194| **PLATFORM** | "migrate from RDS", "migrate from Aurora", "migrate from Azure", "migrate from Cloud SQL", "migrate from Heroku", "migrate from Crunchy Bridge", "migrate from Supabase", "migrate from Neon", "migrate from Aiven", "on-prem postgres" | Load `references/source-platform-guide.md` (router that auto-detects platform and points to the exact per-platform file to read; do not derive filenames from the platform display name) |195| **FULL** | "full migration", "end-to-end migration" | Start with `assess/SKILL.md` |196| **FALLBACK** | (no match above) | Ask user to clarify intent, then route |197198## Migration Methods199200### 1. Logical Replication (Near-Zero Downtime)201- Best for: Production databases requiring minimal downtime202- Requirements: PostgreSQL 10+ source, tables with primary keys, network connectivity (Target→Source)203- Process: Network verify → Live sync → Cutover → Validation204205### 2. pg_dump/pg_restore (Offline)206- Best for: Development/staging, smaller databases, simple migrations207- Requirements: Downtime window available208- Process: Dump → Transfer → Restore → Validation209210### 3. Direct COPY (Bulk Transfer)211- Best for: Individual tables, data refresh scenarios212- Requirements: Network connectivity between source and target213214### 4. RDS S3 Parquet Export + pg_lake (AWS Only)215- Best for: Very large RDS/Aurora databases (200GB+)216- Requirements: pg_lake extension, S3 bucket, IAM roles217218### 5. Hybrid Migration (Mixed Workloads)219- Best for: Databases with mix of replicable and non-replicable objects220- Use when: Unlogged tables, table inheritance, tables without PKs that cannot be modified221- Process: Logical replication for qualifying tables + pg_dump for blockers222- Tool: `<SKILL_DIR>/migrate/scripts/generate_hybrid_plan.py` generates phased plan223224**For time estimates, see `references/time-estimation.md`**225226## Workflow Overview227228```229┌─────────────┐ ┌─────────────────────┐ ┌──────────────┐ ┌──────────────┐230│ SCOPE CHECK │────▶│ ASSESS │────▶│ APPROVAL │────▶│ SECURITY │231│ │ │ │ │ │ │ (if opted) │232│ • Database? │ │ • Blockers │ │ Review │ │ │233│ • Schemas? │ │ • Size │ │ findings │ │ • Roles │234│ • Roles? │ │ • Features │ │ Choose method│ │ • Grants │235└─────────────┘ └─────────────────────┘ └──────┬───────┘ └──────┬───────┘236 │ │237 ┌──────────────────────────────────┘ ┌───────────────┘238 │ │239 ▼ ▼240 ┌──────────────────────────────┐ ┌──────────────────────┐241 │ Method: Replication │ │ Method: Dump/Restore│242 │ ───────────────── │ │ ──────────────── │243 │ Replicate → Monitor → ... │ │ pg_dump → restore │244 └──────────────┬───────────────┘ └──────────┬───────────┘245 │ │246 │ ┌──────────────────────────────┐ │247 │ │ Method: Hybrid │ │248 │ │ ───────────────── │ │249 │ │ Replicate (PK tables) │ │250 │ │ + pg_dump (non-replicable) │ │251 │ └──────────────┬───────────────┘ │252 │ │ │253 └──────────┬───────┘────────────────────┘254 │255 ▼256 ┌──────────────┐ ┌──────────────┐257 │ VALIDATE │────▶│ CUTOVER │258 │ │ │ │259 │ • Row counts │ │ • Stop writes│260 │ • Checksums │ │ • Switch DNS │261 │ • pgCompare │ │ • Sync seqs │262 └──────────────┘ └──────────────┘263```264265## Long-Running Phases266267Use background agents only for **read-mostly observation** during long-running migration work: initial sync, long `pg_dump` / `pg_restore`, replica catch-up, or a short post-cutover soak check.268269- **Background agents are safe for monitoring, summarizing status, and surfacing alerts.**270- **`resume/SKILL.md` remains the durable path** for anything that may span hours, days, or a new session.271- **Do not hand off state-changing or downtime-sensitive steps** to background agents: credential setup, target create/reset, schema DDL, subscription create/drop, cutover, or rollback.272273## User Prompts Summary274275| Step | Prompt | Options/Type |276|------|--------|--------------|277| 1 | **Assessment** | Yes / No |278| 2 | **Migration Scope** | Single DB / Multiple DBs / All DBs |279| 2a | Database Name (if single) | Follow-up chat with exact name |280| 2b | Database List (if multiple) | Follow-up chat with exact names |281| 3 | **Schema Scope** | All schemas / Specific / Exclude |282| 4 | **Users/Roles** | Yes / No / Partial |283| 5 | **Method** (if no assessment) | Logical replication / pg_dump / Hybrid |284| 5 | **Method** (if assessment done) | Chosen at assess/SKILL.md approval checkpoint |285| 6 | **Connection Setup** | See `references/connection-setup.md` |286| If Hybrid | **Dump Timing** | Now (during migration) / At cutover (with sequences) |287| Any phase | **Pause** | Update state file, exit. Resume with "resume migration" |288| Any phase | **Repeat Phase** | Re-run a completed phase (e.g., validation before cutover) |289| Before Long Ops | **Monitor Progress** | Live dashboard / Manual / Background |290| After Migration | **Validation Method** | Row counts / Checksums / pgCompare (multi-select) |291292**CRITICAL: Each fixed-choice prompt uses `ask_user_question` - NEVER dump all questions as text.**293294## Critical Migration Facts295296**Supported in Snowflake Postgres:** 70+ extensions (pgvector, PostGIS, pg_cron, pglogical), logical replication as subscriber, standard PostgreSQL features.297298**Not supported / requires manual handling:** See [`references/blockers-checklist.md`](references/blockers-checklist.md) for the full list of 21 blockers (unlogged tables, table inheritance, large objects, sequences, MVs, missing PKs, pgvector indexes, etc.) with detection queries and remediation steps. The **assessment phase auto-detects all of these** — `assess/SKILL.md` Step 4 produces the report.299300**Operational ordering for things logical replication does not carry:**301- **Users/Roles/Grants** — migrate FIRST via `security/SKILL.md` (uses `pg_dumpall --globals-only`). Required so dump ownership/grants resolve on the target.302- **Sequences** — sync as the FINAL cutover step via `cutover_tools.py sequences --execute`.303- **pgvector indexes** — rebuild AFTER replication catches up (data replicates, IVFFlat/HNSW indexes do not).304305## Safety Rules306307- **MANDATORY PREFLIGHT CHECK** before any migration: run `prepare_target.py preflight-check --schemas <list>` to verify that target schemas (except `public`) do not already exist with objects. If they do, abort and ask the user to clean or choose a different target.308- **MANDATORY CHECKPOINT** after assessment - user must approve before migration309- **MANDATORY CHECKPOINT** before creating Snowflake Postgres instance (billable)310- **MANDATORY CHECKPOINT** before cutover (point of no return)311- **MANDATORY CHECKPOINT** before any destructive operation (DROP, TRUNCATE)312- Always verify network connectivity before starting replication313- Never expose connection credentials in chat314- **Always have a rollback plan before cutover**315316## Tool Usage Rules317318- **Prefer the Python migration helpers where available.** Assessment, connectivity, validation, and replication setup are Python-based (`<SKILL_DIR>/migrate/scripts/` and `<SKILL_DIR>/scripts/shared/`), but dump/restore and some legacy operator workflows still require PostgreSQL client tools such as `pg_dump`, `pg_restore`, and `psql`.319- **Always pass `--no-psqlrc` (short form: `-X`) to every `psql` invocation in migration workflows.** A user's `~/.psqlrc` can silently flip `AUTOCOMMIT`, `ON_ERROR_STOP`, output format (`\x`, `\pset`, `\timing`), and aliases — any of which can corrupt heredocs, break output parsing in validation scripts, or leave DDL half-applied. Since PG 9.6, `psql -c "..."` no longer implies `-X`, so even one-liners need it explicitly. This applies to every form: `psql -c`, `psql -f`, `psql <<EOF`, and `... | psql`. The flag is not needed for `pg_dump` / `pg_restore` / `pg_dumpall` (they don't read `psqlrc`).320- **After assessment, ALWAYS generate the HTML report.** Open it automatically when an interactive desktop/browser is available; otherwise provide the report path and summary. `run_assessment.py` opens the report by default (pass `--no-open` to suppress for non-interactive runs; pass `--open <file>` to reopen an existing report without re-running).321- **Python dependencies** are managed by `uv` via `<SKILL_DIR>/pyproject.toml`. The `uv run --project <SKILL_DIR> python …` invocations in this skill resolve `psycopg2-binary` and `pg8000` automatically — no manual `pip install` or virtualenv setup required. Scripts call `pg_common.check_driver()` at entry and surface install guidance if the driver is missing.322323## Tools324325### Python Scripts326327> **Full CLI reference with all flags, subcommands, and examples:** see [`references/script-usage.md`](references/script-usage.md)328329#### Migration scripts (in `migrate/scripts/`)330331| Script | Purpose |332|--------|---------|333| `run_assessment.py` | Full assessment + HTML report (supports `--schemas` for scoped assessment) |334| `validate_migration.py` | Compare row counts, checksums, aggregates (handles materialized views separately) |335| `prepare_target.py` | Pre-restore target prep: preflight-check, extensions, check-data, clean-schemas |336| `cutover_tools.py` | Generate/execute sequence sync + trigger management |337| `setup_replication.py` | **Safe-DSN CREATE/DROP SUBSCRIPTION wrapper** — resolves source password from `~/.pgpass` via `--source-service`, constructs DSN in-process, never leaks credentials to chat transcripts or shell history. Use instead of the legacy `psql <<EOF ... password=$SOURCE_PGPASSWORD ... EOF` heredoc pattern. |338| `migration_monitor.py` | Monitor replication lag, sync progress, dashboard |339| `migration_helpers.py` | PostGIS assessment, pgvector index rebuild, replication blocker detection, readiness check |340| `validate_schema_compatibility.py` | Pre-flight schema validation (extensions, types, indexes) |341| `generate_hybrid_plan.py` | Generate hybrid migration plan for mixed workloads |342| `post_migration_cleanup.py` | Tear down replication artifacts (subscriptions, publications, slots, test objects) — wired in by `cutover/SKILL.md` after final validation |343| `filter_vendor_dump.py` | Filter vendor-specific commands from pg_dump (Crunchy, RDS, Azure, GCP, Neon platform roles). Invoke via `python` or `uv run python`. Reads stdin or a positional input file; supports `--stats` and `--verbose`. |344345#### Shared scripts (in `scripts/shared/`)346347| Script | Purpose |348|--------|---------|349| `pg_common.py` | Shared DB connection, query, arg-parsing, identifier-quoting utilities (used by every script above; includes venv detection) |350| `test_connectivity.py` | Test source/target connections + network path (DNS, TCP, auth, replication readiness, target→source via postgres_fdw) |351352### Sub-Skills353354| Sub-Skill | Purpose |355|-----------|---------|356| `assess/` | Pre-migration assessment and blocker detection |357| `replicate/` | Logical replication setup (near-zero downtime) |358| `large-db/` | Replica-assisted migration for very large databases |359| `dump-restore/` | pg_dump/pg_restore workflow (offline) |360| `validate/` | Post-migration validation (incl. pgCompare) |361| `security/` | Users, roles, and permissions migration |362| `cutover/` | Step-by-step cutover runbook |363| `rollback/` | Rollback and failback strategies |364| `monitor/` | Replication monitoring and alerting |365| `resume/` | Track state and resume after interruption |366367### Reference Documents368369| Reference | Purpose |370|-----------|---------|371| `references/connection-setup.md` | Connection configuration (Steps 5-9) |372| `references/connection-troubleshooting.md` | Auth methods, common errors |373| `references/command-logging.md` | Audit trail setup |374| `references/time-estimation.md` | Migration duration estimates |375| `references/instance-sizing.md` | Snowflake Postgres instance sizing recommendations based on source DB |376| `references/source-platform-guide.md` | Platform router — auto-detects source (RDS, Aurora, Azure, GCP, Heroku, Crunchy, Supabase, Neon, Aiven, on-prem) and points to the exact per-platform reference path in `references/source-platforms/` |377| `references/blockers-checklist.md` | Migration blockers with detection queries |378| `references/complex-migrations.md` | Index: PostGIS, partitions, custom types, LOBs (split into 3 focused docs) |379| `references/complex-spatial-vector.md` | PostGIS spatial data and pgvector index migration |380| `references/complex-schema-objects.md` | Partitions, inheritance, functions, triggers, custom types, FTS, JSON, LOBs |381| `references/complex-migration-strategies.md` | Unlogged tables, hybrid migration, audit script, PgBouncer, app compat |382| `references/migration-overview.md` | Architecture and concepts |383| `references/lessons-learned.md` | Real-world issues and solutions from migrations |384| `dump-restore/references/dump-commands.md` | Detailed pg_dump commands and monitoring |385| `dump-restore/references/restore-commands.md` | Detailed pg_restore, post-tasks, sequences |386| `replicate/references/subscription-management.md` | Publication and subscription setup |387| `replicate/references/initial-sync.md` | Initial sync monitoring and management |388| `replicate/references/cutover-sequence.md` | Cutover, validation, and sequence sync |389| `validate/references/validate-row-counts.md` | Row count validation procedures |390| `validate/references/validate-checksum.md` | Checksum-based validation |391| `validate/references/validate-snowconvert.md` | SnowConvert SQL validation |392| `validate/references/validate-pgcompare.md` | pgCompare data comparison |393| `validate/references/validate-sample-data.md` | Sample data row comparison |394| `validate/references/validate-aggregation.md` | Aggregate value comparison |395| `large-db/references/platform-specific.md` | Large DB platform-specific instructions |396| `large-db/references/rds-parquet-export.md` | RDS S3 Parquet export with pg_lake |397398## Common Pitfalls to Avoid399400| Pitfall | Prevention |401|---------|------------|402| No rollback plan | Setup reverse replication BEFORE cutover |403| Forgot scheduled jobs | Audit ALL database consumers |404| ORM cache issues | Restart apps after DNS switch |405| Replication slot WAL bloat | Monitor slots, drop orphaned ones |406| Sequence values not synced | **Run sequence sync as FINAL step** |407| Forgot users/roles | **Ask if roles should be migrated; if yes, migrate FIRST** |408| Network rules not configured | **Configure EGRESS rules BEFORE creating subscription** |409| Schema not copied before subscription | **Run pg_dump --schema-only BEFORE creating subscription** |410| Vendor-specific pg_dump errors | **Filter Crunchy/RDS/Azure commands from pg_dump output** |411| CREATE SUBSCRIPTION in transaction | **Use heredoc or -f file, not psql -c flag** |412413## Troubleshooting414415For connection issues, see `references/connection-troubleshooting.md`.416417### Network Connectivity Issues (Logical Replication)418419**Error: "could not connect to publisher"**420→ Snowflake Postgres cannot reach the source. Check:4211. Network rules on Snowflake Postgres allow egress to source host:port4222. Source firewall/security groups allow ingress from Snowflake Postgres4233. Source `pg_hba.conf` allows replication connections424425**To configure network rules for Snowflake Postgres egress:**426427**⚠️ MANDATORY: Always confirm with the user before creating or modifying any network rules or network policies. Show the exact SQL that will be executed and wait for explicit approval.**428429⚠️ **CRITICAL**: Snowflake Postgres egress rules MUST use:430- `TYPE = IPV4` (NOT `HOST_PORT`)431- `MODE = POSTGRES_EGRESS` (NOT `EGRESS`)432433```sql434-- Step 1: Resolve source hostname to IP address435-- Run: dig +short source-host.example.com436-- Example result: 3.150.49.165437438-- Step 2: Create network rule with POSTGRES_EGRESS mode and IPV4 type439CREATE OR REPLACE NETWORK RULE <database>.<schema>.migration_egress_rule440 TYPE = IPV4441 VALUE_LIST = ('3.150.49.165/32')442 MODE = POSTGRES_EGRESS443 COMMENT = 'Egress to source PostgreSQL for migration';444445-- Step 3: Add rule to existing network policy attached to Postgres instance446ALTER NETWORK POLICY <your_network_policy> SET447 ALLOWED_NETWORK_RULE_LIST = (448 <existing_ingress_rules>,449 <database>.<schema>.migration_egress_rule450 );451```452453**Common mistakes:**454- Using `TYPE = HOST_PORT` → Will fail, must use `TYPE = IPV4`455- Using `MODE = EGRESS` → Will fail, must use `MODE = POSTGRES_EGRESS`456- Using hostname instead of IP → Resolve with `dig +short` first457458### Other Common Errors459460| Error | Solution |461|-------|----------|462| "table does not have a REPLICA IDENTITY" | Add primary key or set `REPLICA IDENTITY FULL` |463| "permission denied for replication" | `ALTER ROLE user REPLICATION;` |464| "wal_level must be logical" | Set `wal_level = logical` and restart |465| Replication lag increasing | Check network bandwidth, target instance size |466| WAL directory filling up | Check for inactive replication slots |467468## Output469470Routes to the appropriate sub-skill and guides through complete migration workflow.