New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PostgreSQL configuration example #7
Changes from 4 commits
8265ad2
23ffa0d
01192c9
a656440
400ab4e
6f5bcc6
f7575a2
15d9701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
|
||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## PostgreSQL | ||
|
||
Using PostgreSQL container with PostGIS support provided by [mdillon/postgis | ||
](https://hub.docker.com/r/mdillon/postgis). | ||
|
||
### Installation | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A note: People will often want to use the 'php' project type, so that ddev doesn't naively try to mess with their database configuration (AdditionalConfiguration.php or settings.ddev.php, etc) |
||
1. Copy `docker-compose.postgres.yaml` to your project | ||
2. Copy `command/postgres` to your project | ||
dacostafilipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
3. *(optional)* Update your config.yaml file to support auto-import/auto-export (see bellow) | ||
dacostafilipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Connection | ||
|
||
Connect to `postgres` with | ||
dacostafilipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
Host: postgres | ||
User: db | ||
Password: db | ||
Database: db | ||
``` | ||
|
||
For external access, use the port used in your `docker-compose.postgres.yaml` and `127.0.0.1` as host. | ||
|
||
When using multiple project with PostgreSQL support, remember to update your `docker-compose.postgres.yaml` to use different ports: | ||
|
||
``` | ||
ports: | ||
- <EXTERNAL_PORT>:5432 | ||
``` | ||
|
||
### Import / Export | ||
|
||
Two new `ddev` commands are provided: | ||
|
||
- `ddev pgsql_export` : Use `pg_dump` to export `db` to `import-db/postgresql.db.sql` | ||
- `ddev pgsql_import` : Use `pgsql` to import `import-db/postgresql.db.sql` into `db` | ||
|
||
To import/export the `db` table automatically add the following hooks to your `config.yaml`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't a docker volume suit most people better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember why we did it that way, will look into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, seems like it was just an example of |
||
|
||
``` | ||
hooks: | ||
pre-stop: | ||
- exec-host: ddev pgsql_export | ||
post-start: | ||
- exec-host: ddev pgsql_import | ||
``` | ||
|
||
### PostGIS | ||
|
||
The `postgres` image support `postgis`, but you will need to create the extension before using it: | ||
|
||
``` | ||
CREATE EXTENSION IF NOT EXISTS `postgis`; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
su postgres -c "pg_dump db --username=db --host=localhost --port=5432 --column-inserts > /mnt/ddev_config/import-db/postgresql.db.sql" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
su postgres -c "psql -U db db < /mnt/ddev_config/import-db/postgresql.db.sql" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: '3.6' | ||
services: | ||
postgres: | ||
container_name: ddev-${DDEV_SITENAME}-postgres | ||
image: mdillon/postgis:11 | ||
ports: | ||
- 32784:5432 | ||
environment: | ||
- POSTGRES_PASSWORD=db | ||
- POSTGRES_USER=db | ||
- POSTGRES_DB=db | ||
volumes: | ||
- ".:/mnt/ddev_config" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a docker volume for the Postgres data so it's not volatile? |
||
labels: | ||
com.ddev.site-name: ${DDEV_SITENAME} | ||
com.ddev.approot: $DDEV_APPROOT | ||
com.ddev.app-url: $DDEV_URL | ||
dacostafilipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
web: | ||
links: | ||
- postgres:postgres | ||
dacostafilipe marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Why?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most of our project, we need some kind of spatial search (locations around you, locations in polygon, distance between locations, ... ) and it's really easy and fast with PostGIS. Until activated, there's zero performance penalty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was saying to say "why" in the README or docker-compose file. So people can understand why you made the choice (and maybe understand whether they should also be using this, or maybe the library version)