Requirements¶
How to install PostgreSQL¶
Linux¶
If you are on Arch Linux
you can use the following command:
to install it, but if you are on other Linux
distributions just change the Package Manager.
Note
If you have never used PostgreSQL on Linux
I suggest you follow this guide.
macOS¶
If you are on macOS
you can use Homebrew
to install PostgreSQL with the following command:
or you can use MacPorts
with the following command:
Configure PostgreSQL¶
Linux¶
After the installation of PostgreSQL you need to use the following commands:
sudo -u postgres initdb -D /var/lib/postgres/data
sudo mkdir -p /var/lib/postgres/data
sudo chown postgres:postgres /var/lib/postgres/data
to initialize the database and create the necessary directories. Then you can use the following command to start the PostgreSQL service:
and to enable it at startup use the following command:
How to create a database¶
Once you have downloaded PostgreSQL you need to create the todolist
database. Open a terminal and write:
this command allows you to change your computer user by selecting the postgres
user. Now use the following command to create a database called todolist
:
Now run the command:
you will get something like this:
then write:
you should get a message similar to this:
Now if you open the src/table.sql
file you will find this code inside:
compact this code as follows:
and write it immediately after todolist=#
and you should get this message:
Now use the following SQL
code to see the description
and id
columns that are part of the tasks
table:
and in particular you should get something similar to this:
Now that you have successfully created the todolist
database and created a tasks
table to place the information in, you can exit psql
using the \q
command and then you can switch back to the main user using the exit
command.