Restore backups to postgres instance on another server through pgbackrest - postgresql

I'm trying to backup/restore from one postgres instance on one virtual machine to another postgres on another vm. How to give paths in pg_hba.conf?
[global]
repo1-path=/var/lib/pgsql/12/backups/
log-level-console=info
log-level-file=debug
start-fast=y
repo1-retention-full-type=time
repo1-retention-full=15
[my_stanza]
pg1-path=/var/lib/pgsql/12/data/
Also is it possible to restore on another postgres instance if backups are stored on S3, GCS or Azure? If yes, How?

Related

Binary backup of AWS RDS PostgreSQL

I am looking for a way to do a regular binary backup of my AWS RDS PostgreSQL database to use this copy locally and mount it in my docker postgis container. As far as I have understood, I cannot connect to the RDS host and do pg_basebackup.
So what is the best way to do this task?
The best workflow would be: There is an automatic daily binary backup stored in AWS S3. Then locally, some shell script to download the files to a folder that is mounted to the postgis folder.
Any ideas if that is possible?
I have one more additional requirement: I would like to exclude specific tables in the backup.

How to copy a Postgres database from a mounted disk to a live Postgres server

We have a disk on which a Postgres server used to be running, with one important database.
We need to move (and import) one of the databases that were live on that disk, to a live server.
Is that even possible?
I seem to only find scenarios where the server(s) are running when migrating data.
You need to use pg_dump and pg_restore because there is no way in PostgreSQL to copy database files for one single database between 2 instances.
However there is the possibility to copy the old PGDATA to a new PGDATA on new machine
(see How to copy a Postgres database from a mounted disk to a live Postgres server). But you need to have the corresponding PostgreSQL binaries to be able to move the database with pg_dump from old instance to new instance with pg_restore.

AWS RDS vs local database in EC2 instance

I want to understand AWS Relational Database Service (RDS) and discover benefits from using it.
Why RDS is better than manually installed PostgreSQL database in EC2 instance?
Is it possible to connent existing database in EC2 instance with Amazon RDS?
How it really works?
How I should automation RDS?
When I want create new database in existing EC2 instance I can use Ansible in simply way. How I should connect my application with database which uses RDS ?
Thanks in advance!
I want to understand AWS Relational Database Service (RDS) and discover benefits from using it.
As already commented, read the docs and whitepapers.
Why RDS is better than manually installed PostgreSQL database in EC2 instance?
you can be sure it is well setup, you will get point in time recovery, backups and high availability. As well you can set it up yourself, however using RDS you have it all already configured.
Ifs it possible to connent existing database in EC2 instance with Amazon RDS? How it really works?
you don't have access to any underlying configuration, so nope, you cannot really connect ec2 database w/ rds (e. g. wal for wal streaming).
you still can use database migration tools to migrate all databases and updates to or from rds
How I should automation RDS? When I want create new database in existing EC2 instance I can use Ansible in simply way.
you can use a cloudformation template or cli commands
How I should connect my application with database which uses RDS ?
when you create a rds instance, you will define an admin user and receive a connection url
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.Scenarios.html#USER_VPC.Scenario1

How does initdb of PostgreSQL work? How to use it for testing?

Many suggestions for integration testing which includes Postgres Database say that I can initdb a new whole cluster in RAM disk and work on it.
As far as I understand initdb is a new folder like thing related to databases.
According to Postgres docs:
initdb creates a new PostgreSQL database cluster. A database cluster is a collection of databases that are managed by a single server instance.
Does it create a new server? Or a new Database?
Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalogue tables (tables that belong to the whole cluster rather than to any particular database), and creating the template1 and Postgres databases. When you later create a new database, everything in the template1 database is copied. (Therefore, anything installed in template1 is automatically copied into each database created later.) The Postgres database is a default database meant for use by users, utilities and third party applications.
Does the above sentence mean that from now on whatever database is created it is stored in that new "cluster"? If not how to create tables in such a cluster of RAM disk?
How can I use it to set it up for testing?
In the terminology your image uses (from pgAdmin?), initdb would create the data directory for a new “server”.
In PostgreSQL, this is not called a server, but a database cluster. It has a data directory, which is created with initdb. If you start the cluster with pg_ctl start, a PostgreSQL server process (called postmaster) is started, which listens for incoming connections and starts backend processes that work on the data directory.
There can be more than one PostgreSQL database clusters on one machine, you just have to give them different port numbers.
It should be no problem to run initdb to create a database cluster for your integration tests. After initdb you have to edit postgresql.conf appropriately (e.g. to set port) and start the postmaster with pg_clt start -D <data directory>.

Heroku Postgres configure data center location

My understanding is that Heroku Postgres runs on top of AWS. Is it possible to configure which datacenter your database is running in? I'm also wondering if the database files are stored on an encrypted filesystem.
Yes, Heroku runs on AWS. But you are not able to specify which datacenter to run your database. For encryption look at http://www.postgresql.org/docs/current/static/pgcrypto.html.
Heroku runs out of Amazon US-East - once you've add a postgres db to your app heroku config will give you the database connection URL which you would be able to tracert on to see where it is