I have error loading data into PostgreSQL database - postgresql

follow up to the question, this is the command line i used but it could not recognizecommand line my password
The Image
I have a PostGreSQL script that contains table definition and sample data but whenever i tried to run the script, i get the error as shown in the diagram.
Please, does anyone has any idea o what is wrong?
I am new to PostgreSQL

From the image, it looks as if you're using pgAdmin to load a database dump created with pg_dump. I'm not sure whether this will work with pgAdmin's query tool; you should try instead loading it from the command line:
psql -f the_dump_file.sql my_database
Full details here:
https://www.postgresql.org/docs/9.6/static/app-pgdump.html
https://www.postgresql.org/docs/9.6/static/app-psql.html

Related

ERM from PostgreSQL via psql (SQL Shell)

I need to understand the relations between tables in a PostgreSQL database. I will not have the ability to download pgAdmin4 like I am used to working in. So after looking around I found pg_dump.exe built into PostgreSQL. I thought I could just do something like this in the SQL Shell (psql) to get a dump of the database and then have the ability to upload it into another system:
database=# pg_dump database > path/to/save/file.sql;
Based on the docs >> https://www.postgresql.org/docs/9.3/app-pgdump.html
But when I run that I get an error:
ERROR: syntax error at or near "pg_dump"
LINE 1: pg_dump database > path/to/save/file.sql;
^
I saw on this stack overflow question was similar to my issue with the pg_dump error. In the solutions, Adrian says that pg_dump does not work within psql. When I run the code that Adrian suggested, I also get an error.
Any thoughts on how I can use psql to get the information that I need of this database?
Note: I am accessing a Linux VM on a Windows machine.

Restore dump locally without pre-existing database

I have received a backup file from a customer and wish to restore it.
I've tried executing the following on the command line (which runs for ages, seems to get to the end, but does not produce a new database in my localhost server).
pg_restore --create -h localhost c:\temp\myBackup.backup
I've also tried to run the restore through pgAdmin4 but it reports that indexes already exist if I tried to create an empty database and restore into it and I can't seem to locate the correct options to restore the database and create a new one (without having first selected an empty database).
Any pointers would be greatly appreciated. I'm happy to use any method.

How to dump a postgres DB into a .sql file

I have a "cinema" DB in postgres and I want to dump all its tables and data in a cinema.sql file.
This file will contain all the sql code for re-creating the schema, tables and filling them with the data.
I already have a bank.sql file (for the "bank" DB) which I can execute via PSQL console in pg Admin III and import using the command
/i *path to my bank.sql file*
Now, I want to produce a cinema.sql file like bank.sql, but I don't know how to do it.
It's not the backup/restore feature of course, because it produces a .backup file.
I've also tried
pg dump > cinema.dump
In PSQL console but I can't find a .sql file anywhere, so I don't think it is what I'm looking for either.
Couldn't find anything useful for what I need in Postgres documentation unfortunately so I hope you can help me because I'm just a beginner.
Thanks.
As mentioned in the comments and the documentation, you should use pg_dump command line tool.
pg_dump cinema > cinema.sql
I've made it! Don't know if it's the 100% right way to do it, though, but I think it is.
I'll report here just in case someone else might need this in the future and it can be of help.
I selected the db I wanted to dump in .sql file and then right click -> backup.
Here, as format, I chose plain instead of custom, and "mydbdump.sql" as file name.
In Dump Options #1 and Dump Options #2 I checked the checkboxes to include everything I needed (e.g. "include CREATE DATABASE statement").
I compared this newly created .sql dump with the one I already had (using Notepad++) and they look the same (even if, of course, they are from different dbs).

Unable to create new Postgres database

I'm unable to create a new database for the first time after installing postgres.app on my macbook pro
Anyone here can point me to the origin of the problem ?
createdb is not a SQL statement, it's program for the command line (like psql or grep).
Inside psql you need to use the SQL statement CREATE DATABASE:
http://www.postgresql.org/docs/current/static/sql-createdatabase.html
And don't forget to terminate every SQL statement with a ; (if you had done that with createdb you would have gotten an error message immediately).

How to create sql script of postgres database schema?

I want sql script of postgres 9 database schema which is not on local server. I tried pg_dump command on sql editor of pgAdmin and its not working there. I m not sure where to run that command. Please assist me with the same....
Thanks..
pg_dump is a command line utility; it isn't SQL, so it won't work in pgAdmin or anywhere else that executes SQL.
pgAdmin however does have a facility to do what you want:
Right-click on the database you want to export
Select Backup from the pop-up menu
Chose "format" Plain
Chose "plain option" Only schema
You can also use pgAdmin tool to generate or take plain text Database Backup.
You can generate plain text backup for data or schema only.
I have shared few screen shots, please visit this blog for more details.