Access Your Database
There are three different solutions to access Scalingo’s databases:
- Remote console: an interactive console is started and you access it directly.
- Encrypted tunnel: if you want a full access to the database, you have to build an SSH-encrypted tunnel, then you will be able to access the database as if it was running locally. You have to use this solution if you want to import/export data.
- Direct encrypted access to the database.
Interactive Remote Console
The following commands let you open a console for the database of your choice. Note that your should have added the appropriate addon from your application dashboard prior to run one of these commands.
# Open a console using the `mysql` client
scalingo --app my-app mysql-console
# Open a console using the `psql` client
scalingo --app my-app pgsql-console
# Open a console using the `mongo` client
scalingo --app my-app mongo-console
# Open a console using the `redis-cli` client
scalingo --app my-app redis-console
# Open a console using the `InfluxDB shell` client
scalingo --app my-app influxdb-console
Manually install the databases CLI in one-off
If you started a Bash process in a one-off container, you can download various CLI tools for all databases available at Scalingo:
Database | Keyword | Installed Tools |
---|---|---|
PostgreSQL |
pgsql , postgresql , psql
|
psql , pg_basebackup , pg_controldata , pg_dump , pg_isready , pg_recvlogical , pg_restore , pg_test_fsync , pg_upgrade , pg_archivecleanup , pg_config , pg_ctl , pg_dumpall , pg_receivewal , pg_resetwal , pg_rewind , pg_test_timing , pg_waldump
|
MySQL | mysql |
mysql , mysqldump
|
MongoDB | mongo |
mongo , mongodump , mongorestore , mongoexport , mongoimport
|
Redis | redis |
redis-cli |
InfluxDB |
influxdb , influx
|
influx |
You can use our utility tool dbclient-fetcher
to download and install the
tools for your database. To do so, call dbclient-fetcher
with the keyword
corresponding to your database (see table above).
For example, to download the tools to interact with your MySQL addon:
[10:48] Scalingo ~ $ dbclient-fetcher mysql
---> Download and extract the database CLI
---> Database CLI installed:
mysql Ver 8.0.33 for Linux on x86_64 (Source distribution)
If you ever need a specific version, just add it as a second parameter:
[10:48] Scalingo ~ $ dbclient-fetcher mysql 8.0
---> Download and extract the database CLI
---> Database CLI installed:
mysql Ver 8.0.33 for Linux on x86_64 (Source distribution)
Connect to the Database
By default, databases hosted on Scalingo are not directly available on the Internet.
To access your database remotely from your workstation you need to setup an encrypted connection: either via an encrypted tunnel or by forcing TLS connection to your database and enabling direct Internet access.
Encrypted Tunnel
Since we don’t want unencrypted network traffic from/to your databases, the DB tunnel provides an encrypted way to access them. However, it does not provide any additional security layer. We will only verify that your public key is registered on our platform. The DB tunnel is an encrypted bridge between your laptop and our infrastructure.
Another possibility is to make your database accessible from internet.
Build the Tunnel
By running the following command, an encrypted SSH tunnel will be built between you and your database.
$ scalingo --app my-app db-tunnel MONGO_URL
Building tunnel to <dbhost>:<dbport>
You can access your database on '127.0.0.1:<localport>'
Use any client to read, import or export your data
Once the tunnel has been built, you can use any tool you need by connecting it to the
127.0.0.1:<localport>
host.
Example
$ scalingo --app my-app db-tunnel MONGO_URL
Building tunnel to <dbhost>:<dbport>
You can access your database on '127.0.0.1:10000'
# In another terminal
$ scalingo --app my-app env | grep MONGO_URL
MONGO_URL=mongo://user:secret@<dbhost>:<dbport>/database?options
$ mongo "mongo://user:secret@<dbhost>:<dbport>/database?options"
$ mongodump -u user -p secret -h localhost:10000 -d database
If you are connecting to the database using SSL/TLS, you should add both options --ssl
and
--sslAllowInvalidCertificates
to the mongo
command.
Build the tunnel with the OpenSSH client
Our command line tool handles it in a single command, but you might want to use the tunnel without it. With the standard OpenSSH client, the way to build the tunnel is:
ssh -L <local port>:<database host>:<database port> git@<SSH hostname> -p <SSH port> -N
The SSH hostname and port depend on the region of your application:
- osc-fr1:
ssh.osc-fr1.scalingo.com
- osc-secnum-fr1:
ssh.osc-secnum-fr1.scalingo.com
The database host and database port can be found in the environment variable
representing the connection string of your database instance. Get it from the
dashboard or with the env
command of the CLI. It should look like:
SCALINGO_<TYPE>_URL
The value of this variable is an URL which represents:
scheme://user:password@host:port/database_name
As stated previously, you need to get the host
and port
from the URL.
Example:
If the app is in the region osc-fr1
and if the environment variable is the following:
SCALINGO_POSTGRESQL_URL=postgresql://user:secret@my-db.postgresql.a.osc-fr1.scalingo-dbs.com:30000/my-db
The command to run is:
ssh -L 10000:my-db.postgresql.a.osc-fr1.scalingo-dbs.com:30000 git@ssh.osc-fr1.scalingo.com -N
Then you connect on localhost:10000
to reach your Scalingo database. (You’ll still need to authenticate to the
database with the credential you can get from the connection string)
Access the Same Database From Multiple Applications
If you need to share a database addon between multiple applications, you can do it by adding an environment variable in every application wanting to communicate with the database.
In the application containing the database, you should have an environment variable containing the connection string needed to connect to the database. For a PostgreSQL addon, it should look like SCALINGO_POSTGRESQL_URL
. It contains your database address, as well as its credentials. Keep this value secret!
Copy this value, and in the application that needs to access it, create a new environment variable, and set it to the value you just copied. After a restart, your app will have the connection address it needs.
Internet Accessibility
It is possible to make your database reachable from anywhere on the Internet. Head to your database dashboard. From there you first need to force TLS connections to your database. You can then toggle “Internet Accessibility” to make it reachable from the Internet.