A snapshot brings the database back to the moment when it was taken. Often you need a more exact moment, for example one second before someone ran a wrong DROP TABLE or UPDATE without WHERE. With point-in-time recovery (PITR), RDS restores the last daily snapshot and then replays the transaction logs up to the second that you choose.
In this step, you simulate an accident: you create a table, drop it, then recover the table on a new DB instance restored to a moment between the two commands.
You can restore to any second between the earliest restorable time and the latest restorable time. The latest restorable time is usually less than 5 minutes behind the current time, because RDS uploads the transaction logs every 5 minutes.
On the App server, create a table with 1,000 rows:
psql -d pglab -c "CREATE TABLE important_data AS SELECT g AS id, md5(g::text) AS payload, now() AS created_at FROM generate_series(1,1000) g;"
Wait a few seconds, then drop the table, and write down the time of the drop:
psql -d pglab \
-c "SELECT count(*), max(created_at) AS created_time FROM important_data;" \
-c "SELECT now() AS drop_time;" \
-c "DROP TABLE important_data;" \
-c "SELECT count(*) FROM important_data;"
01:23:22 UTC.01:23:46 UTC.
You will restore the database to 01:23:35 UTC, which is after the table was created and before it was dropped. Your times are different: choose a second between your created_time and your drop_time.
Wait about 5 minutes, then check the latest restorable time in AWS CloudShell:
aws rds describe-db-instances \
--db-instance-identifier rdspg-lab-db \
--query 'DBInstances[0].{BackupRetentionPeriod:BackupRetentionPeriod,LatestRestorableTime:LatestRestorableTime}' \
--output table

In the list of databases:
rdspg-lab-db.
In Restore time:
01:23:35 UTC is 08:23:35 UTC+7.
In Settings:
rdspg-lab-db.rdspg-lab-db-pitr
In Instance configuration and Availability and durability:
db.t4g.micro
In Connectivity:
rdspg-lab-subnet-grouprds-sg onlyKeep the other settings and choose Restore to point in time at the bottom of the page.

Wait until the status of rdspg-lab-db-pitr is Available, about 10 to 15 minutes:
rdspg-lab-db-pitr is Available.
Open rdspg-lab-db-pitr and copy its Endpoint. On the App server, connect to the restored DB instance and count the rows. Enter the master password when psql asks for it:
psql -h <endpoint of rdspg-lab-db-pitr> -d pglab \
-c "SELECT count(*), max(created_at) AS created_time FROM important_data;"
important_data exists again, with its 1,000 rows.
In a real incident, you now copy the table back to the production database, for example with pg_dump -t important_data from rdspg-lab-db-pitr and psql into rdspg-lab-db, or you switch the application to the restored DB instance.
rdspg-lab-db-pitr: select it, choose Actions > Delete, clear Create final snapshot and Retain automated backups, select the acknowledgment, type delete me, then choose Delete.