I ran and new node application that used a Postgres SQL server. It created a default database called postgres
and I wanted to remove it.
I used the below command and close the connection and was able to remove that database.
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'postgres';
Now the pgAdmin looks like the below image.
I am not sure how to add a database again here. It always gives me errors while adding a new server that Database "postgres" does not exist.
Any ideas or search query to google about this issue?
2
Answers
You are connecting as user "postgres" and the default database name it will try is also "postgres". You should be able to specify a different database in the pgadmib settings though. Try "template0" and connect to that to create a new db.
I am tempted to say that if you are randomly deleting system databases without first researching if they are needed, you deserve what you get. But while it is customary to leave the
postgres
database as default database for tools to connect to, it is certainly not forbidden to drop it.The solution in your case is probably to reconfigure your pgAdmin connection to use
template1
instead ofpostgres
as "maintenance database". The only problem with that (and the main reason why thepostgres
database was introduced) is that it will prevent you from creating new databases withtemplate1
as the (default) template if others are connected to that database as well.