PostgreSQL database in SourceLair

SourceLair’s PostgreSQL capabilities

SourceLair PostgreSQL database is a fully functional PostgreSQL server. You can connect to it from your SourceLair project like you would with any other server of yours. The only difference is that it shares networking only with your project’s processes, making it visible to your web server and terminal, but invisible to everyone else.

Database information:

Version: 9.5Host: postgresUser: postgresPassword: mysecretpassword

Accessing your database server

To connect to your PostgreSQL server from your SourceLair Terminal, type in the following command

psql -h postgres -U postgres

and then enter your password (the default password is: mysecretpassword).

Avoiding entering password every time

If you want to avoid going through the password prompt step every time, there are a few alternatives.

Pass the password as an environment variable

To store your password in the PGPASSWORD environment variable and then connect to your PostgreSQL server, run the following command in your terminal:

PGPASSWORD=mysecretpassword psql -h postgres -U postgres

💡 Tip: Add PGPASSWORD=mysecretpassword in your .env file and connect to your server by just running

Use a PostgreSQL password file

Then, all you have to do to connect to your PostgreSQL server is run the following command in your terminal:

psql -h postgres -U postgres

After connecting to your server from the Terminal, you can change the default password by running the following command in your terminal:

ALTER USER postgres WITH PASSWORD 'mypass';

where 'mypass' is your desired new password.

⚠️ Attention: If you are using a .pgpass file and change your password, remember to update it in the .pgpass file as well.

Accessing your database

SourceLair creates a database named “sourcelair” by default and makes sure it exposes the URL for
accessing your database in the
DATABASE_URL=postres://postgres:mysecretpassword@postgres:5432/sourcelair environment variable.
This allows you to use libraries like
Django Database URL or
parse-database-url to connect to the correct
database in each environment - ie SourceLair and Heroku. If you’d like to change the default
settings, like change your password or rename the database, you can always change your project’s
environment using a .env file.