Assume that your user name are:
- root on WSL
- jackj on Windows
1 Install WSL
Please refer to Windows 10 Installation Guide
2 Install postgresql
sudo apk-get install postgresql # install postgresql
3 Add user
To use postgresql, we should add your user name to postgresql
sudo service postgresql start # start postgresql service, note you cannot use pg_clt -start
sudo su postgres # login as user "postgres" which is automatically created by postgresql
psql postgres # open database "postgres" which is the default database created by postgresql
Now we should see postgres=#
create user root; # add your user name to postgresql
alter user root with superuser; # alter your user's role to superuser
\q # quit
Close WSL window and restart.
4 Transfer file
In order to transfer files from Windows to WSL, we need to create a symbolic link.
ln -s "/mnt/c/Users/jackj/Documents/WSL" /root/WSL
After that, My Documents/WSL on Windows to /root/WSL on WSL are linked together.
5 Use postgresql
You may put your file schema.sql on My Documents/WSL
sudo service postgresql start # start server
cd ~/WSL # enter your working directory
createdb a2 # create database
psql a2 # open database
\i shema.sql # insert schema.sql and do anything you like just as same as what we did in lab
6 Link DataGrip
Download JetBrains DataGrip
File - Data Sources - add(left top corner) postgresql
Create password in your database:
psql a2
\password
\q
Fill the blanks in DataGrip:
- Host: localhost
- Port: 5432
- Database: a2 # your database
- User: root
- Password: <your password>
Press Test Connection when finish.