Connecting to a remote PostgreSQL database
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
\q to quit or use a different terminal window.