Categories: Snippets

Backup & Restore Database in PostgreSQL

1) Backup data with pg_dump

pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f 
"/usr/local/backup/10.70.0.61.backup" old_db

To list all of the available options of pg_dump , please issue following command.

pg_dump -?

  • -p, –port=PORT database server port number
  • -i, –ignore-version proceed even when server version mismatches
  • -h, –host=HOSTNAME database server host or socket directory
  • -U, –username=NAME connect as specified database user
  • -W, –password force password prompt (should happen automatically)
  • -d, –dbname=NAME connect to database name
  • -v, –verbose verbose mode
  • -F, –format=c|t|p output file format (custom, tar, plain text)
  • -c, –clean clean (drop) schema prior to create
  • -b, –blobs include large objects in dump
  • -v, –verbose verbose mode
  • -f, –file=FILENAME output file name

2) Restore data with pg_restore

pg_restore -i -h localhost -p 5432 -U postgres -d old_db -v 
"/usr/local/backup/10.70.0.61.backup"

To list all of the available options of pg_restore , please issue following command.

pg_restore -?

  • -p, –port=PORT database server port number
  • -i, –ignore-version proceed even when server version mismatches
  • -h, –host=HOSTNAME database server host or socket directory
  • -U, –username=NAME connect as specified database user
  • -W, –password force password prompt (should happen automatically)
  • -d, –dbname=NAME connect to database name
  • -v, –verbose verbose mode

DUMP Single Table

pg_dump.exe --host localhost --port 5432 --username "postgres" --no-password  --format plain --section pre-data --section data --section post-data --encoding UTF8 --inserts --column-inserts --verbose --file "C:\Users\NIC\Desktop\office.sql" --table "public.c_offices" "secure20160804"

 

Recent Posts

Generate Slug URL in MySQL

A slug is a short name using human-readable keywords to identify a web page. For…

5 years ago

How to use SQL LIKE condition with multiple values in PostgreSQL?

[crayon-662d8b7d7fcca015121349/]  

5 years ago

SELECT Null

[crayon-662d8b7d7fded988284119/]  

5 years ago

ALTER Column SET NOT NULL – pgSQL

[crayon-662d8b7d7ff3c961348454/]  

5 years ago

ADD new Column – pgSQL

[crayon-662d8b7d80085887783940/] [crayon-662d8b7d8008b881965437/]  

5 years ago