{"id":712,"date":"2021-03-03T11:09:02","date_gmt":"2021-03-03T05:09:02","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=712"},"modified":"2021-03-03T11:09:02","modified_gmt":"2021-03-03T05:09:02","slug":"how-to-backup-postgresql-database-from-command-line","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/how-to-backup-postgresql-database-from-command-line.html","title":{"rendered":"How to Backup PostgreSQL Database from Command Line"},"content":{"rendered":"\n<p><strong>Question<\/strong><\/p>\n\n\n\n<p>How to Backup PostgreSQL Database from Command Line<\/p>\n\n\n\n<p><strong>Solution<\/strong><\/p>\n\n\n\n<p>Postgresql comes with two utilities called &#8216;pg_dump and &#8216;pgsql&#8217;. These can be used to backup and restore database.<\/p>\n\n\n\n<p>To backup postgresql database using command line, you can use this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pg_dump database_name > database_name.sql<\/pre>\n\n\n\n<p>This would take the backup and store it in .sql file.<\/p>\n\n\n\n<p>To restore postgresql (.sql) file to a database using command line, you can use this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pgsql database_name &amp;lt; database_name.sql<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Question How to Backup PostgreSQL Database from Command Line Solution Postgresql comes with two utilities called &#8216;pg_dump and &#8216;pgsql&#8217;. These can be used to backup and restore database. To backup postgresql database using command line, you can use this: This would take the backup and store it in .sql file. To restore postgresql (.sql) file &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/how-to-backup-postgresql-database-from-command-line.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Backup PostgreSQL Database from Command Line&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[412,523],"tags":[37,526,527,524,525],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/712"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":1,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":713,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions\/713"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}