Loading the Sample Datasets – Linux
Most exercises in this book use a sample database, sqlda
, which contains fabricated data for a fictional electric vehicle company called ZoomZoom. Set it up by performing the following steps:
- Switch to the
postgres
user by typing the following command in the terminal. Press the return key to execute it:sudo su postgres
You should see your shell change as follows:
- Type or paste the following command to create a new database called
sqlda
. Press the return key to execute it:createdb sqlda
You can then type the psql
command to enter the PostgreSQL shell, followed by \l
(a backslash followed by lowercase L) to check if the database was successfully created:
Enter \q
and then press the return key to quit the PostgreSQL shell.
- Download the
data.dump
file from theDatasets
folder in the GitHub repository of this book by running this command:wget "https://github.com/PacktPublishing/SQL-for-Data-Analytics-Third-Edition/tree/main/Datasets/data.dump"
- Navigate to the folder where you have downloaded the file using the
cd
command. Then, type the following command:psql -d sqlda < data.dump
- Then, wait for the dataset to be imported:
- To test whether the dataset was imported correctly, type
ppsql postgres
and then press the return key to enter the PostgreSQL shell. Then, run\c sqlda
followed by\dt
to see the list of tables within the database:
Note
You are importing the database using the postgres
superuser for demonstration purposes only. It is advised in production environments to use a separate account.