docbrown/docs/installation/postgresql.md
Jacob Herrington 7d0aeeefe5 Improve the clarity of the docs and fix Prettier config (#4899)
* Improve format and clarity of the docs [ci skip]

While this change produces a lot of git noise by enacting what seems
like an arbitrary linewrap on most of the files in the documentation it
will result in better version control and tracking of the changes in the
documentation.

For example, as it currently stands, if one was to make a
PR to move a comma in a sentence because each paragraph in most of the
files is on a single line, that small change would look in the git
history like the author had modified the entire paragraph. In reality,
this author just moved a comma.

This change also includes a significant number of modifications to the
more article-esque docs. Many of these docs were written in a sort of
stream-of-conciousness and aren't as easy to read as they could be.
Hopefully this is the first of several readability changes. If we could
get these docs to a more accessible reading level, we would probably see
an increase in contributions. :)

* Delegate markdown wrapping to Prettier

* Add linewrapping explanation in the docs [ci skip]
2019-11-26 08:40:53 -05:00

64 lines
2.3 KiB
Markdown

---
title: PostgreSQL
---
# Setup your application with PostgreSQL
Follow the instructions in the installation guide below that corresponds to your
operating system:
1. macOS
- [Postgres.app](https://postgresapp.com/): PostgreSQL installation as a Mac
app
- [Homebrew](https://brew.sh/): if you use Homebrew you can easily install
PostgreSQL with `brew install postgresql`
1. Linux (Ubuntu)
- [Ubuntu
`14.04`](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04)
- [Ubuntu `16.04 and higher`](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04)
1. [Windows](https://www.postgresql.org/download/windows/)
_You can find all installation options for a variety of operating systems [on
the official PostgreSQL download page](https://www.postgresql.org/download/)_.
## Configuration
By default, the application is configured to connect to a local database named
`PracticalDeveloper_development`. If you need to specify a username and a
password, you can go about it by using the environment variable `DATABASE_URL`
with a connection string.
The [official Rails
guides](https://guides.rubyonrails.org/configuring.html#connection-preference)
go into depth on how Rails merges the existing `database.yml` with the
connection string.
### Setup `DATABASE_URL` in application.yml
1. Open your `config/application.yml`
1. Add the following:
```yml
DATABASE_URL: postgresql://USERNAME:PASSWORD@localhost
```
1. Replace `USERNAME` with your database username, `PASSWORD` with your database
password.
You can find more details on connection strings in [PostgreSQL's own
documentation](https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNSTRING).
NOTE: due to how Rails merges `database.yml` and `DATABASE_URL` it's recommended
not to add the database name in the connection string. This will default to your
development database name also during tests, which will effectively empty the
development DB each time tests are run.
## Troubleshooting tests
- While running test cases, if you get an error message `postgresql connection timeout`, please re-run the tests by increasing the statement timeout, for
example:
```shell
STATEMENT_TIMEOUT=10000 bundle exec rspec
```