Oto Shavadze
Oto Shavadze

Reputation: 42853

Export and import table dump (.sql) using pgAdmin

I have pgAdmin version 1.16.1 installed on my machine.

For exporting a table dump, I do:

Right click on the table => Choose backup => Set Format to Plain => Save the file as some_name.sql

Then I remove the table.

Ok, now I need to import the backup I just created from some_name.sql into the database.

How am I supposed to do this? I can't find any clear instructions on how to import table's .sql dump into database using pgAdmin.

I'd appreciate some guidance.

Upvotes: 145

Views: 453701

Answers (7)

Shehan Jayalath
Shehan Jayalath

Reputation: 704

To Backup a database using pgAdmin4 (To get a data dump using a pgAdmin4):

  1. Open pgAdmin 4 and connect to your server.
  2. Select the database you wish to back up from the left sidebar.
  3. Right-click on the database and choose Backup.
  4. Specify the file path and name for the backup file in the Filename field.
  5. Choose the format you want (e.g., Custom, Tar, Plain, Directory) from the format dropdown.
  6. Click Backup

The Custom and Tar formats save the backup in binary SQL, which is more suitable for restores involving more complex data types and faster restoration.

Upvotes: 0

relliv
relliv

Reputation: 863

An another way, you can do it easily with CMD on Windows

Put your installed version (mine is 11).

cd C:\Program Files\PostgreSQL\11\bin\

and run simple query

psql -U <postgre_username> -d <db_name> > <C:\path\data_dump.sql>

enter password then wait the final console message.

Note: Make sure to remove <> from the above query except for the > between db_name & file path.

Example: psql -U postgres -d dumb_db > D:\db_dump.sql

Upvotes: 31

alexx ramzzx
alexx ramzzx

Reputation: 111

Follow the steps in pgadmin

host-DataBase-Schemas- public (click right) CREATE script- open file -(choose xxx.sql) , then click on the option execute query write result to file -export data file ok- then click in save.its all. it work to me.

note: error in version command script enter image description herede sql over pgadmin can be search, example: http://www.forosdelweb.com/f21/campo-tipo-datetime-postgresql-245389/

enter image description here

Upvotes: 10

Tomas Greif
Tomas Greif

Reputation: 22661

  1. In pgAdmin, select the required target schema in object tree (databases ->your_db_name -> schemas -> your_target_schema)
  2. Click on Plugins/PSQL Console (in top-bar)
  3. Write \i /path/to/yourfile.sql
  4. Press enter

Upvotes: 199

milaoshutapintou
milaoshutapintou

Reputation: 190

Click "query tool" button in the list of "tool".

image

And then click the "open file" image button in the tool bar.

image

Upvotes: 11

Kavindu Gayan
Kavindu Gayan

Reputation: 394

Using PgAdmin step 1: select schema and right click and go to Backup..enter image description here

step 2: Give the file name and click the backup button.

enter image description here

step 3: In detail message copy the backup file path.

enter image description here

step 4:

Go to other schema and right click and go to Restore. (see step 1)

step 5:

In popup menu paste aboved file path to filename category and click Restore button.

enter image description here

Upvotes: 29

Humming
Humming

Reputation: 453

If you have Git bash installed, you can do something like this:

/c/Program\ Files\ \(x86\)/PostgreSQL/9.3/bin/psql -U <pg_role_name> -d <pg_database_name> < <path_to_your>.sql

Upvotes: 2

Related Questions