title: How do I connect to PostgreSQL without specifying a database name?
body: <p>I need to connect to some PostgreSQL server providing some credentials, and print a list of available databases on that host for a given user.</p>
  
  <p>I am trying:</p>
  
  <pre><code>&lt;?php
      $connection = pg_connect("host=localhost user=testuser password=123 connect_timeout=5");
  ?&gt;
  </code></pre>
  
  <p>And I get:</p>
  
  <pre><code>Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: database "testuser" does not exist in /var/www/test.php on line 56
  </code></pre>
  
  <p>I thought this must be possible because phpPgAdmin does it, but I looked at phpPpAdmin sources and found that they connect to a database named <code>template1</code>.</p>
  
  <p>From <a href="http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html" rel="noreferrer">http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html</a>:</p>
  
  <blockquote>
    <p>CREATE DATABASE actually works by copying an existing database. By
    default, it copies the standard system database named template1. Thus
    that database is the "template" from which new databases are made. If
    you add objects to template1, these objects will be copied into
    subsequently created user databases. This behavior allows site-local
    modifications to the standard set of objects in databases. For
    example, if you install the procedural language PL/pgSQL in template1,
    it will automatically be available in user databases without any extra
    action being taken when those databases are made.</p>
  </blockquote>
  
  <p>Is there a way to connect without specifying any database?</p>