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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8265ad2
Add PostreSQL configuration example
dacostafilipe 23ffa0d
Updated documentation
dacostafilipe 01192c9
Renamed folder to match service name
dacostafilipe a656440
Update main README file with link to postgres documentation
dacostafilipe 400ab4e
Multiple typos fixed
dacostafilipe 6f5bcc6
Merge branch 'master' into feature-pgsql
dacostafilipe f7575a2
Reverted changes to commands because of issues with usage in hooks
dacostafilipe 15d9701
Minor improvements to docs and custom commands
rfay File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
## PostgreSQL | ||
|
||
Using PostgreSQL container with [PostGIS](https://postgis.net/) support provided by [mdillon/postgis](https://hub.docker.com/r/mdillon/postgis). | ||
|
||
### Installation | ||
|
||
1. Copy `docker-compose.postgres.yaml` to your project | ||
2. Copy the full `commands/postgres` directory to your project's `.ddev/commands` directory. For example `cp -r commands/postgres /.ddev/commands` | ||
3. *(optional)* Update your config.yaml file to support auto-import/auto-export (see below) | ||
|
||
### Connection | ||
|
||
Connect to `postgres` host/db server from within the web container with: | ||
|
||
``` | ||
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 `.ddev/import-db/postgresql.db.sql` | ||
- `ddev pgsql_import` : Use `pgsql` to import `.ddev/import-db/postgresql.db.sql` into `db` - Note that this must be executed with an empty database. | ||
|
||
Example `config.yaml` hooks configuration to automatically import/export the `db` table: | ||
|
||
``` | ||
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`; | ||
``` | ||
|
||
### TODO | ||
|
||
Future enhancements (PR's welcome here) include: | ||
|
||
* Non-volatile postgres database (store it on a docker volume like ddev's normal mariadb container does) | ||
* Provide interactive custom commands to interact with the `postgres` utility in the container interactively. | ||
* Consider changing suggested import/export hooks into "exec" hooks with "service: postgres" instead of running `ddev pg*` on the host. |
7 changes: 7 additions & 0 deletions
7
docker-compose-services/postgres/commands/postgres/pgsql_export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
## Description: Dump the postgresql database to .ddev/import-db/postgresql.db.sql | ||
## Usage: pgsql_export | ||
## Example: ddev pgsql_export | ||
|
||
mkdir -p /mnt/ddev_config/import-db && su postgres -c "pg_dump db --username=db --host=localhost --port=5432 --column-inserts > /mnt/ddev_config/import-db/postgresql.db.sql" |
8 changes: 8 additions & 0 deletions
8
docker-compose-services/postgres/commands/postgres/pgsql_import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
## Description: Load to an empty postgresql database from .ddev/import-db/postgresql.db.sql | ||
## Usage: pgsql_import | ||
## Example: ddev pgsql_import | ||
|
||
# Import via user postgres to avoid credentials prompt | ||
su postgres -c "psql -U db db < /mnt/ddev_config/import-db/postgresql.db.sql" |
19 changes: 19 additions & 0 deletions
19
docker-compose-services/postgres/docker-compose.postgres.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 | ||
web: | ||
links: | ||
- postgres:postgres |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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)