This page describes how to confirm that your migrated data is complete and
accurate. At a minimum, you should verify that your databases and tables exist in the
migrated AlloyDB for PostgreSQL cluster.

1. Connect to your AlloyDB for PostgreSQL cluster with a client or query tool where you can run SQL commands against your migrated databases (for example, AlloyDB Studio in the Google Cloud console or `psql`).

   For more information on connecting to AlloyDB for PostgreSQL clusters and instances, see
   [AlloyDB for PostgreSQL connection overview](https://docs.cloud.google.com/alloydb/docs/connection-overview.md.txt).
2. Run client-agnostic ANSI SQL queries to verify your migrated data:

   #### List all databases

   Run the following query to verify that your destination AlloyDB for PostgreSQL cluster
   contains all the source databases you migrated:

   ```sql
   SELECT datname FROM pg_database
   WHERE datistemplate = false;
   ```

   #### List all tables in a database

   Run the following query to list all user tables in your database:

   ```sql
   SELECT table_schema, table_name
   FROM information_schema.tables
   WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
     AND table_type = 'BASE TABLE'
   ORDER BY table_schema, table_name;
   ```

   #### Check table column definitions and data types

   Run the following query to verify the column names, data types, and nullability
   for a specific table:

   ```sql
   SELECT
     column_name,
     data_type,
     character_maximum_length,
     is_nullable,
     column_default
   FROM information_schema.columns
   WHERE table_name = 'TABLE_NAME'
   ORDER BY ordinal_position;
   ```

   #### Check table row counts and sample data

   Run the following queries to verify row counts and inspect sample rows
   in a specific table:
   1. Verify the total row count:

      ```sql
      SELECT COUNT(*) FROM TABLE_NAME;
      ```
   2. View a sample of migrated records:

      ```sql
      SELECT * FROM TABLE_NAME LIMIT 10;
      ```

   #### Verify primary keys and constraints

   Run the following query to verify that primary keys, foreign keys, and unique
   constraints were created correctly:

   ```sql
   SELECT
     table_schema,
     table_name,
     constraint_name,
     constraint_type
   FROM information_schema.table_constraints
   WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
   ORDER BY table_schema, table_name, constraint_type;
   ```

   #### Verify indexes

   Run the following query to verify that indexes were created on your migrated tables:

   ```sql
   SELECT
     schemaname,
     tablename,
     indexname,
     indexdef
   FROM pg_indexes
   WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
   ORDER BY schemaname, tablename, indexname;
   ```

   #### Verify sequences

   Run the following query to verify that sequences exist in your migrated database:

   ```sql
   SELECT
     sequence_schema,
     sequence_name,
     data_type
   FROM information_schema.sequences
   ORDER BY sequence_schema, sequence_name;
   ```
3. Compare the results of these queries with your source database to ensure that all objects, row counts, and schema structures match.

For large tables where running `COUNT(*)` queries might be resource-intensive,
consider using the open-source
[Data Validation Tool (DVT)](https://github.com/GoogleCloudPlatform/professional-services-data-validator). It provides an automated and repeatable
method to perform custom validations across different environments.

If everything you check is as you expect, then Database Migration Service has migrated the data correctly.