{"id":2426,"date":"2025-03-13T08:50:30","date_gmt":"2025-03-13T01:50:30","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=2426"},"modified":"2025-03-13T10:06:57","modified_gmt":"2025-03-13T03:06:57","slug":"pg_dumpall","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/","title":{"rendered":"pg_dumpall"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you&#8217;ll learn how to use the <code>pg_dumpall<\/code> tool to export the entire database cluster, including all databases, roles, and other global objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction-to-pg_dumpall-tool\" id='introduction-to-pg_dumpall-tool'>Introduction to pg_dumpall tool <a href=\"#introduction-to-pg_dumpall-tool\" class=\"anchor\" id=\"introduction-to-pg_dumpall-tool\" title=\"Anchor for Introduction to pg_dumpall tool\">#<\/a><\/h2>\n\n\n\n<p><code>pg_dumpall<\/code>&nbsp;is a command-line tool that allows you to export an entire PostgreSQL database cluster into a file.<\/p>\n\n\n\n<p>Unlike the&nbsp;<code>pg_dump<\/code>&nbsp;tool, which exports a single database without roles and other global objects, the&nbsp;<code>pg_dumpall<\/code>&nbsp;exports all databases with global objects, including database <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-role\/\">roles<\/a>, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-tablespaces\/\">tablespaces<\/a>, and privilege grants for configuration parameters. However,&nbsp;<code>pg_dumpall<\/code>&nbsp;only supports plain SQL format.<\/p>\n\n\n\n<p>To use the&nbsp;<code>pg_dumpall<\/code>&nbsp;tool, you follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, open your terminal.<\/li>\n\n\n\n<li>Second, execute the&nbsp;<code>pg_dumpall<\/code>&nbsp;command:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">pg_dumpall -h db_host -p db_port -U username<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>db_host<\/code>&nbsp;is the database host you want to connect to. It defaults to the local PostgreSQL server.<\/li>\n\n\n\n<li><code>db_port<\/code>&nbsp;is the port on which the PostgreSQL listens. It defaults to the port <code>5432<\/code>. Since&nbsp;<code>pg_dumpall<\/code>&nbsp;reads all databases, you must connect to the PostgreSQL server with a superuser.<\/li>\n<\/ul>\n\n\n\n<p>If you have multiple databases,&nbsp;<code>pg_dumpall<\/code>&nbsp;will prompt for a password each time it connects to each database if you use password authentication.<\/p>\n\n\n\n<p>Therefore, using a <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-password-file\/\">PostgreSQL password file<\/a> for using the\u00a0<code>pg_dumpall<\/code>\u00a0to automatically connect to a PostgreSQL server is much more convenient.<\/p>\n\n\n\n<p>After having a dump file, you can restore it using the&nbsp;<code>psql<\/code>&nbsp;tool.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pg_dumpall-examples\" id='pg_dumpall-examples'>pg_dumpall examples <a href=\"#pg_dumpall-examples\" class=\"anchor\" id=\"pg_dumpall-examples\" title=\"Anchor for pg_dumpall examples\">#<\/a><\/h2>\n\n\n\n<p>The following command exports all databases on the local PostgreSQL server to a file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">pg_dumpall -U postgres &gt; D:\\backup\\<span class=\"hljs-keyword\">all<\/span>.<span class=\"hljs-keyword\">sql<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can replace the path to the backup file with your actual one.<\/p>\n\n\n\n<p>To dump only global objects, you use the&nbsp;<code>-g<\/code>&nbsp;flag:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">pg_dumpall -g &gt; D:\\backup\\globals.<span class=\"hljs-keyword\">sql<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To restore the dump file to a PostgreSQL server, you use the&nbsp;<code>psql<\/code>&nbsp;tool:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">psql -U postgres -f <span class=\"hljs-keyword\">all<\/span>.<span class=\"hljs-keyword\">sql<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"why-use-pg_dumpall\" id='why-use-pg_dumpall'>Why Use pg_dumpall? <a href=\"#why-use-pg_dumpall\" class=\"anchor\" id=\"why-use-pg_dumpall\" title=\"Anchor for Why Use pg_dumpall?\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cluster-wide Backup<\/strong>:&nbsp;<code>pg_dumpall<\/code>&nbsp;can back up all databases in a PostgreSQL instance.<\/li>\n\n\n\n<li><strong>Backup Roles and Tablespaces<\/strong>: Besides databases,&nbsp;<code>pg_dumpall<\/code>&nbsp;backs up the user roles and tablespaces.<\/li>\n\n\n\n<li><strong>Simplifies Server Migration<\/strong>:&nbsp;<code>pg_dumpall<\/code>&nbsp;can help transfer entire PostgreSQL clusters between servers.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the&nbsp;<code>pg_dumpall<\/code>&nbsp;tool to export all databases, including user roles and tablespaces.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2426\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/\"\n\t\t\t\tdata-post-title=\"pg_dumpall\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2426\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/\"\n\t\t\t\tdata-post-title=\"pg_dumpall\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2269,"menu_order":19,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2426","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>pg_dumpall<\/title>\n<meta name=\"description\" content=\"You&#039;ll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.\" \/>\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.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pg_dumpall\" \/>\n<meta property=\"og:description\" content=\"You&#039;ll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-13T03:06:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/pg_dumpall\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/pg_dumpall\\\/\",\"name\":\"pg_dumpall\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2025-03-13T01:50:30+00:00\",\"dateModified\":\"2025-03-13T03:06:57+00:00\",\"description\":\"You'll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/pg_dumpall\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/pg_dumpall\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/pg_dumpall\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Database Administration\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"pg_dumpall\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"pg_dumpall","description":"You'll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.","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.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/","og_locale":"en_US","og_type":"article","og_title":"pg_dumpall","og_description":"You'll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-03-13T03:06:57+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/","url":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/","name":"pg_dumpall","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2025-03-13T01:50:30+00:00","dateModified":"2025-03-13T03:06:57+00:00","description":"You'll learn how to use the\u00a0pg_dumpall\u00a0tool to export the entire database cluster, including all databases, roles, and other global objects.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/pg_dumpall\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Database Administration","item":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/"},{"@type":"ListItem","position":3,"name":"pg_dumpall"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=2426"}],"version-history":[{"count":4,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2426\/revisions"}],"predecessor-version":[{"id":2439,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2426\/revisions\/2439"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2269"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=2426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}