Installing the PostgreSQL database

PostgreSQL is an open-source database that can be installed on multiple platforms. On Ubuntu, it can be installed using the following commands:

To add the repo to the package list:


sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

To update the package list:


sudo apt-get update apt-get install postgresql postgresql-contrib

This installs the database on an Ubuntu machine and starts a server on port 5432. Now, in order to enter the database shell, use these commands. PostgreSQL creates a default user called postgres to log in. Take a look at the following command:

sudo su - postgres

Now the user has access to the database. Launch the PostgreSQL shell using the psql command:

psql

This shows that PostgreSQL follows a different approach for entering into the shell compared to other similar databases such as MySQL or SQLite3. On Windows, the installation is done by clicking the binary installer file. It is a GUI-based installation where the port and password for superuser should be supplied. Once the database is installed, we can check that using the pgAdmin3 tool. The macOS X setup is similar to Ubuntu, except the installation is done through Homebrew. Take a look at the following command:

brew install postgresql

And then make the database server run even when the system is rebooted by using the following command:

pg_ctl -D /usr/local/var/postgres start && brew services start postgresql

Now, the PostgreSQL server starts running and is available to store and retrieve data on macOS X.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.151.220