![]() ![]() I hope this note-to-self quickie will be of some help to you as-well. These steps are mostly for moving development data around or pulling (partial) production data locally for debugging, or something along those lines. If you use any of these manual steps as a means to create backups, you're probably doing something not entirely correct. Please keep in mind that you should always ensure your production databases are properly backed up, and ideally automatically so. There are certainly other ways to achieve something similar, but this method will work in a pinch. manually created) container to another, you could use pipes to do this in one command, like so: docker exec -i pg_old_container_name /bin/bash -c "PGPASSWORD=pg_password pg_dump -username pg_username database_name" | docker exec -i pg_new_container_name /bin/bash -c "PGPASSWORD=pg_password psql -username pg_username database_name" Conclusions If you, for example, are moving data from one (e.g. This way it can be restored in the existing database, or it can be discovered with a future version of PostGIS using the command. If you would instead prefer to stop the import completely upon error, be sure to add -set ON_ERROR_STOP=on to your above command. For PostGIS, make sure you are following the hard upgrade procedure: pgdump -h localhost -p 5432 -U postgres -Fc -b -v -f file.backup thedatabase. Note: By default PostgreSQL keeps importing even when errors occur. Note: If you are attempting to restore data from a custom format dump, you should instead use pg_restore as I described in my How to set up and use Postgres locally article. The resulting file must be transferred to another VPS or dedicated server. By using the above syntax, we can dump the database that means we export the database. Importing a PostgreSQL database dump to pgAdmin 4. pgdump u username databasename > dbexport.pgsql. Since you are not able to provide a password directly through arguments, we rely on the PGPASSWORD environment variable: docker exec -i pg_container_name /bin/bash -c "PGPASSWORD=pg_password psql -username pg_username database_name" < /path/on/your/machine/dump.sql In which we dump the database by using the pgdump command through the command line as follows. Dump using pg_dump docker exec -i pg_container_name /bin/bash -c "PGPASSWORD=pg_password pg_dump -username pg_username database_name" > /desired/path/on/your/machine/dump.sql Restore using psql This quickie assumes you have nothing directly installed on your development machine, so everything is run straight from and to the Docker PostgreSQL container you're running. Depending on why you need to dump/restore a database, this might help for you, too. I ran into this just today, and thought I'd share one method that I felt was easy, fast and served my purpose. : Updated the guide with a more up-to-date method for sending a password along with the commands. ![]()
0 Comments
Leave a Reply. |