Copy a single database from one RDS instance (Postgres) to another - postgresql

I have 2 RDS instances with Postgres.
I need to transfer one of the databases from RDS instance A to RDS instance B.
How am I supposed to do it, if pg_dump is not accessible outside a bash shell and you can't access bash shell from an RDS instance?
Some advice would be appreciated.

Related

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?

What's the difference between initdb /usr/local/var/[db] and createdb [db]

I am starting to use PostgreSQL and I am confused about the two ways to create a database. When I installed it the first time, the instructions said I have to create a default database with initdb /usr/local/var/postgres When I lookup my databases, I can see that I have a database called postgres. Now I am able to create a database with two other commands whereas the former is the command line script and the latter the SQL command. In the case of a "postgres" called database it would be:
createdb postgres
CREATE DATABASE postgres
Both are setting up a database in my list of databases. When I try to create another database with initdb /usr/local/var/[someDbName] though, it doesn't appear in my list of databases. So what's the difference between initdb and createdb then?
initdb is not used to create a "new database".
As documented in the manual you need it to create a "cluster" or "data directory" which then stores databases created with create database.
Quote from the manual:
Before you can do anything, you must initialize a database storage area on disk. We call this a database cluster. (The SQL standard uses the term catalog cluster.) A database cluster is a collection of databases that is managed by a single instance of a running database server
[...]
In file system terms, a database cluster is a single directory under which all data will be stored. We call this the data directory or data area
In short: initdb creates the necessary directory layout on the harddisk to be able to create and manage databases.
It's a necessary part of the installation process of a Postgres server.

Obtain aws cli command to create RDS instance from existing database

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

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.