{"id":6552,"date":"2018-04-07T11:04:17","date_gmt":"2018-04-07T16:04:17","guid":{"rendered":"http:\/\/www.carnaghan.com\/?post_type=epkb_post_type_1&p=6552"},"modified":"2018-04-07T11:04:17","modified_gmt":"2018-04-07T16:04:17","slug":"how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file","status":"publish","type":"epkb_post_type_1","link":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/","title":{"rendered":"How to create a backup of a PostgreSQL database to a SQL file"},"content":{"rendered":"

How to create a\u00a0backup<\/strong>\u00a0of a\u00a0PostgreSQL<\/strong>\u00a0database<\/strong>\u00a0to a\u00a0sql<\/strong>\u00a0file? This\u00a0sql<\/strong>\u00a0file then can be used to\u00a0restore<\/strong>\u00a0the\u00a0database<\/strong>\u00a0on a later stage.<\/p>\n

Follow the steps below in order to create a backup<\/p>\n

    \n
  1. Open a\u00a0Terminal Window<\/strong>\u00a0if not yet in\u00a0command line<\/strong><\/li>\n
  2. Login as user postgres.\u00a0eg.\u00a0sudo su postgres\u00a0<\/em><\/strong><\/li>\n
  3. Type in the following command
    \npg_dump db_name -CdiOv > \/tmp\/db_name_backup.sql<\/span><\/p>\n
      \n
    • pg_dump<\/strong>\u00a0= Utility to backup a PostgreSQL db.<\/li>\n
    • -C<\/strong>\u00a0= Begin the output with a command to create the database itself and reconnect to the created database.<\/li>\n
    • -d<\/strong>\u00a0= Dump the data as INSERT commands<\/li>\n
    • -i\u00a0<\/strong>= Ignores version mismatch between the old database server and the new database server.<\/li>\n
    • -O<\/strong>\u00a0= No owner, the database does not belong to any specific owner that was specified in the database<\/li>\n
    • -v\u00a0<\/strong>= Verbose, will output a detailed report of pg_dump if ran in command line.<\/li>\n
    • > \/tmp\/db_name_backup.sql<\/strong>\u00a0= dump the output of the command into a file called\u00a0db_name_backup.sql\u00a0<\/strong>(Here you may choose any location on your drive where you want the backup to be stored)<\/li>\n<\/ul>\n<\/li>\n
    • Now you have a\u00a0backup<\/strong>\u00a0of your\u00a0pqsl<\/strong>\u00a0database<\/strong>\u00a0in\u00a0sql<\/strong>\u00a0file format<\/li>\n<\/ol>\n


      \nNOTE<\/strong>: PostgreSQL 8.3.7 has been used and installed on Ubuntu 9.04 with this how-to<\/p>\n","protected":false},"excerpt":{"rendered":"

      How to create a\u00a0backup\u00a0of a\u00a0PostgreSQL\u00a0database\u00a0to a\u00a0sql\u00a0file? This\u00a0sql\u00a0file then can be used to\u00a0restore\u00a0the\u00a0database\u00a0on a later stage. Follow the steps below in order to create a backup Open a\u00a0Terminal Window\u00a0if not yet in\u00a0command line Login as user postgres.\u00a0eg.\u00a0sudo su postgres\u00a0 Type in the following command pg_dump db_name -CdiOv > \/tmp\/db_name_backup.sql pg_dump\u00a0= Utility to backup a PostgreSQL db. […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"epkb_post_type_1_category":[4427],"epkb_post_type_1_tag":[],"yoast_head":"\nHow to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan\" \/>\n<meta property=\"og:description\" content=\"How to create a\u00a0backup\u00a0of a\u00a0PostgreSQL\u00a0database\u00a0to a\u00a0sql\u00a0file? This\u00a0sql\u00a0file then can be used to\u00a0restore\u00a0the\u00a0database\u00a0on a later stage. Follow the steps below in order to create a backup Open a\u00a0Terminal Window\u00a0if not yet in\u00a0command line Login as user postgres.\u00a0eg.\u00a0sudo su postgres\u00a0 Type in the following command pg_dump db_name -CdiOv > \/tmp\/db_name_backup.sql pg_dump\u00a0= Utility to backup a PostgreSQL db. […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Ian Carnaghan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@icarnaghan\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/\",\"url\":\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/\",\"name\":\"How to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan\",\"isPartOf\":{\"@id\":\"https:\/\/www.carnaghan.com\/#website\"},\"datePublished\":\"2018-04-07T16:04:17+00:00\",\"dateModified\":\"2018-04-07T16:04:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.carnaghan.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create a backup of a PostgreSQL database to a SQL file\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.carnaghan.com\/#website\",\"url\":\"https:\/\/www.carnaghan.com\/\",\"name\":\"Ian Carnaghan\",\"description\":\"Software Developer, Blogger, Educator\",\"publisher\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.carnaghan.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\",\"name\":\"Ian Carnaghan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"caption\":\"Ian Carnaghan\"},\"logo\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\"},\"description\":\"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.\",\"sameAs\":[\"http:\/\/www.carnaghan.com\",\"https:\/\/x.com\/icarnaghan\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan","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:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/","og_locale":"en_US","og_type":"article","og_title":"How to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan","og_description":"How to create a\u00a0backup\u00a0of a\u00a0PostgreSQL\u00a0database\u00a0to a\u00a0sql\u00a0file? This\u00a0sql\u00a0file then can be used to\u00a0restore\u00a0the\u00a0database\u00a0on a later stage. Follow the steps below in order to create a backup Open a\u00a0Terminal Window\u00a0if not yet in\u00a0command line Login as user postgres.\u00a0eg.\u00a0sudo su postgres\u00a0 Type in the following command pg_dump db_name -CdiOv > \/tmp\/db_name_backup.sql pg_dump\u00a0= Utility to backup a PostgreSQL db. […]","og_url":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/","og_site_name":"Ian Carnaghan","twitter_card":"summary_large_image","twitter_site":"@icarnaghan","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/","url":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/","name":"How to create a backup of a PostgreSQL database to a SQL file - Ian Carnaghan","isPartOf":{"@id":"https:\/\/www.carnaghan.com\/#website"},"datePublished":"2018-04-07T16:04:17+00:00","dateModified":"2018-04-07T16:04:17+00:00","breadcrumb":{"@id":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.carnaghan.com\/knowledge-base\/how-to-create-a-backup-of-a-postgresql-database-to-a-sql-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.carnaghan.com\/"},{"@type":"ListItem","position":2,"name":"How to create a backup of a PostgreSQL database to a SQL file"}]},{"@type":"WebSite","@id":"https:\/\/www.carnaghan.com\/#website","url":"https:\/\/www.carnaghan.com\/","name":"Ian Carnaghan","description":"Software Developer, Blogger, Educator","publisher":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.carnaghan.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5","name":"Ian Carnaghan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","caption":"Ian Carnaghan"},"logo":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/"},"description":"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.","sameAs":["http:\/\/www.carnaghan.com","https:\/\/x.com\/icarnaghan"]}]}},"_links":{"self":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/epkb_post_type_1\/6552"}],"collection":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/epkb_post_type_1"}],"about":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/types\/epkb_post_type_1"}],"author":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/comments?post=6552"}],"version-history":[{"count":0,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/epkb_post_type_1\/6552\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/media?parent=6552"}],"wp:term":[{"taxonomy":"epkb_post_type_1_category","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/epkb_post_type_1_category?post=6552"},{"taxonomy":"epkb_post_type_1_tag","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/epkb_post_type_1_tag?post=6552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}