Move db from 9.6 to 11.6 postgres server - postgresql

After moving a database from postgres 9.6 to 11.6 we are having performance issues running some queries.
Have two postgres servers running in parallel. 9.6 and 11.6. Bother are AWS RDS`s.
Used the pg_dump command to dump the database to a file (11.6 postgres tools). Connected to RDS running Postgres 9.6. (PGPASSWORD=<password> pg_dump -Fc --host=<hostname> --port=5432 --username=<username> -f /tmp/filename.dump --exclude-table-data 'table_a' --exclude-table-data 'table_b' --exclude-table-data 'table_c' --exclude-table-data 'table_d' <dbname>
Used the pg_restore command to load the database to a file (11.6 postgres tools). Connected to RDS running Postgres 11.6. (pg_restore -Fc -d $PGDATABASE -v -j2 <filename>
The database restored and all seemed ok however a small number of queries are taking a very long time to run or failing.
Is there something we missed or another way we should have done this? We have run ANALYZE but it didn't help.

Related

pg_dump 0 bytes backup file, stuck after saving database definition

I am trying to backup Postgres database but I always get 0 bytes backup size. If I use the verbose switch, I can see that it is stuck at
pg_dump: saving database definition
I have tried taking backup of specific table and it works fine. Below is my command:
pg_dump -U backupuser -p 5432 -Ft -v -d database > database.tar
I was able to resolve this. When I was creating the backup, I checked the postgres logs and it was clearly written there that during backup the server wasn't reachable. Now to resolve this, I have added a command to restart the postgres before the scheduled backup and it is working fine now.

Copying Postgresql DB dump from remote server to local

I want to take a DB dump from a remote server and then copy this dump to my local.
I tried couple of commands but didn't worked.
Lastly I tried the command below;
pg_dump -h 10.10.10.70 -p 5432 -U postgres -d mydb | gzip > db1.gz
I succesffully take the DB and tried with restore from Pgadmin, it gives;
pg_restore: error: input file appears to be a text format dump. Please use psql
But at this point I can't use psql, I have to use Pgadmin and not sure if I'm able to get successfully DB dump to my local. I mean I can't verify with restore.
How can I take DB dump from remote server to my local?
Thanks!
Use the "custom" format:
pg_dump -F c -h 10.10.10.70 -p 5432 -U postgres -f mydb.dmp mydb
That can be restores with pg_restore and hence with pgAdmin.
You do not have to use pgAdmin. pgAdmin uses pg_restore, and there is nothing that keeps you from using it too.

PostgreSQL Backup and Restore (Multiple Instances)

Can anyone help me out how to backup and restore a specific database instance if I have multiple PostgreSQL instances running on a single server?
For example, I have db1, db2 and db3 on a single server. How do I backup db1 and restore it without affecting db2 and db3?
Here's how I restart the instances separately.
/usr/pgsql-9.6/bin/pg_ctl restart -D /var/lib/pgsql/9.6/db1
/usr/pgsql-9.6/bin/pg_ctl restart -D /var/lib/pgsql/9.6/db2
/usr/pgsql-9.6/bin/pg_ctl restart -D /var/lib/pgsql/9.6/db3
Thank you, #FatFreddy.
I was able to backup and restore a specific database instance on a server having multiple PostgreSQL instances using the following commands:
Backup: pg_dumpall -p 5435 > /var/lib/pgsql/9.6/db1/PostgreSQL_db1_{date}.sql
Restore: psql -U postgres -p 5435 -f /var/lib/pgsql/9.6/db1/PostgreSQL_db1_{date}.sql

Issues with putting dockerized Postgres OLTP database in read only

I have a dockerized postgres 9.3.5 OLTP instance that I'm going to update to 9.5.2. Instead of shutting it down and doing a pg_dumpal to a file and then load it I would like to spin up a new docker container and pipe the database pg_dumpall -h localhost -p [port] -U postgres | psql -h localhost -U postgres -p [port]. I'm thinking I could alter the postgresql.conf to be in read only mode. This would temporarily mess with my app but at least users could still SELECT. Is there a better way to go about this? Are there any big issues with putting in read only mode while I pipe the database over?

How to restore PostgreSQL database backup without psql and pg_restore?

I am using postgresql on an embedded device running yocto (customized linux). The package containing postgresql does not provide psql or pg_restore. /usr/bin provides the following tools:
pg_basebackup indicates that I am able to create backups. But how am I supposed to restore a backup within a terminal? With pg_restore or psql this would not be a problem for me.
Please note: I want to use a backup created on my windows/linux computer to create the initial database on the embedded device.
Create backup of the db using command:
pg_basebackup -h {host_ip} -D pg_backup -U {USER}
for restoring just change the data folder to pg_backup. Now start the psql server.