Skip to content
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 8 commits into from Aug 23, 2019

Conversation

dacostafilipe
Copy link
Contributor

Example of the configuration we use internally for using PostgreSQL with ddev

Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So awesome. I made a few comments, worth minor updates. Most important is you'll probably want a docker volume.

For Drupal 8, the technique would be:

  • Edit settings.php and add to the bottom (below settings.ddev.php inclusion):
$databases['default']['default'] = array(
  'database' => "db",
  'username' => "db",
  'password' => "db",
  'host' => 'postgres',
  'driver' => 'pgsql',
);

## PostgreSQL

Using PostgreSQL container with PostGIS support provided by [mdillon/postgis
](https://hub.docker.com/r/mdillon/postgis).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Why?)

Copy link
Contributor Author

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.

Copy link
Member

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)

docker-compose-services/postgres/README.md Outdated Show resolved Hide resolved
- POSTGRES_USER=db
- POSTGRES_DB=db
volumes:
- ".:/mnt/ddev_config"
Copy link
Member

Choose a reason for hiding this comment

The 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?

](https://hub.docker.com/r/mdillon/postgis).

### Installation

Copy link
Member

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)

docker-compose-services/postgres/README.md Outdated Show resolved Hide resolved
- `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`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a docker volume suit most people better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, seems like it was just an example of calculated laziness. We needed the import/export commands and they "just worked" for us when restarting projects.

docker-compose-services/postgres/README.md Outdated Show resolved Hide resolved
@rfay
Copy link
Member

rfay commented Aug 19, 2019

$ ddev pgsql_export
WARNING: The DDEV_URL variable is not set. Defaulting to a blank string.
bash: /mnt/ddev_config/import-db/postgresql.db.sql: No such file or directory
Failed to run pgsql_export : exit status 1

I don't think the import-db directory is ever there in ddev any more, it's from long-ago versions of ddev?

Wouldn't it be better to export to stdout though? Let people do with that what they will?

DDEV_URL is obsolete, I'll comment there.

@dacostafilipe
Copy link
Contributor Author

I don't think the import-db directory is ever there in ddev any more, it's from long-ago versions of ddev?

1.9 I think.

Wouldn't it be better to export to stdout though? Let people do with that what they will?

That's how the script worked at the beginning. But I had issues with the import part where I did not find an easy way to pass stdin into su -c. I will rewrite the import to create a temp file with the stdin instead.

Rewrite of pgsql_* commands to use stdin/stdout instead of hardcoded file
@dacostafilipe
Copy link
Contributor Author

The changes to the commands do not seems to work correctly. Executing them manually works, but running them in the hooks does not. Could be stdin/stdout issue as it worked before the change.

@dacostafilipe
Copy link
Contributor Author

I reverted the commands for now.

@rfay
Copy link
Member

rfay commented Aug 22, 2019

@dacostafilipe I pushed some minor changes to the readme and the commands in 15d9701 - if this is OK with you and you're ready for this to be pulled I'll pull it.

@dacostafilipe
Copy link
Contributor Author

I'm okay with the changes. Added those to my projects.

@rfay rfay merged commit aeacfb3 into ddev:master Aug 23, 2019
@dacostafilipe dacostafilipe deleted the feature-pgsql branch August 23, 2019 13:15
@rfay
Copy link
Member

rfay commented Aug 29, 2019

ddev/ddev#1819 will add the ability to omit the db container, and it will be good to add that here, it should make things less confusing for people.

@steffenr
Copy link

steffenr commented Nov 9, 2020

We are using pgsql for one of our clients in a ddev setup. Usually we "fire" some post-import-db Commands after DB Import. But those commands are not fired after importing the pgsql.

Is this still possible?

@dacostafilipe
Copy link
Contributor Author

dacostafilipe commented Nov 9, 2020

@steffenr

Yes, it works on our postgresql project.

Our hooks look like this:

hooks:
  pre-start:
    - exec-host: bash .ddev/run-os-export.sh
  pre-stop:
    - exec-host: ddev pgsql_export
  post-start:
    - exec-host: ddev pgsql_import
    - exec: ./console.php queue:worker --queueType=realtime

@steffenr
Copy link

steffenr commented Nov 9, 2020

@dacostafilipe
You are using the global hooks - we had the post-db-import hook for firing our commands. Those commands are triggered every ddev start/ stop
In our case we only want to reset password/ activate stage_file_proxy after importing the db.

@rfay
Copy link
Member

rfay commented Nov 9, 2020

Since importing doesn't use ddev import-db you can't use the post-import-db hooks. But you can use a post-start hook that runs a script that's smart enough to check to see if stage_file_proxy is already activated, for example, and if not, activate it. Or use a flag in the database or on disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants