Installing Postgres
Installation, Creating a User And Creating a Database
Setting Up The Postgresql Database
Install Postgres
If you are using ubuntu 16.04 this is very easy to set up. First thing is to update your system:
sudo apt-get update
Now use apt-get to install Postgres:
sudo apt-get install postgresql postgresql-contrib
Check that Postgres is installed by opening another terminal and switch to the default Postgres user:
sudo -i -u postgres
Then log into Postgres:
psql
You can also access Postgres without switching accounts using this command:
sudo -u postgres psql
While in the Postgres terminal, create a password for the Postgres user:
\password postgres
Create a new user
While logged in as the Postgres’ default user you can create new users and adjust their roles.
postgres@satalite2:~$createuser --interactive
Or if you did not switch accounts:
sudo -u postgres createuser --interactive
Database GUI
I found DBeaver is the easiest to install on Ubuntu here is the link:
Once DBeaver installs select Postgres. Then connect to your database using the password you created.
Host is localhost and database and User are set to postgres
Create a database
Log into Postgres from the terminal:
sudo -u postgres psql
Once logged in create a database:
create database djDemo owner postgres;
You can check your new database with the \l command from the Postgres terminal. You can exit the Postgres terminal with \q or ctrl + d.
To see the new database in DBeaver reconnect with the same credentials but change the database name.
Here are some system commands ran with sudo for the Postgres server on Ubuntu:
- stop service:
systemctl stop postgresql
- start service:
systemctl start postgresql
- show status of service:
systemctl status postgresql
- disable service(not auto-start any more):
systemctl disable postgresql
- enable service postgresql(auto-start):
systemctl enable postgresql