PostgreSQL: Unable to Restore .backup using pgAdmin III Restore - postgresql

In reference to this question:
PostgreSQL Job Scheduling: Creating Schedule Backup using Bat File
It made me successful to have a back-up for my database.
Filename: Database_backup.backup
However, using PgAdmin III using Restore selection, i wasn't able to restore it, it shows Error:
C:\Program Files\PostgreSQL\9.4\bin\pg_restore.exe --host localhost
--port 5432 --username "postgres" --dbname "db_name" --no-password --list "C:\Users\Name\Documents\Backup_20160805.backup"
pg_restore: [archiver] input file appears to be a text format dump.
Please use psql.
What I am missing here?
Is it in Backup?
Again, I need your guidance here.
Thanks so much.

pg_dump, which is called by pgAdmin III to perform backups, can create them in four formats:
plain: SQL commands
custom: compressed proprietary binary format
directory: one backup file per table
tar: like "directory", but as a tar archive
There is a "format" dropdown in pgAdmin III that lets you select the format.
To restore a plain format dump, you'll have to execute the SQL script with pgAdmin III or psql.
For the other three formats, you use pg_restore, which is internally called by pgAdmin III's "restore" functionality.
So you took a plain format dump, which causes the reported error with pg_restore. Execute it as a SQL script instead!

Related

How do I restore a .sql file backup in pgadmin

I have a .sql file of the database backup. PostgreSQL is installed in my system and I use pgadmin4 to communicate with database. I want to restore this .sql file using pgadmin. Can someone please guide me.
An SQL script that was generated with pg_dump without the --inserts option cannot be restored with pgAdmin, because the COPY data are mixed with the statements. You need psql for that.
You could use one of the other backup formats ("custom", "directory" or "tar") and use pgAdmin to restore that. But all that pgAdmin does in this case is call pg_restore, so you might as well do that yourself from the command line.
Another option is to launch the "psql tool" from pgAdmin, which is nothing else than psql. Then you can load the dump with \i dumpfile.sql.

Problem restoring databse between 2 RDS instances using pg_dump and pg_restore

I'm having difficulty restoring a DB to an AWS RDS Postgresql instance. Context is that i am backing up from one RDS instance and restoring to another RDS insurance. They both have the same version of Postgresql 9.6.5.
I was able to take a dump using the following command:
./pg_dump.exe -U dbuser -W -h prod-pgsql-rds.3ft5coqxjdnq.eu-west-2.rds.amazonaws.com -d devdb > c:\tmp\backup.sql
From the resulting .sql file, I then attempted a restore to another RDS instance which is also using Postgresql 9.6.5 using below command:
./pg_restore.exe -U dbuser -d testdevdb -h dev-pgsql-rds.cym8coqx52lq.eu-west-2.rds.amazonaws.com "c:\tmp\backup.sql"
*I also tried the -f switch in the above restore command instead of the " " quotes before/after the file name
But when I try to restore it to a newly created database I get the following error:
pg_restore: [archiver] input file does not appear to be a valid archive
Can anyone help? FYI, I am using PGAdmin 4 via Windows PowerShell. I have to edit some of the values in the strings above due to data sensitivity.
pg_restore is only used for the other, non-plain-text output formats that pg_dump can output. For .sql dumps, you just use psql. See the docs on restoring from backups.
In a Unix env, you'd do psql [yourflags] < /tmp/backup.sql, but I'm unfamiliar with powershell and don't know if it supports < for input redirection; hopefully either it's present or you know the equivalent PowerShell syntax.
So I couldn't get psql or pg_restore to work so opted to import the .SQL file into via the SQL query tool in PGAmdin. This through up some errors so had to make several changes to the .SQL file and perform below:
Commented out a couple of lines that were causing errors
Elevated permissions for the user and made him the owner of for the Schema and DB properties by right-clicking on these via PGAdmin
The .sql file was making several references to the user from the source RDS DB so had to do a find and replace with a user account created for the destination RDS DB. Alternatively, I could have just created a new user on the destination DB with the same username and password as the source DB and then make him the owner in ref to step 2.

How to view pg_dump data with .sql extension?

I have downloaded pg_dump data from DeepDive Open Datasets. It is a file with extension .sql and to my knowledge that is a text file with SQL commands in it to recreate the database. I'm trying to peruse the data. How do I set up a Postgres database to do that?
I tried to use pgAdmin4 to view the data. However, I'm not sure how to set up and add a new server to read the data. I'm not sure if that is the correct approach.
I would appreciate any guidance with this.
You would view the dump itself with a pager like more or less; such a dump is a plain text file with SQL statements.
To restore such a dump you need to use psql, the command line client:
psql -U postgres -d adatabase -f dumpfile.sql
pgAdmin cannot restore such a dump, because it contains COPY ... FROM STDIN statements intermixed with the data.

Pgadmin 4 pg_restore: [archiver] input file appears to be a text format dump. Please use psql

Hi I am using Postgres 11 and pgadmin 4.1. I have a SQL file i am trying to import in my newly created database in pgadmin 4.
I know its a generalized error but I tried my best to resolve it, but not working for me.
Here is the error:
Here are a few SQL file lines.
There are two things in a plain text dump that may prevent it being restored using the query tool og pgAdmin:
backslash commands, like the \connect you get if you use the --create option of pg_dump (only psql understands these)
COPY commands to load the data, because pgAdmin does not support mixing SQL and data the way that psql does
So if the dump was created without --create and with either --schema-only or --inserts, it will probably load fine.

Copying CSV to Amazon RDS hosted Postgresql database

I have a database hosted using Amazon's RDS service and I am attempting to write a web service that will update said database. The problem I am having is that it will not let me use the COPY command as I get this error: "ERROR: must be superuser to COPY to or from a file". I am using the only user I have made for the database and I am fairly certain it has superuser access. I can, however, use PGAdmin's import tool to import the data which, when looking at the log, uses almost the exact same command as I do. The only difference is instead of the file path it has stdin. How can I fix this error?
You're using:
COPY tablename FROM 'filename';
this won't work - RDS has no idea what 'filename' is.
You must use the psql command's \copy, which copies from the local client, or PgAdmin-III's "import data" option.
The RDS manual covers this in more detail.
Workaround without using psql
1) Import data locally to a temporary table using simple copy command
2) Right click the table in the pgAdmin III object browser and select "Backup..."
3) Set the format to Plain and save the file as a .sql file
4) Click on the Dump Options #1 Tab and check Data
5) Click on the Dump Options #2 Tab and check Use Column Inserts and Use Insert Commands
6) Click Backup button
7) Now you can open the sql file and run it in your RDS server
Alternatively you can use the below command to generate the sql file
pg_dump --host localhost --port 5432 --username "postgres" --no-password --format plain --section data --inserts --column-inserts --file "C:\test\test.sql" --table "public.envelopes" "testdb"