DEV Community

kawasaki031677
kawasaki031677

Posted on

Direct S3 Data Import to Aurora PostgreSQL - A Performance Comparison

Introduction

Aurora PostgreSQL has a built-in feature that allows direct data exchange with S3. This capability enables you to import data directly from S3 to PostgreSQL without going through your application layer, which was previously the standard approach.

This approach offers several advantages:

  • No need to handle files on the application side
  • No concerns about application disk space
  • Simpler implementation

In this article, I'll demonstrate this feature and compare it with traditional import methods.

For more details about this feature, please refer to the AWS documentation.

Test Environment

  • AWS Tokyo Region
  • Aurora PostgreSQL 17.4 (db.t3.medium)
  • large_test_data.csv (10 million rows test data)
  • test_table (table for data storage)

Importing Files from S3

  1. First, install the extension for S3 integration:
CREATE EXTENSION IF NOT EXISTS aws_s3 CASCADE;
Enter fullscreen mode Exit fullscreen mode
  1. Import the file from S3:
postgres=> SELECT aws_s3.table_import_from_s3(
    'test_table',
    '',       
    '(format csv, header true)',
    '<S3 bucket name>',
    'large_test_data.csv',
    'ap-northeast-1',
    '<IAM role name associated with Aurora>'
);
                                         table_import_from_s3                                         
-----------------------------------------------------------------------------------------------------
 10000000 rows imported into relation "test_table" from file large_test_data.csv of 208888910 bytes
(1 row)

Time: 11639.759 ms (00:11.640)
postgres=>
Enter fullscreen mode Exit fullscreen mode

Traditional Method (Import via Application)

  1. First, download the file from S3:
~ $ time aws s3 cp s3://<S3 bucket name>/large_test_data.csv ./
download: s3://<S3 bucket name>/large_test_data.csv to ./large_test_data.csv

real    0m2.301s
Enter fullscreen mode Exit fullscreen mode
  1. Import using the COPY command:
postgres=> \COPY test_table (id, name, age)
FROM 'large_test_data.csv'
WITH (FORMAT csv, HEADER true);
COPY 10000000
Time: 11416.487 ms (00:11.416)
postgres=>
Enter fullscreen mode Exit fullscreen mode

Summary

Here are the results:

Method Processing Time
S3 Integration 11.6 seconds
Via Application 13.7 seconds (Download: 2.3 seconds, COPY command: 11.4 seconds)

The S3 integration method proved to be slightly faster. While the performance difference isn't dramatic, the main advantage is bypassing the application layer entirely. This article demonstrated importing, but exporting is also possible. Additionally, Aurora can even invoke Lambda functions.

Although this feature isn't widely used or known in the field, it offers many benefits and should be actively utilized in more projects.


๐Ÿค– Generated with Claude Code

Top comments (1)

Collapse
 
officialmailkr profile image
์˜คํ”ผ์…œ๋ฉ”์ผ •

๋‹ค์šด๋กœ๋“œ ์‹œ๊ฐ„์„ ํฌํ•จํ•œ ์ „์ฒด ์‹œ๊ฐ„๊ณผ DB ์ ์žฌ ์‹œ๊ฐ„์„ ๋”ฐ๋กœ ์ œ์‹œํ•ด ๋น„๊ต ๋ฒ”์œ„๊ฐ€ ๋ช…ํ™•ํ•˜๋„ค์š”. ์•ฑ์˜ ๋””์Šคํฌ ์‚ฌ์šฉ๊ณผ ํŒŒ์ผ ์ฒ˜๋ฆฌ ๊ฒฝ๋กœ๋ฅผ ์—†์• ๋Š” ์žฅ์ ์„ ์„ฑ๋Šฅ ์ˆ˜์น˜์™€ ๋ถ„๋ฆฌํ•œ ์ ๋„ ์ข‹์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ณต ์ธก์ • ํšŸ์ˆ˜์™€ ์บ์‹œ ์ƒํƒœ, ์ธ๋ฑ์Šคยท์ œ์•ฝ ์กฐ๊ฑด์˜ ์œ ๋ฌด๊นŒ์ง€ ๋ง๋ถ™์ด๋ฉด, 11.6์ดˆ์™€ 13.7์ดˆ์˜ ์ฐจ์ด๋ฅผ ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ํ•ด์„ํ•˜๊ธฐ ๋” ์‰ฌ์šธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.