title: RDS instance unusably slow after restoring from snapshot
body: <p><strong>Details:</strong></p>
  
  <p>Database: Postgres.<br>
  Version: 9.6<br>
  Host: Amazon RDS</p>
  
  <p><strong>Problem:</strong> After restoring from snapshot, the database is unusably slow.</p>
  
  <p><strong>Why:</strong> 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 <code>dd</code> or <code>fio</code> to pre-touch the data because RDS does not allow access to the mounted EBS volumes.</p>
  
  <p><strong>What I've done:</strong> Contact AWS support. They acknowledged that it's a problem, that they are working on it and that the only solution is to <code>select *</code> from all tables.</p>
  
  <p><strong>Why I still need help:</strong> The <code>select *</code> strategy did speed things up (I selected everything from the <code>public</code> schema), but not as much as is needed. So I read up on how postgres <a href="https://www.postgresql.org/docs/9.6/static/storage-file-layout.html" rel="noreferrer">stores data to disk</a>. There's a heck of a lot on disk that wouldn't be "touched" by a simple select from user-defined tables.</p>
  
  <p><strong>My question:</strong> 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?</p>