31

I need to restore a big table (250mb) in PostgreSQL database in console tool. How I can do this using ps_dump or psql?

1
  • you can get the help for all commands with \h in the psql shell Commented Feb 24, 2012 at 10:04

5 Answers 5

55

Just connect to database with psql and run \i /path/to/filename.sql.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked while using psql like: psql -d newdb -f db.sql did nothing. Anyone have a clue why? BTW thanks very much.
this restores the whole DB not a single table
27
psql --username yourusername --dbname yourdatabasename -f yourfile.sql

as clarified here. Depending on configuration, may ask for your password.

If it is a newly installed database engine with no your database yet, use postgres for the database name and try to omit the username part (new installation should normally grant the full access to the current user who installed it).

If you still can’t login, edit temporarily pg_hba.conf wherever it could be in your installation and temporarily set the localhost to trusted. Then you can specify postgres both as username and as the database name.

Don’t forget to revert pg_hba.conf changes when done.

Comments

19
psql dbname < /path/to/dump.sql

You may even modify your dump on the fly if required:

sed 's/OWNER TO olduser/OWNER TO newuser/g' <  /path/to/dump.sql | psql dbname

1 Comment

This was highly useful. I needed something that could be executed from a script. Thanks!
5
psql -U postgres -d doctor_dev < /home/ravi/mydevelopment

1 Comment

This isn't an answer. This code only sends unknown sql statements from file to the postgresql database.
0

psql -d <db_name> -f <path_to>/<latest_DB_BACKUP>.psql

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.