pg-dump

Using pg_dump and pg_restore correctly

偶尔善良 提交于 2019-12-01 23:25:10
So I regularly backup and restore databases and schema's using pgadmin4. I would like to do it with a batch file using commands as pg_dump and pg_restore. I however always fail to succeed in this and could use some help. The way I try to dump one schema (with data) is the following: pg_dump -U postgres -F c -d database -n schema > mw2 Then I try to restore it with pg_restore: pg_restore -U postgres -d otherdatabase -n schema mw2 First I tried to use .dump in stead of tar but the result stays the same; which is an empty schema in my database. Or the following error message: pg_restore:

Unable to restore psql database from pg_dump with a different username

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 18:38:30
I need to dump a postgres database from computer1 with postgres username1 and then restore it on computer2 with postgres username2. I keep running into the error that looks like the backup file wants to use username1: When I run this on computer2: psql dbname < backupname.pgsql I get this error: ERROR: role "username1" does not exist I have tried: // Dumping from computer1: pg_dump dbname > backupname.sql pg_dump dbname > backupname.pgsql pg_dump -U username1 dbname -N topology -T spacial_ref_sys > backupname.pgsql // Restoring on computer2: psql dbname < backupname.pgsql Is it the dumping or

How to exclude PL/pgSQL functions in export?

只愿长相守 提交于 2019-12-01 09:49:14
问题 I use following command to dump some structures from server' database to be able to create sample of data on my local hard drive. pg_dump -h myserver.com -U product_user -s -f ./data/base.structure.postgresql.sql -F p -v -T public.* -T first_product.* -T second_product.* -T another_product.locales mydatabase I need to exclude some schemas otherwise it would ended up on permissions or other errors. Even that I exclude schema public, it dumps all functions in that schema, like this: REVOKE ALL

Why is pg_restore returning successfully but not actually restoring my database?

て烟熏妆下的殇ゞ 提交于 2019-11-29 20:25:23
I have a Postgres 8.4 database on a linux server that I have dumped using the following command: pg_dump --format=c --exclude-table=log --file=/path/to/output my_db I then ftp the created file to my local Windows 7 machine and attempt to restore the file to my local Postgres 8.4 instance using the following command: pg_restore --create --exit-on-error --verbose c:\path\to\file The restore command generates plenty of output claiming it created my database, connected to it, and then created all the other tables as expected. However, when I view the databases on my local machine through pgAdmin

Which pgdump format is best for small storage size and fast restore?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 14:26:16
This a first time foray in PostgreSQL backups (db dumps) and I've been researching the different pgdump formats, other pgdump options, and pgdumpall. For a Postgres beginner looking at taking an hourly dump (will overwrite previous dump) of two databases that contain table triggers and two different schemas in each db, what would be the backup format and options to easily achieve the following: Small file size (single file per db or ability to choose which db to restore) Easy to restore as clean db (with & without same db name[s]) Easy to restore on different server (user maybe different)

Use pg_restore to restore from a newer version of PostgreSQL

落爺英雄遲暮 提交于 2019-11-29 02:02:03
I have a (production) DB server running PostgreSQL v9.0 and a development machine running PostgreSQL v8.4. I would like to take a dump of the production DB and use it on the development machine. I cannot upgrade the postgres on the dev machine. On the production machine, I run: pg_dump -f nvdls.db -F p -U nvdladmin nvdlstats On the development machine, I run: pg_restore -d nvdlstats -U nvdladmin nvdls.db And I got this error: pg_restore: [archiver] unsupported version (1.12) in file header This occurs regardless of whether I choose the custom, tar, or plain_text format when dumping. I found

I want to restore the database with a different schema

让人想犯罪 __ 提交于 2019-11-28 16:29:30
I have taken a dump of a database named temp1 , by using the follwing command $ pg_dump -i -h localhost -U postgres -F c -b -v -f pub.backup temp1 Now I want to restore the dump in a different database called "db_temp" , but in that I just want that all the tables should be created in a "temp_schema" ( not the default schema which is in the fms temp1 database ) which is in the "db_temp" database. Is there any way to do this using pg_restore command? Any other method also be appreciated! There's no way in pg_restore itself. What you can do is use pg_restore to generate SQL output, and then send

Postgresql 9.2 pg_dump version mismatch

不问归期 提交于 2019-11-28 15:29:40
I am trying to dump a Postgresql database using the pg_dump tool. $ pg_dump books > books.out How ever i am getting this error. pg_dump: server version: 9.2.1; pg_dump version: 9.1.6 pg_dump: aborting because of server version mismatch The --ignore-version option is now deprecated and really would not be a a solution to my issue even if it had worked. How can I upgrade pg_dump to resolve this issue? francs You can either install PostgreSQL 9.2.1 in the pg_dump client machine or just copy the $PGHOME from the PostgreSQL server machine to the client machine. Note that there is no need to initdb

How to fix pg_dump version mismatch errors?

强颜欢笑 提交于 2019-11-27 12:05:43
When trying to get local data to Heroku, I am encountering a version mismatch between two different versions of pg_dump. Specifically, I am getting this message: pg_dump: server version: 9.2.2; pg_dump version: 9.1.4 pg_dump: aborting because of server version mismatch I have found others with this problem, but do not know enough to implement the proposed solutions. (I am new to Ruby on Rails, PostgreSQL, Heroku, and the Mac! Very much at the stage of playing around the picking things up as I go.) I was thinking I might simplify my life if I uninstalled all PostgreSQL on my local machine and

I want to restore the database with a different schema

廉价感情. 提交于 2019-11-27 09:39:55
问题 I have taken a dump of a database named temp1 , by using the follwing command $ pg_dump -i -h localhost -U postgres -F c -b -v -f pub.backup temp1 Now I want to restore the dump in a different database called "db_temp" , but in that I just want that all the tables should be created in a "temp_schema" ( not the default schema which is in the fms temp1 database ) which is in the "db_temp" database. Is there any way to do this using pg_restore command? Any other method also be appreciated! 回答1: