Friday, August 11, 2017

PostgreSQL on Ubuntu

Installing PostgreSQL on Ubuntu
To install both client and server with the newest version of Postgresql (the newest one on Ubuntu's repository), we can do it by apt-get

apt-get install postgresql

Setting up PostgreSQL
Installing via apt-get, everything (all configurations) has been set up, and Ubuntu's user 'postgres' will be created. We can access the database as this postgres user. Some tutorial talks about initdb command to create database cluster (database location on file system) but I can't find this command. However, database cluster has been created already after the installation.
There is a database has been created after install, the name is postgres. We can access this database to give the password of our postgres user.

sudo -u postgres psql postgres
\password


Start using database
We can create database with createdb command.

sudo -u postgres createdb mydb

To access it, use psql command. psql -h localhost mydb postgres

References
https://help.ubuntu.com/community/PostgreSQL

No comments: