How could I connect to the postgresql in vagrant

(Berniegao) #1

I have my discourse up and running through the guideline Discourse as Your First Rails App. which put the postgre in the VM connected through ssh. How could I connect to the database?

(Mittineague) #2

If you do

vagrant up
vagrant ssh
rm -rf tmp
bundle install
bundle exec rake db:migrate
bundle exec rails c

do you get a “pry” prompt?

If you are not familiar with ActiveRecord the query syntax may take a little getting used to. eg.
instead of
SELECT * FROM topic_links ORDER BY clicks DESC LIMIT 1
TopicLink.order("clicks DESC").limit(1)

(Jens Maier) #3

If you want to connect to the database directly with a program running on the vagrant host, run vagrant ssh -- -L 15432:localhost:5432 and simply leave the session running in the background. You can now connect to the VM’s PostgreSQL database through an SSH tunnel at host’s localhost:15432.

(Pavel Chuchuva) #4

I get this error:

vagrant ssh -- -L 15432:localhost:5432
An invalid option was specified. The help for this command is available below.

Usage: vagrant ssh [options] [name] [-- extra ssh args]


    -c, --command COMMAND            Execute an SSH command directly
    -p, --plain                      Plain mode, leaves authentication up to user
    -h, --help                       Print this help

Do you know why?

(Jens Maier) #5

I can only guess that it’s because Vagrant doesn’t stick to its own documentation or uses an ssh client binary behind the scenes that doesn’t understand the -L option.

Looks like this might be an issue for the vagrant community support?

(Eric Vantillard) #7

is working has expected on mac os x

(Pavel Chuchuva) #8

Perhaps it’s a problem with Vagrant on Windows. I worked around this by connecting directly to my VM using its IP address on port 5432.