Reputation: 309
I'm trying to create db on PostgreSQL on linux machine. And I use following command to create the DB.
createdb mydbname;
This is throwing following error.
createdb: could not connect to database postgres: FATAL: database "postgres" does not exist
I'm new to PostgreSQL. Can you please guide me to go through this error? Simply I want to create a DB on psql.
Upvotes: 2
Views: 1429
Reputation: 324375
It looks like you dropped the postgres
database. It's the default used for many admin operations, so you might want to re-create it:
createdb --maintenance-db=template1 -T template0 postgres;
What that's doing is connecting to the built-in DB template1
in order to create the db postgres
by making a copy of template0
.
Once that's done, your command:
createdb mydbname;
will work as normal.
Upvotes: 5
Reputation: 17837
su - postgres change user to postgres
createdb
createdb somedatabase
psql somedatabase
The first line changes to the postgres system user. The second line creates a database for the postgres admin user. The third line creates the database you were trying to make. The fourth line connects to it as the postgres user.
Upvotes: 0
Reputation: 1261
su - postgres
change user to postgres
psql
- run psql terminal
postgres# create database somedatabase
create database;
postgres#\c somedatabase
connecto to database
somedatabase#
your are connected to that database as postgres user
Upvotes: 1