# Anyone thought of connecting Hasura to Discourse's Postgres database for a potentially more customised (or narrowed down) FE?

**URL:** <https://meta.discourse.org/t/anyone-thought-of-connecting-hasura-to-discourses-postgres-database-for-a-potentially-more-customised-or-narrowed-down-fe/149576>\
**Category:** Development\
**Created:** [April 28, 2020, 9:58am UTC](https://meta.discourse.org/t/anyone-thought-of-connecting-hasura-to-discourses-postgres-database-for-a-potentially-more-customised-or-narrowed-down-fe/149576 "2020-04-28T09:58:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dnk8n](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dnk8n](https://meta.discourse.org/u/dnk8n)\
**Post date:** [May 19, 2020, 8:15am UTC](https://meta.discourse.org/t/anyone-thought-of-connecting-hasura-to-discourses-postgres-database-for-a-potentially-more-customised-or-narrowed-down-fe/149576/4 "2020-05-19T08:15:21Z")

</div>

For your information, to get a running psql shell of a running Discourse’s Postgres database server you can do `docker exec --user postgres -it app psql -d discourse`, so to get a full dump you can do (note, I am dropping -t option here as it is not needed in this case):

`docker exec --user postgres -i app pg_dump -Fc -d discourse > discourse.sql.pgcustom`

Should now be able to restore that to a dockerized postgres (`docker pull postgres:10.12`) and connect it to Hasura for development (only really useful at read-only level because it is a seperate database now).

To do this on production level, I would set the environment discourse provides and host your database in something like Amazon RDS. You then have easy access to read and write to that database.

To restore the dump above locally:

1. Create a docker network:

```plaintext
docker network create discourse-dev-net

```

1. In first shell:

```plaintext
docker run --rm -it -p 2345:5432 -e POSTGRES_DB=discourse -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres --name=discourse-dev-pg --network=discourse-dev-net postgres:10.12

```

(If you want it running in background, I think you can just replace -it for -d; `-p 2345:5432` is optional but convenient if you want to connect to postgres from your host)

1. In another shell, create discourse user in postgres (needed for dump):

```plaintext
docker run --rm -it -v /path/to/discourse.sql.pgcustom:/discourse.sql.pgcustom:ro -e PGPASSWORD=postgres --network=discourse-dev-net postgres:10.12 createuser -h discourse-dev-pg -U postgres -P discourse

```

(you then type password in prompt twice, I used `discourse` as password)

1. Perform the restore:

```plaintext
docker run --rm -i -v /home/dean/Downloads/discourse.sql.pgcustom:/discourse.sql.pgcustom:ro -e PGPASSWORD=postgres --network=discourse-dev-net postgres:10.12 pg_restore -h discourse-dev-pg -U postgres -d discourse /discourse.sql.pgcustom

```

1. To connect Hasura to the above:

```plaintext
docker run --rm -it --network=discourse-dev-net -p 1234:1234 -e HASURA_GRAPHQL_ENABLE_CONSOLE=true -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@discourse-dev-pg:5432/discourse hasura/graphql-engine:v1.2.1 graphql-engine serve --server-port=1234

```

(You can now visit [http://localhost:1234](http://localhost:1234))

---

_[View the full topic](https://meta.discourse.org/t/anyone-thought-of-connecting-hasura-to-discourses-postgres-database-for-a-potentially-more-customised-or-narrowed-down-fe/149576)._
