Adding data to a source Aurora DB cluster and querying it in Amazon S3 Tables
This is preview documentation for the Aurora PostgreSQL integration with Amazon S3
Tables. Before using this capability, review the Betas and Previews terms in
the AWS Service
Terms
After an Aurora PostgreSQL integration with Amazon S3 Tables has a status of active,
you continue to write data to the source DB cluster as usual. You query the replicated data in
the target table bucket.
Topics
Adding data to the source DB cluster
Connect to the source DB cluster and write data as you normally would. For instructions, see Connecting to an Amazon Aurora DB cluster.
The integration captures inserts, updates, and deletes on replicated tables and applies them to the target tables. A change appears in the target within a few minutes. For more information, see How replication works.
Make sure that each table that you want to replicate has a primary key that meets
the requirements in Aurora PostgreSQL table limitations.
Otherwise, the table enters the FAILED state and is not
replicated.
To find the tables that do not have a primary key, run the following query on the source DB cluster. Run it in each database that the integration replicates.
SELECT n.nspname AS schema_name, c.relname AS table_name FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'information_schema') AND NOT EXISTS (SELECT 1 FROM pg_constraint p WHERE p.conrelid = c.oid AND p.contype = 'p');
Querying with Amazon Athena
The target tables are Apache Iceberg tables. Before an engine such as Amazon Athena can read them, turn on integration with AWS analytics services in the AWS Region of the table bucket. You do this once for each Region. For instructions, see Turning on integration with AWS analytics services.
After you turn it on, the tables appear under the s3tablescatalog catalog
in the AWS Glue Data Catalog. You can query them from any engine that reads the catalog, including
Aurora, Amazon Athena, AWS Glue, Amazon EMR, Apache Spark, Amazon Redshift, and Trino.
The Amazon RDS console links directly to Athena from the Table status tab of an integration. For more information, see Per-table status. You can run other queries against the target tables in Athena in the same way.
In Athena, name a table as
"s3tablescatalog/.
For example:table-bucket"."namespace"."table"
SELECT * FROM "s3tablescatalog/my-table-bucket"."my_prefix_sales"."public_orders" LIMIT 10;
While a target table is being resynced, you can still query it, but its data is fresh only up to when the replication previously stopped. For more information, see Resyncing integrations with Amazon S3 Tables.
Querying with Apache Spark
You can query the target tables with Apache Spark by using the Amazon S3 Tables Iceberg
catalog. Spark runs in a compute environment, such as Amazon EMR, Amazon EMR Serverless,
AWS Glue, or a self-managed installation that has the Apache Iceberg and Amazon S3 Tables
catalog libraries. The following example uses the interactive
spark-shell.
Configure a Spark session with a catalog backed by the Amazon S3 Tables catalog, and set the warehouse to the Amazon Resource Name (ARN) of the target table bucket:
spark-shell \ --packages org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.6.1,software.amazon.s3tables:s3-tables-catalog-for-iceberg-runtime:0.1.4 \ --conf spark.sql.catalog.s3t=org.apache.iceberg.spark.SparkCatalog \ --conf spark.sql.catalog.s3t.catalog-impl=software.amazon.s3tables.iceberg.S3TablesCatalog \ --conf spark.sql.catalog.s3t.warehouse=arn:aws:s3tables:us-east-1:111122223333:bucket/my-table-bucket\ --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions
At the spark-shell prompt, use spark.sql to list the
namespaces in the table bucket, list the tables in a namespace, and query a
table:
spark.sql("SHOW NAMESPACES IN s3t").show() spark.sql("SHOW TABLES IN s3t.my_prefix_sales").show() spark.sql("SELECT * FROM s3t.my_prefix_sales.public_ordersLIMIT 10").show()
Validating replicated data
To confirm that the target tables match the source tables, compare row counts,
primary key uniqueness, columns, and sample rows, and verify that new changes replicate.
The following examples run in spark-shell and use the s3t
catalog from Querying with Apache Spark.
To validate replicated data
-
Count the rows in a target table:
spark.sql("SELECT count(*) AS target_rows FROM s3t.my_prefix_sales.public_orders").show() -
Check that no primary key value appears more than once. Replace
idwith the name of the table's primary key column:spark.sql("SELECTid, count(*) AS n FROM s3t.my_prefix_sales.public_ordersGROUP BYidHAVING count(*) > 1").show()If the primary key has more than one column, list every key column in the
SELECTandGROUP BYclauses. A result with no rows means that each primary key appears once. -
To confirm that an excluded column is not replicated, list the target table's columns, and check that the excluded column is not in the list:
spark.table("s3t.my_prefix_sales.public_orders").columns.foreach(println)This command checks only the table's current schema. If a column was replicated before you excluded it, earlier Apache Iceberg snapshots of the table can still contain that column's data. For more information, see Changing data rules.
-
Compare the target row count with the source row count for the same table.
-
Spot-check sample rows: select a few rows by primary key value from both the source table and the target table, and confirm that the column values match.
-
To check change data capture (CDC), insert a row with a known primary key value on the source, wait a few minutes, and then query the target table to confirm that the row appears. Optionally, update and then delete the row and confirm that the target reflects each change.