27

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

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
NiLL
  • 13,645
  • 14
  • 46
  • 59

4 Answers4

51

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

Tometzky
  • 22,573
  • 5
  • 59
  • 73
23
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.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
16
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
Ruslan Kabalin
  • 6,580
  • 2
  • 28
  • 20
2
psql -U postgres -d doctor_dev < /home/ravi/mydevelopment
FelixSFD
  • 6,052
  • 10
  • 43
  • 117