1

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.

enter image description here

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 2

2

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 of postgres as "maintenance database". The only problem with that (and the main reason why the postgres database was introduced) is that it will prevent you from creating new databases with template1 as the (default) template if others are connected to that database as well.

Sign up to request clarification or add additional context in comments.

3 Comments

Ah, I couldn't remember if your own connection would prevent you using it as a template too.
@RichardHuxton No, your own connection is no problem.
Thank you very much for your answer and for your time. Tbh it was easier to uninstall the server to fix the issue. I have tried so many things and was fed up. Was glad, I did this in the begging.
0

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.

1 Comment

You cannot connect to template0, and it is illegal to change that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.