FATAL: database "[DB]" does not exist on remote connection
<p>I'm running a postgresql database on our server. I know the error is common if you do not specify a database and haven't created on with the same name as your user. If I ssh into the server I can successfully access the database (<code>DB</code>).</p>

<p>However, if I try to connect remotely, I get <code>FATAL: database "[DB]" does not exist</code>, but it does exists, since I can access it on the server. It does not matter which username I choose, I always get the message.</p>

<p><em>Command to connect:</em></p>

<pre><code>psql --host="192.168.1.XXX" --port="5433" --dbname="[DB]" -U postgres
</code></pre>

<p><em>Contents of <code>pg_hba.conf</code>:</em></p>

<pre><code># Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             192.168.1.1/16          trust

# IPv6 local connections:
host    all             all             ::1/128                 md5
</code></pre>

<p><em>Contents of <code>postgresql.conf</code> (excerpt):</em></p>

<pre><code>listen_addresses = '*'
port = 5433
max_connections = 100

ssl = true
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
</code></pre>

<p><em>The output from <code>\l</code> (abbreviated):</em></p>

<pre><code>  Name   |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
---------+----------+----------+-------------+-------------+-----------------------
  DB     | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |  postgres=CTc/postgres
</code></pre>

<p><em>The output from <code>\du</code>:</em></p>

<pre><code>                               List of roles
 Role name   |                   Attributes                   | Member of 
 ------------+------------------------------------------------+-----------
  admin      | Create role, Create DB                         | {}
  &lt;username&gt; | Create role, Create DB                         | {admin}
  postgres   | Superuser, Create role, Create DB, Replication | {}
</code></pre>

<p><code>&lt;username&gt;</code> is the user name on my computer and server.</p>