Skip to content

Instantly share code, notes, and snippets.

@psychicbologna
Last active October 14, 2019 18:05
Show Gist options
  • Save psychicbologna/f840247bb0614f129a33f27d5f84bc5a to your computer and use it in GitHub Desktop.
Save psychicbologna/f840247bb0614f129a33f27d5f84bc5a to your computer and use it in GitHub Desktop.

WSL INSTALLATION

This is how I got my WSL environment running for testing.

WSL Installation

Postgresql Installation

Link

  • In the Ubuntu terminal, go to the root by typing cd.

  • Type sudo nano ../../etc/apt/sources.list.d/pgdg.list to open the file in Nano if you're into that, or VSCode it with sudo code ../../etc/apt/sources.list.d/pgdg.list, and enter deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main Your Ubuntu version will be a name like bionic or xenial.

  • Copy paste this script:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
  • Run apt-get install postgresql postgresql-contrib and select 'yes' when prompted to continue. Taken note of the path of the directory it is installed in.

Follow Up

  • Change the password for the postgres user by running su passwd postgres and specifying a password.

  • Change up your environment to have some aliases for convenient running. Using sudo nano ~/.profile or sudo code ~/.profile (be careful not to change anything else in this file), copy/paste or write out the following (for version 11) in here and make sure to change it later when you change versions:

# Postgres aliases
export PGSQLCLUSTER='sudo -i -u postgres pg_ctlcluster 11 main'

alias pgstart='$PGSQLCLUSTER start'
alias pgstop='$PGSQLCLUSTER stop'

#This bypasses password login for postgres user to login to database
alias runpg='sudo -i -u postgres psql'

Note

  • VSCode suggests a WSL extension that makes it the primary bash and allows you to use the 'code' command to open files. I'll probably end up switching it off to access my Windows bash for the scripts and settings I have there when not developing server-side stuff.

  • You may have the change the port in etc/postgresql/11/main/postgresql.conf to whatever node is attempting to connect to. If you ever need to make changes to this file, reload postgres (pgstop/pgstart)

Issues

  • You're gonna end up needing to set up your ssh keys if you want to run git easily here, which means you'll be doing github updates and Zeit from windows still. I saw a tutorial online for transferring the ssh keys from Windows, maybe that would work?

  • Maybe a pgpass file will help expedite things when interacting with psql commands? Maybe these links could help? https://www.postgresql.org/docs/current/libpq-pgpass.html https://linuxandryan.wordpress.com/2013/03/07/creating-and-using-a-pgpass-file/

  • I couldn't make the 'status' pg_ctlcluster function print out from an alias, and you aren't getting too much feedback from the stop function either. There must be some way to path to /usr/lib/postgresql/11/bin to get pg_ctl and the usual stuff to function correctly but I can't figure it out atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment