{"id":17675,"date":"2020-12-04T13:37:53","date_gmt":"2020-12-04T13:37:53","guid":{"rendered":"https:\/\/dbtut.com\/?p=17675"},"modified":"2020-12-07T07:17:15","modified_gmt":"2020-12-07T07:17:15","slug":"how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/","title":{"rendered":"How To Backup and Restore PostgreSQL Database using pg_dump and psql"},"content":{"rendered":"<p>In this article, we will backup and restore the PostgreSQL database using pg_dump.<\/p>\n<h2>What is pg_dump?<\/h2>\n<p>pg_dump is a utility used to back up the Postgresql database.<\/p>\n<p>The dump files backed up by pg_dump are completely consistent because the dump is a snapshot of the data when pg_dump started running.<br \/>\npg_dump does not prevent other users from accessing the database (read or write).<br \/>\nA normal user can run pg_dump if he or she has been granted authority over a database.<\/p>\n<p>pg_dump only backs up one database. Pg_dumpall is used to back up the entire cluster or to back up common objects (such as roles and tablespace) that are common to all databases in the cluster.<\/p>\n<h3>pg_dump file types<\/h3>\n<p>Dump files can be exported in script or archive file formats.<\/p>\n<p>Scripted dump files are plain text files that contain SQL commands required to recovery the database to the state it was in when it was saved. Using the script created in this way; it is sufficient to run the generated sql file with psql or another tool to restore the database to its current state . The relevant database must have been created before this command is run, otherwise the objects are created in the postgres database by default. Due to its ease of use, it can be used to restore the database in architecture and machine changes.<\/p>\n<p>If we do not want to create the database manually, we must create backups in the archive file format (custom, directory, tar) with pg_dump. However, in this case, we need to do the restore with the pg_restore tool instead of psql.<\/p>\n<p>pg_restore is selective about what is being restored. It even allows you to rearrange items before they are restored, so we have a more flexible method.<\/p>\n<h3>pg_dump syntax<\/h3>\n<p>The syntax of the pg_dump command is as follows;<\/p>\n<pre class=\"lang:default decode:true \">pg_dump [connection-option\u2026] [option\u2026] [dbname]<\/pre>\n<p>We specify the host of the database we want to backup with the -h parameter and the port with the -p parameter. The default server is the local server or whatever is specified in the PGHOST variable. Likewise, the value of the default port is the value specified in the PGPORT variable or takes the default value compiled.<\/p>\n<p>Like other PostgreSQL client applications, by default pg_dump will connect to the database username that is equal to the current OS user&#8217;s name. To do this with a different user, we can use either the -U parameter or the PGUSER variable.<\/p>\n<h2>PostgreSQL pg_dump Examples<\/h2>\n<h3>Backup Postgres Database psql<\/h3>\n<p>We can generate the SQL dump file of the database named mydb with several different syntaxes.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump mydb &gt; db.sql\r\npg_dump -h localhost -p 5432 -U postgres mydb &gt; db.sql\r\npg_dump -h localhost -p 5432 -U postgres mydb -f db.sql<\/pre>\n<h3>Restore Postgres Database From sql file<\/h3>\n<p>We can restore the create dump file as another database named newdb.<\/p>\n<pre class=\"lang:default decode:true \">psql -d newdb -f db.sql\r\npsql -f db.sql -d newdb -p 5432 -U postgres<\/pre>\n<h3>PostgreSQL pg_dump custom format<\/h3>\n<p>The dump of mydb database is created in custom file format with the following command. The backup file produced in this way will be much smaller than the sql file because in the background the file is compressed with zlib.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -Fc mydb &gt; db.dump<\/pre>\n<h3>Restore PostgreSQL Database From custom file format dump<\/h3>\n<pre class=\"lang:default decode:true \">pg_restore -d newdb db.dump<\/pre>\n<h3>PostgreSQL pg_dump directory format<\/h3>\n<p>The dump of mydb database is created in directory format with the following command.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -Fd mydb -f dumpdirectory<\/pre>\n<h3 class=\"LC20lb DKV0Md\">Parallel pg_dump backups<\/h3>\n<p>Using the command below, we can create a dump file with directory format in parallel.<\/p>\n<p><strong>NOTE:<\/strong> You can only use this option with a directory format. Because it is the only format that multiple processes can write their data at the same time.<\/p>\n<pre class=\"lang:default decode:true\">pg_dump -Fd mydb -j 5 -f dumpdir<\/pre>\n<h3>Restore PostgreSQL Database From directory file<\/h3>\n<p>The command that can be used to restore the directory file.<\/p>\n<pre class=\"lang:default decode:true \">pg_restore -Fd -l dumpdirectory<\/pre>\n<h3>PostgreSQL pg_dump tar format<\/h3>\n<p>The command below creates the dump file of the mydb database in tar file format.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -Ft mydb &gt; db.tar<\/pre>\n<h3>Restore Postgres Database From tar file<\/h3>\n<p>We can restore the backup taken as tar with the following command.<\/p>\n<pre class=\"lang:default decode:true \">pg_restore -Ft -d newdb db.tar<\/pre>\n<h3>PostgreSQL Backup Specific Tables<\/h3>\n<p>If we want to back up only the specified table, we can use the following command.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -t test_table -d mydb &gt; table.sql<\/pre>\n<h3>PostgreSQL Backup Tables Starting With x<\/h3>\n<p>If we want to back up the tables whose names starting with test_table, we can use the following command.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -t 'test_table*' -d mydb &gt; table.sql\r\n<\/pre>\n<p>If we want to back up the tables whose names starting with test_table but not test_table_mustafa, we can use the following command.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -t 'test_table*' -T test_table_mustafa -d mydb &gt; table.sql\r\n<\/pre>\n<p>To backup all schemas whose names start with east or west and end with gsm, and to exclude all schemas whose names contain the word test, we use the following;<br \/>\n<strong>NOTE:<\/strong> This command contains the schema itself as well as all the objects it contains.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb &gt; db.sql\r\npg_dump -n '(east|west)*gsm' -N '*test*' mydb &gt; db.sql<\/pre>\n<p>Normally, no matter how we write the table name uppercase or lowercase, pg_dump assumes it as small. But if we want the value we write to be taken into account exactly, we need to write it in double quotes (&#8220;). Of course, double quotes are a special character for the shell, so we have to act like an escape charecter as follows.<\/p>\n<pre class=\"lang:default decode:true\">pg_dump -t \"\\\"MixedCaseName\\\"\" mydb &gt; mytab.sql\r\n<\/pre>\n<p>The following command is used to restore directly from one database to another. Of course, in this case, the database named newdb must be in the specified cluster.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump mydb | psql -h 192.168.10.106 newdb<\/pre>\n<p>If we want to get data only, not metadata, the command is as follows.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump -a test &gt; test.sql\r\npg_dump --data-only test &gt; test.sql<\/pre>\n<h3>PostgreSQL pg_dump compression<\/h3>\n<p>The following command is used to take a compressed backup with pg_dump.<\/p>\n<pre class=\"lang:default decode:true \">pg_dump mydb | gzip -9 &gt; mydb.gz<\/pre>\n<h3>PostgreSQL pg_dump split<\/h3>\n<p>If you want to split the dump output into multiple files of certain sizes, the command is as follows.<\/p>\n<pre class=\"lang:default decode:true\">pg_dump mydb | split -b 1m - filename\r\n<\/pre>\n<h3>PostgreSQL restore split dump file<\/h3>\n<pre class=\"lang:default decode:true \">cat filename* | psql dbname<\/pre>\n<h3>PostgreSQL pg_dump ON_ERROR_STOP<\/h3>\n<p>By default; If an error occurs while restoring, psql will ignore the error and continue to run. We can customize this case by setting the ON_ERROR_STOP variable. After this command, the codes will run until the line where the error occurred, but subsequent lines will not be processed.<\/p>\n<pre class=\"lang:default decode:true \">psql --set ON_ERROR_STOP=on mydb &lt; mydb.sql<\/pre>\n<h3>PostgreSQL pg_dump single-transaction<\/h3>\n<p>Alternatively, we can specify that the restore must be completed in a single operation, that is, it will either be completely completed or completely rolled back. If we want it to take no action in the event of an error, we can do it this way.<\/p>\n<pre class=\"lang:default decode:true\">psql --single-transaction mydb &lt; mydb.sql<\/pre>\n<h2>PostgreSQL pg_dumpall<\/h2>\n<p>pg_dump can back up only one database at a time, not roles or tablespaces. Because these are information covering more than one database rather than a database. We use pg_dumpall to properly backup all the contents of a cluster. pg_dumpall creates a backup of each database in a given cluster and also a backup of data such as cluster-wide role and tablespace definitions.<\/p>\n<pre class=\"lang:default decode:true \">pg_dumpall &gt; dumpfile.sql\r\npg_dumpall -f dumpfile.sql<\/pre>\n<pre class=\"lang:default decode:true \">psql postgres &lt; dumpfile.sql \r\npsql -f dumpfile.sql postgres<\/pre>\n<p>When restoring with pg_dumpall, superuser access is always needed to restore role and tablespace information. While doing these operations, if we are using tablespace, we need to make sure that the paths of these tablespaces also exist.<br \/>\npg_dumpall sends commands to create roles, tables, and empty databases, then runs pg_dump for each database. That is, each database will be consistent within itself, but other databases will not be synchronized instantly.<\/p>\n<p>Mustafa Bekta\u015f Tepe<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_17675\" class=\"pvc_stats all  \" data-element-id=\"17675\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will backup and restore the PostgreSQL database using pg_dump. What is pg_dump? pg_dump is a utility used to back up the Postgresql database. The dump files backed up by pg_dump are completely consistent because the dump is a snapshot of the data when pg_dump started running. pg_dump does not prevent other &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_17675\" class=\"pvc_stats all  \" data-element-id=\"17675\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":926,"featured_media":17680,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[5],"tags":[10256,10259,10255,10264,10268,10260,10265,10258,10254,10253,10270,10273,10279,10275,10261,10277,10269,10271,10272,10278,10274,10267,10276,10257,10266,10262,10263,10252],"class_list":["post-17675","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-postgres","tag-dump-and-sql","tag-backup-postgres-database-psql","tag-differences-between-dump-and-sql-in-pg_dump","tag-parallel-pg_dump-backups","tag-pg_dump-compression","tag-pg_dump-custom-format","tag-pg_dump-directory-format","tag-pg_dump-examples","tag-pg_dump-file-type","tag-pg_dump-file-types","tag-pg_dump-on_error_stop","tag-pg_dump-single-transaction","tag-pg_dump-split","tag-pg_dumpall","tag-postgresql-database-from-custom-file-format-dump","tag-postgresql-pg_dump-compression","tag-postgresql-pg_dump-examples","tag-postgresql-pg_dump-on_error_stop","tag-postgresql-pg_dump-single-transaction","tag-postgresql-pg_dump-split","tag-postgresql-pg_dumpall","tag-postgresql-restore-database-to-another-server","tag-postgresql-restore-split-dump-file","tag-restore-postgres-database-from-sql-file","tag-restore-postgres-database-from-tar-file","tag-restore-postgresql-database-from-custom-file-format-dump","tag-restore-postgresql-database-from-directory-file","tag-what-is-pg_dump"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials<\/title>\n<meta name=\"description\" content=\"How To Backup and Restore PostgreSQL Database using pg_dump and psql\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"How To Backup and Restore PostgreSQL Database using pg_dump and psql\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-04T13:37:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-07T07:17:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"818\" \/>\n\t<meta property=\"og:image:height\" content=\"460\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mustafa Bekta\u015f Tepe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mustafa Bekta\u015f Tepe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\"},\"author\":{\"name\":\"Mustafa Bekta\u015f Tepe\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/bf61379dc4b6cb1df9a84293fc5da608\"},\"headline\":\"How To Backup and Restore PostgreSQL Database using pg_dump and psql\",\"datePublished\":\"2020-12-04T13:37:53+00:00\",\"dateModified\":\"2020-12-07T07:17:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\"},\"wordCount\":1163,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg\",\"keywords\":[\".dump and .sql\",\"Backup Postgres Database psql\",\"Differences between .dump and .sql in pg_dump\",\"Parallel pg_dump backups\",\"pg_dump compression\",\"pg_dump custom format\",\"pg_dump directory format\",\"pg_dump Examples\",\"pg_dump file type\",\"pg_dump file types\",\"pg_dump ON_ERROR_STOP\",\"pg_dump single-transaction\",\"pg_dump split\",\"pg_dumpall\",\"postgresql database from custom file format dump\",\"PostgreSQL pg_dump compression\",\"PostgreSQL pg_dump Examples\",\"PostgreSQL pg_dump ON_ERROR_STOP\",\"PostgreSQL pg_dump single-transaction\",\"PostgreSQL pg_dump split\",\"PostgreSQL pg_dumpall\",\"postgresql restore database to another server\",\"PostgreSQL restore split dump file\",\"restore postgres database from sql file\",\"restore postgres database from tar file\",\"restore postgresql database from custom file format dump\",\"Restore PostgreSQL Database From directory file\",\"What is pg_dump?\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\",\"name\":\"How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg\",\"datePublished\":\"2020-12-04T13:37:53+00:00\",\"dateModified\":\"2020-12-07T07:17:15+00:00\",\"description\":\"How To Backup and Restore PostgreSQL Database using pg_dump and psql\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg\",\"width\":818,\"height\":460},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Backup and Restore PostgreSQL Database using pg_dump and psql\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/bf61379dc4b6cb1df9a84293fc5da608\",\"name\":\"Mustafa Bekta\u015f Tepe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ce2391ff3d363a1456f398312ea70eb44d6ef7740742d9cfede93c491d3e7500?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ce2391ff3d363a1456f398312ea70eb44d6ef7740742d9cfede93c491d3e7500?s=96&d=mm&r=g\",\"caption\":\"Mustafa Bekta\u015f Tepe\"},\"url\":\"https:\/\/dbtut.com\/index.php\/author\/mustafabektas\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials","description":"How To Backup and Restore PostgreSQL Database using pg_dump and psql","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/","og_locale":"en_US","og_type":"article","og_title":"How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials","og_description":"How To Backup and Restore PostgreSQL Database using pg_dump and psql","og_url":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/","og_site_name":"Database Tutorials","article_published_time":"2020-12-04T13:37:53+00:00","article_modified_time":"2020-12-07T07:17:15+00:00","og_image":[{"width":818,"height":460,"url":"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg","type":"image\/jpeg"}],"author":"Mustafa Bekta\u015f Tepe","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mustafa Bekta\u015f Tepe","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/"},"author":{"name":"Mustafa Bekta\u015f Tepe","@id":"https:\/\/dbtut.com\/#\/schema\/person\/bf61379dc4b6cb1df9a84293fc5da608"},"headline":"How To Backup and Restore PostgreSQL Database using pg_dump and psql","datePublished":"2020-12-04T13:37:53+00:00","dateModified":"2020-12-07T07:17:15+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/"},"wordCount":1163,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg","keywords":[".dump and .sql","Backup Postgres Database psql","Differences between .dump and .sql in pg_dump","Parallel pg_dump backups","pg_dump compression","pg_dump custom format","pg_dump directory format","pg_dump Examples","pg_dump file type","pg_dump file types","pg_dump ON_ERROR_STOP","pg_dump single-transaction","pg_dump split","pg_dumpall","postgresql database from custom file format dump","PostgreSQL pg_dump compression","PostgreSQL pg_dump Examples","PostgreSQL pg_dump ON_ERROR_STOP","PostgreSQL pg_dump single-transaction","PostgreSQL pg_dump split","PostgreSQL pg_dumpall","postgresql restore database to another server","PostgreSQL restore split dump file","restore postgres database from sql file","restore postgres database from tar file","restore postgresql database from custom file format dump","Restore PostgreSQL Database From directory file","What is pg_dump?"],"articleSection":["PostgreSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/","url":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/","name":"How To Backup and Restore PostgreSQL Database using pg_dump and psql - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg","datePublished":"2020-12-04T13:37:53+00:00","dateModified":"2020-12-07T07:17:15+00:00","description":"How To Backup and Restore PostgreSQL Database using pg_dump and psql","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#primaryimage","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2020\/12\/pgdump.jpg","width":818,"height":460},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2020\/12\/04\/how-to-backup-and-restore-postgresql-database-using-pg_dump-and-psql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"How To Backup and Restore PostgreSQL Database using pg_dump and psql"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/bf61379dc4b6cb1df9a84293fc5da608","name":"Mustafa Bekta\u015f Tepe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ce2391ff3d363a1456f398312ea70eb44d6ef7740742d9cfede93c491d3e7500?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ce2391ff3d363a1456f398312ea70eb44d6ef7740742d9cfede93c491d3e7500?s=96&d=mm&r=g","caption":"Mustafa Bekta\u015f Tepe"},"url":"https:\/\/dbtut.com\/index.php\/author\/mustafabektas\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/17675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/926"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=17675"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/17675\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media\/17680"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=17675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=17675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=17675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}