-
Book Overview & Buying
-
Table Of Contents
SQL for Data Analytics - Third Edition
By :
Before exploring the book in detail, you need to set up specific software and tools. In the following section, you shall see how to do that.
The following sections list the instructions for installing and setting up PostgreSQL 14 on Windows, Linux, and macOS.
First, download and install PostgreSQL on Windows:
Windows from the list of Packages and Installers.
Figure 0.1: PostgreSQL Downloads page
Download the installer.
Figure 0.2: PostgreSQL interactive installer download
14.2 as this is the version that is used in this book.
Figure 0.3: PostgreSQL downloads page
Next for most of the installation steps. You will be asked to specify a data directory. It is recommended that you specify a path that you will easily remember in the future.
Figure 0.4: PostgreSQL installation – Windows
postgres superuser.
Figure 0.5: Setting the superuser password
Figure 0.6: PostgreSQL port settings
Next to proceed through the rest of the steps and wait for the installation to finish.To validate whether the PATH variable has been set correctly, open the command line, type or paste the following command, and press the return key:
psql -U postgres
If you get the following error, you need to add the PostgreSQL binaries directory to the PATH variable:
Figure 0.7: Error – Path variable not set
The following steps will help you do that:
environment variables in Windows Search:
Figure 0.8: Windows Search for environment variables
Environment Variables:
Figure 0.9: Windows System Properties
Path and then click Edit:
Figure 0.10: Setting the PATH variable
New:
Figure 0.11: Setting the PATH variable
bin folder of the PostgreSQL installation:
Figure 0.12: Entering the path
OK and restart the system.psql -U postgres
Figure 0.13: PostgreSQL shell
\q and press the return key to exit the shell:
Figure 0.14: Exiting the PostgreSQL shell
The following steps will help you install PostgreSQL on Ubuntu or a Debian-based Linux system.
Figure 0.15: Commands on the Terminal
postgres. You will need to log in as that user to access the PostgreSQL shell:sudo su postgres
You should see your shell prompt change as follows:
Figure 0.16: Accessing the PostgreSQL shell on Linux
psql
You can type \l (a backslash and a lowercase L) to see a list of all the databases that are loaded by default:
Figure 0.17: List of databases on Linux
Note
You have covered how to install PostgreSQL on Ubuntu and Debian-based systems here. For instructions to install it on other distributions, please refer to your distribution's documentation. The PostgreSQL download page for Linux can be found at https://www.postgresql.org/download/linux/.
This section will help you install PostgreSQL on macOS. Before you start installing the software, make sure you have the Homebrew package manager installed on your system. If you do not, head over to https://brew.sh/ and paste the script provided on the webpage in a macOS Terminal (the Terminal app) and press the return key.
Follow the prompts that appear and wait for the script to finish the installation.
Note
The following instructions are written based on macOS Catalina version 10.15.6, which was the latest version at the time of writing. For more help on using Terminal, refer to the following link: https://support.apple.com/en-in/guide/terminal/apd5265185d-f365-44cb-8b09-71a064a42125/mac.
Figure 0.18: Installing Homebrew
Once Homebrew is installed, follow these steps to install PostgreSQL:
brew doctor brew update brew install postgres
Wait for the installation to complete. Depending on your local setup and connection speed, you will see messages like those shown below (note that only the partial installation log is shown here):
Figure 0.19: Installation progress (partially shown) for PostgreSQL
pg_ctl -D /usr/local/var/postgres start
You should see an output similar to the following:
Figure 0.20: Starting the PostgreSQL process
postgres as follows (press the return key to execute the command):psql postgres
\l (a backslash and a lowercase L) followed by the return key to see a list of all the databases that are loaded by default:
Figure 0.21: List of databases loaded by default
\q and then press the return key to quit the PostgreSQL shell.Note
pgAdmin will get installed automatically along with PostgreSQL 14.
System Properties window of your OS.To install Python on Linux, you have a couple of good options:
python3 --version.sudo apt-get update sudo apt-get install python3.9
Similar to Linux, you have a couple of methods for installing Python on a Mac. To install Python on macOS, do the following:
terminal in the open search box, and hit Enter.xcode-select—install.Homebrew, which is installed through the command line by running ruby -e "$(curl -fsSL https://raw. githubusercontent.com/Homebrew/install/master/install)".$PATH environment variable. Open your profile in the command line by running sudo nano ~/.profile and inserting export PATH="/usr/local/opt/python/libexec/bin:$PATH" at the bottom.brew install python.Change the font size
Change margin width
Change background colour