Make sure your Postgres server is listening on the correct port
In postgresql.conf (Probably located somewhere like /etc/postgresql/9.3/main/postgresql.conf
comment out
#listen_addresses = 'localhost'
and add a listen on all ports
listen_addresses = '*'
The Postgres config files will likely be owned by Postgres which can make them more difficult to find.
Log into your postgres database and run
SHOW config_file;
This should give you the location for you to then be able to edit the file
Have a look at this StackOverflow thread for further info on this
After editing the file ( you will probably need sudo privileges to do this i.e. sudo vim path_to/config_file
) you will need to restart postgres for the changes to take effect. How you restart will depend on how pg is set up but most likely it is runing as a service so tyhe following should do the trick.
sudo service postgres restart
If not then ask your host how to restart
Create an entry in your database.yml file for the remote server
e.g.
remote:
adapter: postgresql
database: remote_db_name
username: xxx
password: xxx
pool: 5
timeout: 5000
host: ip_address_for_remote_server
port: prob_3306_but_whatever_port_you_have_configured_on_remote_server
strict: false
Then create a specific set of models to deal with the remote database and establish a connection with the database.yml entry
e.g.
class SomeTableNameOnRemoteServer < ActiveRecord::Base
establish_connection :remote
#etc...
Don't be tempted to try to use models that already connect to your local database. If you want to share logic then create a module and just include the module in both model classes
Some further reading might help. This is a guide on how to setup and configure pg on a DigitalOcean droplet
https://www.digitalocean.com/community/tutorials/scaling-ruby-on-rails-setting-up-a-dedicated-postgresql-server-part-3
some way down the page there is a section on remote access but you may find the whole document useful so not pasting content in here.