Change postgres default behavior for connection to database when dbname not supplied According to postgres documentation: 

https://www.postgresql.org/docs/10/libpq-connect.html


  dbname
  The database name. Defaults to be the same as the user name. In certain contexts, the value is checked for extended formats; see Section 33.1.1 for more details on those.


for instance, issuing the following command:

psql -U username -h 0.0.0.0 -c "SELECT * from some.table"


will automatically issue the command on a database named 'username' if that database exists.

Is there a way to change the default behavior to require an explicit database name rather than the default behavior?
According to the same Postgres documentation

The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb, PQsetdbLogin and PQsetdb if no value is directly specified by the calling code[...]

PGDATABASE behaves the same as the dbname connection parameter.


If you want psql to fail if the database name is not explicitly given on the command line, set the variable PGDATABASE to point to a non-existent database, e.g. export PGDATABASE=&quot; &quot; or export PGDATABASE=&quot;&quot;.
As to your question:

whether or not the default behavior can be modified to not connect to a database named after the user if no database name is supplied either through an environment variable, or the psql command line utility.

we can find a definitive answer in the libpq source code:
/*
 * If database name was not given, default it to equal user name
 */
if (conn-&gt;dbName == NULL || conn-&gt;dbName[0] == '\0')
{
    if (conn-&gt;dbName)
        free(conn-&gt;dbName);
    conn-&gt;dbName = strdup(conn-&gt;pguser);
    if (!conn-&gt;dbName)
        goto oom_error;
}

The only way to modify the default behaviour is to edit the code fragment shown above and recompile the library.