Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql creating database

Tags:

postgresql

Well I installed the latest postgreql database on my Windows 7.

Now I'm trying to create a database via the psql.exe command line

When I open it, it says

psql: FATAL: database "Jansu" does not exist

So I read somewhere, that when no database is specified, it tried to find database with my username or something.

Anyways..how do i create a new database, when I can't access the commandline.

like image 403
Jaanus Avatar asked Apr 20 '11 19:04

Jaanus


People also ask

Which command creates a database in PostgreSQL?

createdb creates a new PostgreSQL database. Normally, the database user who executes this command becomes the owner of the new database. However, a different owner can be specified via the -O option, if the executing user has appropriate privileges. createdb is a wrapper around the SQL command CREATE DATABASE .

How do I create a database in PostgreSQL pgAdmin 4?

Run pgAdmin. Right-click on the item Servers , select Create -> Server and provide the connection to your PostgreSQL instance set up in step 1. In the default PostgreSQL setup, the administrator user is postgres with an empty password. In the connection tab be sure to have the host set to localhost .

Which are the methods PostgreSQL provides to create a new database?

PostgreSQL provides two methods for creating a new database: the CREATE DATABASE SQL command, and the createdb command-line executable.


1 Answers

Read psql syntax. You can specify database, user and other parameters. If it's a new installation, there should be a default database 'postgres', you can connect to that one.

 psql -U postgres postgres 

(In Unix environments you might need to add -h localhost in order to force a TCP connection, otherwise it'd try to use Unix-domain sockets, which might not work for other than the postgres user. )

You can create databases from there, or from the command line with createdb

like image 71
leonbloy Avatar answered Sep 23 '22 18:09

leonbloy