First, make sure your system is up to date:
sudo apt update
sudo apt upgrade
Install PostgreSQL and its contrib package:
sudo apt install postgresql postgresql-contrib
Start the PostgreSQL service:
sudo service postgresql start
Switch to the postgres account:
sudo -i -u postgres
You can now access the PostgreSQL prompt by typing:
psql
While in the PostgreSQL prompt:
CREATE USER yourusername WITH PASSWORD 'yourpassword';
CREATE DATABASE yourdatabase;
GRANT ALL PRIVILEGES ON DATABASE yourdatabase TO yourusername;
Replace 'yourusername', 'yourpassword', and 'yourdatabase' with your preferred values.
Exit the PostgreSQL prompt:
\q
Exit the postgres user account:
exit
Edit the PostgreSQL configuration file:
sudo nano /etc/postgresql/[version]/main/postgresql.conf
Make sure to replace [version] your actual PostgreSQL version eg: 12.
You can find this by running psql --version.
Find the line that says listen_addresses
and change it to:
listen_addresses = '*'
Find the line that says password_encryption
and change it to:
password_encryption = md5
Edit the client authentication configuration file:
sudo nano /etc/postgresql/[version]/main/pg_hba.conf
Add this line at the end of the file:
host all all 0.0.0.0/0 md5
Restart the PostgreSQL service to apply changes:
sudo service postgresql restart
Install psycopg2, the PostgreSQL adapter for Python:
pip install psycopg2-binary
Make sure to start the PostgreSQL service every time you start your WSL instance:
sudo service postgresql start
- Login database to Create tables in the database
psql -U postgres -h localhost -d postgres
- Run the query found in alpha_calls_table.sql to create the table.