How do I connect to PostgreSQL without specifying a database name? How do I connect to PostgreSQL without specifying a database name? postgresql postgresql

How do I connect to PostgreSQL without specifying a database name?


You have to connect to a database. Which database you could use for a "maintenance database" depends on the installation and the subsequent administration. After a default installation there are 2 databases that could be used for the initial connection - "template1" and "postgres". It's wise to create a new user and a database with the same name and use those.


Why don't you connect to your Maintenance DB (usually postgres?). I don't know if that'll work. But I believe you'll have to query this database anyway to retrieve the databases available to a given user.


As the manual of pg_connect says the dbname parameter in the connection string defaults to the value of the user parameter. That's why it uses 'testuser'. If you want dbname to be empty, try "... dbname='' ...".