At Vinosmith we use Amazon RDS - Postgres as our primary data store. I love it. RDS has seamless master/slave failover and great performance for my needs. Its wonderful not to have to monitor my primary DB myself and wait for the dreaded 3AM phone call.

Anyways. With RDS you get 7 days of log retention. After 7 days the logs are not accessible.

In my case I have log_statements=mod because I find it very helpful to see the DML statements that are made.

Furthermore, sometimes I need to research an issue that goes back weeks.

Hence the need to download RDS logs and store them on S3 for archival purposes.

Fortunately, the RDS API offers an easy way to download logs via the AWS CLI.

I have the following Ruby script set up as an hourly cron. The script downloads the previous hour log file, compresses it with gzip and archives it to S3.