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

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.

Related

Problems to perform PostgreSQL restore

I'm having trouble performing the restore from a dump. The scenario is as follows: I am migrating an environment from GCP to AWS, and at the moment I am working on the migration of the bank.
A partner dumped db that is in GCP and placed the file on AWS S3 (I don't know the command he used to perform the dump).
I created an EC2 in the AWS environment and copied the dump from S3 to EC2 (the file is 13 GB). I also created the RDS to host the new db with all the correct security group settings.
Here comes the problem, I connect to the RDS from the server (EC2) without problems, but when doing the restore using pg_restore I get the following error message: pg_restore: too many command line arguments (first is "dbclient. dump ").
The complete command I used was this:
pg_restore -h client-aurora-cluster-hmg-legado-instance-1.c23ltjbbz7ms.us-east-1.rds.amazonaws.com -U postgres -d db_hmg_legado dbclient.dump -W
OK, I changed the approach. I tried with psql instead of pg_restore and then the command was like this:
psql -h client-aurora-cluster-hmg-legado-instance-1.c23ltjbbz7ms.us-east-1.rds.amazonaws.com -U postgres -d db_hmg_legado dbclient.dump -W
Only this time it worked !!!!
But I received some error messages while performing the restore. Which I put below:
psql: dbclient.dump: 23: ERROR: schema "dw" already exists
CREATE EXTENSION
psql: dbclient.dump: 37: ERROR: must be owner of extension hstore
CREATE EXTENSION
psql: dbclient.dump: 51: ERROR: must be owner of extension intarray
CREATE EXTENSION
psql: dbclient.dump: 65: ERROR: must be owner of extension pg_trgm
CREATE EXTENSION
psql: dbclient.dump: 79: ERROR: must be owner of extension unaccent
But the restore takes a long time and is partially finished.
In general I wanted to understand why pg_restore didn't work. Has anyone ever experienced this?
And about these owner errors does anyone know how to resolve this using psql?
As documented in the manual the file to be restored is the last parameter and it is specified without a "switch". But you are using -W after the dump file. Move the -W parameter somewhere before that (although it's usually not necessary to begin with)
So you need something like this:
pg_restore -W -h ... -U postgres -d db_hmg_legado dbclient.dump
However, if the restore worked when using psql then the dump file is a "plain text" dump which can't be restored using pg_restore to begin with.
Concerning the errors:
You should restore the dump into an empty database that doesn't contain any schemas except the default ones.
You need a superuser for CREATE EXTENSION, which you don't have in a hosted database. So pre-install these extensions with the techniques that Amazon provides, then restore the dump and ignore the errors.

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.

Creating a database dump doesn't seem to be working

I have PostgresQL 9.6.2 installed, and I'm trying to make a backup of one of my databases (my_database) using pg_dump command. It doesn't seem to be working as I see no output file.
I'm using a Mac and from my terminal (and in my project directory) I use:
psql postgres postgres
pg_dump my_database > my_database.bak
being postgres my database default user and password.
I've already tried using sudo psql postgres postgres with the same results.
I imagine that I'm experiencing some kind of lack of permissions but cannot understand it.
So, how to have the right permissions to do this?
Postgres comes with a bunch of stuff, including command-line tools. That includes the standard client, psql, and also the command pg_dump. That needs to be invoked from a shell command line.
If you type it into a psql command line, you'll get a syntax error once you terminate the line (with a ';') -- it's not valid sql, nor a valid command to psql.
Hope that helps!

PostgreSQL: Unable to Restore .backup using pgAdmin III Restore

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!