It appears that your package manager failed to create the database named $user for you. The reason that
psql -d template1
works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:
createdb
and then see if you can log in again with
psql -h localhost
This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.
Answer from Kirk Roybal on Stack OverflowIt appears that your package manager failed to create the database named $user for you. The reason that
psql -d template1
works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:
createdb
and then see if you can log in again with
psql -h localhost
This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.
From the terminal, just Run the command on your command prompt window. (Not inside psql).
createdb <user>
And then try to run postgres again.
FATAL: database "postgres" does not exist
postgresql - psql: fatal database does not exist error - Database Administrators Stack Exchange
postgresql - ERROR: database "dbname" does not exist - Database Administrators Stack Exchange
FATAL: database "dave" does not exist
There are two different ways of creating a database in PostgreSQL. One is from the command line. The other is from the PostgreSQL console.
Command Line
In order to be able to create a database from the command line, you must first change to a user with rights to create a database. As you have shown with the \du command above, the user with those rights is postgres.
root@eric-desktop:/home/eric# su postgres
postgres@eric-desktop:/home/eric$ createdb prismatest2
postgres@eric-desktop:/home/eric$
As you can see, the creatdb command does not give any feedback. You need to confirm the creation by listing the current databases:
psql -U postgres -l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
prismatest | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
prismatest2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
PostgreSQL Console
Another possibility is to use the PostgreSQL console. To enter the console:
root@eric-desktop:/home/eric# sudo -u postgres psql psql (15.7 (Debian 15.7-0+deb12u1)) Type "help" for help.
postgres=#
postgres=# CREATE DATABASE "prismatest3";
CREATE DATABASE
postgres=#
To confirm the creation of the database, list the databases:
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
prismatest | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
prismatest2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
prismatest3 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
Notice how the prompt has changed from the first line to the second:
v
postgres=# createdb prismatest
postgres-# \l
^
psql is hinting that you are entering more lines of the same command.
Enter the semicolon (";") that terminates the create database statement.
postgres=# createdb prismatest ;
Hi guys, I've been googling around on how to solve the problem with resolving my issue into getting back into postgresql 11...
I dropped the postgres database in my software then it led to me not able to reconnect to the server.
I've tried doing some code on the command line with adding a database and entering password but not working or recovering the access with psql -u postgres.
None haven't worked. IDK where to go because I'ved seen like several sources and no luck. I wanna resume coding on postgresql.
Thanks...
In Database Navigator > Right click on PostgreSQL > Edit Connection
In Connection settings > general tab, enter your host (e.g. localhost), database (e.g. postgres) and leave User blank. Check Show all databases.
Right click on PostgreSQL and refresh. You should get a green checkmark in the PostgreSQL icon.
That's how I fixed mine, hopefully it'll work for you too.
Like Joseph, I had to leave the localhost but I had to clear all the fields, tick Show Databases:

Then refreshing on the databases I got prompted for the Username and Password (must have been an old version in cache):

This works, and you'll see there's potentially more than one schema:

Hello everyone, I had a python Django project I worked on a while back, I am trying to revisit this project but I am running into issues when I try to run the server locally. Not sure what is causing this issue.
in the second screenshot It shows that the database cannot be found! However the deployed version of the website seems to still work, I just added the third entry in the screenshot.
Note: I was using PostgreSQL13 with this project, How can I verify if the database is still there or was erased( deployed version is working!) ?
I have existing multiple *_development and *_test databases on postgres 12. Postgres by default creates a postgres user upon installation. I am always logged in as the current linux user on my system.
Why doesnt psql let me login into psql without specifying a specific database by throwing the error message psql: error: could not connect to server: FATAL: database "<current username>" does not exist?
Instead, the commands psql -d my_application_development and sudo -u postgres psql work even though the latter does not say which database
PS what is template0 and template1? was it a mistake in name