Automate DB restore from DB snapshot PostgreSQL AWS - postgresql

I have a Postgres instance on AWS from which snapshots are taken daily. I have manually restored the latest snapshot to another instance for reporting purpose,
but I'm wondering if it is possible to automate this so I can restore the snapshots daily?

You can schedule the restoration CLI command to get executed on particular event or at particular time.
aws rds restore-db-instance-from-db-snapshot --db-instance-identifier mynewdbinstance --db-snapshot-identifier mydbsnapshot

Related

Scheduling AWS RDS snapshot migrations

I am trying to set up a process in which a postgres staging database is populated with production data.
I have some working implementation with pg_dump and pg_restore but I was wondering if something in RDS itself is possible.
We have nightly snapshots on our production database. My goal would be RDS takes the latest database snapshot, migrates it to an existing database and does this on some scheduled cadence (1/week or something like that).
Is this possible to configure in the console? If not are there some some combination of lambda/cloud formation that can do this?
My goal would be RDS takes the latest database snapshot, migrates it to an existing database
RDS never loads a snapshot into an existing database. It always creates an entirely new database server/cluster from a snapshot.
Is this possible to configure in the console? If not are there some some combination of lambda/cloud formation that can do this?
You would have to write some code that creates a new staging database server from the production snapshot, and deletes your current server.
If you are using CloudFormation, then it could manage this for you if you specify the DBSnapshotIdentifier parameter. You would have to modify that parameter each week, and then update your CloudFormation stack.

Refresh postgres materialized view using scheduler

I was trying to figure-out how we can schedule to refresh the materialized view on azure postgres database single server which is in azure cloud, one solution is to use pg_cron extension, but it
seems it is only available on azure flexible postgres database server and not on azure postgres database single server, I did not get any other option available, any suggestion in this regard will be really helpful.
I did not find any postgres scheduler extension for the db hosted on Azure, so created one microservice to schedule the db functions.
Example Link

Backup and Restore AWS RDS Aurora cluster

I would like to backup every single PostgreSql database of my AWS RDS Cluster (Aurora DB Engine). Are there some managed tools (like Veeam or N2WS) or best practices, how to backup and restore a single database or schema from AWS S3?
Many thanks
You can use automatic backup combined with manual backup for Aurora PostgreSql database. For automatic backup, the max retention period is 35 days, and support any point in time restore and recovery. However, if you need a backup beyond the backup retention period (35 days), you can also take a snapshot of the data in your cluster volume.
If you use third-party tools, such as Veeam, it will also invoke AWS RDS snapshot API to take the backup, so the underly mechanism is the same.
You can also use the pg_dump utility for backing up the RDS for PostgreSQL database, and run pg_dump on read replica to minimize the performance impact to the primary database.

How can I learn more about AWS's RDS Aurora PostgreSQL 9.6.19 upgrade failure?

I'm trying to upgrade an RDS database cluster engine from Aurora PostgreSQL 9.6.19 before its end of life, I made copy and tried to upgrade to 9.6.21 and 10.16 but everytime the same problem happens:
Database cluster is in a state that cannot be upgraded: Postgres cluster is in a state where pg_upgrade can not be completed successfully.
The status of the database is Available so maybe it refers to something else but I don't know what and how to fix it, I've tried looking for answers to no avail.
Has anyone fixed this?
The pg_upgrade_internal log file will usually contain details on any failures/errors.
You can take a look on these logs using the command line:
aws rds describe-db-log-files --db-instance-identifier my-db-instance
Or via console, or RDS API.
For more information take a look on these links: Upgrading the PostgreSQL DB engine for Amazon RDS, Viewing and listing database log files

What's a good way to backup a (AWS) Postgres DB

what's a good way to backup a Postgres DB (running on Amazon RDS).
The built in snapshoting from RDS is by default daily and you can not export the snapshots. Besides that, it can take quite a long time to import a snapshot.
Is there a good service that takes dumps on a regular basis and stores them on e.g. S3? We don't want to spin up and maintain a ec2 instance which does that.
Thank you!
I want the backups to be automated, so I would prefer to have dedicated service for that.
Your choices:
run pg_dump from an EC2 instance on a schedule. This is a great use case for Spot instances.
restore a snapshot to a new RDS instance, then run pg_dump as above. This reduces database load.
Want to run a RDS snapshot more often than daily? Kick it off manually.
These are all automateable. For "free" (low effort on your part) you get daily snapshots. I agree, I wish they could be sent to S3.
SOLUTION: Now you can do a pg_dumpall and dump all Postgres databases on a single AWS RDS Instance.
It has caveats and so its better to read the post before going ahead and compiling your own version of pg_dumpall for this. Details here.