Crane Cloud
Published in

Crane Cloud

Connecting to a remote PostgreSQL database

Photo by Jan Antonin Kolar on Unsplash

The process is pretty much the same as that of a MySQL database, with a few minor changes. For that reason I recommend you read the MySQL guide for explanations, as I will only be providing commands in this guide.

One more thing, I will assume you’re comfortable with postgres and the psql client — of course you are! But just in case you need to brush up on anything here’s a link.


psql -h <Host> -p <Port> -d <Name> -U <User> -W

Yup, that’s it!

Name is a placeholder for the database name and User for the database user. The -W flag will prompt for the password on pressing Enter. Paste the password from your Crane Cloud dashboard and you should see such a prompt — you’ve successfully logged into your remote database!

Migrating data from an existing database.

First export/dump the data.

pg_dump -h <Host> -p <Port> -d <Name> -U <User> -W > <filename.sql>

If the database is local: pg_dump <dbname> > <outfile>.

Then import the data into your new database.

psql -h <Host> -p <Port> -d <Name> -U <User> -W < <filename.sql>

For a local database: psql <dbname> < <infile>.

Run these commands at the terminal, not at the psql prompt. If you’re at the psql prompt, \q to quit or use a different terminal window.

That’s it!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store