Τρίτη 8 Ιουνίου 2010

PostgreSQL

It is very unclear to me why noone has a clear method on how to create and manage a PostgreSQL database in an ubuntu (and other linux) system.

First open synaptic to install
postgresql

This does nothing but installs the service and the clients

in order to actually use the database you must be fluent with some things:
1. the client (psql) tries to connect to the default database with the default user name which means that:
if your user name in ubuntu is John then the default database is John and the default user name is John

Maybe (maybe, maybe....) you have been added to users of PostgreSQL.
if you try to use the client program by issuing:
psql
at the command prompt and you get a:
psql: FATAL: database "John" does not exist
This means there is no database so you cannot connect with the client to PostgreSQL
There is no such thing that "I connect to PostgreSQL with the client"
There is only
with the client: "I connect to a specific database in a specific server"
There are other programs that create databases inside the PostgreSQL (the most used is: createdb)

So from the begining:
1. Install from "synaptic" (or by other program that has a gui for installation programs like "Ubuntu Software Center") the postgresql (which will install service and the client programs as well the needed "sub"programs. This will install the latest version that your ubuntu supports.)
2. open a terminal
Since the only user who can connect to a fresh install is the postgres user, here is how to create yourself a database account (which is in this case also a database superuser) with the same name as your login name

2a. type:
whoami
(this will show your user name. You must see your user name because maybe from previous typings you changed the user)

2b. sudo -u postgres createuser --superuser $USER
this will create a user with your "user name" with superuser priviledges (the command line inperpreter will change the $USER with the your user name.
type:
createdb YOURUSERNAMEHERE
(this will create a database with your username as the name of the database and it will belong to you. In the above typing you must type your user name and NOT the "YOURUSERNAMEHERE" )
If no errors occur then proceed to next step
3. type:
psql
And ooops you are in a client enviroment that you can issue SQL comments!!!
To exit type control + D (the key Ctrl plus the key D simultaneously)

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου