Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RDS instance unusably slow after restoring from snapshot

Details:

Database: Postgres.
Version: 9.6
Host: Amazon RDS

Problem: After restoring from snapshot, the database is unusably slow.

Why: Something AWS calls the "first touch penalty". When a newly restored instance becomes available, the EBS volume attachment is complete but not all the data has been migrated to the attached EBS volume from S3. Only after initially "touching" the data will RDS realize the data isn't on the EBS volume and it needs to pull it from S3. This completely destroys our performance. We also cannot use dd or fio to pre-touch the data because RDS does not allow access to the mounted EBS volumes.

What I've done: Contact AWS support. They acknowledged that it's a problem, that they are working on it and that the only solution is to select * from all tables.

Why I still need help: The select * strategy did speed things up (I selected everything from the public schema), but not as much as is needed. So I read up on how postgres stores data to disk. There's a heck of a lot on disk that wouldn't be "touched" by a simple select from user-defined tables.

My question: Being limited to only SQL queries/functions and not having direct access to the underlying disk, what are the best sql statements I can use to "touch" as much as possible on the disk in order to get it loaded on the EBS volume from S3?

like image 632
bbuckley123 Avatar asked Dec 08 '17 15:12

bbuckley123


1 Answers

My suggestion would be to manually trigger a vacuum analyze, this will do a full table scan of each table within scope to update the planner with fresh statistics. You can scope this fairly easily to only a certain schema, the database in question and the Postgres schema for example could help keep total time down if you have multiple databases within the one host.

The operation is rather time consuming and I'm not aware of a good way to parallelize it. There is also the vacuumdb utility but this just runs a query with a vacuum statement in it.

Source: I asked RDS support this very question a few days ago.

[1] https://www.postgresql.org/docs/9.5/static/sql-vacuum.html

edit: will reformat later, on mobile

like image 192
dom_hutton Avatar answered Sep 21 '22 23:09

dom_hutton