Postgresql is unable to connect to the database server without specifying an existing database.
The reason you get this error:
SQLSTATE[08006] [7] FATAL: database "admin" does not exist
is that if you do not specify a database name, by default it will try to connect to the database with the same name as the user you specified (see the description of the dbname connection parameter).
When postgresql is first initialized, three default databases are created:
- postgres - designed for a general-purpose database for the
postgres admin user to access - template0 - Main template - should not be changed after initialization
- template1 - default template - used to create all new databases from
For more information about them, see Template Databases .
If you want to get a list of available databases, you will need to connect to one of the above databases.
I would usually use template1 for this, because theoretically the postgres database could be deleted, and it would be dangerous to connect to the template0 database if you accidentally change it. Since template1 used as the default template when creating databases, it is likely to exist.
Also note that any user with whom you connect must have permission to connect to this database. All three of these databases are owned by the postgres user, which means that if you do not connect using this user, you need to make sure that the user you are using has permission to access the database.
harmic
source share