Using postgresql database files version 8.4 with Docker postgresql 10 - postgresql

I have a Docker image for postgresql that is 10.4. I have old database files that are postgresql 8.4. I want to upgrade these to use in 10.4 but don't really have a good way to do this. Is it possible to use the Docker image and upgrade the old files?

I think you can run the postgres:8.4 image, execute pg_dumpall inside it and save the result to the host using, for example, a volume or docker cp command.
After that you can run postgres:10 image, provide the result file to it (a volume or docker cp again) and restore the data.

Related

Is there any way of of get backup of postgres db in docker container without generating sql file?

I am new in Docker, I want to get a backup for my postgress database running in docker. All solutions i saw are offering to generate a dump sql script and restore db with running this script. But i dont want to do this? Is it possible backup and restore by migrating binary files of the db?
You can build Postgres image from plain empty Postgres db image. In Dockerfile you add SQL script which runs on db initialization (docker-entrypoint-initdb.d). The SQL script contains dblink to your backed up db and commands create table my_table as select * from my_table#remotedb. After docker build you have image with backup of your original database tables.
I do something similar with Oracle with more complexity (copying only subset of original database, preserving indexes etc.). Oracle docker image differs from PG in some properties but I believe the rough idea is applicable. It is some time ago I worked with PG so I won't advise you how to migrate binary files (though I believe it would be possible too).

pg_upgradecluster taking too much time(around 8 hours for 165GB database) any workarounds?

I am trying upgrade postgres-9.3 to postgres-10 with database size around 165GB. I am using "sudo pg_upgradecluster 9.3 main" to do so but it's taking around 8hours which is way too much downtime for my live webapp. Any suggestions to make it better with lesser downtime and faster.
You can tell pg_upgradecluster to use Postgres' pg_upgrade tool with the --link option which should then finish in minutes rather than hours:
pg_upgradecluster --method=upgrade --link ......
Note that --link will not copy your data, so the only way to revert the upgrade is to restore your last backup to a 9.3 installation.
Quote from the Postgres manual
If you use link mode, the upgrade will be much faster (no file copying) and use less disk space, but you will not be able to access your old cluster once you start the new cluster after the upgrade.
...
If you want to use link mode and you do not want your old cluster to be modified when the new cluster is started, make a copy of the old cluster and upgrade that in link mode. To make a valid copy of the old cluster, use rsync to create a dirty copy of the old cluster while the server is running, then shut down the old server and run rsync --checksum again to update the copy with any changes to make it consistent.

Restoring PostgreSQL database without having a dump just the database files

My hoster upgraded my Ubuntu server and it's not booting any more. The only way I can access my data any more is in read mode via a rescue environment (SSH shell).
I am running a postgres 9.1 installation on the crashed server. I am not able to start the postgres server in the rescue environment. I also do not have a dababase dump created with pg_dump.
However, I was able to copy the whole /var/lib/postgresql folder to a new machine . I installed Postgres 9.1 on this machine. Afertwards I replaced the /var/lib/postgresql with my old files.
When I start the postgres server, I get something like "incorrect checksum in control file".
I there any way to restore the database content without using pg_dump (since I don't have a current dump and I am not able to run it on the defective machine).
Indeed it was an issue between 32bit and 64bit. I had another old server running on 32bit Ubuntu. Initially I tried to restore the data on a 64bit machine. With the 32bit machine it simply worked by copying the postgres main directory. Finally I was able to log into the database and create a dump.

Why does my postgres docker image not contain any data?

I'd like to create a docker image with data.
My attempt is as follows:
FROM postgres
COPY dump_testdb /image
RUN pg_restore /image
RUN rm -rf /image
Then I run docker build -t testdb . and docker run -d testdb.
When I connect to the container I don't see the restored db. How do I get an image with the restored data?
COPY the dump file, with a .sql extension, into /docker-entrypoint-initdb.d/. Do not try to RUN anything. The postgres image will run everything in that directory the first time a container is started on a particular data directory.
You generally can’t RUN commands that interact with the database in a Dockerfile because the database won’t be running at that point. (There is a script in the base image that goes through some complicated gymnastics to do the first-time setup.) In any case, because of the mechanics of Docker’s volume system, you can’t create an image that contains prepopulated database data; you have to use a mechanism like this to cause the image to restore a dump or otherwise set itself up at first start.

running Postgis Database in Docker Container

i am trying to run my Postgis Database in a Docker Container. Therefore i dumped my database and created a Dockerfile like this:
FROM mdillon/postgis
COPY z_myDump.sql /docker-entrypoint-initdb.d/
I use the mdillon postgis as base image (Postgis Extensions are already included) and copy my dump. The container disappears after a few seconds with the following error:
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/z_myDump.sql
/docker-entrypoint-initdb.d/z_myDump.sql: Permission denied
any idea?
changing permissions of the .sql file before building the image did the job ... my bad