Skip to content

Instantly share code, notes, and snippets.

@justingarrick
Created April 22, 2014 14:05
Show Gist options
  • Save justingarrick/11180527 to your computer and use it in GitHub Desktop.
Save justingarrick/11180527 to your computer and use it in GitHub Desktop.
Use PostgreSQL on OS X VM Host via Parallels Windows VM
This assumes Postgres is installed via Postgres.app
1) Setup a PGDATA environment variable in ~/.zshrc, e.g.
### PostgreSQL data
export PGDATA="/Users/justingarrick/Library/Application Support/Postgres/var-9.3"
2) In $PGDATA/postgresql.conf, add
listen_addresses = '*'
3) In $PGDATA/pg_hba.conf, add
# Allow access from Windows VM
host all all 0.0.0.0/0 md5
4) In Parallels, go to Preferences > Advanced > Click the Change Settings... button next to Network > Shared > Show in System Preferences
5) In OS X, find the Parallels Shared connection under System Preferences > Network, copy the IP Address, e.g. 10.211.55.2
6) In the Windows VM, edit the hosts file, e.g. C:\Windows\System32\drivers\etc\hosts, add an entry for this IP, e.g.
10.211.55.2 vmhost
7) In the Windows VM, add inbound and outbound firewall rules to allow TCP port 5432
8) Restart the Windows VM
9) In OS X, restart Postgres, e.g.
$pg_ctl restart
10) Add a connection to vmhost:5432 in PGAdmin on the Windows VM
@khun84
Copy link

khun84 commented Dec 12, 2018

for step 3, it didn't work for me. Eventually I need to put the VM ip instead. To get the VM IP, fire ipconfig in command prompt/powershell and you shall see it. Then add the ip to pg_hba.conf.

hostnossl   all   all   vm-ip/32   trust # use md5 if there's a password. use host if you need ssl connection, but i wasn't able to get it work, probably due to CA cert..couldn't bother to figure out why

Step 4, 5 and 6 are not absolutely necessary. However, we do need to get the host ip. To get your host IP, do ifconfig in OS X terminal and look for something as below:

vnic0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=3<RXCSUM,TXCSUM>
	ether 00:1c:42:00:00:08
	inet <host-ip> netmask 0xffffff00 broadcast 10.211.55.255
	media: autoselect
	status: active

The rest of the steps do work. I was able to connect to OS X postgres from windows PgAdmin and Powerbi database connector.

A side note, make sure npgsql was installed (with GAC feature) if you are connecting to postgresql via dot net application.

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