<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>The Standard Output (postgresql)</title><link>http://thestandardoutput.com/</link><description></description><atom:link href="http://thestandardoutput.com/tag/postgresql.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 12 Oct 2015 07:59:00 GMT</lastBuildDate><generator>https://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Manage your PostgreSQL Database from a Remote Machine</title><link>http://thestandardoutput.com/posts/manage-your-postgresql-database-from-a-remote-machine/</link><dc:creator>Jonas Gorauskas</dc:creator><description>&lt;div&gt;&lt;p&gt;At home I have my main development workstation and then I spin up VMs that mimic
my production environment to run different types of integration tests. One of
these VMs is running a relatively recent version of PostgreSQL. By default,
PostgreSQL is setup to allow connections coming from the local host only. In
this article I will walk through the steps of setting up PostgreSQL so that it
allows connections from other machines also.&lt;/p&gt;
&lt;h3&gt;Setup Remote Connections&lt;/h3&gt;
&lt;p&gt;There are, essentially, two lines in two different PostgreSQL configuration
files that need to be changed to allow remote connections to work.  The first
file is &lt;code&gt;postgresql.conf&lt;/code&gt; and this is usually found at
&lt;code&gt;/etc/postgresql/9.1/main/&lt;/code&gt; on Debian-based systems. Open that file and find the
line that starts with &lt;code&gt;listen_addresses&lt;/code&gt;. By default the value assigned to it
should be &lt;code&gt;'localhost'&lt;/code&gt;. Change that so the line reads like this:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;listen_addresses = '*'
&lt;/pre&gt;


&lt;p&gt;The second file is called &lt;code&gt;pg_hba.conf&lt;/code&gt;. In this file you need to look for a
IPv4 local connections line that starts with &lt;code&gt;host&lt;/code&gt;. By default, the line reads
the following:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;host    all             all             127.0.0.1/32            md5
&lt;/pre&gt;


&lt;p&gt;You need to change this line to read like this:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;host    all             all             10.0.0.0/24             trust
&lt;/pre&gt;


&lt;p&gt;For all intents and purposes, the default is telling PostgreSQL to accept
connections only from the localhost (that's what the &lt;code&gt;/32&lt;/code&gt; is for), while we are
changing the value to allow any host with an IP starting with 10.0.0.* to
connect. The above will only work after you restart PostgreSQL with the
following command:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;sudo /etc/init.d/postgresql restart
&lt;/pre&gt;


&lt;p&gt;Again, YMMV if you are using anything other than Debian.&lt;/p&gt;
&lt;h3&gt;Allowing Connections Through a Firewall&lt;/h3&gt;
&lt;p&gt;The above is really all you have to do with PostgreSQL proper to allow remote
connections. But if you are like me, you are probably running a firewall on your
systems also and you will need to punch a whole for PostgreSQL to talk through.
You can find out more about how I setup my IPTables firewall by
&lt;a href="http://gorauskas.org/SecuringYourDebianBasedVM.html" title="Securing your Debian-based VM"&gt;reading this&lt;/a&gt;. In my case, I need to allow only one system (my
workstation) to connect to the VM hosting PostgreSQL. I created the following
lines in my IPTables configuration file:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;# Allow connections to Postgres DB Server from hurricane
-A INPUT -p tcp -s 10.0.0.90 --sport 1024:65535 -d 10.0.0.60 --dport 5432 \
         -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -s 10.0.0.60 --sport 5432 -d 10.0.0.90 --dport 1024:65535 \
         -m state --state ESTABLISHED -j ACCEPT
&lt;/pre&gt;


&lt;p&gt;In the above, the first line allows traffic on port 5432 into the local system
from the &lt;code&gt;10.0.0.90&lt;/code&gt; IP address, which is my development workstation. The second
line allows the local system to send traffic out via port 5432, which is the
default port used by PostgreSQL.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;To allow remote connections to your PostgreSQL instance, all you have to do is
edit &lt;code&gt;postgresql.conf&lt;/code&gt; and &lt;code&gt;pg_hba.conf&lt;/code&gt;. Also remember to address firewall
configuration issues that may arise.&lt;/p&gt;&lt;/div&gt;</description><category>database</category><category>debian</category><category>linux</category><category>postgresql</category><guid>http://thestandardoutput.com/posts/manage-your-postgresql-database-from-a-remote-machine/</guid><pubDate>Fri, 29 Nov 2013 05:56:11 GMT</pubDate></item></channel></rss>