Obtain aws cli command to create RDS instance from existing database - postgresql

Is there a way to automatically generate the database creation string for an empty database with settings from an existing database?
I created an AWS RDS postgresql database instance using the console in my browser. I selected all kind of setting in my browser and launched the instance. Now I want to replicate this database (empty) with a command for programmatic use. I would like to delete the existing RDS instance so a raw command would be preferred (no reference to another RDS) but something like:
aws create-db-instance --db-name database02 --allocated-storage 200 --engine postgres etc.

You'll need to create a snapshot of the source Database, instance or cluster and then create a new database based on that snapshot. You can delete the source database after the snapshot is complete.
aws rds create-db-snapshot
--db-snapshot-identifier mydbsnapshot
--db-instance-identifier mydb
aws rds restore-db-instance-from-db-snapshot
--db-instance-identifier mynewdbinstance
--db-snapshot-identifier mydbsnapshot
http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-snapshot.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html
http://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-instance-from-db-snapshot.html

Related

Is it possible to rename a Cloud SQL database using the gcloud CLI?

I would like to rename a Cloud SQL database using only the gcloud CLI.
I can see that I can patch a database using the CLI. However it seems to only patch either the collation or the charset but not the database name itself.
Do you know if there is a way to achieve it with the CLI ?
If not, I will use a Cloud SQL Auth Proxy and run the ALTER command directly on the database.
I don't think, there is an in-built option to rename database using gcloud command-line.
Available option is login to database engine and alter database name using ALTER DATABASE command, if it supports in-place database alteration.
Another option is use gcloud sql to export your database to sql file, make changes to your database name and import it back to Cloud SQL instance.
If you are using Cloud SQL MySQL instance, you can use mysqldump to backup and restore with new database name or use rename table with new database name.

Copy Postgres Production RDS Database to Development RDS Instance

I'm trying to figure out an efficient way to copy data directly from my AWS RDS Production Postgres Instance to my AWS RDS Development Instance.
Right now I do a pg_dump on my local machine of the production instance. Then do a pg_restore on my local machine to the development RDS instance.
How can I copy the data directly from the Production RDS Postgres Instance to the Development RDS Postgres Instance?

Cloud sql postgres DB create Cross project replication

In the Gcloud SQL Postgres database, I am currently using gcloud export and import command to create database backup in a different project. which takes a long time.
As gcloud allows us to create read replica but it creates with in the same project.
my question is?
how can i create a replica of cloud sql postgres instance in another project postgres instacne?

Amazon RDS postgres Data wiped and can't connect to database?

I created an RDS Postgres instance. I'm new to RDS.
db host:
demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com
db identifier:
demodb
Every tutorial says to connect with this URL:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/demodb
but every time I do I get this error-
FATAl: database "demodb" does not exist.
I am able to connect using this:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/postgres
Now, while I was excited to connect after I used SQL workbench to create tables and insert data into those tables, a few hours later all my tables and data were deleted/wiped/dropped. Why would this happen? and How can I prevent it from happening in the future?
FATAl: database "demodb" does not exist.
demodb is db instance identifier. It is NOT the name of your database inside of PostgreSQL.
By default RDS PostgreSQL does not create a database for you. It seems to me that you haven't created an actual database when you setup your RDS PostgreSQL.
To create a database at RDS creation there is an option called Initial database name where you should specify the name of the database you want. Otherwise, no database is created, which is a default behavior:

Automate backup of a single schema in PostgreSQLl on AWS RDS

Setup --
I have a postgresql db running on AWS RDS. We access it from an EC2 instance using pgAdmin 3.
Current Scenario --
AWS takes a daily backup of the entire RDS instance as RDS snapshots which is stored for 15 days.
I take a manual backup of one important schema (all the data in schema included) using pgAdmin and then push this backup file to s3.
Question --
How do I automate this backup of a single schema (including data) in postgresql and store it on S3 (any application or script). Is there a way to automate it in pgadmin just for one schema and not the entire database.
You need to use a command line tool pg_dump:
pg_dump \
--host=myhostname.qwertyuiop.sc-moon-1.rds.amazonaws.com \
--username=myusername --dbname=mydbname \
--format=custom --file=mydbname.pg_dump
It needs to be the same major version as the database.