I have an AWS RDS Postgresql instance with some data stored in it. Now, I want to take a snapshot of the mentioned RDS instance and create a new RDS instance from that snapshot. The issue is when the new RDS instance is created from the snapshot, the old RDS instance closes down all the active connections for some reason. I can not afford to do this as many others will be using the same database and closing of connection will be problematic for them. Any lead would be appreciated.
-
"when the new RDS instance is created from the snapshot, the old RDS instance closes down all the active connections for some reason" That is not possible as you have described. There has to be something else going on here. You need to provide a lot more detail about how you are creating the new instance. It sounds like you are somehow modifying the connection settings of the existing servers or something. Are you doing this via a CloudFormation or Terraform template?Mark B– Mark B2023-04-12 13:43:07 +00:00Commented Apr 12, 2023 at 13:43
-
Let me explain what I have tried. 1.Open a connection to the existing postgres RDS using python boto3 client 2.Take the snapshot of the DB manually from aws console. 3.Now restore the snapshot to a new RDS instance and wait for the process to complete. 4. Now, using the connection obtained in step 1, trying to query one of the tables of the DB. 5. Get the below error: "server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request". If I create a new connection as I did in 1st step, and try to query, everything works fineLoki– Loki2023-04-12 19:08:25 +00:00Commented Apr 12, 2023 at 19:08
-
1That just sounds like your connection is timing out or something. Creating a new RDS instance in no way affects any of the other running RDS instances.Mark B– Mark B2023-04-12 20:19:34 +00:00Commented Apr 12, 2023 at 20:19
1 Answer
When an RDS snapshot is taken of instance, AWS creates a new storage volume from the snapshot which is used to create the new RDS instance. During this process, the original RDS instance remains in read-only mode to ensure data consistency in the snapshot.
However, the old RDS instance closing all active connections during the snapshot creation process seems unexpected. One solution to prevent this issue is to create a read replica of the original RDS instance and then take a snapshot of the replica instead of the original instance.
To create a read replica, follow these steps:
- Go to the Amazon RDS console and select the original RDS instance you want to create a read replica for.
- Click on "Create read replica" button and configure the replica instance.
- Once the replica is created and running, take a snapshot of the replica instance instead of the original instance.
- Create a new RDS instance from the snapshot of the replica instance.
This approach ensures that the original RDS instance remains unaffected and all active connections are maintained. The read replica can be used for reporting or backup purposes, and the snapshot of the replica can be used to create a new RDS instance.
Please be aware that creating a read replica may incur additional costs for running the replica instance.
Please share your feedback