{"id":14408,"date":"2020-09-01T13:02:45","date_gmt":"2020-09-01T11:02:45","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/"},"modified":"2020-09-01T13:02:45","modified_gmt":"2020-09-01T11:02:45","slug":"configure-postgresql-to-allow-remote-connection","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/","title":{"rendered":"Configure PostgreSQL to allow remote connection"},"content":{"rendered":"<p>By default, PostgreSQL will only allow localhost connection. If you want allow remote connections, you need to configure it.<\/p>\n<h2>Configuring postgresql.conf<\/h2>\n<p>First we need to find out where our conf file is located. You have two options:<br \/>\nIf you are new to Postgres, you would like to use the classic &#8216;find&#8217; command:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">find \/ -name \"postgresql.conf\"\n<\/pre>\n<p>And the Pro users would be use:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 0\">psql -c \"show config_file\" postgres config_file\n<\/pre>\n<p>After you find the location of the configuration file, you need to replace the value at &#8216;listen_addresses&#8217;\u00a0with &#8216;*&#8217; or your IP address. <strong>For security reasons do not use the &#8216;*&#8217;.<\/strong> By default it&#8217;s &#8216;localhost&#8217;.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">listen_addresses = '*'\n<\/pre>\n<p>Now the server will accept remote connections from the client IP address \/ subnet which you have configured. But you will not be able to connect, because we did not configure which users can connect remotely.<\/p>\n<h2>Configuring pg_hba.conf<\/h2>\n<p>To configure the users which we want to allow to connect remotely, you need to configure the pg_hba.conf file.<\/p>\n<p>First we need out where our pg_hba.conf file is located.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">find \/ -name \"pg_hba.conf\"\n<\/pre>\n<p>And then add following line to the end of the file<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"># TYPE  DATABASE    USER    ADDRESS       METHOD\nhost\u00a0 \u00a0 all\u00a0 \u00a0 \u00a0    all\u00a0 \u00a0 \u00a00.0.0.0\/0\u00a0 \u00a0 \u00a0md5\n<\/pre>\n<p><strong>For Security reasons you should never use 0.0.0.0\/0, limit to an IP address or to a Subnet. For example as below:<br \/>\n<\/strong><\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"># TYPE  DATABASE    USER    ADDRESS            METHOD\nhost\u00a0 \u00a0 all\u00a0 \u00a0 \u00a0    all\u00a0 \u00a0 \u00a0192.168.50.0\/24\u00a0 \u00a0 md5\n<\/pre>\n<p>Now restart the PostgreSQL server.<\/p>\n<p>PostgreSQL is now ready to accept remote connections.<\/p>\n<h2>Don&#8217;t forget to open Firewall ports<\/h2>\n<p>By default PostgreSQL is using Port 5432. To to open the port on Redhat\/CentOS\/SUSE:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">firewall-cmd --permanent --add-port=5432\/tcp\nfirewall-cmd --reload\n<\/pre>\n<p>Well done! We successfully configure remote connection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, PostgreSQL will only allow localhost connection. If you want allow remote connections, you need to configure it. Configuring postgresql.conf First we need to find out where our conf file is located. You have two options: If you are new to Postgres, you would like to use the classic &#8216;find&#8217; command: find \/ -name [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[],"type_dbi":[],"class_list":["post-14408","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Configure PostgreSQL to allow remote connection - dbi Blog<\/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.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configure PostgreSQL to allow remote connection\" \/>\n<meta property=\"og:description\" content=\"By default, PostgreSQL will only allow localhost connection. If you want allow remote connections, you need to configure it. Configuring postgresql.conf First we need to find out where our conf file is located. You have two options: If you are new to Postgres, you would like to use the classic &#8216;find&#8217; command: find \/ -name [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-01T11:02:45+00:00\" \/>\n<meta name=\"author\" content=\"Open source Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Open source Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\"},\"author\":{\"name\":\"Open source Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"headline\":\"Configure PostgreSQL to allow remote connection\",\"datePublished\":\"2020-09-01T11:02:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\"},\"wordCount\":246,\"commentCount\":0,\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\",\"name\":\"Configure PostgreSQL to allow remote connection - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2020-09-01T11:02:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Configure PostgreSQL to allow remote connection\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\",\"name\":\"Open source Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"caption\":\"Open source Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Configure PostgreSQL to allow remote connection - dbi Blog","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.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/","og_locale":"en_US","og_type":"article","og_title":"Configure PostgreSQL to allow remote connection","og_description":"By default, PostgreSQL will only allow localhost connection. If you want allow remote connections, you need to configure it. Configuring postgresql.conf First we need to find out where our conf file is located. You have two options: If you are new to Postgres, you would like to use the classic &#8216;find&#8217; command: find \/ -name [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/","og_site_name":"dbi Blog","article_published_time":"2020-09-01T11:02:45+00:00","author":"Open source Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Open source Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/"},"author":{"name":"Open source Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"headline":"Configure PostgreSQL to allow remote connection","datePublished":"2020-09-01T11:02:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/"},"wordCount":246,"commentCount":0,"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/","url":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/","name":"Configure PostgreSQL to allow remote connection - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2020-09-01T11:02:45+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/configure-postgresql-to-allow-remote-connection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Configure PostgreSQL to allow remote connection"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b","name":"Open source Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","caption":"Open source Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/14408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=14408"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/14408\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=14408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=14408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=14408"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=14408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}